org.mega.gasp.platform.impl
Class ApplicationInstanceImpl

java.lang.Object
  extended byorg.mega.gasp.platform.impl.ApplicationInstanceImpl
All Implemented Interfaces:
ApplicationInstance, OnDataEvent, OnEndEvent, OnEvent, OnJoinEvent, OnQuitEvent, OnStartEvent

public class ApplicationInstanceImpl
extends java.lang.Object
implements ApplicationInstance, OnJoinEvent, OnStartEvent, OnEndEvent, OnDataEvent, OnQuitEvent

ApplicationInstance represent a game session of a specific application. It contains a vector of ActorSession representing the actors want to play in. This classes manage the in game events.

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

Field Summary
private  java.util.Vector actorSessions
           
private  int applicationInstanceID
           
private  java.lang.String applicationInstanceName
           
private  byte applicationModel
           
private  org.apache.log4j.Category cat
           
private  CustomTypes customTypes
           
private  boolean isPublicAI
           
private  boolean isRunningAI
           
private  java.util.Vector listeners
           
private  MasterApplicationInstance masterApp
           
private  int maxA
           
private  int minA
           
private  int ownerActorSessionID
           
private  GASPServer server
           
private  boolean toDestroy
           
 
Constructor Summary
ApplicationInstanceImpl(MasterApplicationInstance masterApplication, Session ownerSession, int minActors, int maxActors, java.lang.String[] actors, java.lang.String path, byte model)
           
 
Method Summary
 int actorSessionSize()
          Returns the current number of ActorSession objects, e.g the number of actors ready to play this game session.
private  void addActors(java.lang.String[] actors)
          Set the pool of actors required for a private Application Instance.
 boolean addActorSession(ActorSession actorSession)
          Add the actor to the actors vector.
 void addListener(java.lang.Object listener)
          Provides to add a listener on events of application instance.
 boolean containsActorSession(int actorSessionID)
          Determine if the ActorSession associated with the ActorSession ID is contained by this ApplicationInstance or not.
 int createNewActorSession(int aIID, Session session)
          Create a new ActorSession in the ApplicationInstance corresponding to the user Session object informations.
 java.util.Iterator enumerateActorSession()
          Returns an iterator on the actor sessions vector.
 ActorSession getActorSession(int actorSessionID)
          Returns the ActorSession object corresponding to the ActorSession ID.
 int getApplicationInstanceID()
          Returns the ID of the ApplicationInstance.
 ApplicationInstanceInfos getApplicationInstanceInfos()
          For Lobby service, this method provide informations of the ApplicationInstance.
 java.lang.String getApplicationInstanceName()
          Returns the name of the ApplicationInstance.
 CustomTypes getCustomTypes()
          Returns the encoder of the application associated with the application instance.
 int getMaxActors()
          Returns the maximum number of actors can play the game session.
 int getMinActors()
          Returns the minimum number of actors required to start the game session.
 int getOwnerAID()
          Returns the ActorId of the ApplicationInstanceID owner.
 GASPServer getServer()
          Returns the server associated with the ApplicationInstance.
 boolean isActorSessionEmpty()
          Determine if the vector of ActorSession objects is empty or not.
 boolean isDestroyable()
          Determine if the owner master application can destroy or not the AI.
 boolean isJoinable()
          Determine if the the application instance is joignable by a player or not, eg if: the AI is not destroyable the AI is not running the max of players is reached
 boolean isPublic()
          Determine if the ApplicationInstance is public or not.
 boolean isRunning()
          Determine if the ApplicationInstance is running or not.
 boolean isStartable()
          Determine if the the application instance is startable by the player owner or not.
private  void notifyDataToListeners(DataEvent e)
          Raise the DataEvent to all external listenners, in particular the game server logic thread.
private  void notifyEndToListeners(EndEvent e)
          Raise the EndEvent to all external listenners, in particular the game server logic thread.
private  void notifyJoinToListeners(JoinEvent e)
          Raise the JoinEvent to all external listenners, in particular the game server logic thread.
private  void notifyQuitToListeners(QuitEvent e)
          Raise the QuitEvent to all external listenners, in particular the game server logic thread.
private  void notifyStartToListeners(StartEvent e)
          Raise the StartEvent to all external listenners, in particular the game server logic thread.
private  void notifyToAllOtherActorSession(Event e)
          Put the event in event vectors of the ApplicationInstance ActorSessions.
 void onDataEvent(DataEvent e)
          When a DataEvent arrives, notify to all listeners.
 void onEndEvent(EndEvent e)
          When a EndEvent arrives, if the actor session ID of the event is the ownerASID then notify to all listeners and to all other actor sessions else do nothing.
 void onJoinEvent(JoinEvent e)
          When a JoinEvent arrives, notify to all listeners and to all other actor sessions
 void onQuitEvent(QuitEvent qe)
          When a QuitEvent arrives, then notify to all listeners and to all other actor sessions
 void onStartEvent(StartEvent e)
          When a StartEvent arrives, if the actor session ID of the event is the ownerASID then notify to all listeners and to all other actor sessions else do nothing.
 void raisePseudoModification(int actorSessionID, java.lang.String pseudoname)
          Raise a JoinEvent to all other players containing the new pseudo
 boolean removeActorSession(int actorSessionID)
          Remove the ActorSession object corresponding to the ActorSessionID.
 int retrieveApplicationID()
          Retrieve the applicationID from the master application instance.
 void sendDataToActorSession(int actorSessionID, DataEvent dataEvent)
          Send a dataEvent to a specific actorSession.
private  void sendPlayersInfos(ActorSession actorSession)
          This method provide the new player to know all of the players currently in the application instance.
 void sendPlayersInfos(int aSID)
          This method provide the new player to know all of the players currently in the application instance.
 void setApplicationInstanceName(java.lang.String appInstanceName)
          Specify the name of the Application Instance.
 java.lang.String treatPseudo(java.lang.String name)
          If the pseudo already exist in the AI modify it, else no modifications.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

actorSessions

private java.util.Vector actorSessions

applicationInstanceID

private int applicationInstanceID

masterApp

private MasterApplicationInstance masterApp

ownerActorSessionID

private int ownerActorSessionID

minA

private int minA

maxA

private int maxA

applicationInstanceName

private java.lang.String applicationInstanceName

isPublicAI

private boolean isPublicAI

isRunningAI

private boolean isRunningAI

listeners

private java.util.Vector listeners

customTypes

private CustomTypes customTypes

server

private GASPServer server

cat

private org.apache.log4j.Category cat

applicationModel

private byte applicationModel

toDestroy

private boolean toDestroy
Constructor Detail

ApplicationInstanceImpl

public ApplicationInstanceImpl(MasterApplicationInstance masterApplication,
                               Session ownerSession,
                               int minActors,
                               int maxActors,
                               java.lang.String[] actors,
                               java.lang.String path,
                               byte model)
Method Detail

getServer

public GASPServer getServer()
Returns the server associated with the ApplicationInstance.

Specified by:
getServer in interface ApplicationInstance
Returns:
the MGP server

getApplicationInstanceID

public int getApplicationInstanceID()
Returns the ID of the ApplicationInstance.

Specified by:
getApplicationInstanceID in interface ApplicationInstance
Returns:
the ApplicationInstanceID

getMinActors

public int getMinActors()
Returns the minimum number of actors required to start the game session.

Specified by:
getMinActors in interface ApplicationInstance
Returns:
the minimum number of actors

getMaxActors

public int getMaxActors()
Returns the maximum number of actors can play the game session.

Specified by:
getMaxActors in interface ApplicationInstance
Returns:
the maximum number of actors

getOwnerAID

public int getOwnerAID()
Returns the ActorId of the ApplicationInstanceID owner.

Specified by:
getOwnerAID in interface ApplicationInstance
Returns:
the Actor ID

