Package org.agrona.concurrent
Class CompositeAgent
- java.lang.Object
-
- org.agrona.concurrent.CompositeAgent
-
-
Field Summary
Fields Modifier and Type Field Description private int
agentIndex
private Agent[]
agents
private java.lang.String
roleName
-
Constructor Summary
Constructors Constructor Description CompositeAgent(java.util.List<? extends Agent> agents)
CompositeAgent(Agent... agents)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
doWork()
An agent should implement this method to do its work.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.
-
-
-
Field Detail
-
agents
private final Agent[] agents
-
roleName
private final java.lang.String roleName
-
agentIndex
private int agentIndex
-
-
Constructor Detail
-
CompositeAgent
public CompositeAgent(java.util.List<? extends Agent> agents)
- Parameters:
agents
- the parts of this composite, at least one agent and no null agents allowed- Throws:
java.lang.IllegalArgumentException
- if an empty array of agents is providedjava.lang.NullPointerException
- if the array or any element is null
-
CompositeAgent
public CompositeAgent(Agent... agents)
- Parameters:
agents
- the parts of this composite, at least one agent and no null agents allowed- Throws:
java.lang.IllegalArgumentException
- if an empty array of agents is provided, or single agent providedjava.lang.NullPointerException
- if the array or any element is null
-
-
Method Detail
-
roleName
public java.lang.String roleName()
Get the name of this agent's role.
-
onStart
public void onStart()
To be overridden by Agents that need to do resource init on start.This method will be called by the agent thread once on start.
Note that one agent throwing an exception on start will not prevent other agents from being started.
-
doWork
public int doWork() throws java.lang.Exception
An agent should implement this method to do its work.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.
-
onClose
public void onClose()
To be overridden by Agents that need to do resource cleanup on close.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 will not prevent other agents from being closed.
-
-