uk.org.iscream.cms.server.clientinterface
Class TCPControlHandler

java.lang.Object
  extended byjava.lang.Thread
      extended byuk.org.iscream.cms.server.clientinterface.TCPControlHandler
All Implemented Interfaces:
Runnable

class TCPControlHandler
extends Thread

Acts as a Control Handler to a TCP based client.

Version:
$Id: TCPControlHandler.java,v 1.29 2004/08/01 10:40:48 tdb Exp $
Author:
$Author: tdb $

Field Summary
private  String _clientName
          The name of the Client we're connected to
private  ConfigurationManager _configManager
          A reference to the Configuration Manager the system is using
private  TCPDataHandler _dataHandler
          A reference to the DataHandler, if there is one
private  String _hostList
          The host list the Client has requested
private  Logger _logger
          This holds a reference to the system logger that is being used.
private  String _name
          This is the friendly identifier of the component this class is running in.
private  PacketSorter _packetSorter
          A reference to the PacketSorter.
private  Socket _socket
          The socket we are talking on
private  BufferedReader _socketIn
          A hook to the inbound data from the socket
private  PrintWriter _socketOut
          A hook to the outbound stream for the socket
static String PROTOVER
          This is our protocol version.
 String REVISION
          The current CVS revision of this class
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TCPControlHandler(Socket socket, PacketSorter packetSorter)
          Construct a new TCPControlHandler, and setup the reader and writer for the new Socket.
 
Method Summary
private  boolean closeData()
          Attempt to close down the DataHandler.
 void run()
          This method initiates the thread, setting things up, and then reading commands from the Client.
private  void send(String message)
          Send any String message to the outgoing Socket.
private  void sendERROR()
          Send an ERROR message to the outgoing Socket.
private  void sendOK()
          Send an OK message to the outgoing Socket
 String toString()
          Overrides the Object.toString() method to provide clean logging (every class should have this).
 
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, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REVISION

public final String REVISION
The current CVS revision of this class

See Also:
Constant Field Values

PROTOVER

public static final String PROTOVER
This is our protocol version. It is hardcoded to ensure that it doesn't get accidently changed. A change to the protocol would also require changing this classes code !

See Also:
Constant Field Values

_name

private String _name
This is the friendly identifier of the component this class is running in. eg, a Filter may be called "filter1", If this class does not have an owning component, a name from the configuration can be placed here. This name could also be changed to null for utility classes.


_logger

private Logger _logger
This holds a reference to the system logger that is being used.


_configManager

private ConfigurationManager _configManager
A reference to the Configuration Manager the system is using


_socket

private Socket _socket
The socket we are talking on


_socketIn

private BufferedReader _socketIn
A hook to the inbound data from the socket


_socketOut

private PrintWriter _socketOut
A hook to the outbound stream for the socket


_packetSorter

private PacketSorter _packetSorter
A reference to the PacketSorter.


_dataHandler

private TCPDataHandler _dataHandler
A reference to the DataHandler, if there is one


_clientName

private String _clientName
The name of the Client we're connected to


_hostList

private String _hostList
The host list the Client has requested

Constructor Detail

TCPControlHandler

public TCPControlHandler(Socket socket,
                         PacketSorter packetSorter)
                  throws IOException
Construct a new TCPControlHandler, and setup the reader and writer for the new Socket.

Parameters:
socket - The Socket connected to the new Client
packetSorter - A reference to the PacketSorter in the component
Method Detail

run

public void run()
This method initiates the thread, setting things up, and then reading commands from the Client. It handles setting up of the DataHandler, and clean shutting down.


toString

public String toString()
Overrides the Object.toString() method to provide clean logging (every class should have this). This uses the uk.org.iscream.cms.util.NameFormat class to format the toString()

Returns:
the name of this class and its CVS revision

closeData

private boolean closeData()
Attempt to close down the DataHandler. This will return true if it managed to close it down, or false if there wasn't a DataHandler to close.

Returns:
whether the channel could be closed

sendOK

private void sendOK()
Send an OK message to the outgoing Socket


sendERROR

private void sendERROR()
Send an ERROR message to the outgoing Socket.


send

private void send(String message)
Send any String message to the outgoing Socket.

Parameters:
message - The message/command to send.


Copyright © 2000-2003 i-scream. All Rights Reserved.