aa.core
Class Platform

java.lang.Object
  extended byjava.lang.Thread
      extended byaa.tool.SystemThread
          extended byaa.core.Platform
All Implemented Interfaces:
java.lang.Runnable

public class Platform
extends SystemThread

This class represents an actor platform.

History:

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

Field Summary
static boolean bDEBUG
          Indicates whether debuging messages are printed on the screen.
static boolean bERROR
          Indicates whether error messages are printed on the screen.
static java.util.Hashtable g_htCreators
          Hasth table to be used for delivering a name of a new actor from the actor thread class to the actor behavior class
private static int ID_DF
           
private static int ID_PLATFORM
           
private  ActorManager m_amActorManager
           
private  ActorName m_anDirectoryManager
           
private  ActorName m_anPlatform
           
private  CyberOrgManager m_comCyberOrgManager
           
private  int m_iAppActorStartID
           
private static int m_iID_AGENT
           
private static int m_iID_MSG
           
private  MessageManager m_mmMessageManager
           
private  MigrationManager m_mmMigrationManager
           
private static Platform m_pPlatform
           
private  Queue m_qMsgQueue
           
private static java.lang.String m_strHostAddress
           
private  View m_viewMain
           
static java.lang.String MSG_CREATE_ACTOR
          Actor communicaiton message that requests an actor creation.
static java.lang.String MSG_DEREGISTER_AGENT
          Actor communication message that indicates that a mobile actor is destroyed, and hence, information about the agnet should be removed.
static java.lang.String MSG_RECEIVE_AGENT
          Actor communication message that includes a mobile actor.
static java.lang.String MSG_TRANSITION_END
          Actor communication message that indicates that a mobile actor finishes its migration.
static java.lang.String MSG_TRANSITION_START
          Actor communication message that indicates that a mobile actor starts its migration.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Platform(View p_viewMain, java.lang.Integer p_intPort)
          Creates a mulit-actor platform.
 
Method Summary
 void afterMigrateActor(ActorName p_anActor, java.lang.Thread p_thread)
          This method is called in remote CyberOrg Migration, after migrating an actor, we need to insert it to the destination cyberorg, reallocate resource to it through the local scheduler
protected  void becomeActor(ActorThread p_athreadCaller, Queue p_qMsgQueue, boolean[] p_baFlags, java.lang.String p_strActorClass, java.lang.Object[] p_objaArgs)
          Change the behavior of an actor.
 void changePortNumber(java.lang.Integer p_intPort)
          Changes the port number for the Transprot Manager.
 ActorName createActor(ActorName p_anCreator, java.lang.String p_strActorClass, java.lang.Object[] p_objaArgs)
          Create an Actor.
 ActorName createActor(java.lang.String p_strActorClass, java.lang.Object[] p_objaArgs)
          Creates an actor.
 java.lang.Object createCyberOrg(java.lang.Long p_longTicks, java.lang.Long p_longTicksRate, java.lang.Long p_longECash, java.lang.String p_strFacilitatorClass, java.lang.Object[] p_objaAgs)
          Create root cyberorg, default CyberOrg class: aa.core.CyberOrg
 java.lang.Object createCyberOrg(java.lang.String p_strCyberOrgClass, java.lang.Object[] p_objaAgs)
          Create root cyberorg, using user defined cyberorg class
private static ActorName createNewActorName()
          Creates a new actor name.
private  void createRemoteActor(ActorMessage p_amMsg)
          Creates a remote actor.
protected static java.lang.String creteMessageID()
          Creates a new message ID.
 void disactiveCyberOrg(CyberOrg p_cybToDisactive)
           
 CyberOrg findBestDestination()
           
private  java.lang.reflect.Constructor findConstructor(java.lang.Class p_classActor, java.lang.Object[] p_objaArgs)
          Finds a proper constructor.
 ActorName getActorNameOfPlatform()
          Returns the actor name of this platform.
 ActorName getActorNameOfPlatform(java.lang.String p_strHostName)
          Returns the actor name of the specified platform.
 int getAppActorStartID()
          Returns the start number for identifications of application actors.
protected  ActorName getDefaultDirectoryManager()
          Returns the name of the default Direcotry Manager actor.
protected  ActorName getDefaultDirectoryManager(java.lang.String p_strHostName)
          Returns the name of the default Direcotry Manager actor of the specified platform.