getCustomTypes

public CustomTypes getCustomTypes()
Returns the encoder of the application associated with the application instance.

Specified by:
getCustomTypes in interface ApplicationInstance
Returns:
the Actor ID

isPublic

public boolean isPublic()
Determine if the ApplicationInstance is public or not.

Specified by:
isPublic in interface ApplicationInstance
Returns:
boolean

isRunning

public boolean isRunning()
Determine if the ApplicationInstance is running or not.

Specified by:
isRunning in interface ApplicationInstance
Returns:
boolean

isDestroyable

public boolean isDestroyable()
Determine if the owner master application can destroy or not the AI.

Specified by:
isDestroyable in interface ApplicationInstance
Returns:
boolean

isJoinable

public boolean isJoinable()
Determine if the the application instance is joignable by a player or not, eg if: the AI is not destroyable the AI is not running the max of players is reached

Specified by:
isJoinable in interface ApplicationInstance
Returns:
boolean

isStartable

public boolean isStartable()
Determine if the the application instance is startable by the player owner or not.

Specified by:
isStartable in interface ApplicationInstance
Returns:
boolean

createNewActorSession

public int createNewActorSession(int aIID,
                                 Session session)
Create a new ActorSession in the ApplicationInstance corresponding to the user Session object informations. Returns the ActorSession ID.

Specified by:
createNewActorSession in interface ApplicationInstance
Parameters:
aIID - the ApplicationInstance
session - the Session object of the user
Returns:
the ActorSession ID

sendPlayersInfos

public void sendPlayersInfos(int aSID)
This method provide the new player to know all of the players currently in the application instance.

Specified by:
sendPlayersInfos in interface ApplicationInstance
Parameters:
aSID - the actor session associated to the player

sendPlayersInfos

private void sendPlayersInfos(ActorSession actorSession)
This method provide the new player to know all of the players currently in the application instance.

Parameters:
actorSession - the actor session associated to the player

getActorSession

public ActorSession getActorSession(int actorSessionID)
Returns the ActorSession object corresponding to the ActorSession ID.

Specified by:
getActorSession in interface ApplicationInstance
Parameters:
actorSessionID - the ActorSession ID
Returns:
the ActorSession object

removeActorSession

public boolean removeActorSession(int actorSessionID)
Remove the ActorSession object corresponding to the ActorSessionID.

Specified by:
removeActorSession in interface ApplicationInstance
Parameters:
actorSessionID - the ActorSesion ID
Returns:
boolean representing the operation success

isActorSessionEmpty

public boolean isActorSessionEmpty()
Determine if the vector of ActorSession objects is empty or not.

Specified by:
isActorSessionEmpty in interface ApplicationInstance
Returns:
boolean "empty or not"

actorSessionSize

public int actorSessionSize()
Returns the current number of ActorSession objects, e.g the number of actors ready to play this game session.

Specified by:
actorSessionSize in interface ApplicationInstance
Returns:
the number of actors

containsActorSession

public boolean containsActorSession(int actorSessionID)
Determine if the ActorSession associated with the ActorSession ID is contained by this ApplicationInstance or not.

Specified by:
containsActorSession in interface ApplicationInstance
Parameters:
actorSessionID -
Returns:
boolean "present or not"

getApplicationInstanceInfos

public ApplicationInstanceInfos getApplicationInstanceInfos()
For Lobby service, this method provide informations of the ApplicationInstance.

Specified by:
getApplicationInstanceInfos in interface ApplicationInstance
Returns:
an ApplicationInstanceInfos object

getApplicationInstanceName

public java.lang.String getApplicationInstanceName()
Returns the name of the ApplicationInstance.

Returns:
the name of the AI

enumerateActorSession

public java.util.Iterator enumerateActorSession()
Returns an iterator on the actor sessions vector.

Specified by:
enumerateActorSession in interface ApplicationInstance
Returns:
iterator on ActorSession vector

addActors

