public abstract class AsyncMessagingCore
extends java.lang.Object
implements java.lang.Runnable
Modifier and Type | Field and Description |
---|---|
private int |
active
Indicates, whether there's an active thread handling a message inside the agent's body
|
private static int |
ACTIVE |
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 static int |
PASSIVE |
private MessageQueue |
queue
Incoming messages
|
private Pool |
threadPool |
Modifier | Constructor and Description |
---|---|
protected |
AsyncMessagingCore(Pool threadPool) |
Modifier and Type | Method 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
|
(package private) Pool |
getThreadPool() |
protected abstract 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 abstract void |
registerError(java.lang.Throwable e) |
void |
run()
Handles a single message from the message queue
|
(package private) 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
|
private Pool threadPool
private volatile boolean fair
private final MessageQueue queue
private volatile int active
private static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<AsyncMessagingCore> activeUpdater
private static final int PASSIVE
private static final int ACTIVE
protected AsyncMessagingCore(Pool threadPool)
public final void attachToThreadPool(Pool threadPool)
threadPool
- The thread pool to usePool getThreadPool()
public boolean isFair()
public void makeFair()
public void store(java.lang.Object message)
message
- A value or a closurevoid schedule()
public java.lang.Object sweepNextMessage()
public final void run()
run
in interface java.lang.Runnable
protected boolean continueProcessingMessages()
protected void threadUnassigned()
protected void threadAssigned()
protected abstract void registerError(java.lang.Throwable e)
protected abstract void handleMessage(java.lang.Object message)