protected  java.lang.String getHostAddress()
          Returns the Inet adress of this platform.
protected static Platform getPlatform()
          Returns the reference of this platform.
protected  void init()
          Processes some necessay routines before entering the while loop in the run method .
 void killActor(ActorName p_anToKill)
           
 void localMigrate(CyberOrg p_cybToMigrate, ActorName p_anDestFacilitator, Contract p_conContract)
          Local migrate it is called when a cyberorg is migrating to a local destination cyberorg
 CyberOrg lookupHost(java.lang.Object p_objFacilitator)
           
 void migrateActor(ActorName p_anActor, java.net.InetAddress p_iaDestHost)
          Migrates the specified actor to a different host.
protected  void processMessage(ActorMessage p_amMsg)
          Processes a communcation message.
 void reactiveCyberOrg(CyberOrg p_cybToActive)
          These two methods are called when a cyberorg runs out of resource, and when it gets more resources and can be scheduled again.
protected  void registerActor(ActorThread p_athread, java.lang.Integer p_intState)
          Registers an actor thread to the Actor Manager of this platform.
 void registerActorCyb(java.lang.Object p_anActor, CyberOrg p_cybHost)
          Register actor and its host to the CyberOrgManager it is called in remote migration
 void registerCyberOrg(CyberOrg p_coToBeRegistered)
           
 void remoteMigrate(CyberOrg p_cybToMigrate, ActorName p_anDestFacilitator, Contract p_conContract)
          Remote migrate it is called when a cyberorg is migrating to a remote destination cyberorg
protected  void removeActor(ActorName p_anActor)
          Removes the specified actor from the Actor Manager.
 void removeCyberOrg(CyberOrg p_coToBeRemoved)
           
protected  void reportFailure(java.lang.String p_strMsg)
          Reports that starting this platform fails.
protected  void reportMessage(ActorMessage p_amMsg)
          Reports a message.
 boolean resAlloc(ActorName p_anToAlloc, long rateAssign)
          Reallocate resource for specific actor called by cyberorg isolate
 long returnRes(ActorName p_anActor)
          Resource Return to old host by the actors called by cyberorg isolate
 void sendMessage(ActorMessage p_amMsg)
          Sends a message through the Message manager.
 void uninit()
          Uninitializes this program.
protected  void updateActor(ActorThread p_athread, java.lang.Integer p_intState)
          Updates information about an actor on the Actor Manager.
 
Methods inherited from class aa.tool.SystemThread
deliverMessage, run
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

bDEBUG

public static final boolean bDEBUG
Indicates whether debuging messages are printed on the screen.

See Also:
Constant Field Values

bERROR

public static final boolean bERROR
Indicates whether error messages are printed on the screen.

See Also:
Constant Field Values

MSG_DEREGISTER_AGENT

public static final java.lang.String MSG_DEREGISTER_AGENT
Actor communication message that indicates that a mobile actor is destroyed, and hence, information about the agnet should be removed.

See Also:
Constant Field Values

MSG_RECEIVE_AGENT

public static final java.lang.String MSG_RECEIVE_AGENT
Actor communication message that includes a mobile actor.

See Also:
Constant Field Values

MSG_TRANSITION_START

public static final java.lang.String MSG_TRANSITION_START
Actor communication message that indicates that a mobile actor starts its migration.

See Also:
Constant Field Values

MSG_TRANSITION_END

public static final java.lang.String MSG_TRANSITION_END
Actor communication message that indicates that a mobile actor finishes its migration.

See Also:
Constant Field Values

MSG_CREATE_ACTOR

public static final java.lang.String MSG_CREATE_ACTOR
Actor communicaiton message that requests an actor creation.

See Also:
Constant Field Values

g_htCreators

public static java.util.Hashtable g_htCreators
Hasth table to be used for delivering a name of a new actor from the actor thread class to the actor behavior class


ID_PLATFORM

private static final int ID_PLATFORM
See Also:
Constant Field Values

ID_DF

private static final int ID_DF
See Also:
Constant Field Values

m_pPlatform

private static Platform m_pPlatform

m_iID_AGENT

private static int m_iID_AGENT

m_strHostAddress

private static java.lang.String m_strHostAddress

m_iID_MSG

private static int m_iID_MSG

m_iAppActorStartID

private int m_iAppActorStartID

