com.mischiefbox.pollserve
Class ConnectionInfo

java.lang.Object
  |
  +--com.mischiefbox.pollserve.ConnectionInfo

public class ConnectionInfo
extends Object

Connection information object. Provides information about a single connection.

Version:
$Id$
Author:
Chris Jones

Field Summary
protected  BufferedInputStream bis
          The input stream associated with the socket.
protected  BufferedOutputStream bos
          The output stream associated with the socket.
protected  ConnectionHandler handler
          The connection handler that created and is responsible for the connection.
protected  int iErrorCount
          The consecutive error count on the connection.
protected  long lLastUseMillis
          The last recorded time I/O was performed on the socket.
static int MAX_ERROR
          The maximum number of consecutive errors permitted for the connection.
protected  String sConnectionId
          The connection id (used to identify the connection).
protected  Socket sock
          The Socket associated with the connection.
 
Constructor Summary
ConnectionInfo(ConnectionHandler handler, Socket sock, int iConnectionId)
          Create a new connection info object.
 
Method Summary
 void addError()
          Add to and check the error count.
protected  void finalize()
          Finalizer, in case this goes out of scope.
 String getConnectionId()
          Get the connection id.
 int getErrors()
          Get the number of errors on the connection.
 BufferedInputStream getInputStream()
          Get the input stream.
 long getLastUsedTime()
          Get the last used time (in milliseconds).
 BufferedOutputStream getOutputStream()
          Get the output stream.
 void resetError()
          Reset the error count to zero (success in I/O).
 void setLastUsedTime()
          Set the last used time to now.
 void shutdown()
          Shut down the connection gracefully.
 void terminate()
          Close the socket connection immediately.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ERROR

public static final int MAX_ERROR
The maximum number of consecutive errors permitted for the connection.

handler

protected ConnectionHandler handler
The connection handler that created and is responsible for the connection.

sock

protected Socket sock
The Socket associated with the connection.

bis

protected BufferedInputStream bis
The input stream associated with the socket.

bos

protected BufferedOutputStream bos
The output stream associated with the socket.

sConnectionId

protected String sConnectionId
The connection id (used to identify the connection).

iErrorCount

protected int iErrorCount
The consecutive error count on the connection. After MAX_ERROR errors, the connection will be dropped.

lLastUseMillis

protected long lLastUseMillis
The last recorded time I/O was performed on the socket. I/O may be performed without recording that it was done.
Constructor Detail

ConnectionInfo

public ConnectionInfo(ConnectionHandler handler,
                      Socket sock,
                      int iConnectionId)
Create a new connection info object. The new ConnectionInfo object is responsible for registering itself with the ConnectionHandler if the info object initializes properly.
Parameters:
handler - the connection handler that created the connection info object.
sock - the socket this connection will use for I/O.
iConnectionId - the connection id.
Method Detail

getConnectionId

public String getConnectionId()
Get the connection id.
Returns:
the connection id.

getLastUsedTime

public long getLastUsedTime()
Get the last used time (in milliseconds).
Returns:
the last used time.

setLastUsedTime

public void setLastUsedTime()
Set the last used time to now. Synchronized access to last used time field.

getInputStream

public BufferedInputStream getInputStream()
Get the input stream.
Returns:
the input stream for the connection.

getOutputStream

public BufferedOutputStream getOutputStream()
Get the output stream.
Returns:
the output stream for the connection.

terminate

public void terminate()
Close the socket connection immediately. This will not unregister the connection from the handler, nor will it do any housekeeping outside this class. Intended to be called by the ConnectionHandler only! This should be the last call in the chain when a connection is shut down gracefully (the connection info object unregistered, etc).

shutdown

public void shutdown()
Shut down the connection gracefully. This will ask the handler to unregister this connection info. The handler will invoke the terminate() method and null the reference to the connection info object.

getErrors

public int getErrors()
Get the number of errors on the connection.
Returns:
the number of consecutive errors on this connection.

addError

public void addError()
Add to and check the error count.

resetError

public void resetError()
Reset the error count to zero (success in I/O).

finalize

protected void finalize()
                 throws Throwable
Finalizer, in case this goes out of scope.
Overrides:
finalize in class Object


Copyright © 2001 by Christopher R. Jones. All Rights Reserved.