public abstract class AsyncMessagingCore extends java.lang.Object
Modifiers | Name | Description |
---|---|---|
private static int |
ACTIVE |
|
private static int |
PASSIVE |
|
private int |
active |
Indicates, whether there's an active thread handling a message inside the agent's body |
private static java.util.concurrent.atomic.AtomicIntegerFieldUpdater<AsyncMessagingCore> |
activeUpdater |
|
private boolean |
fair |
Fair agents give up the thread after processing each message, non-fair agents keep a thread until their message queue is empty. |
private MessageQueue |
queue |
Incoming messages |
private Pool |
threadPool |
Constructor and description |
---|
protected AsyncMessagingCore
(Pool threadPool) |
Type | Name and description |
---|---|
void |
attachToThreadPool(Pool threadPool) Sets a new thread pool to be used by the agent |
protected boolean |
continueProcessingMessages() Informs about a new thread being assigned to process the next message |
Pool |
getThreadPool() |
protected void |
handleMessage(java.lang.Object message) |
boolean |
isFair() Retrieves the agent's fairness flag Fair agents give up the thread after processing each message, non-fair agents keep a thread until their message queue is empty. |
void |
makeFair() Makes the agent fair. |
protected void |
registerError(java.lang.Throwable e) |
void |
run() Handles a single message from the message queue |
void |
schedule() Schedules processing of a next message, if there are some and if there isn't an active thread handling a message at the moment |
void |
store(java.lang.Object message) Adds the message to the agent\s message queue |
java.lang.Object |
sweepNextMessage() Removes the head of the message queue |
protected void |
threadAssigned() Informs about the thread being removed from the task |
protected void |
threadUnassigned() Informs about a new thread being assigned to process the next message |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(), java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Indicates, whether there's an active thread handling a message inside the agent's body
Fair agents give up the thread after processing each message, non-fair agents keep a thread until their message queue is empty.
Incoming messages
Sets a new thread pool to be used by the agent
threadPool
- The thread pool to useInforms about a new thread being assigned to process the next message
Retrieves the agent's fairness flag Fair agents give up the thread after processing each message, non-fair agents keep a thread until their message queue is empty. Non-fair agents tend to perform better than fair ones.
Makes the agent fair. Agents are non-fair by default. Fair agents give up the thread after processing each message, non-fair agents keep a thread until their message queue is empty. Non-fair agents tend to perform better than fair ones.
Handles a single message from the message queue
Schedules processing of a next message, if there are some and if there isn't an active thread handling a message at the moment
Adds the message to the agent\s message queue
message
- A value or a closureRemoves the head of the message queue
Informs about the thread being removed from the task
Informs about a new thread being assigned to process the next message
Copyright © 2008–2014 Václav Pech. All Rights Reserved.