m_anPlatform

private ActorName m_anPlatform

m_qMsgQueue

private Queue m_qMsgQueue

m_viewMain

private View m_viewMain

m_amActorManager

private ActorManager m_amActorManager

m_mmMessageManager

private MessageManager m_mmMessageManager

m_mmMigrationManager

private MigrationManager m_mmMigrationManager

m_anDirectoryManager

private ActorName m_anDirectoryManager

m_comCyberOrgManager

private CyberOrgManager m_comCyberOrgManager
Constructor Detail

Platform

public Platform(View p_viewMain,
                java.lang.Integer p_intPort)
Creates a mulit-actor platform.

Parameters:
p_viewMain - the reference to View
p_intPort - the port number of a server socket for in-coming messages
Method Detail

reportFailure

protected void reportFailure(java.lang.String p_strMsg)
Reports that starting this platform fails.
This method is called by the Platform constructor, or the init method, or the Message Manager.

Parameters:
p_strMsg - a message to describe the reason of a failure.

init

protected void init()
Processes some necessay routines before entering the while loop in the run method .
This is called by the run method of the super class.

Specified by:
init in class SystemThread

uninit

public void uninit()
Uninitializes this program.
This method is called by the 'View' class.


processMessage

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

Specified by:
processMessage in class SystemThread
Parameters:
p_amMsg - the communication message.

createNewActorName

private static ActorName createNewActorName()
Creates a new actor name.

Returns:
a new actor name.

creteMessageID

protected static java.lang.String creteMessageID()
Creates a new message ID.

Returns:
a new message ID.

getPlatform

protected static Platform getPlatform()
Returns the reference of this platform.

Returns:
the reference of this platform.

getAppActorStartID

public int getAppActorStartID()
Returns the start number for identifications of application actors.
This method is called by the 'View' class.

Returns:
the start number for identifications of application actors.

getHostAddress

protected java.lang.String getHostAddress()
Returns the Inet adress of this platform.

Returns:
the Inet adress of this platform.

getActorNameOfPlatform

public ActorName getActorNameOfPlatform()
Returns the actor name of this platform.

Returns:
the actor name of this platform.

getActorNameOfPlatform

public ActorName getActorNameOfPlatform(java.lang.String p_strHostName)
Returns the actor name of the specified platform.

Parameters:
p_strHostName - the host address of a platform.
Returns:
the actor name of this platform or the specified paltform if the platform exists;
null otherwise.

getDefaultDirectoryManager

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

Returns:
the name of the default Directory Manager actor.

getDefaultDirectoryManager

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

Parameters:
p_strHostName - the host address of a platform.
Returns:
the name of the default Directory Manager of the specified platform if the platform exists;
null otherwise.

createRemoteActor

private void createRemoteActor(ActorMessage p_amMsg)
Creates a remote actor.
This method is initiated by an actor on another platform, and it is called by the processMessage method.

Parameters:
p_amMsg - the communication message.

createActor

public ActorName createActor(java.lang.String p_strActorClass,
                             java.lang.Object[] p_objaArgs)
                      throws CreateActorException
Creates an actor.
This method is called by either an actor thread or GUI.

Parameters:
p_strActorClass - the class of an actor to be created.
p_objaArgs - arguments of the constructor of the actor.
Returns:
the name of a new actor.
Throws:
CreateActorException - it occurs when actor creation fails.

createActor

public ActorName createActor(ActorName p_anCreator,
                             java.lang.String p_strActorClass,
                             java.lang.Object[] p_objaArgs)
Create an Actor. It is called by an actor thread. We want to know the creator, in order to put the new actor into the same cyberorg as the creator is in


becomeActor

protected void becomeActor(ActorThread p_athreadCaller,
                           Queue p_qMsgQueue,
                           boolean[] p_baFlags,
                           java.lang.String p_strActorClass,
                           java.lang.Object[] p_objaArgs)
                    throws BecomeActorException
Change the behavior of an actor.
This method is called by an actor.

Parameters:
p_athreadCaller - the name of an actor thread that called this method.
p_baFlags - the internal state flag of the caller actor.
p_strActorClass - the class name of a new actor to be replaced.
p_objaArgs - arguments of the constructor of the new actor.
Returns:
the name of a new actor.
Throws:
CreateActorException - it occurs when actor creation fails.
BecomeActorException

