public class AgentRunner
extends java.lang.Object
implements java.lang.Runnable, java.lang.AutoCloseable
Agent
which is run on a Thread
.
Note: An instance should only be started once and then discarded, it should not be reused.
Modifier and Type | Field and Description |
---|---|
static java.lang.Thread |
TOMBSTONE
Indicates that the runner is being closed.
|
Constructor and Description |
---|
AgentRunner(IdleStrategy idleStrategy,
ErrorHandler errorHandler,
AtomicCounter errorCounter,
Agent agent)
Create an agent runner and initialise it.
|
Modifier and Type | Method and Description |
---|---|
Agent |
agent()
The
Agent which is contained |
void |
close()
Stop the running Agent and cleanup.
|
void |
close(int retryCloseTimeoutMs,
java.util.function.Consumer<java.lang.Thread> onCloseTimeoutFunction)
Stop the running Agent and cleanup.
|
boolean |
isClosed()
Has the
Agent been closed? |
void |
run()
Run an
Agent . |
static java.lang.Thread |
startOnThread(AgentRunner runner)
Start the given agent runner on a new thread.
|
static java.lang.Thread |
startOnThread(AgentRunner runner,
java.util.concurrent.ThreadFactory threadFactory)
Start the given agent runner on a new thread.
|
java.lang.Thread |
thread()
Get the thread which is running that
Agent . |
public static final java.lang.Thread TOMBSTONE
public AgentRunner(IdleStrategy idleStrategy, ErrorHandler errorHandler, AtomicCounter errorCounter, Agent agent)
idleStrategy
- to use for Agent run looperrorHandler
- 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 static java.lang.Thread startOnThread(AgentRunner runner)
runner
- the agent runner to startpublic static java.lang.Thread startOnThread(AgentRunner runner, java.util.concurrent.ThreadFactory threadFactory)
runner
- the agent runner to start.threadFactory
- the factory to use to create the thread.public java.lang.Thread thread()
Agent
.
If null then the runner has not been started. If TOMBSTONE
then the runner is being closed.
Agent
.public void run()
run
in interface java.lang.Runnable
public final void close()
This is equivalent to calling close(int, Consumer)
using the default RETRY_CLOSE_TIMEOUT_MS
value and a
null action.
close
in interface java.lang.AutoCloseable
public final void close(int retryCloseTimeoutMs, java.util.function.Consumer<java.lang.Thread> onCloseTimeoutFunction)
This will wait for the work loop to exit. The close timeout parameter controls how long we should wait before retrying to stop the agent by interrupting the thread.
An optional action can be invoked whenever we time out while waiting which accepts the agent runner thread as the parameter (e.g. to obtain and log a stack trace from the thread). If the action is null, a message is written to standard output. Please note that a retry close timeout of zero waits indefinitely, therefore the close timeout action is never called.
retryCloseTimeoutMs
- how long to wait before retryingonCloseTimeoutFunction
- function to invoke before retrying after close timeoutCopyright © 2014-2018 Real Logic Ltd. All Rights Reserved.