jap.forward
Class JAPRoutingServerStatisticsListener

java.lang.Object
  extended by java.util.Observable
      extended by jap.forward.JAPRoutingServerStatisticsListener
All Implemented Interfaces:
java.lang.Runnable, java.util.Observer

public class JAPRoutingServerStatisticsListener
extends java.util.Observable
implements java.util.Observer, java.lang.Runnable

This class is the implementation for the forwarding server statistics update. Every class interested in the forwarding server statistics should add itself to the observers of this class. It gets an update message with JAPRoutingMessage.SERVER_STATISTICS_UPDATED, every time some values might have changed. So it can ask for the instance of this class for the new values. This class is also available, if the server is not running (but fetching of new statistics is only done, when the forwarding server is running).


Field Summary
private  int m_acceptedConnections
          Stores the number of accepted connections.
private  int m_currentBandwidthUsage
          Stores the current bandwidth usage in bytes/sec.
private  int m_currentlyForwardedConnections
          Stores the number of currently forwarded connections.
private  ForwardSchedulerStatistics m_currentStatisticsInstance
          Stores the current statistics instance from where we obtain the data.
private  int m_rejectedConnections
          Stores the number of rejected connections.
private  java.lang.Thread m_statisticsThread
          Stores the current instance of the statistics fetching thread (if we are in server mode).
private  long m_transferedBytes
          Stores the number of transfered bytes.
private static long SERVER_STATISTICS_UPDATE_INTERVAL
          This is the update interval for the server statistics panel in milliseconds.
 
Constructor Summary
JAPRoutingServerStatisticsListener()
          Creates a new instance of JAPForwardingServerStatisticsListener.
 
Method Summary
 int getAcceptedConnections()
          Returns the number of accepted connections.
 int getCurrentBandwidthUsage()
          Returns the current bandwidth usage.
 int getCurrentlyForwardedConnections()
          Returns the number of currently forwarded connections.
 int getRejectedConnections()
          Returns the number of rejected connections.
 long getTransferedBytes()
          Returns the total number of transfered bytes in the current forwarding server session.
 void run()
          This is the implementation of the forwarding server statistics fetch thread.
private  void startStatistics()
          This starts fetching the statistics from the forwarding server.
private  void stopStatistics()
          This stops the fetch thread of the forwarding server statistics.
 void update(java.util.Observable a_notifier, java.lang.Object a_message)
          This is the observer implementation.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SERVER_STATISTICS_UPDATE_INTERVAL

private static final long SERVER_STATISTICS_UPDATE_INTERVAL
This is the update interval for the server statistics panel in milliseconds.

See Also:
Constant Field Values

m_rejectedConnections

private int m_rejectedConnections
Stores the number of rejected connections.


m_acceptedConnections

private int m_acceptedConnections
Stores the number of accepted connections.


m_currentlyForwardedConnections

private int m_currentlyForwardedConnections
Stores the number of currently forwarded connections.


m_transferedBytes

private long m_transferedBytes
Stores the number of transfered bytes.


m_currentBandwidthUsage

private int m_currentBandwidthUsage
Stores the current bandwidth usage in bytes/sec.


m_currentStatisticsInstance

private ForwardSchedulerStatistics m_currentStatisticsInstance
Stores the current statistics instance from where we obtain the data.


m_statisticsThread

private java.lang.Thread m_statisticsThread
Stores the current instance of the statistics fetching thread (if we are in server mode).

Constructor Detail

JAPRoutingServerStatisticsListener

public JAPRoutingServerStatisticsListener()
Creates a new instance of JAPForwardingServerStatisticsListener. It's required, that the server isn't running at the moment of creation. Also the new instance must be added to the observers of JAPRoutingSettings after creation.

Method Detail

getRejectedConnections

public int getRejectedConnections()
Returns the number of rejected connections. If there is no forwarding server running at the moment, 0 is returned.

Returns:
The number of rejected connections.

getAcceptedConnections

public int getAcceptedConnections()
Returns the number of accepted connections. If there is no forwarding server running at the moment, 0 is returned.

Returns:
The number of accepted connections.

getCurrentlyForwardedConnections

public int getCurrentlyForwardedConnections()
Returns the number of currently forwarded connections. If there is no forwarding server running at the moment, 0 is returned.

Returns:
The number of currently forwarded connections.

getCurrentBandwidthUsage

public int getCurrentBandwidthUsage()
Returns the current bandwidth usage. If there is no forwarding server running at the moment, 0 is returned.

Returns:
The current bandwidth usage in bytes/sec.

getTransferedBytes

public long getTransferedBytes()
Returns the total number of transfered bytes in the current forwarding server session. If there is no forwarding server running at the moment, 0 is returned.

Returns:
The total number of transfered bytes.

update

public void update(java.util.Observable a_notifier,
                   java.lang.Object a_message)
This is the observer implementation. If the routing mode is changed to server mode in JAPRoutingSettings, we fetch the new statistics instance of the server and also notify the observers of this instance of JAPForwardingServerStatisticsListener periodically about new values. If the forwarding server was shutted down, we stop the periodical notification of the observers of this instance (one last notification after the shutdown is sent).

Specified by:
update in interface java.util.Observer
Parameters:
a_notifier - The observed Object. This should always be JAPRoutingSettings at the moment.
a_message - The reason of the notification. This should always be a JAPRoutingMessage at the moment.

run

public void run()
This is the implementation of the forwarding server statistics fetch thread. Once per update interval the statistics are fetched and the observers of this class are notified, so they can obtain the new statistics values.

Specified by:
run in interface java.lang.Runnable

startStatistics

private void startStatistics()
This starts fetching the statistics from the forwarding server. First, all currently running fetch threads are stopped and then a new thread is started (if we are in server routing mode).


stopStatistics

private void stopStatistics()
This stops the fetch thread of the forwarding server statistics. If there is no thread currently running, nothing is done.