private void addActors(java.lang.String[] actors)
Set the pool of actors required for a private Application Instance.

Parameters:
actors - the table of actorID

setApplicationInstanceName

public void setApplicationInstanceName(java.lang.String appInstanceName)
Specify the name of the Application Instance.

Specified by:
setApplicationInstanceName in interface ApplicationInstance
Parameters:
appInstanceName -

addActorSession

public boolean addActorSession(ActorSession actorSession)
Add the actor to the actors vector.

Specified by:
addActorSession in interface ApplicationInstance
Parameters:
actorSession - the ActorSession object
Returns:
boolean of the operation success

onJoinEvent

public void onJoinEvent(JoinEvent e)
When a JoinEvent arrives, notify to all listeners and to all other actor sessions

Specified by:
onJoinEvent in interface OnJoinEvent

onStartEvent

public void onStartEvent(StartEvent e)
When a StartEvent arrives, if the actor session ID of the event is the ownerASID then notify to all listeners and to all other actor sessions else do nothing.

Specified by:
onStartEvent in interface OnStartEvent

onEndEvent

public void onEndEvent(EndEvent e)
When a EndEvent arrives, if the actor session ID of the event is the ownerASID then notify to all listeners and to all other actor sessions else do nothing.

Specified by:
onEndEvent in interface OnEndEvent

onQuitEvent

public void onQuitEvent(QuitEvent qe)
When a QuitEvent arrives, then notify to all listeners and to all other actor sessions

Specified by:
onQuitEvent in interface OnQuitEvent

onDataEvent

public void onDataEvent(DataEvent e)
When a DataEvent arrives, notify to all listeners.

Specified by:
onDataEvent in interface OnDataEvent

addListener

public void addListener(java.lang.Object listener)
Provides to add a listener on events of application instance.

Parameters:
listener - the object to become a listener

notifyToAllOtherActorSession

private void notifyToAllOtherActorSession(Event e)
Put the event in event vectors of the ApplicationInstance ActorSessions.

Parameters:
e - the event

notifyJoinToListeners

private void notifyJoinToListeners(JoinEvent e)
Raise the JoinEvent to all external listenners, in particular the game server logic thread.

Parameters:
e - the JoinEvent

notifyEndToListeners

private void notifyEndToListeners(EndEvent e)
Raise the EndEvent to all external listenners, in particular the game server logic thread.

Parameters:
e - the EndEvent

notifyStartToListeners

private void notifyStartToListeners(StartEvent e)
Raise the StartEvent to all external listenners, in particular the game server logic thread.

Parameters:
e - the StartEvent

notifyQuitToListeners

private void notifyQuitToListeners(QuitEvent e)
Raise the QuitEvent to all external listenners, in particular the game server logic thread.

Parameters:
e - the QuitEvent

notifyDataToListeners

private void notifyDataToListeners(DataEvent e)
Raise the DataEvent to all external listenners, in particular the game server logic thread.

Parameters:
e - the DataEvent

sendDataToActorSession

public void sendDataToActorSession(int actorSessionID,
                                   DataEvent dataEvent)
Send a dataEvent to a specific actorSession.

Specified by:
sendDataToActorSession in interface ApplicationInstance
Parameters:
actorSessionID -
dataEvent -

treatPseudo

public java.lang.String treatPseudo(java.lang.String name)
If the pseudo already exist in the AI modify it, else no modifications.

Specified by:
treatPseudo in interface ApplicationInstance
Parameters:
name -
Returns:
valid pseudo name

raisePseudoModification

public void raisePseudoModification(int actorSessionID,
                                    java.lang.String pseudoname)
Raise a JoinEvent to all other players containing the new pseudo

Specified by:
raisePseudoModification in interface ApplicationInstance
Parameters:
actorSessionID -

retrieveApplicationID

public int retrieveApplicationID()
Retrieve the applicationID from the master application instance.

Specified by:
retrieveApplicationID in interface ApplicationInstance