groovyx.gpars.agent
Class AgentCore

java.lang.Object
  extended by groovyx.gpars.agent.AgentCore
Direct Known Subclasses:
AgentBase

public abstract class AgentCore
extends java.lang.Object

Author:
Vaclav Pech Date: 13.4.2010

Field Summary
private  AsyncMessagingCore core
           
private  java.util.List<java.lang.Throwable> errors
          Holds agent errors
 
Constructor Summary
protected AgentCore()
           
 
Method Summary
 void attachToThreadPool(Pool threadPool)
          Sets a new thread pool to be used by the agent
 void call(java.lang.Object message)
          Adds the message to the agent\s message queue
 java.util.List<java.lang.Throwable> getErrors()
          Retrieves a list of exception thrown within the agent's body.
(package private) abstract  void handleMessage(java.lang.Object message)
          Dynamically dispatches the method call
 boolean hasErrors()
          Indicates whether there have been exception thrown within the agent's body.
 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 leftShift(java.lang.Object message)
          Adds the message to the agent\s message queue
 void makeFair()
          Makes the agent fair.
(package private)  void registerError(java.lang.Throwable e)
          Adds the exception to the list of thrown exceptions
 void send(java.lang.Object message)
          Adds the message to the agent\s message queue
 void setPGroup(groovyx.gpars.group.PGroup pGroup)
          Sets an actor group to use for task scheduling
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

core

private final AsyncMessagingCore core

errors

private java.util.List<java.lang.Throwable> errors
Holds agent errors

Constructor Detail

AgentCore

protected AgentCore()
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

setPGroup

public void setPGroup(groovyx.gpars.group.PGroup pGroup)
Sets an actor group to use for task scheduling

Parameters:
pGroup - The pGroup to use

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.


send

public final void send(java.lang.Object message)
Adds the message to the agent\s message queue

Parameters:
message - A value or a closure

leftShift

public final void leftShift(java.lang.Object message)
Adds the message to the agent\s message queue

Parameters:
message - A value or a closure

call

public final void call(java.lang.Object message)
Adds the message to the agent\s message queue

Parameters:
message - A value or a closure

handleMessage

abstract void handleMessage(java.lang.Object message)
Dynamically dispatches the method call

Parameters:
message - A value or a closure

registerError

void registerError(java.lang.Throwable e)
Adds the exception to the list of thrown exceptions

Parameters:
e - The exception to store

getErrors

public java.util.List<java.lang.Throwable> getErrors()
Retrieves a list of exception thrown within the agent's body. Clears the exception history

Returns:
A detached collection of exception that have occurred in the agent's body

hasErrors

public boolean hasErrors()
Indicates whether there have been exception thrown within the agent's body.

Returns:
True, if any exceptions have occurred in the agent's body

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