sendMessage

public void sendMessage(ActorMessage p_amMsg)
Sends a message through the Message manager.
When the platform receives a message from an actor or other components, it delivers the message to the Message manager that will deliver the message to the receiver actor.

Parameters:
p_amMsg - an actor communication message.

registerActor

protected void registerActor(ActorThread p_athread,
                             java.lang.Integer p_intState)
Registers an actor thread to the Actor Manager of this platform.
This method is (should be) called by an actor thread or the Migration Manager of this platform.

Parameters:
p_athread - the reference to an actor thread.
p_intState - an actor state.

updateActor

protected void updateActor(ActorThread p_athread,
                           java.lang.Integer p_intState)
Updates information about an actor on the Actor Manager.
This method is (should be) called by an actor thread.

Parameters:
p_athread - reference to an actor thread.
p_intState - actor state.

removeActor

protected void removeActor(ActorName p_anActor)
Removes the specified actor from the Actor Manager.
This method is (shoule be) called by an actor thread.

Parameters:
p_anActor - Actor Name of the selected actor.

migrateActor

public void migrateActor(ActorName p_anActor,
                         java.net.InetAddress p_iaDestHost)
                  throws MigrateActorException
Migrates the specified actor to a different host.
This method is (should be) called by the actor.

Parameters:
p_anActor - the name of an actor to be moved.
p_iaDestHost - the Internet address of the destination host.
Throws:
MigrateActorException - it occurs when an exception happens during the actor migration.

changePortNumber

public void changePortNumber(java.lang.Integer p_intPort)
Changes the port number for the Transprot Manager.
This method is called by the 'View' class.

Parameters:
p_intPort - the new port number for transport manager.

reportMessage

protected void reportMessage(ActorMessage p_amMsg)
Reports a message.

Parameters:
p_amMsg - an actor communicaiton message.

createCyberOrg

public java.lang.Object createCyberOrg(java.lang.Long p_longTicks,
                                       java.lang.Long p_longTicksRate,
                                       java.lang.Long p_longECash,
                                       java.lang.String p_strFacilitatorClass,
                                       java.lang.Object[] p_objaAgs)
Create root cyberorg, default CyberOrg class: aa.core.CyberOrg


createCyberOrg

public java.lang.Object createCyberOrg(java.lang.String p_strCyberOrgClass,
                                       java.lang.Object[] p_objaAgs)
Create root cyberorg, using user defined cyberorg class


registerCyberOrg

public void registerCyberOrg(CyberOrg p_coToBeRegistered)

removeCyberOrg

public void removeCyberOrg(CyberOrg p_coToBeRemoved)

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 createCyberOrg 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.

returnRes

public long returnRes(ActorName p_anActor)
Resource Return to old host by the actors called by cyberorg isolate


resAlloc

public boolean resAlloc(ActorName p_anToAlloc,
                        long rateAssign)
Reallocate resource for specific actor called by cyberorg isolate


localMigrate

public void localMigrate(CyberOrg p_cybToMigrate,
                         ActorName p_anDestFacilitator,
                         Contract p_conContract)
Local migrate it is called when a cyberorg is migrating to a local destination cyberorg


remoteMigrate

public void remoteMigrate(CyberOrg p_cybToMigrate,
                          ActorName p_anDestFacilitator,
                          Contract p_conContract)
Remote migrate it is called when a cyberorg is migrating to a remote destination cyberorg


registerActorCyb

public void registerActorCyb(java.lang.Object p_anActor,
                             CyberOrg p_cybHost)
Register actor and its host to the CyberOrgManager it is called in remote migration


afterMigrateActor

public void afterMigrateActor(ActorName p_anActor,
                              java.lang.Thread p_thread)
This method is called in remote CyberOrg Migration, after migrating an actor, we need to insert it to the destination cyberorg, reallocate resource to it through the local scheduler


lookupHost

public CyberOrg lookupHost(java.lang.Object p_objFacilitator)

killActor

public void killActor(ActorName p_anToKill)

reactiveCyberOrg

public void reactiveCyberOrg(CyberOrg p_cybToActive)
These two methods are called when a cyberorg runs out of resource, and when it gets more resources and can be scheduled again.


disactiveCyberOrg

public void disactiveCyberOrg(CyberOrg p_cybToDisactive)

findBestDestination

public CyberOrg findBestDestination()