// network.
DistributedSCADomain distributedDomain = new DistributedSCADomainNetworkImpl(domainName);
// create the node that runs the calculator component
EmbeddedNode node = new EmbeddedNode(nodeName);
SCADomain domain = node.attachDomain(distributedDomain);
// the application components are added. The null here just gets the node
// implementation to read a directory from the classpath with the node name
// TODO - should be done as a management action.
node.addContribution(domainName, null);
// start the node
// TODO - should be done as a management action.
node.start();
// 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 =
domain.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));
} 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
domain.close();
} catch(Exception ex) {
System.err.println("Exception in node - " + ex.getMessage());
ex.printStackTrace(System.err);
}