public abstract class BaseService extends java.lang.Object implements Service
BaseService abstract class partially implements
the Service interface, providing a simple and uniform
mechanism for slice management and service discovery.
Developers interested in creating JADE kernel level services should
extend BaseService instead of directly implementing the
Service interfaceService.Slice| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ALL_DUMP_KEY |
static java.lang.String |
MAIN_SLICE |
protected ServiceFinder |
myFinder |
protected Logger |
myLogger |
static java.lang.String |
THIS_SLICE |
ADOPTED_NODE, DEAD_NODE, DEAD_PLATFORM_MANAGER, DEAD_REPLICA, DEAD_SLICE, NEW_NODE, NEW_REPLICA, NEW_SLICE, REATTACHED, RECONNECTED| Constructor and Description |
|---|
BaseService() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addAlias(java.lang.String alias,
java.lang.String name)
This protected method allows subclasses to define their own
naming schemes, by adding aliases for existing slice names.
|
void |
boot(Profile p)
Performs the active initialization step of a kernel-level
service.
|
void |
broadcast(HorizontalCommand cmd,
boolean includeMyself) |
protected void |
clearCachedSlice(java.lang.String name) |
protected CallbackInvokator |
createInvokator() |
java.lang.String |
dump(java.lang.String key)
This method can be redefined to support service internal data inspection by means of the ContainerMonitorAgent
included in the misc add-on.
|
Service.Slice[] |
getAllSlices()
The
getAllSlices() implementation of this class
directly retrieves the current list of slices from the Service
Manager. |
Behaviour |
getAMSBehaviour()
This should be properly implemented
by the services that require a service specific Behaviour
running in the AMS.
|
Filter |
getCommandFilter(boolean direction)
This should be properly implemented
by the services that have filters.
|
Sink |
getCommandSink(boolean direction)
This should be properly implemented
by the services that have sinks.
|
protected Service.Slice |
getFreshSlice(java.lang.String name) |
ServiceHelper |
getHelper(Agent a)
This should be properly implemented
by the services that have helpers.
|
java.lang.Class |
getHorizontalInterface()
This should be properly implemented
by the services that have non-empty slices.
|
protected IMTPManager |
getIMTPManager() |
Node |
getLocalNode() |
Service.Slice |
getLocalSlice()
This should be properly implemented
by the services that have non-empty slices.
|
int |
getNumberOfSlices()
This method returns the current number of slices known to this
service on this node.
|
java.lang.String[] |
getOwnedCommands()
This should be properly implemented
by the services that owns vertival commands.
|
Service.Slice |
getSlice(java.lang.String name)
The
getSlice() implementation of this class works
as follows:
First, the name alias table is used to convert the given
slice name into another name, if any
Then, the new name (which may or may not be different
from the original one) is used to look up an internal table
keeping the service slices
If no slice was found, the
ServiceFinder is asked to provide the slice,
which is then put into the local table. |
void |
init(AgentContainer ac,
Profile p)
Performs the passive initialization step of the service.
|
boolean |
isLocal() |
protected java.lang.String |
lookupAlias(java.lang.String alias)
This protected method is used by
getSlice() to
dereference aliases for slice names. |
void |
shutdown()
Performs the shutdown step of a kernel-level service.
|
static java.lang.String |
stringifySlice(Service.Slice s) |
java.lang.Object |
submit(VerticalCommand cmd)
Allows submitting a vertical command for processing.
|
public static final java.lang.String MAIN_SLICE
public static final java.lang.String THIS_SLICE
public static final java.lang.String ALL_DUMP_KEY
protected ServiceFinder myFinder
protected transient Logger myLogger
public void init(AgentContainer ac, Profile p) throws ProfileException
Serviceboot() method.init in interface Serviceac - The agent container this service is activated on.p - The configuration profile for this service.ProfileException - If the given profile is not valid.public Service.Slice getSlice(java.lang.String name) throws ServiceException
getSlice() implementation of this class works
as follows:
ServiceFinder is asked to provide the slice,
which is then put into the local table.getSlice in interface Servicename - A name for the requested slice. The name must be
unique within this service.Slice object that is a part of this
service and is identified by the given name, or
null if no such slice exists.ServiceException - If some underlying error (e.g. a
network problem) occurs, that does not allow to decide whether
the requested slice exists or not.public int getNumberOfSlices()
getNumberOfSlices in interface Servicepublic Node getLocalNode() throws IMTPException
IMTPExceptionpublic Service.Slice[] getAllSlices() throws ServiceException
getAllSlices() implementation of this class
directly retrieves the current list of slices from the Service
Manager. Note that slices are retrieved directly from the Main and not
from the cache.getAllSlices in interface ServiceService.Slice objects, whose
elements are the slices of this service deployed at the
different platform nodes.ServiceException - If some underlying error (e.g. a
network problem) occurs, that does not allow to retrieve the
full slice list.public void broadcast(HorizontalCommand cmd, boolean includeMyself) throws IMTPException, ServiceException
IMTPExceptionServiceExceptionprotected void addAlias(java.lang.String alias,
java.lang.String name)
alias - The new alias name.name - The real name this alias must be mapped to.protected java.lang.String lookupAlias(java.lang.String alias)
getSlice() to
dereference aliases for slice names. Subclasses can override
this method to build their own service-specific naming schema.alias - The alias name to map to a real slice name.public Filter getCommandFilter(boolean direction)
direction
parameter this method MUST always return the same object!getCommandFilter in interface Servicedirection - One of the two constants
Filter.INCOMING and Filter.OUTGOING,
distinguishing between the two filter chains managed by the
command processor.Filter object, used by this service to
intercept and process kernel-level commands. If the service
does not wish to install a command filter for one or both
directions, it can just return null when
appropriate.jade.core.CommandProcessorpublic Sink getCommandSink(boolean direction)
getCommandSink in interface Servicedirection - One of the two constants
Sink.COMMAND_SOURCE or
Sink.COMMAND_TARGET, to state whether this sink
will handle locally issued commands or commands incoming from
remote nodes.Sink interface, that will be invoked by the
kernel in order to consume any incoming vertical command owned
by this service. If the service does not wish to install a
command sink, it can just return null.Service.getOwnedCommands()public java.lang.String[] getOwnedCommands()
getOwnedCommands in interface Servicenull as well.jade.core.Service#getCommandSink()public java.lang.Class getHorizontalInterface()
getHorizontalInterface in interface ServiceClass object, representing the interface
that is implemented by the slices of this service. Let
s be the Class object corresponding
to the Service.Slice interface, and let
c be the returned Class object. Then,
the two following conditions must hold:
c.isInterface() == trues.isAssignableFrom(c) == truepublic Service.Slice getLocalSlice()
getLocalSlice in interface Servicenull if no such slice exists.public boolean isLocal()
public ServiceHelper getHelper(Agent a) throws ServiceException
getHelper in interface Servicea - The agent which the helper is requested for.ServiceExceptionAgentToolkit.getHelper(jade.core.Agent, java.lang.String),
Agent.getHelper(java.lang.String)public Behaviour getAMSBehaviour()
getAMSBehaviour in interface ServiceBehaviour object associated with this
service, or null if no such behaviour exists.public void boot(Profile p) throws ServiceException
Serviceboot in interface Servicep - The configuration profile for this service.ServiceException - If a problem occurs during service
initialization.public void shutdown()
Servicepublic java.lang.Object submit(VerticalCommand cmd) throws ServiceException
ServicegetOwnedCommands(), or an
exception is thrownsubmit in interface Servicecmd - The command to submit to the service.null if this
command produced no result. If an exception was produced, it
will not be thrown, but will be returned as well.ServiceException - If the passed command does not belong
to this service.protected Service.Slice getFreshSlice(java.lang.String name) throws ServiceException
ServiceExceptionprotected IMTPManager getIMTPManager()
protected void clearCachedSlice(java.lang.String name)
public java.lang.String dump(java.lang.String key)
key - A hint indicating which service data should be dumpedpublic static final java.lang.String stringifySlice(Service.Slice s)
protected CallbackInvokator createInvokator()