Modifier and Type | Class and Description |
---|---|
static class |
DynamicCompositeAgent.Status |
Constructor and Description |
---|
DynamicCompositeAgent(java.lang.String roleName)
Construct a new composite that has no
Agent s to begin with. |
DynamicCompositeAgent(java.lang.String roleName,
Agent... agents) |
DynamicCompositeAgent(java.lang.String roleName,
java.util.List<? extends Agent> agents) |
Modifier and Type | Method and Description |
---|---|
int |
doWork()
An agent should implement this method to do its work.
|
boolean |
hasAddAgentCompleted()
Has the last successful
tryAdd(Agent) operation been processed in the doWork() cycle? |
boolean |
hasRemoveAgentCompleted()
Has the last
tryRemove(Agent) operation been processed in the doWork() cycle? |
void |
onClose()
To be overridden by Agents that need to do resource cleanup on close.
|
void |
onStart()
To be overridden by Agents that need to do resource init on start.
|
java.lang.String |
roleName()
Get the name of this agent's role.
|
DynamicCompositeAgent.Status |
status()
Get the
DynamicCompositeAgent.Status for the Agent. |
boolean |
tryAdd(Agent agent)
Try and add a new
Agent to the composite. |
boolean |
tryRemove(Agent agent)
Try and remove an
Agent from the composite. |
public DynamicCompositeAgent(java.lang.String roleName)
Agent
s to begin with.roleName
- to be given for Agent.roleName()
.public DynamicCompositeAgent(java.lang.String roleName, java.util.List<? extends Agent> agents)
roleName
- to be given for Agent.roleName()
.agents
- the parts of this composite, at least one agent and no null agents allowedjava.lang.NullPointerException
- if the array or any element is nullpublic DynamicCompositeAgent(java.lang.String roleName, Agent... agents)
roleName
- to be given for Agent.roleName()
.agents
- the parts of this composite, at least one agent and no null agents allowedjava.lang.NullPointerException
- if the array or any element is nullpublic DynamicCompositeAgent.Status status()
DynamicCompositeAgent.Status
for the Agent.DynamicCompositeAgent.Status
for the Agent.public void onStart()
This method will be called by the agent thread thread once on start..
Note that one agent throwing an exception on start may result in other agents not being started.
public int doWork() throws java.lang.Exception
Agent
The return value is used for implementing a backoff strategy that can be employed when no work is currently available for the agent to process.
If the Agent wished to terminate and close then a AgentTerminationException
can be thrown.
public void onClose()
This method will be called after the agent thread has terminated or if the agent is closed before it runs.
Note that one agent throwing an exception on close may result in other agents not being closed.
public java.lang.String roleName()
Agent
public boolean tryAdd(Agent agent)
Agent
to the composite. This method does not block and will return false if another
concurrent attempt to add is in progress.
The agent will be added during the next invocation of doWork()
if this operation is successful.
If the Agent.onStart()
method throws an exception then it will not be added and Agent.onClose()
will be called.
agent
- to be added to the composite.hasAddAgentCompleted()
public boolean hasAddAgentCompleted()
tryAdd(Agent)
operation been processed in the doWork()
cycle?tryAdd(Agent)
operation been processed in the doWork()
cycle?tryAdd(Agent)
public boolean tryRemove(Agent agent)
Agent
from the composite. The agent is removed during the next doWork()
duty cycle if this operation is successful. This method does not block and will return false if another
concurrent attempt to remove is in progress..
The Agent
is removed by identity. Only the first found is removed.
agent
- to be removed.hasRemoveAgentCompleted()
public boolean hasRemoveAgentCompleted()
tryRemove(Agent)
operation been processed in the doWork()
cycle?tryRemove(Agent)
operation been processed in the doWork()
cycle?tryRemove(Agent)
Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.