使用 Sun SPOT 作为构建监视器
2009-12-22 00:00:00 来源:WEB开发网updateBuildStatus() 方法处理 MIDlet 的主要工作,如清单 5 所示:
清单 5. 侦听 CanaryHandler 发送的消息的方法/**
* Reflect the status of the continuous build process taking place on the
* host PC by setting the colours of the SPOT's LEDs appropriately.
*/
private void updateBuildStatus() throws IOException {
setColour(LEDColor.WHITE, "");
String baseStationAddress = getAppProperty("BaseStationAddress");
String portNumber = getAppProperty("PortNumber");
String connectionString = "radiostream://" + baseStationAddress + ':' +
portNumber;
// Open a connection to the base station.
connection = (RadiostreamConnection) Connector.open(connectionString);
dis = connection.openDataInputStream();
dos = connection.openDataOutputStream();
while (true) {
// dis will block here forever until it has something from the host
// to read.
String buildStatus = dis.readUTF();
if (buildStatus.equals("RUN")) {
setColour(LEDColor.BLUE, buildStatus);
} else if (buildStatus.equals("SUCCESS")) {
setColour(LEDColor.GREEN, buildStatus);
} else if (buildStatus.equals("FAIL")) {
setColour(LEDColor.RED, buildStatus);
} else {
throw new IllegalArgumentException("The build status of " +
buildStatus + " isn't recognised.");
}
dos.writeUTF("Build status updated to " + buildStatus);
dos.flush();
}
}
更多精彩
赞助商链接