Our original hello world was a client of a hello world service. Here it is again, and we'll discuss it after. First, the imports:
package org.jtrix.project.helloworld; import org.jtrix.base.*; import org.jtrix.project.libjtrix.netlet.NullService; /** Netlet which accesses a hello world service using a warrant * read from an incoming parameter. */ public class Hello1Client implements INetlet {
The initialise() method does the main work:
public byte[] initialise(INode node, Object param, byte[] unsigned) throws InitialiseException { try { // Get the warrant, use it bind the service, and then get the facet Warrant warrant = (Warrant)param; IService service = node.bindService(warrant, new NullService()); String hf_name = IHelloFacet.class.getName(); IHelloFacet facet = (IHelloFacet) service.bindFacet(hf_name); // Use the facet System.out.println(facet.getMessage()); return null; } catch (Throwable e) { System.out.println("Sorry, no message available"); e.printStackTrace(); throw new InitialiseException(e.toString()); } }
The class ends with minimal implementations of the rest of the INetlet methods:
public void terminate(long date, INetlet.IShutdownProgress progress) { // Nothing to clean up when we terminate } public IService bindService(Warrant warrant, IService consumer) throws ServiceBindException { // This netlet offers no services to other netlets using warrants throw new ServiceBindException(); } public String[] getFacets() { // This netlet offers no facets to the node return new String[0]; } public IRemote bindFacet(String facet) throws FacetBindException { // The node shouldn't try to bind facets from here throw new FacetBindException(); } } // Hello1Client