Class NetLogClient.LogConnectionMgr

java.lang.Object
  extended byjava.lang.Thread
      extended byNetLogClient.LogConnectionMgr
All Implemented Interfaces:
Runnable
Enclosing class:
NetLogClient

private class NetLogClient.LogConnectionMgr
extends Thread

This inner class is designed to maintain the socket connection from the NetLogClient to the NetLogServer. The class will test the connection every so-many seconds, and if the connection is broken, it will attempt to reconnect it, waiting so-many seconds between attempts.

Author:
Kevin Thompson [antiduh@csh.rit.edu]

Field Summary
static int CHECK_WAIT_TIME
          This is the amount of time (in seconds) to wait between checks.
private  byte[] nop
          The string to write as the 'no operation' operation command.
static int RECONNECT_WAIT_TIME
          This is the amount of time (in seconds) to wait between reconnection attempts.
private  OutputStream testOut
          Our output stream for testing the connection.
private  boolean wasConnected
          Used to keep track of whether or not the client was connected.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
NetLogClient.LogConnectionMgr()
          Initialize the class by saving the OutputStream and figuring out the connections initial state.
 
Method Summary
 void reconnect()
          Loops forever trying to reconnect the socket.
 void run()
          Run in an infinite loop testing the connection, reconnecting it when the connection fails.
 boolean testConnected()
          Tests the connection to see if it is connected or not.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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

CHECK_WAIT_TIME

public static final int CHECK_WAIT_TIME
This is the amount of time (in seconds) to wait between checks.

See Also:
Constant Field Values

RECONNECT_WAIT_TIME

public static final int RECONNECT_WAIT_TIME
This is the amount of time (in seconds) to wait between reconnection attempts.

See Also:
Constant Field Values

nop

private final byte[] nop
The string to write as the 'no operation' operation command.


wasConnected

private boolean wasConnected
Used to keep track of whether or not the client was connected. This is used for determing if the connection state changed.


testOut

private OutputStream testOut
Our output stream for testing the connection.

Constructor Detail

NetLogClient.LogConnectionMgr

public NetLogClient.LogConnectionMgr()
Initialize the class by saving the OutputStream and figuring out the connections initial state.

Method Detail

run

public void run()
Run in an infinite loop testing the connection, reconnecting it when the connection fails.


testConnected

public boolean testConnected()
Tests the connection to see if it is connected or not. Due to a quirk with the TINI's implementation of the Java 1.4 SDK, there is no Socket.isConnected() method. Therefore, to test the connection, we need to actually try to send information and see if the Socket throws an exception.


reconnect

public void reconnect()
Loops forever trying to reconnect the socket. Once the socket is reconnected, it stops.