The consumer service plugin is the inverse of the AdminServiceProvider--our
basic facet collection is non-empty (it contains an implementation
of ISkeletonFacet, plus the same thing wrapped as a console
facet) and it is not an admin service. See Section
for more on services and Section
for more on implementing console interfaces. See Section
for some details on the Debug class.
package org.jtrix.project.skeleton2.plugins;
import org.jtrix.base.*;
import org.jtrix.facets1.util.properties.*;
import org.jtrix.facets1.service.common.*;
import org.jtrix.project.libjtrix.netlet.*;
import org.jtrix.project.libjtrix.debug.*;
import org.jtrix.project.beatrix.common.*;
import org.jtrix.project.beatrix.plugins.*;
import org.jtrix.project.beatrix.plugins.util.*;
import org.jtrix.project.skeleton2.facets.ISkeletonFacet;
/**
* Provides a service to be plugged into the SkeletonWorker.
*
* @author ulf@jtrix.org
* @author nadia@jtrix.org
* @version $Revision: 1.14 $
*/
public class SkeletonServiceProvider
extends AbstractPlugin implements ISimpleServiceProvider, IPlugin
{
/**
* Create a facet collection for this service label, called once
* for each service bind request.
* @param session Service session from client
* @param service_type Service name requested by client
* @param args Property arguments from client's warrant
*/
public IFacetCollection createFacetCollection(String service_type,Property args)
{
FacetCollection fc = new FacetCollection();
fc.addFacet( ISkeletonFacet.class.getName(), new SkeletonFacet() );
try
{
IConsoleFacet my_console = new ConsoleFacetFactory(ISkeletonFacet.class)
.createConsoleFacet(new SkeletonFacet());
fc.addFacet( IConsoleFacet.class.getName(), new JointConsoleFacet(
my_console, peerSupport().getStandardConsole()) );
}
catch(ConsoleFacetFactory.InvalidFacetException e)
{
// Our skeleton facet is not suitable to be made into a console
Debug.exc(this,e,"ISkeletonFacet can't be made into a console");
}
catch(ConsoleFacetFactory.InvalidImplementationException e)
{
// If SkeletonFacet is not an implementation of ISkeletonFacet
Debug.exc(this,e,"SkeletonFacet doesn't implement ISkeletonFacet");
}
return fc;
}
/**
* @return true if this Service Provider is an admin service.
*/
public boolean isAdminProvider()
{
return false;
}
/** An implementation of ISkeletonFacet, which is also an
* ICommunicationServer and hence can respond to connection loss.
*/
static class SkeletonFacet implements ICommunicationServer, ISkeletonFacet
{
public void connectionClosed()
{
// Respond to connection loss
}
public String getMessage()
{
return "Hello, skeleton plugin world";
}
}
}
Nik Silver 2002-03-09