Package org.agrona.concurrent
Interface Agent
- All Known Implementing Classes:
CompositeAgent
,DynamicCompositeAgent
public interface Agent
-
Method Summary
Modifier and TypeMethodDescriptionint
doWork()
An agent should implement this method to do its work.default void
onClose()
To be overridden by Agents that need to do resource cleanup on close.default void
onStart()
To be overridden by Agents that need to do resource init on start.roleName()
Get the name of this agent's role.
-
Method Details
-
onStart
default 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.
-
doWork
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.- Returns:
- 0 to indicate no work was currently available, a positive value otherwise.
- Throws:
Exception
- if an error has occurred
-
onClose
default 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.
-
roleName
String roleName()Get the name of this agent's role.- Returns:
- the name of this agent's role.
-