HelloWorld Service Clara-2.x Tutorial-2 By V. Gyurjyan
Clara-2..x Design Concept Review Cloud consists of distributed processes, called Clara- Data-Processing-Environment (JVM’s) running one in each computing node. Master Clara-Container is called Platform and runs administrative services. Each Clara-Container runs a pub-sub server and contains one or many Service-Containers Service-Container deploys one or many User-Engines as a services.
Clara-2.x naming Convention Service Name : DPE-Host/Service-Container/User-Engine Service-Container name is arbitrary (given by the user) User-Engine name is defined by the engine developer and accessed through the Clara interface public String getName() { return ”myName” }
HelloWorldService class package examples.service; import org.jlab.clas12.tools.MimeType; import org.jlab.coda.clara.core.JioSerial; import org.jlab.coda.clara.system.CConstants; import org.jlab.coda.clara.system.CUtil; import org.jlab.coda.clara.user.JService; /** * Hello world service * Vardan Gyurjyan 2.x */ public class HelloWorldService extends JService {
HelloWorldService public String getName() { return "Hello"; public String getAuthor() { return "Gyurjyan"; public String getDescription() { return "Hello World service"; }
HelloWorldService public String getVersion() { return "1.0"; public String getLanguage() { return CConstants.LANG_JAVA; }
HelloWorldService public JioSerial execute(JioSerial[] data) { return null; public void configure(JioSerial data) { public void destruct() { }
HelloWorldService public JioSerial execute(JioSerial data) { // output transient data object JioSerial out = new JioSerial(); out.setLanguage(CConstants.LANG_JAVA); // check the input data mime-type if(data.getMimeType().type().equals(MimeType.STRING.type())){ // get the data content String inputDataObject = data.getStringObject(); // generate the output data out.setData(CUtil.getCurrentTime()+": Hello World from "+inputDataObject); out.setDataDescription("response to " + inputDataObject); out.setStatus(CConstants.info);
HelloWorldService class } else { // Reject with an execution status = error out.setData(CConstants.REJECT); out.setDataDescription("I can accept only strings"); out.setStatus(CConstants.error); } return out; }
Compiling javac -cp $CLARA_SERVICES/lib/Clara.jar:$CLARA_SERVICES/lib/j tools-1.0.jar:$CLARA_SERVICES/lib/cMsg-3.3.jar HelloWorldService.java -d $CLARA_SERVCIES/