org.mega.gasp.platform.impl
Class PlatformImpl

java.lang.Object
  extended byorg.mega.gasp.platform.impl.PlatformImpl
All Implemented Interfaces:
Platform

public class PlatformImpl
extends java.lang.Object
implements Platform

Platform is the base of the GAming Services Platform(GASP), the container of all GP representing objects. So it contains all MasterApplicationInstance objects in a vector. It hold all of the service instances (Lobby,...) and system instances (DB manager, ID manager, ...).

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

Field Summary
 org.apache.log4j.Category cat
           
private  DBManager dbManager
           
 boolean gaspDBOK
           
 boolean gaspInstanciationOK
           
protected  java.lang.String home_path
           
private  IDManager idManager
           
private  Lobby lobby
           
private  java.util.Vector masterApplicationInstances
           
protected  int platformTimeout
           
private  PropertiesReader propertiesReader
           
private static PlatformImpl singleton
           
 
Constructor Summary
private PlatformImpl(java.lang.String path)
           
 
Method Summary
private  boolean addMasterApplicationInstance(MasterApplicationInstance masterAppInstance)
          Add the created MasterApplication to the MasterApplications vector.
private  int alreadyLogged(int aID)
          Return the sID of the user requiring to log in if he's already logged, else 0.
 boolean containsMasterApplicationInstance(int applicationID)
          Determine if the MasterApplicationInstance of the application associated with the application ID is initialized or not.
 int createAI(int sID, int minActors, int maxActors, java.lang.String[] actors)
          Provide to a user with a valid session ID to create an ApplicationInstance with a minimum start number of actors and a maximum number of actors.
 java.util.Iterator enumerateMasterApplicationInstance()
          Returns an iterator on the MasterApplicationInstance vector.
 MasterApplicationInstance getActorOwner(int aID)
          Return the MasterApplicationInstance containing the aID.
 ApplicationInstance getActorSessionOwner(int aSID)
          Return the ApplicationInstance containing the aSID.
 DBManager getDBManager()
          Return the platform DB manager .
 IDManager getIDManager()
          Return the platform ID manager .
private  MasterApplicationInstance getLinkedSessionOwner(int aSID)
          Return the MasterApplication hosts the Session linked to the ActorSession ID.
 Lobby getLobby()
          Return the Lobby service.
 MasterApplicationInstance getMasterApplicationInstance(int applicationID)
          Returns the MasterApplicationInstance associated with the application ID or if it is not already instantiates, initialize it.
static PlatformImpl getPlatform()
           
static PlatformImpl getPlatform(java.lang.String path)
           
 PropertiesReader getPropertiesReader()
          Return the platform ID manager .
 MasterApplicationInstance getSessionOwner(int sID)
          Return the MasterApplicationInstance containing the sID.
 boolean isMasterApplicationInstanceEmpty()
          Determine if the vector of MasterApplicationInstance is empty or not.
 int joinAI(int sID, int aIID)
          Provide to a user with a valid session ID to join a specific ApplicationInstance of the application open by the user.
 int joinAIRnd(int sID)
          Provide to a user with a valid session ID to join a random ApplicationInstance corresponded to tbe application opened by the user.
 int login(int aID, java.lang.String username, java.lang.String password)
          Log a user in the platform, authentified by actorID, username and password.
 int masterApplicationInstanceSize()
          Return the number of MasterApplicationInstance currently instantiated.
 void quit(int sID)
          This method is called when a user quit the application.
private  int rejoinAI(MasterApplicationInstance masterApp, int aSID)
          Rejoin the linked AI after a deconnection.
 boolean removeMasterApplicationInstance(int applicationID)
          Remove the MasterApplicationInstance associated with the application ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleton

private static PlatformImpl singleton

lobby

private Lobby lobby

dbManager

private DBManager dbManager

idManager

private IDManager idManager

propertiesReader

private PropertiesReader propertiesReader

masterApplicationInstances

private java.util.Vector masterApplicationInstances

cat

public org.apache.log4j.Category cat

home_path

protected java.lang.String home_path

gaspDBOK

public boolean gaspDBOK

gaspInstanciationOK

public boolean gaspInstanciationOK

platformTimeout

protected int platformTimeout
Constructor Detail

PlatformImpl

private PlatformImpl(java.lang.String path)
Method Detail

getPlatform

public static PlatformImpl getPlatform()

getPlatform

public static PlatformImpl getPlatform(java.lang.String path)

getMasterApplicationInstance

public MasterApplicationInstance getMasterApplicationInstance(int applicationID)
Returns the MasterApplicationInstance associated with the application ID or if it is not already instantiates, initialize it.

Specified by:
getMasterApplicationInstance in interface Platform
Parameters:
applicationID - the application ID
Returns:
the MasterApplicationInstance object

addMasterApplicationInstance

private boolean addMasterApplicationInstance(MasterApplicationInstance masterAppInstance)
Add the created MasterApplication to the MasterApplications vector.

Parameters:
masterAppInstance -
Returns:
boolean

removeMasterApplicationInstance

public boolean removeMasterApplicationInstance(int applicationID)
Remove the MasterApplicationInstance associated with the application ID.

