aa.core
Class ActorThread

java.lang.Object
  extended byaa.core.ActorThread
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable

public class ActorThread
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable

This class describes an actor thread. An actor thread works with an Actor (behavior) class.

History

Version:
$Date: 2008/01/01 00:23:49 $ $Revision: 1.1 $
Author:
Myeong-Wuk Jang
See Also:
Serialized Form

Field Summary
private  Actor m_actorBehavior
           
private  ActorName m_anActorName
           
private  boolean m_bDestroy
           
private  boolean m_bMigrate
           
protected  boolean m_bRetire
           
private  boolean m_bSuspend
           
private  java.lang.Class m_classActor
           
private  java.util.Hashtable m_htMethods
           
private  java.net.InetAddress m_iaDestHost
           
private  Platform m_pPlatform
           
private  Queue m_qMsgQueue
           
private  java.lang.String m_strClassName
           
private  java.lang.String m_strLastErrorMessage
           
 
Constructor Summary
ActorThread(ActorName p_anActor, boolean p_bCreate)
          Creates an actor thread.
 
Method Summary
protected  void becomeActor(java.lang.String p_strClassName, java.lang.Object[] p_objaArgs)
          Change the behavior of this actor.
protected  java.lang.Object callMessage(ActorName p_anReceiver, java.lang.String p_strMethod, java.lang.Object[] p_objaArgs)
          Sends an out-going message, and wait the response.
protected  ActorName createActor(java.lang.String p_strClassName, java.lang.Object[] p_objaArgs)
          Creates a new actor.
private  void createMethodTable()
          Creates a method table.
protected  ActorName createRemoteActor(java.lang.String p_strHost, java.lang.String p_strClassName, java.lang.Object[] p_objaArgs)
          Create a new actor on a remote system.
protected  void deliverMessage(ActorMessage p_amMsg)
          Inserts a message into the mail queue of this actor, and wakes up sleeping actors.
protected  void destroyActor()
          Destroys this actor thread.
private  java.lang.reflect.Constructor findConstructor(java.lang.Class p_classActor, java.lang.Object[] p_objaArgs)
          Finds a proper constructor.
protected  java.lang.String getActorClassName()
          Returns the class name of this actor.
 ActorName getActorName()
          Returns the name of this actor.
protected  ActorName getDefaultDirectoryManager()
          Returns the actor name of the default Direcotry Manager actor.
protected  ActorName getDefaultDirectoryManager(java.lang.String p_strHostName)
          Returns The actor name of the default Direcotry Manager actor on the specified host.
protected  java.lang.String getLastErrorMessage()
          Returns the last error message of asynchronous operations.
protected  void initAfterMigration()
          Re-initialize after actor migration.
protected  void kill()
          Kills this actor.
protected  void migrateActor(java.net.InetAddress p_iaDestHost)
          Initializes the migration of this actor.
protected  void processMessage(ActorMessage p_amMsg)
          Processes a communication message.
protected  void resume()
          Resumes this actor.
 void run()
          Executes the main loop of this thread.
protected  void sendMessage(ActorName p_anReceiver, java.lang.String p_strMethod, java.lang.Object[] p_objaArgs)
          Sends an out-going message to the sepcified actor.
protected  void setBehavior(java.lang.String p_strActorClass, java.lang.Object[] p_objaArgs, Queue p_qMsgQueue)
          Sets the behavior of this actor thread.
protected  void setLastErrorMessage(java.lang.String p_strMsg)
          Sets the error message of an asynchronous operation.
protected  void suspend()
          Suspends this actor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_anActorName

private ActorName m_anActorName

m_classActor

private java.lang.Class m_classActor

m_strClassName

private java.lang.String m_strClassName

m_actorBehavior

private Actor m_actorBehavior

m_strLastErrorMessage

private java.lang.String m_strLastErrorMessage

m_iaDestHost

private java.net.InetAddress m_iaDestHost

m_bSuspend

private boolean m_bSuspend

m_bMigrate

private boolean m_bMigrate

m_bDestroy

private boolean m_bDestroy

m_bRetire

protected boolean m_bRetire

m_qMsgQueue

private Queue m_qMsgQueue

m_htMethods

private transient java.util.Hashtable m_htMethods

m_pPlatform

private transient Platform m_pPlatform
Constructor Detail

ActorThread

public ActorThread(ActorName p_anActor,
                   boolean p_bCreate)
Creates an actor thread.

Parameters:
p_anActor - an actor name of this actor.
Method Detail

findConstructor

private java.lang.reflect.Constructor findConstructor(java.lang.Class p_classActor,
                                                      java.lang.Object[] p_objaArgs)
                                               throws java.lang.NoSuchMethodException
Finds a proper constructor.
This method is called by the setBehavior method.

Parameters:
p_classActor - the class of an actor to be created.
p_objaArgs - arguments of the constructor of the actor.
Returns:
constructor of a new actor.
Throws:
java.lang.NoSuchMethodException - it occurs when the construct cannot be found.

createMethodTable

private void createMethodTable()
Creates a method table.
This method is called by the setBehavior or initAfterMigration.


