Package org.swtpra1
Class Observer
- java.lang.Object
-
- org.swtpra1.Observer
-
public class Observer extends java.lang.Object
This class "observes" the games played on a gameserver and makes the data available for being displayed.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_AUTH_TOKEN
static java.lang.String
DEFAULT_GAMESERVER_URL
-
Constructor Summary
Constructors Constructor Description Observer()
Constructs a new observer loaded with default URL and default token.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connectToGameServer(java.lang.String gameServerUrl, java.lang.String authenticationToken)
void
endDataUpdate()
Ends any unning update tasks and denies any further polling from gameserver.void
exitApplication()
Stops the polling of updates before closing any open windows.java.lang.String
getAuthenticationToken()
Returns the token that is used to authenticate for polling updates.Game[]
getGames()
Returns an array of Game objects, representing all active games on the server.java.lang.String
getGameServerUrl()
Returns the URL that is used to poll updates.Game
getGameWithId(int gameId)
Retrieves a game object with a specific id.ObserverWindow
getWindow()
The ObserverWindow that displays the information of this observer instance.void
openWindow()
Creates a new window to display the current state.void
startDataUpdate()
Starts the task of regularly polling the current state of games.
-
-
-
Field Detail
-
DEFAULT_GAMESERVER_URL
public static final java.lang.String DEFAULT_GAMESERVER_URL
- See Also:
- Constant Field Values
-
DEFAULT_AUTH_TOKEN
public static final java.lang.String DEFAULT_AUTH_TOKEN
- See Also:
- Constant Field Values
-
-
Method Detail
-
getGameServerUrl
public java.lang.String getGameServerUrl()
Returns the URL that is used to poll updates.- Returns:
- URL as string
-
getAuthenticationToken
public java.lang.String getAuthenticationToken()
Returns the token that is used to authenticate for polling updates.- Returns:
- token as String
-
connectToGameServer
public void connectToGameServer(java.lang.String gameServerUrl, java.lang.String authenticationToken)
-
startDataUpdate
public void startDataUpdate()
Starts the task of regularly polling the current state of games. If called while the task is already running it is restarted. First update is delayed by 200 milliseconds to ensure gameserver is ready to respond
-
endDataUpdate
public void endDataUpdate()
Ends any unning update tasks and denies any further polling from gameserver.
-
getGames
public Game[] getGames()
Returns an array of Game objects, representing all active games on the server.- Returns:
- array of Games in no particular order
-
getGameWithId
public Game getGameWithId(int gameId)
Retrieves a game object with a specific id.- Parameters:
gameId
- the id of the game we want- Returns:
- game if exists; null otherwise
-
getWindow
public ObserverWindow getWindow()
The ObserverWindow that displays the information of this observer instance.- Returns:
- ObserverWindow object; null if gui is not started
-
openWindow
public void openWindow()
Creates a new window to display the current state.
-
exitApplication
public void exitApplication()
Stops the polling of updates before closing any open windows.
-
-