org.openflow.gui.net
Class BackendConnection<MSG_TYPE extends Message>

java.lang.Object
  extended by java.lang.Thread
      extended by org.openflow.gui.net.BackendConnection<MSG_TYPE>
All Implemented Interfaces:
java.lang.Runnable

public class BackendConnection<MSG_TYPE extends Message>
extends java.lang.Thread

Connects to a server instance to receive stats and send commands.

Author:
David Underhill

Nested Class Summary
 class BackendConnection.NetStats
          Statistics about this connection.
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.util.concurrent.ConcurrentHashMap<java.lang.Integer,OFGMessage> outstandingStatefulPollRequests
          stateful messages which are being polled by the backend for us
protected  java.util.concurrent.ConcurrentHashMap<java.lang.Integer,OFGMessage> outstandingStatefulRequests
          messages which are expecting a stateful response
static boolean PRINT_MESSAGES
          whether to print messages we send and receive
static int RETRY_WAIT_MSEC_MAX
          maximum time to wait between tries to get connected
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BackendConnection(MessageProcessor<MSG_TYPE> mp, java.lang.String ip, int port)
          Connect to the server at the specified address and port.
 
Method Summary
 boolean isConnected()
          returns true if the connection to the server is currently alive
 boolean isShutdown()
          gets whether the connection has been shutdown yet
 OFGMessage popAssociatedStatefulRequest(int xid)
          Returns the request sent with the specified transaction ID, if any.
 void reconnect()
          tells the connection to disconnect and then connect again
 void run()
          The BackendConnection thread will connect to the server and then continuously read from the socket and pass on received messages to the protocol handler.
protected  void scrubExpiredStatefulRequests()
          Remove cached stateful requests which have been cached for longer than getRequestLifetime()
 void sendMessage(OFGMessage m)
          Tries to send a message and sets the transaction ID of the message to the next available transaction ID.
 void shutdown()
          tells the connection to shut down as soon as possible
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PRINT_MESSAGES

public static final boolean PRINT_MESSAGES
whether to print messages we send and receive

See Also:
Constant Field Values

RETRY_WAIT_MSEC_MAX

public static final int RETRY_WAIT_MSEC_MAX
maximum time to wait between tries to get connected

See Also:
Constant Field Values

outstandingStatefulRequests

protected java.util.concurrent.ConcurrentHashMap<java.lang.Integer,OFGMessage> outstandingStatefulRequests
messages which are expecting a stateful response


outstandingStatefulPollRequests

protected java.util.concurrent.ConcurrentHashMap<java.lang.Integer,OFGMessage> outstandingStatefulPollRequests
stateful messages which are being polled by the backend for us

Constructor Detail

BackendConnection

public BackendConnection(MessageProcessor<MSG_TYPE> mp,
                         java.lang.String ip,
                         int port)
Connect to the server at the specified address and port.

Parameters:
ip - the IP where the server lives
port - the port the server listens on
Method Detail

run

public void run()
The BackendConnection thread will connect to the server and then continuously read from the socket and pass on received messages to the protocol handler. It will automatically try to reconnect if disconnected or if it fails to get connected.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

shutdown

public void shutdown()
tells the connection to shut down as soon as possible


isShutdown

public boolean isShutdown()
gets whether the connection has been shutdown yet


isConnected

public boolean isConnected()
returns true if the connection to the server is currently alive


reconnect

public void reconnect()
tells the connection to disconnect and then connect again


sendMessage

public void sendMessage(OFGMessage m)
                 throws java.io.IOException
Tries to send a message and sets the transaction ID of the message to the next available transaction ID. If m is a POLL_REQUEST message, then the internal message's transaction ID is also set.

Throws:
java.io.IOException

popAssociatedStatefulRequest

public OFGMessage popAssociatedStatefulRequest(int xid)
Returns the request sent with the specified transaction ID, if any. The stateful request returned will no longer be remembered.


scrubExpiredStatefulRequests

protected void scrubExpiredStatefulRequests()
Remove cached stateful requests which have been cached for longer than getRequestLifetime()