public class AgentInvoker
extends java.lang.Object
implements java.lang.AutoCloseable
Agent
container which does not start a thread. It instead allows the duty cycle Agent.doWork()
to be
invoked directly. start()
should be called to allow the Agent.onStart()
to fire before any calls
to invoke()
of the agent duty cycle.
Exceptions which occur during the Agent.doWork()
invocation will be caught and passed to the provided
ErrorHandler
.
Note: This class is not threadsafe.
Constructor and Description |
---|
AgentInvoker(ErrorHandler errorHandler,
AtomicCounter errorCounter,
Agent agent)
Create an agent and initialise it.
|
Modifier and Type | Method and Description |
---|---|
Agent |
agent()
The
Agent which is contained. |
void |
close()
Mark the invoker as closed and call the
Agent.onClose() logic for clean up. |
int |
invoke()
Invoke the
Agent.doWork() method and return the work count. |
boolean |
isClosed()
Has the
Agent been closed? |
boolean |
isRunning()
Has the
Agent been running? |
boolean |
isStarted()
Has the
Agent been started? |
void |
start()
Mark the invoker as started and call the
Agent.onStart() method. |
public AgentInvoker(ErrorHandler errorHandler, AtomicCounter errorCounter, Agent agent)
errorHandler
- to be called if an Throwable
is encounterederrorCounter
- to be incremented each time an exception is encountered. This may be null.agent
- to be run in this thread.public boolean isStarted()
Agent
been started?Agent
been started?public boolean isRunning()
Agent
been running?Agent
been started successfully and not closed?public void start()
Agent.onStart()
method.
Startup logic will only be performed once.
public int invoke()
Agent.doWork()
method and return the work count.
If an error occurs then the AtomicCounter.increment()
will be called on the errorCounter if not null
and the Throwable
will be passed to the ErrorHandler.onError(Throwable)
method. If the error
is an AgentTerminationException
then close()
will be called after the error handler.
If not successfully started or after closed then this method will return without invoking the Agent
.
Agent.doWork()
method.public final void close()
Agent.onClose()
logic for clean up.
The clean up logic will only be performed once.
close
in interface java.lang.AutoCloseable
Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.