Specified by:
removeMasterApplicationInstance in interface Platform
Parameters:
applicationID - the application ID
Returns:
boolean of the operation success

isMasterApplicationInstanceEmpty

public boolean isMasterApplicationInstanceEmpty()
Determine if the vector of MasterApplicationInstance is empty or not.

Specified by:
isMasterApplicationInstanceEmpty in interface Platform
Returns:
boolean

masterApplicationInstanceSize

public int masterApplicationInstanceSize()
Return the number of MasterApplicationInstance currently instantiated.

Specified by:
masterApplicationInstanceSize in interface Platform
Returns:
the number of MasterApplication instances.

containsMasterApplicationInstance

public boolean containsMasterApplicationInstance(int applicationID)
Determine if the MasterApplicationInstance of the application associated with the application ID is initialized or not.

Specified by:
containsMasterApplicationInstance in interface Platform
Parameters:
applicationID -
Returns:
boolean

getLobby

public Lobby getLobby()
Return the Lobby service.

Specified by:
getLobby in interface Platform
Returns:
the Lobby object

getIDManager

public IDManager getIDManager()
Return the platform ID manager .

Specified by:
getIDManager in interface Platform
Returns:
the IDManager object

getPropertiesReader

public PropertiesReader getPropertiesReader()
Return the platform ID manager .

Specified by:
getPropertiesReader in interface Platform
Returns:
the IDManager object

getDBManager

public DBManager getDBManager()
Return the platform DB manager .

Specified by:
getDBManager in interface Platform
Returns:
the DBManager object

getSessionOwner

public MasterApplicationInstance getSessionOwner(int sID)
Return the MasterApplicationInstance containing the sID.

Specified by:
getSessionOwner in interface Platform
Parameters:
sID - the session ID
Returns:
the MasterApplicationInstance object

getActorOwner

public MasterApplicationInstance getActorOwner(int aID)
Return the MasterApplicationInstance containing the aID.

Specified by:
getActorOwner in interface Platform
Parameters:
aID - the actor ID
Returns:
the MasterApplicationInstance object

login

public int login(int aID,
                 java.lang.String username,
                 java.lang.String password)
Log a user in the platform, authentified by actorID, username and password. It consists of creating a new Session in the correct MasterApplicationInstance and return the session ID.

Specified by:
login in interface Platform
Parameters:
aID - the Actor ID attributed at the first login
username -
password -
Returns:
the SessionID of the session created or 0 if the authentification informations are not valid

alreadyLogged

private int alreadyLogged(int aID)
Return the sID of the user requiring to log in if he's already logged, else 0.

Parameters:
aID - the actor ID of the user
Returns:
the session ID

joinAI

public int joinAI(int sID,
                  int aIID)
Provide to a user with a valid session ID to join a specific ApplicationInstance of the application open by the user. Then create un ActorSession in the ApplicationInstance and return the ActorSessionID.

Specified by:
joinAI in interface Platform
Parameters:
sID - the Session ID
aIID - the ApplicationInstance ID
Returns:
the ActorSession ID

rejoinAI

private int rejoinAI(MasterApplicationInstance masterApp,
                     int aSID)
Rejoin the linked AI after a deconnection.

Parameters:
masterApp -

enumerateMasterApplicationInstance

public java.util.Iterator enumerateMasterApplicationInstance()
Description copied from interface: Platform
Returns an iterator on the MasterApplicationInstance vector.

Specified by:
enumerateMasterApplicationInstance in interface Platform
Returns:
iterator

joinAIRnd

public int joinAIRnd(int sID)
Provide to a user with a valid session ID to join a random ApplicationInstance corresponded to tbe application opened by the user.

Specified by:
joinAIRnd in interface Platform
Parameters:
sID - the Session ID
Returns:
the ActorSession ID

createAI

public int createAI(int sID,
                    int minActors,
                    int maxActors,
                    java.lang.String[] actors)
Provide to a user with a valid session ID to create an ApplicationInstance with a minimum start number of actors and a maximum number of actors. The ApplicationInstance status is: "public": if the table of actors is empty. "private": if the table of actors contains some Actor ID. Returns the ID of the ApplicationInstance created.

Specified by:
createAI in interface Platform
Parameters:
sID - the Session ID
minActors - minimum number of actors for starting
maxActors - maximum number of actors
actors - a table of Actor ID
Returns:
the ApplicationInstance ID

quit

public void quit(int sID)
This method is called when a user quit the application. ActorSession, Session, Actor instances corresponding to the user are removed.

Specified by:
quit in interface Platform
Parameters:
sID - the Session ID

getLinkedSessionOwner

private MasterApplicationInstance getLinkedSessionOwner(int aSID)
Return the MasterApplication hosts the Session linked to the ActorSession ID.

Parameters:
aSID - the ActorSessionID
Returns:
the MasterApplication

getActorSessionOwner

public ApplicationInstance getActorSessionOwner(int aSID)
Return the ApplicationInstance containing the aSID.

Specified by:
getActorSessionOwner in interface Platform
Parameters:
aSID - the actor session ID
Returns:
the MasterApplicationInstance object