使用 Sun SPOT 作为构建监视器
2009-12-22 00:00:00 来源:WEB开发网从 清单 2 中可以看到,CanaryHandler 接受 4 个参数:
构建的当前状态,可能的值有:
Running(SPOT 的 LED 中显示蓝色流光)。
Failed(SPOT 的 LED 闪烁红色)。
Successful(SPOT 的 LED 显示为不动的绿条)。
一个远程 SPOT 的地址。每个 SPOT 由一个 64 位的 IEEE 无线地址标识,该地址以 0014.4F01 开头,后面再加上两个四位字节,从而惟一地标识 SPOT。
一个端口号,惟一地标识基站与远程 SPOT 之间的连接。
一个串行端口,标识构建服务器上与基站连接的串行端口。
解析命令行参数后,CanaryHandler 打开与远程 SPOT 的 radiostream 连接,如清单 3 所示:
清单 3. CanaryHandler 中的 main() 方法/**
* Respond to the state a continuous build process by setting the LEDs on a
* remote SPOT accordingly. This is done by writing a simple message to an
* output stream, on the end of which is a SPOT waiting to read.
*
* @param args the command line arguments. See the printUsage
* method further down for a full description of the parameters.
*/
public static void main(String[] args) throws IOException {
createCommandLineParser();
StreamConnection connection = null;
DataOutputStream dos = null;
DataInputStream dis = null;
try {
CommandLine commandLine = parser.parse(options, args);
String spotAddress = commandLine.getOptionValue("spot");
String port = commandLine.getOptionValue("port");
String spotConnection = "radiostream://" + spotAddress + ':' + port;
System.setProperty("SERIAL_PORT", commandLine.getOptionValue("serial"));
log.info("Setting address to " + spotConnection);
connection = (StreamConnection) Connector.open(spotConnection);
dos = connection.openDataOutputStream();
dis = connection.openDataInputStream();
if (commandLine.hasOption("running")) {
log.info("Setting build state to RUN.");
dos.writeUTF("RUN");
dos.flush();
log.info("SPOT responded with: " + dis.readUTF());
} else if (commandLine.hasOption("failed")) {
log.info("Setting build state to FAIL.");
dos.writeUTF("FAIL");
dos.flush();
log.info("SPOT responded with " + dis.readUTF());
} else if (commandLine.hasOption("success")) {
log.info("Setting build state to SUCCESS.");
dos.writeUTF("SUCCESS");
dos.flush();
log.info("SPOT responded with " + dis.readUTF());
} else {
printUsage(options);
System.exit(1);
}
} catch (ParseException e) {
// This will be thrown if the command line arguments are malformed.
printUsage(options);
System.exit(1);
} catch (NoRouteException nre) {
log.severe("Couldn't get a connection to the remote SPOT.");
nre.printStackTrace();
System.exit(1);
} finally {
if (connection != null) {
connection.close();
}
System.exit(0);
}
}
更多精彩
赞助商链接