Hello2Client

The introduction to Hello2Client is simple. It only uses classes from org.jtrix.base.


package org.jtrix.project.helloworld;

import org.jtrix.base.*;

/** Netlet to get a message from a node facet and output it.
 */

public class Hello2Client implements INetlet
{

The netlet's initialise() method only uses the first of its three parameters, which is the link back to the node. It uses this to bind the node facet and then it uses it. Notice that to bind a node facet we just take the INode interface and bind. Compare this to the previous example where we bound a facet from a service.


    /**
     * Called by the node on binding the netlet. Part of the INetlet
     * interface. This method will actually bind the facet,
     * then get the message.
     *
     * @param node      An interface through which we can talk to our node.
     * @param bean      A parameter bean passed in the descriptor. Not used.
     * @param unsigned  Some arbituary data from the bind server.
     * @return          Arbitrary netlet-specific data.
     */
    public byte[] initialise(INode node, Object bean, byte[] unsigned)
        throws InitialiseException
    {
        try
        {
            String facet_name = IHelloFacet.class.getName();
            IHelloFacet facet = (IHelloFacet)(node.bindFacet(facet_name));
            System.out.println(facet.getMessage());
        }
        catch(Exception e)
        {
            System.out.println("Sorry, couldn't get the message");
            e.printStackTrace();
            throw new InitialiseException(e.toString());
        }

        return null;
    }

And finally the rest of the INetlet methods are just as for our previous example, since Hello2Client does nothing more:


    /** No clean-up needed on terminate.
     */
    public void terminate(long date, INetlet.IShutdownProgress progress)
    {
        // No clean-up necessary
    }

    /** Called by another netlet to bind this netlet's services. We don't
     * have any.
     */
    public IService bindService(Warrant warrant, IService consumer)
        throws ServiceBindException
    {
        throw new ServiceBindException();
    }

    /** Called by the node to see what facets we can offer it.
     * @return  An empty array, since we don't offer any facets.
     */
    public String[] getFacets()
    {
        return new String[0];
    }

    /** Allows the node to bind any facets we can offer it.
     * @throws FacetBindException  Thrown every time since we offer no facets.
     */
    public IRemote bindFacet(String facet) throws FacetBindException
    {
        throw new FacetBindException();
    }

} // Hello2Client

And that's the end of the netlet. It binds and uses a node facet during its initialisation, and nothing more.

Nik Silver 2002-03-09