|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectserver.framework.models.AbstractSession<P,EH>
public abstract class AbstractSession<P extends AbstractPlayer,EH extends EventHandler>
This class represents a session. It contains a list of the players connected
to the session, and keeps track of the settings applying to the session.
Also, this model is responsible for
controlling the currently active game threads when running a game, and notifying
the EventHandler
implementation when a message is received that
is likely to cause a game event to occur.
Field Summary | |
---|---|
static long |
ALIVE_REQUEST_INTERVAL
|
protected EH |
eventHandler
|
protected AbstractServer<?,P> |
server
|
Constructor Summary | |
---|---|
AbstractSession(AbstractServer<?,P> server,
TestModule.TestType testtype)
Creates a session, and initialises the variables. |
Method Summary | |
---|---|
void |
addPlayer(P newPlayer)
Adds a new player to the session. |
void |
checkResolution()
Loops through all player's resolution, and finds the maximum resolution that will fit with all connected client phones. |
protected abstract EH |
createEventHandler()
Creates an EventHandler instance of the correct type. |
void |
exit()
Called when the session is closed. |
void |
firePlayerListChanged()
Called when the player list has changed, e.g. because a player has scored. |
void |
firePositionReceived(AbstractPlayer sender,
java.lang.String[] position)
Called when a position is received from one of the session's players. |
void |
fireSettingChanged(java.lang.String[][] values)
Called when one or more setting values have been changed. |
java.lang.Object[] |
getAttributes()
Returns the session's id, name, current number of players and maximum number of players. |
java.lang.Integer |
getId()
|
int |
getMinimumHeight()
|
int |
getMinimumWidth()
|
java.lang.String |
getName()
|
java.util.List<P> |
getPlayers()
|
java.lang.String[] |
getScreenResolution()
|
AbstractServer |
getServer()
|
SessionPanel |
getSessionPanel()
|
SettingsList |
getSettings()
|
TestModule.TestType |
getTestType()
|
void |
handleDisconnect(P player)
Called when a player disconnects from the session. |
boolean |
isGameStarted()
|
abstract void |
notifyAboutEventOccured(Event event,
P sender,
java.lang.Object[] values)
Called when an event has occurred that the EventHandler thread should
handle. |
void |
runTest()
Runs the test when a test has been specified. |
void |
sendAction(Action action,
java.lang.Object[][] values,
AbstractPlayer sender,
boolean skipSender,
boolean confirm)
Sends the specified action to all connected players, except the sender of the action, if he does not need to receive the message. |
void |
sendAction(Action action,
java.lang.Object[][] values,
boolean confirm)
Sends the specified action to all connected players. |
void |
setPlayerPosition(P player,
int[] position)
Sets the position of the specified player. |
void |
setSessionPanel(SessionPanel<P> sessionPanel)
Sets this session's SessionPanel in the server GUI. |
void |
startGame()
Starts a game. |
void |
stopGame(java.lang.String reason)
Method that is called when the game has been stopped for some reason. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final long ALIVE_REQUEST_INTERVAL
protected AbstractServer<?,P extends AbstractPlayer> server
protected EH extends EventHandler eventHandler
Constructor Detail |
---|
public AbstractSession(AbstractServer<?,P> server, TestModule.TestType testtype)
server
- The server to which this session belongs.testtype
- The test type, if any.Method Detail |
---|
public void setSessionPanel(SessionPanel<P> sessionPanel)
SessionPanel
in the server GUI.
sessionPanel
- This session's SessionPanel
public void addPlayer(P newPlayer)
newPlayer
- The new player.public TestModule.TestType getTestType()
public void handleDisconnect(P player)
player
- The disconnected player.public void stopGame(java.lang.String reason)
reason
- The reason why the game was stopped.public void fireSettingChanged(java.lang.String[][] values)
values
- The new setting values.public void firePlayerListChanged()
public int getMinimumWidth()
public int getMinimumHeight()
public java.lang.String[] getScreenResolution()
public void exit()
public java.util.List<P> getPlayers()
public SettingsList getSettings()
public void checkResolution()
public void sendAction(Action action, java.lang.Object[][] values, boolean confirm)
action
- The action to send.values
- The values related to the action.confirm
- Whether the receiver(s) should confirm the receival.public void sendAction(Action action, java.lang.Object[][] values, AbstractPlayer sender, boolean skipSender, boolean confirm)
action
- The action to send.values
- The values related to the action.sender
- The sender of the action.skipSender
- Whether the sender should receive the message or not.confirm
- Whether the receiver(s) should confirm the receival.public java.lang.Integer getId()
public java.lang.Object[] getAttributes()
public java.lang.String getName()
public void startGame()
protected abstract EH createEventHandler()
EventHandler
instance of the correct type.
EventHandler
instance.public AbstractServer getServer()
public void firePositionReceived(AbstractPlayer sender, java.lang.String[] position)
sender
- The sender of the position.position
- The position that was received.public boolean isGameStarted()
public void setPlayerPosition(P player, int[] position)
player
- The player whose position to update.position
- The position of the player.public SessionPanel getSessionPanel()
public void runTest()
public abstract void notifyAboutEventOccured(Event event, P sender, java.lang.Object[] values)
EventHandler
thread should
handle. If the session needs to perform actions because of the event, these actions
are specified in the implementation of this method.
event
- The event that has occured.sender
- The player that caused the event.values
- The values related to the event.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |