Package jade.core
Class BaseService
- java.lang.Object
-
- jade.core.BaseService
-
- All Implemented Interfaces:
Service
- Direct Known Subclasses:
AddressNotificationService,AgentManagementService,AgentMobilityService,AgentReplicationService,BEAgentManagementService,BEManagementService,FaultRecoveryService,LightMessagingService,MainReplicationService,MessagingService,NodeMonitoringService,NotificationService,PersistentDeliveryService,ResourceManagementService,SAMService,TopicManagementService
public abstract class BaseService extends Object implements Service
TheBaseServiceabstract class partially implements theServiceinterface, providing a simple and uniform mechanism for slice management and service discovery. Developers interested in creating JADE kernel level services should extendBaseServiceinstead of directly implementing theServiceinterface- Author:
- Giovanni Rimassa - FRAMeTech s.r.l.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jade.core.Service
Service.Slice, Service.SliceProxy
-
-
Field Summary
Fields Modifier and Type Field Description static StringALL_DUMP_KEYstatic StringMAIN_SLICEprotected ServiceFindermyFinderprotected LoggermyLoggerstatic StringTHIS_SLICE-
Fields inherited from interface jade.core.Service
ADOPTED_NODE, DEAD_NODE, DEAD_PLATFORM_MANAGER, DEAD_REPLICA, DEAD_SLICE, NEW_NODE, NEW_REPLICA, NEW_SLICE, REATTACHED, RECONNECTED
-
-
Constructor Summary
Constructors Constructor Description BaseService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddAlias(String alias, String name)This protected method allows subclasses to define their own naming schemes, by adding aliases for existing slice names.voidboot(Profile p)Performs the active initialization step of a kernel-level service.voidbroadcast(HorizontalCommand cmd, boolean includeMyself)protected voidclearCachedSlice(String name)protected CallbackInvokatorcreateInvokator()Stringdump(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()ThegetAllSlices()implementation of this class directly retrieves the current list of slices from the Service Manager.BehaviourgetAMSBehaviour()This should be properly implemented by the services that require a service specific Behaviour running in the AMS.FiltergetCommandFilter(boolean direction)This should be properly implemented by the services that have filters.SinkgetCommandSink(boolean direction)This should be properly implemented by the services that have sinks.protected Service.SlicegetFreshSlice(String name)ServiceHelpergetHelper(Agent a)This should be properly implemented by the services that have helpers.ClassgetHorizontalInterface()This should be properly implemented by the services that have non-empty slices.protected IMTPManagergetIMTPManager()NodegetLocalNode()Service.SlicegetLocalSlice()This should be properly implemented by the services that have non-empty slices.intgetNumberOfSlices()This method returns the current number of slices known to this service on this node.String[]getOwnedCommands()This should be properly implemented by the services that owns vertival commands.Service.SlicegetSlice(String name)ThegetSlice()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, theServiceFinderis asked to provide the slice, which is then put into the local table.voidinit(AgentContainer ac, Profile p)Performs the passive initialization step of the service.booleanisLocal()protected StringlookupAlias(String alias)This protected method is used bygetSlice()to dereference aliases for slice names.voidshutdown()Performs the shutdown step of a kernel-level service.static StringstringifySlice(Service.Slice s)Objectsubmit(VerticalCommand cmd)Allows submitting a vertical command for processing.
-
-
-
Field Detail
-
MAIN_SLICE
public static final String MAIN_SLICE
- See Also:
- Constant Field Values
-
THIS_SLICE
public static final String THIS_SLICE
- See Also:
- Constant Field Values
-
ALL_DUMP_KEY
public static final String ALL_DUMP_KEY
- See Also:
- Constant Field Values
-
myFinder
protected ServiceFinder myFinder
-
myLogger
protected transient Logger myLogger
-
-
Method Detail
-
init
public void init(AgentContainer ac, Profile p) throws ProfileException
Description copied from interface:ServicePerforms the passive initialization step of the service. This method is called before activating the service. Its role should be simply the one of a constructor, setting up the internal data as needed. Service implementations should not use the Service Manager and Service Finder facilities from within this method. A distributed initialization protocol, if needed, should be exectuted within theboot()method.- Specified by:
initin interfaceService- Parameters:
ac- The agent container this service is activated on.p- The configuration profile for this service.- Throws:
ProfileException- If the given profile is not valid.
-
getSlice
public Service.Slice getSlice(String name) throws ServiceException
ThegetSlice()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
ServiceFinderis asked to provide the slice, which is then put into the local table.
- Specified by:
getSlicein interfaceService- Parameters:
name- A name for the requested slice. The name must be unique within this service.- Returns:
- The
Sliceobject that is a part of this service and is identified by the given name, ornullif no such slice exists. - Throws:
ServiceException- If some underlying error (e.g. a network problem) occurs, that does not allow to decide whether the requested slice exists or not.
-
getNumberOfSlices
public int getNumberOfSlices()
This method returns the current number of slices known to this service on this node. Due to the distributed nature of many JADE services, there is no guaranteed that calling this method for the same service on different nodes will actually result on the same number.- Specified by:
getNumberOfSlicesin interfaceService- Returns:
- The number of slices of this service that are known to this node.
-
getLocalNode
public Node getLocalNode() throws IMTPException
- Throws:
IMTPException
-
getAllSlices
public Service.Slice[] getAllSlices() throws ServiceException
ThegetAllSlices()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.- Specified by:
getAllSlicesin interfaceService- Returns:
- An array of
Service.Sliceobjects, whose elements are the slices of this service deployed at the different platform nodes. - Throws:
ServiceException- If some underlying error (e.g. a network problem) occurs, that does not allow to retrieve the full slice list.
-
broadcast
public void broadcast(HorizontalCommand cmd, boolean includeMyself) throws IMTPException, ServiceException
- Throws:
IMTPExceptionServiceException
-
addAlias
protected void addAlias(String alias, String name)
This protected method allows subclasses to define their own naming schemes, by adding aliases for existing slice names.- Parameters:
alias- The new alias name.name- The real name this alias must be mapped to.
-
lookupAlias
protected String lookupAlias(String alias)
This protected method is used bygetSlice()to dereference aliases for slice names. Subclasses can override this method to build their own service-specific naming schema.- Parameters:
alias- The alias name to map to a real slice name.- Returns:
- A mapped name, or the original one if no mapping was found.
-
getCommandFilter
public Filter getCommandFilter(boolean direction)
This should be properly implemented by the services that have filters. Note that when called multiple times with the same value of thedirectionparameter this method MUST always return the same object!- Specified by:
getCommandFilterin interfaceService- Parameters:
direction- One of the two constantsFilter.INCOMINGandFilter.OUTGOING, distinguishing between the two filter chains managed by the command processor.- Returns:
- A
Filterobject, 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 returnnullwhen appropriate. - See Also:
CommandProcessor
-
getCommandSink
public Sink getCommandSink(boolean direction)
This should be properly implemented by the services that have sinks.- Specified by:
getCommandSinkin interfaceService- Parameters:
direction- One of the two constantsSink.COMMAND_SOURCEorSink.COMMAND_TARGET, to state whether this sink will handle locally issued commands or commands incoming from remote nodes.- Returns:
- Concrete services must return their own implementation
of the
Sinkinterface, 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 returnnull. - See Also:
Service.getOwnedCommands()
-
getOwnedCommands
public String[] getOwnedCommands()
This should be properly implemented by the services that owns vertival commands.- Specified by:
getOwnedCommandsin interfaceService- Returns:
- An array containing the names of all the vertical
commands this service wants to own. If this service has no such
commands (it acts purely as a command filter), it can return an
empty array, or
nullas well. - See Also:
jade.core.Service#getCommandSink()
-
getHorizontalInterface
public Class getHorizontalInterface()
This should be properly implemented by the services that have non-empty slices.- Specified by:
getHorizontalInterfacein interfaceService- Returns:
- A
Classobject, representing the interface that is implemented by the slices of this service. Letsbe theClassobject corresponding to theService.Sliceinterface, and letcbe the returnedClassobject. Then, the two following conditions must hold:c.isInterface() == trues.isAssignableFrom(c) == true
-
getLocalSlice
public Service.Slice getLocalSlice()
This should be properly implemented by the services that have non-empty slices.- Specified by:
getLocalSlicein interfaceService- Returns:
- The slice of this service that resides on the local
platform node, or
nullif no such slice exists.
-
isLocal
public boolean isLocal()
-
getHelper
public ServiceHelper getHelper(Agent a) throws ServiceException
This should be properly implemented by the services that have helpers.- Specified by:
getHelperin interfaceService- Parameters:
a- The agent which the helper is requested for.- Returns:
- The ServiceHelper to be used by the agent.
- Throws:
ServiceException- See Also:
AgentToolkit.getHelper(jade.core.Agent, java.lang.String),Agent.getHelper(java.lang.String)
-
getAMSBehaviour
public Behaviour getAMSBehaviour()
This should be properly implemented by the services that require a service specific Behaviour running in the AMS.- Specified by:
getAMSBehaviourin interfaceService- Returns:
- A
Behaviourobject associated with this service, ornullif no such behaviour exists.
-
boot
public void boot(Profile p) throws ServiceException
Description copied from interface:ServicePerforms the active initialization step of a kernel-level service. When JADE kernel calls this method, the service has already been already associated with its container and registered with the Service Manager.- Specified by:
bootin interfaceService- Parameters:
p- The configuration profile for this service.- Throws:
ServiceException- If a problem occurs during service initialization.
-
shutdown
public void shutdown()
Description copied from interface:ServicePerforms the shutdown step of a kernel-level service. The JADE kernel calls this method just before uninstalling this service
-
submit
public Object submit(VerticalCommand cmd) throws ServiceException
Description copied from interface:ServiceAllows submitting a vertical command for processing. The given vertical command must be owned by this service (i.e. its name must be one of the constants contained in the array returned bygetOwnedCommands(), or an exception is thrown- Specified by:
submitin interfaceService- Parameters:
cmd- The command to submit to the service.- Returns:
- The result of the command, or
nullif this command produced no result. If an exception was produced, it will not be thrown, but will be returned as well. - Throws:
ServiceException- If the passed command does not belong to this service.
-
getFreshSlice
protected Service.Slice getFreshSlice(String name) throws ServiceException
- Throws:
ServiceException
-
getIMTPManager
protected IMTPManager getIMTPManager()
-
clearCachedSlice
protected void clearCachedSlice(String name)
-
dump
public String dump(String key)
This method can be redefined to support service internal data inspection by means of the ContainerMonitorAgent included in the misc add-on. The default implementation just dumps the map of cached slices- Parameters:
key- A hint indicating which service data should be dumped- Returns:
- A string representation of the service internal data
-
stringifySlice
public static final String stringifySlice(Service.Slice s)
-
createInvokator
protected CallbackInvokator createInvokator()
-
-