|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.almende.eve.agent.AgentFactory
public class AgentFactory
The AgentFactory is a factory to instantiate and invoke Eve Agents within the configured state. The AgentFactory can invoke local as well as remote agents. An AgentFactory must be instantiated with a valid Eve configuration file. This configuration is needed to load the configured agent classes and instantiate a state for each agent. Example usage: // generic constructor Config config = new Config("eve.yaml"); AgentFactory factory = new AgentFactory(config); // construct in servlet InputStream is = getServletContext().getResourceAsStream("/WEB-INF/eve.yaml"); Config config = new Config(is); AgentFactory factory = new AgentFactory(config); // create or get a shared instance of the AgentFactory AgentFactory factory = AgentFactory.createInstance(namespace, config); AgentFactory factory = AgentFactory.getInstance(namespace); // invoke a local agent by its id response = factory.invoke(agentId, request); // invoke a local or remote agent by its url response = factory.send(senderId, receiverUrl, request); // create a new agent Agent agent = factory.createAgent(agentType, agentId); String desc = agent.getDescription(); // use the agent agent.destroy(); // neatly shutdown the agents state // instantiate an existing agent Agent agent = factory.getAgent(agentId); String desc = agent.getDescription(); // use the agent agent.destroy(); // neatly shutdown the agents state
Constructor Summary | |
---|---|
AgentFactory()
|
|
AgentFactory(Config config)
Construct an AgentFactory and initialize the configuration |
Method Summary | ||
---|---|---|
void |
addAgents(Config config)
Create agents from a config (only when they do not yet exist). |
|
void |
addTransportService(TransportService transportService)
Add a new transport service |
|
void |
addTransportServices(Config config)
Load transport services for incoming and outgoing messages from a config (for example http and xmpp services). |
|
Agent |
createAgent(Class<?> agentType,
String agentId)
Create an agent. |
|
Agent |
createAgent(String agentType,
String agentId)
Create an agent. |
|
|
createAgentProxy(String senderId,
String receiverUrl,
Class<T> agentInterface)
Create an agent proxy from an java interface |
|
static AgentFactory |
createInstance()
Create a shared AgentFactory instance with the default namespace "default" |
|
static AgentFactory |
createInstance(Config config)
Create a shared AgentFactory instance with the default namespace "default" |
|
static AgentFactory |
createInstance(String namespace)
Create a shared AgentFactory instance with a specific namespace |
|
static AgentFactory |
createInstance(String namespace,
Config config)
Create a shared AgentFactory instance with a specific namespace |
|
void |
deleteAgent(String agentId)
Delete an agent |
|
Agent |
getAgent(String agentId)
Get an agent by its id. |
|
Config |
getConfig()
Get the loaded config file |
|
static String |
getEnvironment()
Retrieve the current environment, using the configured State. |
|
EventLogger |
getEventLogger()
Get the event logger. |
|
static AgentFactory |
getInstance()
Get a shared AgentFactory instance with the default namespace "default" |
|
static AgentFactory |
getInstance(String namespace)
Get a shared AgentFactory instance with a specific namespace |
|
List<Object> |
getMethods(Agent agent,
Boolean asJSON)
|
|
Scheduler |
getScheduler(String agentId)
create a scheduler for an agent |
|
StateFactory |
getStateFactory()
Get the configured state factory. |
|
TransportService |
getTransportService(String protocol)
Get the first registered transport service which supports given protocol. |
|
List<TransportService> |
getTransportServices()
Get all registered transport services |
|
List<TransportService> |
getTransportServices(String protocol)
Get all registered transport services which can handle given protocol |
|
boolean |
hasAgent(String agentId)
Test if an agent exists |
|
JSONResponse |
invoke(String receiverId,
JSONRequest request,
RequestParams requestParams)
Invoke a local agent |
|
void |
removeTransportService(TransportService transportService)
Remove a registered a transport service |
|
JSONResponse |
send(String senderId,
String receiverUrl,
JSONRequest request)
Invoke a local or remote agent. |
|
void |
sendAsync(String senderId,
String receiverUrl,
JSONRequest request,
AsyncCallback<JSONResponse> callback)
Asynchronously invoke a request on an agent. |
|
void |
setConfig(Config config)
Get the loaded config file |
|
static void |
setEnvironment(String env)
Programmatically set the environment |
|
void |
setSchedulerFactory(Config config)
Load a scheduler factory from a config file |
|
void |
setSchedulerFactory(SchedulerFactory schedulerFactory)
Set a scheduler factory. |
|
void |
setStateFactory(Config config)
Load a state factory from config |
|
void |
setStateFactory(StateFactory stateFactory)
Set a state factory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AgentFactory()
public AgentFactory(Config config) throws Exception
config
-
Exception
Method Detail |
---|
public static AgentFactory getInstance()
public static AgentFactory getInstance(String namespace)
namespace
- If null, "default" namespace will be loaded.
public static AgentFactory createInstance() throws Exception
Exception
public static AgentFactory createInstance(Config config) throws Exception
config
-
Exception
public static AgentFactory createInstance(String namespace) throws Exception
namespace
-
Exception
public static AgentFactory createInstance(String namespace, Config config) throws Exception
namespace
- If null, "default" namespace will be loaded.config
- If null, a non-configured AgentFactory will be
created.
Exception
public Agent getAgent(String agentId) throws Exception
agentId
-
Exception
public <T> T createAgentProxy(String senderId, String receiverUrl, Class<T> agentInterface)
senderId
- Internal id of the sender agent.
Not required for all transport services
(for example not for outgoing HTTP requests)receiverUrl
- Url of the receiving agentagentInterface
- A java Interface, extending AgentInterface
public Agent createAgent(String agentType, String agentId) throws Exception
agentType
- full class pathagentId
-
Exception
public Agent createAgent(Class<?> agentType, String agentId) throws Exception
agentType
- agentId
-
Exception
public void deleteAgent(String agentId) throws Exception
agentId
-
Exception
public boolean hasAgent(String agentId) throws Exception
agentId
-
Exception
public EventLogger getEventLogger()
public JSONResponse invoke(String receiverId, JSONRequest request, RequestParams requestParams) throws Exception
receiverId
- Id of the receiver agentrequest
- requestParams
-
Exception
public JSONResponse send(String senderId, String receiverUrl, JSONRequest request) throws Exception
senderId
- Internal id of the sender agent
Not required for all transport services
(for example not for outgoing HTTP requests)receiverUrl
- request
-
Exception
public void sendAsync(String senderId, String receiverUrl, JSONRequest request, AsyncCallback<JSONResponse> callback) throws Exception
senderId
- Internal id of the sender agent.
Not required for all transport services
(for example not for outgoing HTTP requests)receiverUrl
- request
- callback
-
Exception
public static String getEnvironment()
public static void setEnvironment(String env)
env
- The environment, for example "Production" or "Development"public void setConfig(Config config)
public Config getConfig()
public void setStateFactory(Config config)
config
-
Exception
public void addAgents(Config config)
config
- public void setStateFactory(StateFactory stateFactory)
stateFactory
- public StateFactory getStateFactory() throws Exception
Exception
public void setSchedulerFactory(Config config)
config
-
Exception
public void addTransportServices(Config config)
config
- public void addTransportService(TransportService transportService)
transportService
- public void removeTransportService(TransportService transportService)
transportService
- public List<TransportService> getTransportServices()
public List<TransportService> getTransportServices(String protocol)
protocol
- A protocol, for example "http" or "xmpp"
public TransportService getTransportService(String protocol)
protocol
- A protocol, for example "http" or "xmpp"
public List<Object> getMethods(Agent agent, Boolean asJSON)
public void setSchedulerFactory(SchedulerFactory schedulerFactory)
schedulerFactory
- public Scheduler getScheduler(String agentId)
agentId
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |