org.codehaus.gpars

groovyx.gpars.util
[Java] Class AsyncMessagingCore

java.lang.Object
  groovyx.gpars.util.AsyncMessagingCore
All Implemented Interfaces:
java.lang.Runnable

public abstract class AsyncMessagingCore
extends java.lang.Object

Authors:
Vaclav Pech Date: Aug 23, 2010


Field Summary
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 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 Summary
protected AsyncMessagingCore(Pool threadPool)

 
Method Summary
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 java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#wait(long, int), 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()
 

Field Detail

ACTIVE

private static final int ACTIVE


PASSIVE

private static final int PASSIVE


active

@SuppressWarnings({"FieldMayBeFinal", "unused"}) //  TODO:  Eclipse requires this to be tagged as unused.
private int active
Indicates, whether there's an active thread handling a message inside the agent's body


activeUpdater

private static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater activeUpdater


fair

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.


queue

private final MessageQueue queue
Incoming messages


threadPool

private Pool threadPool


 
Constructor Detail

AsyncMessagingCore

protected AsyncMessagingCore(Pool threadPool)


 
Method Detail

attachToThreadPool

public final void attachToThreadPool(Pool threadPool)
Sets a new thread pool to be used by the agent
Parameters:
threadPool - The thread pool to use


continueProcessingMessages

protected boolean continueProcessingMessages()
Informs about a new thread being assigned to process the next message
Returns:
True, if the calculation should proceed


getThreadPool

Pool getThreadPool()


handleMessage

protected void handleMessage(java.lang.Object message)


isFair

public 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. Non-fair agents tend to perform better than fair ones.
Returns:
True for fair agents, false for non-fair ones. Agents are non-fair by default.


makeFair

public void makeFair()
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.


registerError

protected void registerError(java.lang.Throwable e)


run

@Override
@SuppressWarnings({"CatchGenericClass", "ThrowCaughtLocally", "OverlyBroadCatchBlock"})
public final void run()
Handles a single message from the message queue


schedule

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


store

public void store(java.lang.Object message)
Adds the message to the agent\s message queue
Parameters:
message - A value or a closure


sweepNextMessage

public java.lang.Object sweepNextMessage()
Removes the head of the message queue
Returns:
The head message, or null, if the message queue is empty


threadAssigned

@SuppressWarnings({"NoopMethodInAbstractClass"})
protected void threadAssigned()
Informs about the thread being removed from the task


threadUnassigned

@SuppressWarnings({"NoopMethodInAbstractClass"})
protected void threadUnassigned()
Informs about a new thread being assigned to process the next message


 

Copyright © 2008–2010 Václav Pech. All Rights Reserved.