server.framework.threads
Interface EventHandler<P extends AbstractPlayer,S extends AbstractSession>

All Superinterfaces:
java.lang.Runnable
All Known Implementing Classes:
BBEventHandler

public interface EventHandler<P extends AbstractPlayer,S extends AbstractSession>
extends java.lang.Runnable

Implementors of the EventHandler interface are responsible for handling game events that are caused by the session itself and by clients connected to the session. This interface extends the Runnable interface, and should contain a loop that runs continously thoughout a game, generating events. In addition, whenever external game events occur, these should be handled in the implementation of this interface.

Author:
Martin Jarrett, Eivind Sorteberg

Method Summary
 void checkSettings()
          A method that should be called by the thread itself continuously.
 void fireEventOccured(P player, Event event, java.lang.Object[] values)
          Method that should be called whenever an external game event occurs.
 boolean isReady()
          Method that ensures that the thread can perform pre-game calculations before the game is initiated.
 void setSession(S session)
          Sets the session to which this thread is assigned.
 void stop()
          Called when a game is over, and the thread should be stopped.
 
Methods inherited from interface java.lang.Runnable
run
 

Method Detail

setSession

void setSession(S session)
Sets the session to which this thread is assigned.

Parameters:
session - The owner of this thread.

fireEventOccured

void fireEventOccured(P player,
                      Event event,
                      java.lang.Object[] values)
Method that should be called whenever an external game event occurs. How this event is handled is decided by the implementation of this method.

Parameters:
player - The player that caused the event.
event - The event.
values - The values related to the event.

checkSettings

void checkSettings()
A method that should be called by the thread itself continuously. Whenever a setting limit is reached, this thread should notify its models, so that these can act accordingly.


stop

void stop()
Called when a game is over, and the thread should be stopped. This method should make sure the thread releases all its resources.


isReady

boolean isReady()
Method that ensures that the thread can perform pre-game calculations before the game is initiated. Examples of such calculations are player position generations.

Returns:
Whether the thread has completed its pre-game calculations or not.