org.mega.gasp.bluetooth.miniplatform
Class ApplicationInstance

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

public class ApplicationInstance
extends java.lang.Object
implements 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  CustomTypes customTypes
           
private  IDManager idManager
           
private  boolean isPublicAI
           
private  boolean isRunningAI
           
private  java.util.Vector listenners
           
private  int maxA
           
private  int minA
           
private  int ownerActorSessionID
           
 
Constructor Summary
ApplicationInstance(int actorID, int minActors, int maxActors, java.lang.String[] actors, CustomTypes encoder)
           
 
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 addListenner(java.lang.Object listenner)
           
 boolean containsActorSession(int actorSessionID)
          Determine if the ActorSession associated with the ActorSession ID is contained by this ApplicationInstance or not.
 int createNewActorSession(int aIID, int actorID)
          Create a new ActorSession in the ApplicationInstance corresponding to the user actorID.
 boolean end(int aSID)
          End the game managed by the ApplicationInstance.
 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.
 boolean isActorSessionEmpty()
          Determine if the vector of ActorSession objects is empty or not.
 boolean isPublic()
          Determine if the ApplicationInstance is public or not.
 boolean isRunning()
           
private  void notifyDataToListenners(DataEvent e)
          Raise the DataEvent to all external listenners, in particular the game logic threads.
private  void notifyEndToListenners(EndEvent e)
          Raise the EndEvent to all external listenners, in particular the game logic threads.
private  void notifyJoinToListenners(JoinEvent e)
          Raise the JoinEvent to all external listenners, in particular the game logic threads.
private  void notifyQuitToListenners(QuitEvent e)
          Raise the QuitEvent to all external listenners, in particular the game logic threads.
private  void notifyStartToListenners(StartEvent e)
          Raise the StartEvent to all external listenners, in particular the game logic threads.
private  void notifyToAllOtherActorSession(Event e)
          Put the event in event vectors of the ApplicationInstance ActorSessions.
 void onDataEvent(DataEvent e)
           
 void onEndEvent(EndEvent e)
           
 void onJoinEvent(JoinEvent e)
           
 void onQuitEvent(QuitEvent e)
           
 void onStartEvent(StartEvent e)
           
 boolean removeActorSession(int actorSessionID)
          Remove the ActorSession object corresponding to the ActorSessionID.
 void setApplicationInstanceName(java.lang.String appInstanceName)
          Specify the name of the Application Instance.
 boolean start(int aSID)
          Start the game managed by the ApplicationInstance.
 
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

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

listenners

private java.util.Vector listenners

customTypes

private CustomTypes customTypes

idManager

private IDManager idManager
Constructor Detail

ApplicationInstance

public ApplicationInstance(int actorID,
                           int minActors,
                           int maxActors,
                           java.lang.String[] actors,
                           CustomTypes encoder)
Method Detail

getApplicationInstanceID

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

Returns:
the ApplicationInstanceID

getMinActors

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

Returns:
the minimum number of actors

getMaxActors

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

Returns:
the maximum number of actors

getOwnerAID

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

Returns:
the Actor ID

getCustomTypes

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

Returns:
the Actor ID

isPublic

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

Returns:
boolean

isRunning

public boolean isRunning()

createNewActorSession

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

Parameters:
aIID - the ApplicationInstance
actorID - the actorID of the user
Returns:
the ActorSession ID

getActorSession

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

Parameters:
actorSessionID - the ActorSession ID
Returns:
the ActorSession object

removeActorSession

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

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.

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.

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.

Parameters:
actorSessionID -
Returns:
boolean "present or not"

getApplicationInstanceInfos

public ApplicationInstanceInfos getApplicationInstanceInfos()
For Lobby service, this method provide informations of the 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.

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.

Parameters:
appInstanceName -

addActorSession

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

Parameters:
actorSession - the ActorSession object
Returns:
boolean of the operation success

start

public boolean start(int aSID)
Start the game managed by the ApplicationInstance.

Parameters:
aSID - the ActorSession ID
Returns:
boolean of the operation success

end

public boolean end(int aSID)
End the game managed by the ApplicationInstance.

Parameters:
aSID - the ActorSession ID
Returns:
boolean of the operation success

onJoinEvent

public void onJoinEvent(JoinEvent e)
Specified by:
onJoinEvent in interface OnJoinEvent

onStartEvent

public void onStartEvent(StartEvent e)
Specified by:
onStartEvent in interface OnStartEvent

onEndEvent

public void onEndEvent(EndEvent e)
Specified by:
onEndEvent in interface OnEndEvent

onDataEvent

public void onDataEvent(DataEvent e)
Specified by:
onDataEvent in interface OnDataEvent

onQuitEvent

public void onQuitEvent(QuitEvent e)
Specified by:
onQuitEvent in interface OnQuitEvent

addListenner

public void addListenner(java.lang.Object listenner)

notifyToAllOtherActorSession

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

Parameters:
e - the event

notifyJoinToListenners

private void notifyJoinToListenners(JoinEvent e)
Raise the JoinEvent to all external listenners, in particular the game logic threads.

Parameters:
e - the JoinEvent

notifyEndToListenners

private void notifyEndToListenners(EndEvent e)
Raise the EndEvent to all external listenners, in particular the game logic threads.

Parameters:
e - the EndEvent

notifyStartToListenners

private void notifyStartToListenners(StartEvent e)
Raise the StartEvent to all external listenners, in particular the game logic threads.

Parameters:
e - the StartEvent

notifyQuitToListenners

private void notifyQuitToListenners(QuitEvent e)
Raise the QuitEvent to all external listenners, in particular the game logic threads.

Parameters:
e - the QuitEvent

notifyDataToListenners

private void notifyDataToListenners(DataEvent e)
Raise the DataEvent to all external listenners, in particular the game logic threads.

Parameters:
e - the DataEvent