org.mega.gasp.platform.impl
Class MasterApplicationInstanceImpl

java.lang.Object
  extended byorg.mega.gasp.platform.impl.MasterApplicationInstanceImpl
All Implemented Interfaces:
MasterApplicationInstance, java.lang.Runnable

public class MasterApplicationInstanceImpl
extends java.lang.Object
implements MasterApplicationInstance, java.lang.Runnable

MasterApplicationInstance represents the container of all ApplicationInstance of a specific application. So a MasterApplicationInstance contains a vector of ApplicationInstance. It contains also a vector of Session objects, representing the Actors currently using the Application. Finally it contains a vector of the Actor objects, representing a link User-Application.

Author:
PELLERIN Romain (pellerin@cnam.fr) - MEGA Project

Field Summary
private  java.util.Vector actors
           
private  int applicationID
           
private  java.util.Vector applicationInstances
           
private  byte applicationModel
           
private  java.lang.String applicationPath
           
private  int applicationTimeout
           
private  org.apache.log4j.Category cat
           
private  int masterApplicationID
           
private  int platformTimeout
           
private  java.util.Vector sessions
           
private  int timeoutCheckingDeltaTime
           
private  java.lang.Thread timeoutThread
           
 
Constructor Summary
MasterApplicationInstanceImpl(int appID, int _platformTimeout)
           
 
Method Summary
 int actorSize()
          Return the current number of Actor objects in the Actor vector.
 void addActor(Actor actor)
          Add the Actor object actor to the vector of actors in the Master Application.
 boolean addApplicationInstance(ApplicationInstance applicationInstance)
           
 int applicationInstanceSize()
          Returns the current size of the vector of ApplicationInstance objects.
private  void checkForTimeouts()
          Command the applicationInstances to treat the eventuals timeouts on their actor sessions.
 boolean containsApplicationInstance(int applicationInstanceID)
          Determine if the Application Instance associated with applicationInstanceID is hold by this Master Application.
 int createApplicationInstance(Session ownerSession, int minActors, int maxActors, java.lang.String[] actors)
          Create an Application Instance.
 int createNewSession(int aID)
          Create a new session associated with the actor ID.
 java.util.Iterator enumerateActor()
          Return the current number of Session objects in the Session vector.
 java.util.Iterator enumerateApplicationInstance()
          Returns an ApplicationInstance vector iterator.
 java.util.Iterator enumerateSession()
          Return the current number of Session objects in the Session vector.
 Actor getActor(int aID)
          Return the Actor object associated with the actorID.
 java.util.Vector getActors()
           
 ApplicationInstance getActorSessionAI(int aSID)
          Returns the ApplicationInstance object containing the ActorSession linked to the Session.
 Session getAIDAssociatedSession(int aID)
          Return the session associated to the aID.
 int getAnAIID()
          Returns a random ApplicationInstance currently not started.
 int getApplicationID()
          Returns the ID of the application managed by the Master Application Instance.
 ApplicationInstance getApplicationInstance(int applicationInstanceID)
          Returns the required ApplicationInstance object.
 byte getApplicationModel()
          Returns the ID of the application managed by the Master Application Instance.
 Session getASIDAssociatedSession(int aSID)
          Return the session associated to the Actor Session ID.
 int getMasterApplicationID()
          Returns the ID of the Master Application Instance.
 Session getSession(int sID)
          Returns the corresponding session
 java.util.Vector getSessions()
          Remove the ActorSession associciated with the session.
 boolean isActorOwner(int aID)
          Determine if the Master Application is the owner of the Actor object associated with the actorID.
 boolean isApplicationInstanceEmpty()
          Determine if the vector of ApplicationInstance objects is currently empty or not.
 boolean isSessionOwner(int sID)
          Determine if the MasterApplicationInstance is the owner of the session associated with the SessionID.
 boolean removeActor(int aID)
          Remove the Actor object associated with the actorID.
 boolean removeApplicationInstance(int applicationInstanceID)
          Remove the required Application Instance.
 boolean removeSession(int sID)
          Remove the corresponding Session object.
 void run()
           
 int sessionSize()
          Return the current number of Session objects in the Session vector.
 void unlog(int sID)
          Unlog the user represented by this ActorSession ID , delete Actor, Session, ActorSession objects linked to this user, and also the ApplicationInstance would created by this user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