setBehavior

protected void setBehavior(java.lang.String p_strActorClass,
                           java.lang.Object[] p_objaArgs,
                           Queue p_qMsgQueue)
                    throws ActorException
Sets the behavior of this actor thread.

Parameters:
p_strActorClass - the behavior class of an actor to be created.
p_objaArgs - arguments of the constructor of the actor behavior.
p_qMsgQueue - reference to a message queue to be used in this actor.
Throws:
CreateActorException - it occurs when actor creation fails.
ActorException

initAfterMigration

protected void initAfterMigration()
Re-initialize after actor migration.


run

public void run()
Executes the main loop of this thread.

Specified by:
run in interface java.lang.Runnable

processMessage

protected void processMessage(ActorMessage p_amMsg)
Processes a communication message.


deliverMessage

protected void deliverMessage(ActorMessage p_amMsg)
Inserts a message into the mail queue of this actor, and wakes up sleeping actors.
This method is called by the Message Manager thread. That is, the control of this method is occupied by the Message Manager thread.

Parameters:
p_amMsg - an actor communication message.

suspend

protected void suspend()
Suspends this actor.
This method is directly called by an Actor Manager.


resume

protected void resume()
Resumes this actor.
This method is directly called by an Actor Manager.


kill

protected void kill()
Kills this actor.
This method is directly called by an Actor Manager.


getActorName

public ActorName getActorName()
Returns the name of this actor.

Returns:
the name of this actor.

getActorClassName

protected java.lang.String getActorClassName()
Returns the class name of this actor.

Returns:
the class name of this actor.

setLastErrorMessage

protected void setLastErrorMessage(java.lang.String p_strMsg)
Sets the error message of an asynchronous operation.
This method is called by a Migration Manager.

Parameters:
p_strMsg - the error message of an asynchronous operation.

getLastErrorMessage

protected java.lang.String getLastErrorMessage()
Returns the last error message of asynchronous operations.

Returns:
the last error message of asynchronous operations.

getDefaultDirectoryManager

protected ActorName getDefaultDirectoryManager()
Returns the actor name of the default Direcotry Manager actor.

Returns:
The actor name of the default Directory Manager actor.

getDefaultDirectoryManager

protected ActorName getDefaultDirectoryManager(java.lang.String p_strHostName)
Returns The actor name of the default Direcotry Manager actor on the specified host.

Parameters:
p_strHostName - the specified host.
Returns:
The actor name of the default Directory Manager actor on the specified host.

createActor

protected ActorName createActor(java.lang.String p_strClassName,
                                java.lang.Object[] p_objaArgs)
                         throws CreateActorException
Creates a new actor.
This method is called by the 'create' method.

Parameters:
p_strClassName - the class name of a new actor.
p_objaArgs - an array of arguments of a new actor.
Returns:
The actor name of a new actor.
Throws:
CreateActorException

createRemoteActor

protected ActorName createRemoteActor(java.lang.String p_strHost,
                                      java.lang.String p_strClassName,
                                      java.lang.Object[] p_objaArgs)
                               throws CreateActorException
Create a new actor on a remote system.

Parameters:
p_strHost - the host name of a new actor.
p_strClassName - the class name of a new actor.
p_objaArgs - an array of arguments of a new actor.
Returns:
The actor name of a new actor.
Throws:
CreateActorException

becomeActor

protected void becomeActor(java.lang.String p_strClassName,
                           java.lang.Object[] p_objaArgs)
                    throws BecomeActorException
Change the behavior of this actor.
This method is called by the 'become' method.

Parameters:
p_strClassName - the class name of a new actor.
p_objaArgs - an array of arguments of a new actor.
Returns:
The name of a new actor.
Throws:
BecomeActorException

sendMessage

protected void sendMessage(ActorName p_anReceiver,
                           java.lang.String p_strMethod,
                           java.lang.Object[] p_objaArgs)
Sends an out-going message to the sepcified actor.
This method is called by the 'send' method.

Parameters:
p_anReceiver - the name of the receiver actor of this message.
p_strMethod - a message (or method) name (or type).
p_objaArgs - a set of argument objects.

callMessage

protected java.lang.Object callMessage(ActorName p_anReceiver,
                                       java.lang.String p_strMethod,
                                       java.lang.Object[] p_objaArgs)
                                throws CommunicationException
Sends an out-going message, and wait the response.
This method is called by the 'call' method.

Parameters:
p_anReceiver - the name of the receiver actor of this message.
p_strMethod - a message (or method) name (or type).
p_objaArgs - a set of argument objects.
Returns:
object to be returned.
Throws:
CommunicationException - if an error happens while synchoronous message is processed.

migrateActor

protected void migrateActor(java.net.InetAddress p_iaDestHost)
Initializes the migration of this actor.
This method is called by the 'migrate' method of the Actor class.

Parameters:
p_iaDestHost - the Inet address of the destination host where this actor migrate.

destroyActor

protected void destroyActor()
Destroys this actor thread.
This method is called by the 'destroy' method of the Actor class.