com.camelspotting.jotl
Class ServerMonitor

java.lang.Object
  extended by com.camelspotting.jotl.ServerMonitor

public class ServerMonitor
extends Object

This is one of the primary access points for any user of the library. It's for monitoring an ongoing OpenTTD game. It can do updates continously or manually.

Version:
1.0
Author:
Mats Andreassen

Constructor Summary
ServerMonitor(GameQuerier gameQuerier, int updateInterval, boolean updateNow, OpenTTDListener... otls)
          Main constructor for creating the server handler.
 
Method Summary
 void addListeners(OpenTTDListener... otls)
          Method for registering listeners for any events.
 String getServerName()
          Getter for the monitored server's hostname.
 boolean isPaused()
          Getter for easily finding out whether the game is paused or not.
 void removeListeners(OpenTTDListener... otls)
          Method for deregistering listeners.
 void setUpdateInterval(int ms)
          This method is for altering the update interval.
 void start()
          This method is for starting the continous updating.
 void stop()
          This method overrides the setUpdateInterval-method that refuses to lower the interval to lower than 2000 and sets it to -1.
 void update()
          This method is public so that any API-user might update manually. also for the automatic update process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerMonitor

public ServerMonitor(GameQuerier gameQuerier,
                     int updateInterval,
                     boolean updateNow,
                     OpenTTDListener... otls)
              throws JOTLException
Main constructor for creating the server handler. Be aware that if you supply no initial listeners and still tell it to update once immidiately no one will receive any events. An OpenTTD-server runs by default on port 3979. Regardless of what you supply as an update interval it will not start and continous sequence without a call to start(). NOTE: According to the OpenTTD-code a day is about 2 seconds if the machine running it is able to do run it normally.

Parameters:
host - the server to monitor
localPort - the local port to use
remotePort - the remote port to use
updateInterval - update interval in milliseconds, 0 or less for manual
updateNow - do an update at once?
otls - any initial listeners?
Throws:
JOTLException
See Also:
start()
Method Detail

isPaused

public boolean isPaused()
Getter for easily finding out whether the game is paused or not. This variable might contain old data if the ServerHandler has stopped querying the OpenTTD server.

Returns:
whether or not the server is paused

getServerName

public String getServerName()
Getter for the monitored server's hostname.

Returns:
the server hostname

setUpdateInterval

public void setUpdateInterval(int ms)
This method is for altering the update interval. If the new update interval is set to less than or equal to 0 this will as a direct result terminate the automatic updating. Be aware that while the method can stop the updating it will never start it. A separate call to start() must be done to achieve this. NOTE: According to the OpenTTD-code a day is about 2 seconds if the machine running it is able to do run it normally so 2000 is the lower boundary for this setting.

Parameters:
ms - the number of milliseconds to set
See Also:
start(), stop()

start

public void start()
This method is for starting the continous updating. This will either start it with an initial update interval set to the lower boundary of 2000 if the interval is still set to -1.


stop

public void stop()
This method overrides the setUpdateInterval-method that refuses to lower the interval to lower than 2000 and sets it to -1. This will cause the update thread to terminate.

See Also:
setUpdateInterval(int ms), start()

update

public final void update()
                  throws JOTLException
This method is public so that any API-user might update manually. also for the automatic update process. Note that this is the same method invoked internally during the automatic update process. After updating the data is checked to so if anything notable has happened since the last update.

Throws:
JOTLException
See Also:
OpenTTDEvent

addListeners

public final void addListeners(OpenTTDListener... otls)
Method for registering listeners for any events.

Parameters:
otls - the listener to add

removeListeners

public final void removeListeners(OpenTTDListener... otls)
Method for deregistering listeners.

Parameters:
otls - the listeners to remove


Copyright © 2013. All Rights Reserved.