applicationInstances

private java.util.Vector applicationInstances

sessions

private java.util.Vector sessions

actors

private java.util.Vector actors

applicationID

private int applicationID

masterApplicationID

private int masterApplicationID

applicationPath

private java.lang.String applicationPath

cat

private org.apache.log4j.Category cat

applicationModel

private byte applicationModel

platformTimeout

private int platformTimeout

applicationTimeout

private int applicationTimeout

timeoutCheckingDeltaTime

private final int timeoutCheckingDeltaTime
See Also:
Constant Field Values

timeoutThread

private java.lang.Thread timeoutThread
Constructor Detail

MasterApplicationInstanceImpl

public MasterApplicationInstanceImpl(int appID,
                                     int _platformTimeout)
Method Detail

getMasterApplicationID

public int getMasterApplicationID()
Returns the ID of the Master Application Instance.

Specified by:
getMasterApplicationID in interface MasterApplicationInstance
Returns:
MasterApplicationID

getApplicationID

public int getApplicationID()
Returns the ID of the application managed by the Master Application Instance.

Specified by:
getApplicationID in interface MasterApplicationInstance
Returns:
MasterApplicationID

getApplicationModel

public byte getApplicationModel()
Returns the ID of the application managed by the Master Application Instance.

Specified by:
getApplicationModel in interface MasterApplicationInstance
Returns:
MasterApplicationID

createApplicationInstance

public int createApplicationInstance(Session ownerSession,
                                     int minActors,
                                     int maxActors,
                                     java.lang.String[] actors)
Create an Application Instance.

Specified by:
createApplicationInstance in interface MasterApplicationInstance
Parameters:
ownerSession - the Session object representing the actor who create the Application Instance.
minActors - represents the minimum number of actors required to start the Application Instance.
maxActors - represents the maximum number of actors can play this Application Instance.
actors - if the Application Instance is private this vector contains the required actors else if it is a public Application Instance this vector is empty.
Returns:
applicationInstanceID the ID of the Application Instance created.

getApplicationInstance

public ApplicationInstance getApplicationInstance(int applicationInstanceID)
Returns the required ApplicationInstance object.

Specified by:
getApplicationInstance in interface MasterApplicationInstance
Parameters:
applicationInstanceID - the ID of the required Application Instance
Returns:
applicationInstance the object representing the Application Instance

removeApplicationInstance

public boolean removeApplicationInstance(int applicationInstanceID)
Remove the required Application Instance.

Specified by:
removeApplicationInstance in interface MasterApplicationInstance
Parameters:
applicationInstanceID -
Returns:
boolean telling us if the remove was correctly done or not.

isApplicationInstanceEmpty

public boolean isApplicationInstanceEmpty()
Determine if the vector of ApplicationInstance objects is currently empty or not.

Specified by:
isApplicationInstanceEmpty in interface MasterApplicationInstance
Returns:
boolean telling us if the vector is empty or not.

enumerateApplicationInstance

public java.util.Iterator enumerateApplicationInstance()
Returns an ApplicationInstance vector iterator.

Specified by:
enumerateApplicationInstance in interface MasterApplicationInstance
Returns:
iterator

containsApplicationInstance

public boolean containsApplicationInstance(int applicationInstanceID)
Determine if the Application Instance associated with applicationInstanceID is hold by this Master Application.

Specified by:
containsApplicationInstance in interface MasterApplicationInstance
Parameters:
applicationInstanceID -
Returns:
boolean

applicationInstanceSize

public int applicationInstanceSize()
Returns the current size of the vector of ApplicationInstance objects.

Specified by:
applicationInstanceSize in interface MasterApplicationInstance
Returns:
nbApplicationInstance

getAnAIID

public int getAnAIID()
Returns a random ApplicationInstance currently not started.

Specified by:
getAnAIID in interface MasterApplicationInstance
Returns:
the ID of an ApplicationInstance object

getASIDAssociatedSession

