Package jade.wrapper.gateway
Class JadeGateway
- java.lang.Object
-
- jade.wrapper.gateway.JadeGateway
-
public class JadeGateway extends Object
This class provides a simple yet powerful gateway between some non-JADE code and a JADE based multi agent system. It is particularly suited to be used inside a Servlet or a JSP. The class maintains an internal JADE agent (of classGatewayAgentthat acts as entry point in the JADE based system. The activation/termination of this agent (and its underlying container) are completely managed by the JadeGateway class and developers do not need to care about them. The suggested way of using the JadeGateway class is creating proper behaviours that perform the commands that the external system must issue to the JADE based system and pass them as parameters to the execute() method. When the execute() method returns the internal agent of the JadeGateway as completely executed the behaviour and outputs (if any) can be retrieved from the behaviour object using ad hoc methods as exemplified below.
DoSomeActionBehaviour b = new DoSomeActionBehaviour(....);
JadeGateway.execute(b); // At this point b has been completely executed --> we can get results
result = b.getResult();
When using the JadeGateway class as described abovenullshould be passed as first parameter to theinit()method.Alternatively programmers can
- create an application-specific class that extends
GatewayAgent, that redefine its methodprocessCommandand that is the agent responsible for processing all command-requests - initialize this JadeGateway by calling its method
initwith the name of the class of the application-specific agent - finally, in order to request the processing of a Command, you must call the method
JadeGateway.execute(Object command). This method will cause the callback of the methodprocessCommandof the application-specific agent. The methodexecutewill return only after the methodGatewayAgent.releaseCommand(command)has been called by your application-specific agent.
- Version:
- $Date$ $Revision$
- Author:
- Fabio Bellifemine, Telecom Italia LAB
- create an application-specific class that extends
-
-
Field Summary
Fields Modifier and Type Field Description static StringSPLIT_CONTAINER
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddListener(GatewayListener l)static voidcheckJADE()This method checks if both the container, and the agent, are up and running.static voidexecute(Object command)execute a command.static voidexecute(Object command, long timeout)Execute a command specifying a timeout.static DynamicJadeGatewaygetDefaultGateway()static StringgetProfileProperty(String key, String defaultValue)Searches for the property with the specified key in the JADE Platform Profile.static voidinit(String agentClassName, Properties jadeProfile)static voidinit(String agentClassName, Object[] agentArgs, Properties jadeProfile)Initialize this gateway by passing the proper configuration parametersstatic booleanisGatewayActive()Return the state of JadeGatewayvoidremoveListener(GatewayListener l)static voidshutdown()Kill the JADE Container in case it is running.
-
-
-
Field Detail
-
SPLIT_CONTAINER
public static final String SPLIT_CONTAINER
- See Also:
- Constant Field Values
-
-
Method Detail
-
getProfileProperty
public static final String getProfileProperty(String key, String defaultValue)
Searches for the property with the specified key in the JADE Platform Profile. The method returns the default value argument if the property is not found.- Parameters:
key- - the property key.defaultValue- - a default value- Returns:
- the value with the specified key value
- See Also:
Properties.getProperty(String, String)
-
execute
public static final void execute(Object command) throws StaleProxyException, ControllerException, InterruptedException
execute a command. This method first check if the executor Agent is alive (if not it creates container and agent), then it forwards the execution request to the agent, finally it blocks waiting until the command has been executed (i.e. the methodreleaseCommandis called by the executor agent)- Throws:
StaleProxyException- if the method was not able to execute the CommandControllerExceptionInterruptedException- See Also:
AgentController.putO2AObject(Object, boolean)
-
execute
public static final void execute(Object command, long timeout) throws StaleProxyException, ControllerException, InterruptedException
Execute a command specifying a timeout. This method first check if the executor Agent is alive (if not it creates container and agent), then it forwards the execution request to the agent, finally it blocks waiting until the command has been executed. In case the command is a behaviour this method blocks until the behaviour has been completely executed.- Throws:
InterruptedException- if the timeout expires or the Thread executing this method is interrupted.StaleProxyException- if the method was not able to execute the CommandControllerException- See Also:
AgentController.putO2AObject(Object, boolean)
-
checkJADE
public static final void checkJADE() throws StaleProxyException, ControllerExceptionThis method checks if both the container, and the agent, are up and running. If not, then the method is responsible for renewing myContainer. Normally programmers do not need to invoke this method explicitly.
-
init
public static final void init(String agentClassName, Object[] agentArgs, Properties jadeProfile)
Initialize this gateway by passing the proper configuration parameters- Parameters:
agentClassName- is the fully-qualified class name of the JadeGateway internal agent. If null is passed the default class will be used.agentArgs- is the list of agent argumentsjadeProfile- the properties that contain all parameters for running JADE (see jade.core.Profile). Typically these properties will have to be read from a JADE configuration file. If jadeProfile is null, then a JADE container attaching to a main on the local host is launched
-
init
public static final void init(String agentClassName, Properties jadeProfile)
-
shutdown
public static final void shutdown()
Kill the JADE Container in case it is running.
-
isGatewayActive
public static final boolean isGatewayActive()
Return the state of JadeGateway- Returns:
- true if the container and the gateway agent are active, false otherwise
-
addListener
public static void addListener(GatewayListener l)
-
removeListener
public void removeListener(GatewayListener l)
-
getDefaultGateway
public static final DynamicJadeGateway getDefaultGateway()
-
-