|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.curjent.impl.agent.Messengers
final class Messengers
Runs messengers in background threads. Each messenger has an associated task to execute agent calls.
Controller
,
AgentTasks
,
Executor
Field Summary | |
---|---|
private boolean |
busy
true when the last attempt to acquire a task was
unsuccessful. |
private static ThreadLocal<Messenger> |
current
The Messenger , if any, associated with the current thread. |
(package private) static Executor |
DEFAULT_EXECUTOR
Default executor for running messengers in background threads. |
private Executor |
executor
Current executor for starting new messengers. |
private boolean |
pending
true while the executor starts up a new messenger. |
(package private) AgentTasks |
tasks
Source for agent tasks. |
private HashSet<Thread> |
threads
The set of threads running messengers. |
Constructor Summary | |
---|---|
Messengers(AgentTasks tasks)
Initializes the messengers. |
Method Summary | |
---|---|
(package private) static Messenger |
current()
Returns the messenger associated with the current thread or null if none. |
(package private) Executor |
getExecutor()
Returns the current executor. |
(package private) boolean |
isExecutorBusy()
Returns true if an execute operation is
pending. |
(package private) boolean |
isTasksBusy()
Returns true if the last call acquire returned
null . |
(package private) void |
release(Messenger messenger)
Releases a messenger and its task. |
(package private) void |
setExecutor(Executor executor)
Changes the executor. |
(package private) void |
start(Controller controller)
Attempts to start a new messenger. |
(package private) boolean |
startable()
Returns true if neither the tasks nor the executor is busy. |
(package private) void |
started(Messenger messenger)
Clears the pending flag. |
(package private) Thread[] |
threads()
Returns the set of threads running messengers or null if
none. |
String |
toString()
Returns the number of executing threads. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
static final Executor DEFAULT_EXECUTOR
Agent.getDefaultExecutor()
final AgentTasks tasks
private volatile Executor executor
AgentConfig.getExecutor()
private boolean busy
true
when the last attempt to acquire a task was
unsuccessful. No more messengers can start while busy
.
Cleared when a messenger is released.
AgentTasks.acquire()
,
release(Messenger)
private boolean pending
true
while the executor starts up a new messenger. Cleared
after the messenger starts. No more messengers can start while
pending
. This prevents too many threads starting up too
quickly with not enough to do.
Executor.execute(Runnable)
,
Messenger.run()
private static final ThreadLocal<Messenger> current
Messenger
, if any, associated with the current thread.
private final HashSet<Thread> threads
Constructor Detail |
---|
Messengers(AgentTasks tasks)
Method Detail |
---|
boolean startable()
true
if neither the tasks nor the executor is busy.
boolean isTasksBusy()
true
if the last call acquire
returned
null
.
boolean isExecutorBusy()
true
if an execute
operation is
pending.
void start(Controller controller) throws Throwable
busy
or pending
. Otherwise, attempts to acquire a new
task. If AgentTasks.acquire()
returns null
, sets the
busy
flag and returns. If a task is returned, a new
Messenger
is started with the executor and pending
is set to true
.
Throwable
void started(Messenger messenger)
pending
flag. Called when a pending Messenger
starts running.
Messenger.run()
void release(Messenger messenger) throws Throwable
busy
flag. Called
when no messages are currently available for the messenger to execute.
Throwable
Thread[] threads()
null
if
none.
static Messenger current()
null
if none.
Executor getExecutor()
AgentConfig.getExecutor()
void setExecutor(Executor executor)
NullPointerException
- executor
is null
.AgentConfig.setExecutor(Executor)
public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |