Class NetAcctClient.ConnectionMgr

java.lang.Object
  extended byjava.lang.Thread
      extended byNetAcctClient.ConnectionMgr
All Implemented Interfaces:
Runnable
Enclosing class:
NetAcctClient

private class NetAcctClient.ConnectionMgr
extends Thread

Basically, this class keeps track of the connection to the NetAcctServer and trys to ensure that it is always connected. In order to accomplish this, the class will check to see if the socket is connected every CHECK_WAIT_TIME seconds. If it is not connected, then it tries to connect it, waiting RECONNECT_WAIT_TIME seconds between retries.

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.
(package private)  OutputStream testOut
           
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
NetAcctClient.ConnectionMgr()
          Initialize the ConnectionMgr class by getting a reference to the sockets OutputStream, then initializing the 'nop' variable that is used to send pings to the account server.
 
Method Summary
 boolean isConnected()
          Determines if the socket is connected or not.
 void reconnect()
          Attempts to reconnect the accounting client to the server, waiting RECONNECT_WAIT_TIME seconds between attempts.
 void run()
          Loops forever checking that the client is connected.
 
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

testOut

OutputStream testOut

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 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 to print statements when the client loses or regains connection.

Constructor Detail

NetAcctClient.ConnectionMgr

public NetAcctClient.ConnectionMgr()
Initialize the ConnectionMgr class by getting a reference to the sockets OutputStream, then initializing the 'nop' variable that is used to send pings to the account server.

Method Detail

run

public void run()
Loops forever checking that the client is connected. If it is not connected, it attempts to reconnect the client to the server, automatically.


isConnected

public boolean isConnected()
Determines if the socket is connected or not. Since the TINI Java 1.4 sdk does not contain a Socket.isConnected() method, this checks by trying to send a "nop-" command to the server. If the check does not throw an IOException, then it should be good.

Returns:
True if the connection is still valid. False otherwise.

reconnect

public void reconnect()
Attempts to reconnect the accounting client to the server, waiting RECONNECT_WAIT_TIME seconds between attempts.