public Session getASIDAssociatedSession(int aSID)
Return the session associated to the Actor Session ID.

Specified by:
getASIDAssociatedSession in interface MasterApplicationInstance
Parameters:
aSID - the ActorSession ID
Returns:
the Session object associated

getAIDAssociatedSession

public Session getAIDAssociatedSession(int aID)
Return the session associated to the aID.

Specified by:
getAIDAssociatedSession in interface MasterApplicationInstance
Parameters:
aID -
Returns:
the Session object associated

unlog

public void unlog(int sID)
Unlog the user represented by this ActorSession ID , delete Actor, Session, ActorSession objects linked to this user, and also the ApplicationInstance would created by this user.

Specified by:
unlog in interface MasterApplicationInstance
Parameters:
sID - the Session ID

getActorSessionAI

public ApplicationInstance getActorSessionAI(int aSID)
Returns the ApplicationInstance object containing the ActorSession linked to the Session.

Specified by:
getActorSessionAI in interface MasterApplicationInstance
Parameters:
aSID - the session ID
Returns:
the ApplicationInstance object

createNewSession

public int createNewSession(int aID)
Create a new session associated with the actor ID.

Specified by:
createNewSession in interface MasterApplicationInstance
Parameters:
aID - the actor ID
Returns:
the ID of the session created

getSession

public Session getSession(int sID)
Returns the corresponding session

Specified by:
getSession in interface MasterApplicationInstance
Parameters:
sID - the session ID
Returns:
the Session object

removeSession

public boolean removeSession(int sID)
Remove the corresponding Session object.

Specified by:
removeSession in interface MasterApplicationInstance
Parameters:
sID -
Returns:
boolean

isSessionOwner

public boolean isSessionOwner(int sID)
Determine if the MasterApplicationInstance is the owner of the session associated with the SessionID.

Specified by:
isSessionOwner in interface MasterApplicationInstance
Parameters:
sID - the Session ID
Returns:
boolean

sessionSize

public int sessionSize()
Return the current number of Session objects in the Session vector.

Specified by:
sessionSize in interface MasterApplicationInstance
Returns:
the number of sessions

enumerateSession

public java.util.Iterator enumerateSession()
Return the current number of Session objects in the Session vector.

Specified by:
enumerateSession in interface MasterApplicationInstance
Returns:
iterator on Session vector

addActor

public void addActor(Actor actor)
Add the Actor object actor to the vector of actors in the Master Application.

Specified by:
addActor in interface MasterApplicationInstance
Parameters:
actor - the Actor object to add

getActor

public Actor getActor(int aID)
Return the Actor object associated with the actorID.

Specified by:
getActor in interface MasterApplicationInstance
Parameters:
aID - the actor ID
Returns:
the Actor object

removeActor

public boolean removeActor(int aID)
Remove the Actor object associated with the actorID.

Specified by:
removeActor in interface MasterApplicationInstance
Parameters:
aID - the actor ID
Returns:
boolean representing the success of the operation

isActorOwner

public boolean isActorOwner(int aID)
Determine if the Master Application is the owner of the Actor object associated with the actorID.

Specified by:
isActorOwner in interface MasterApplicationInstance
Parameters:
aID - the actor ID
Returns:
boolean

actorSize

public int actorSize()
Return the current number of Actor objects in the Actor vector.

Specified by:
actorSize in interface MasterApplicationInstance
Returns:
the number of actors

enumerateActor

public java.util.Iterator enumerateActor()
Return the current number of Session objects in the Session vector.

Specified by:
enumerateActor in interface MasterApplicationInstance
Returns:
iterator on Actor vector

getSessions

public java.util.Vector getSessions()
Remove the ActorSession associciated with the session.

Specified by:
getSessions in interface MasterApplicationInstance
Returns:
boolean representing the operation success

getActors

public java.util.Vector getActors()
Specified by:
getActors in interface MasterApplicationInstance

addApplicationInstance

public boolean addApplicationInstance(ApplicationInstance applicationInstance)

run

public void run()
Specified by:
run in interface java.lang.Runnable

checkForTimeouts

private void checkForTimeouts()
Command the applicationInstances to treat the eventuals timeouts on their actor sessions.