try {
String domainName = args[0];
String nodeName = args[1];
SCADomain domainNode = SCADomain.newInstance(domainName, nodeName, null, nodeName + "/Calculator.composite");
// nodeA is the head node and runs some tests while all other nodes
// simply listen for incoming messages
if ( nodeName.equals("nodeA") ) {
// do some application stuff
CalculatorService calculatorService =
domainNode.getService(CalculatorService.class, "CalculatorServiceComponent");
// Calculate
System.out.println("3 + 2=" + calculatorService.add(3, 2));
System.out.println("3 - 2=" + calculatorService.subtract(3, 2));
System.out.println("3 * 2=" + calculatorService.multiply(3, 2));
System.out.println("3 / 2=" + calculatorService.divide(3, 2));
// a little hidden loop test to put some load on the nodes
if (args.length > 2){
for (int i=0; i < 1000; i++){
// Calculate
System.out.println("3 + 2=" + calculatorService.add(3, 2));
System.out.println("3 - 2=" + calculatorService.subtract(3, 2));
System.out.println("3 * 2=" + calculatorService.multiply(3, 2));
System.out.println("3 / 2=" + calculatorService.divide(3, 2));
}
}
} else {
// start up and wait for messages
try {
System.out.println("Node started (press enter to shutdown)");
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
}
// stop the node and all the domains in it
domainNode.close();
} catch(Exception ex) {
System.err.println("Exception in node - " + ex.getMessage());
ex.printStackTrace(System.err);
}