uk.org.iscream.cms.conient
Class ConnectionHandler

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--uk.org.iscream.cms.conient.ConnectionHandler
All Implemented Interfaces:
Runnable

public class ConnectionHandler
extends Thread

This is the main thread for the client. Once started i continually checks it actionQueue for actions that other areas of the system have placed there, it then performs those actions. Currently this is the main thread where all non-GUI events are dispatched to.

Version:
$Id: ConnectionHandler.java,v 1.36 2003/02/05 19:35:04 tdb Exp $
Author:
$Author: tdb $

Field Summary
private  Queue _actionQueue
          The queue that actions are added to by other parts of the system
private  Configuration _configuration
          A reference to the system configuration component
private  String _configuredServer
          The server that the config says we should connect to
private  TunnelProcess _controlFirewallProcess
          The process used to start the firewall pipe for the control link.
private  Socket _controlLink
          The control link socket
private  DataPanel _data
          A reference to the displaying class DataPanel
private  TunnelProcess _dataFirewallProcess
          The process used to start the firewall pipe for the data link.
private  BufferedReader _dataInBound
          The input for the data link
private  Socket _dataLink
          The data link socket
private  PrintWriter _dataOutBound
          The output for the data link
private  DataReader _dataReader
          A reference to the DataReader in use
private  BufferedReader _inBound
          The input for the control link
private  int _myQueue
          The queue number that we are reading from on the action queue
private  PrintWriter _outBound
          The output for the control link
private  boolean _running
          The state if this thread
private  String _server
          The server we will be connecting to
static int CONNECT
          Thread action CONNECT.
static int DATAREADER_SHUTDOWN_TIMEOUT
          This is the time in seconds that this class should wait on the DataReader class to fully shutdown after calling shutdown() before forcing a shutdown
static int DEFAULT_FIREWALL_COMMANDWAIT
          The default time in seconds to wait for the firewall setup command to execute
static String DEFAULT_FIREWALL_SERVER
          The default local server to connect to when a firewall is in use if one is not specified in the server
static int DEFAULT_QUEUE_LIMIT
          The default maximum queue size in use for the data queue
static int DISCONNECT
          Thread action DISCONNECT.
static int DONOTHING
          Thread action DONOTHING.
static int GETCONFIGURATION
          Thread action GETCONFIGURATION Starts the command to obtain the configuration from the server.
 double PROTOCOL_VERSION
          The hardcoded protocol version that we are using.
static int QUEUE_ALGORITHM
          The algorithm we use to remove items from the queue if it reaches its maximum size.
static int QUIT
          Thread action QUIT.
 String REVISION
          The current CVS revision of this class
static int STARTDATA
          Thread action STARTDATA.
static int STOPDATA
          Thread action STOPDATA.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ConnectionHandler(DataPanel data, Queue actionQueue)
          Constructs new data handler.
 
Method Summary
private  void closeFirewall(TunnelProcess firewallProcess)
          Checks to see if the given firewall process has been created.
 String getConfigFromServer(String configName, String propertyName)
          This method is called by the Configuration object when a request is made for a server property.
private  String handleFirewall(String server, int port, TunnelProcess firewallProcess)
          Handles opening pipes through firewalls.
 void run()
          Starts this ConnectionHandler running.
private  boolean setHostList(String hostList)
          This method performs the SETHOSTLIST command.
 void shutdown()
          This method allows other classes to shutdown this connection handler.
 void shutdownDataLink()
          Called by the DataReader if the link is unexpectedly lost.
 
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

REVISION

public final String REVISION
The current CVS revision of this class

See Also:
Constant Field Values

PROTOCOL_VERSION

public final double PROTOCOL_VERSION
The hardcoded protocol version that we are using. Used when handshaking with the server

See Also:
Constant Field Values

DONOTHING

public static final int DONOTHING
Thread action DONOTHING. This is an invalid action, but here for completeness if anything sends this action it will warn appropriately but do what it says, ie, nothing ;)

See Also:
Constant Field Values

CONNECT

public static final int CONNECT
Thread action CONNECT. Opens the control link to the i-scream server.

See Also:
Constant Field Values

STARTDATA

public static final int STARTDATA
Thread action STARTDATA. Opens the data link to the i-scream server and prepares all gui data components for data it then starts all relavant threads going.

See Also:
Constant Field Values

STOPDATA

public static final int STOPDATA
Thread action STOPDATA. Closes the data link and shuts down all components that update gui for various things.

See Also:
Constant Field Values

DISCONNECT

public static final int DISCONNECT
Thread action DISCONNECT. Checks to see if STOPDATA has been called if not, it will add STOPDATA and then DISCONNECT to the action queue and return. If STOPDATA has been called it closes down the Control Link and tidies up all relevant threads

See Also:
Constant Field Values

QUIT

public static final int QUIT
Thread action QUIT. Checks the status of the two links, if either are still up, it queues the appropriate commands to close them down. It then System.exit(0)'s!

See Also:
Constant Field Values

GETCONFIGURATION

public static final int GETCONFIGURATION
Thread action GETCONFIGURATION Starts the command to obtain the configuration from the server. It then passes the IO to the Configuration object so it can obtain any specific configuration

See Also:
Constant Field Values

DATAREADER_SHUTDOWN_TIMEOUT

public static final int DATAREADER_SHUTDOWN_TIMEOUT
This is the time in seconds that this class should wait on the DataReader class to fully shutdown after calling shutdown() before forcing a shutdown

See Also:
Constant Field Values

DEFAULT_FIREWALL_SERVER

public static final String DEFAULT_FIREWALL_SERVER
The default local server to connect to when a firewall is in use if one is not specified in the server

See Also:
Constant Field Values

DEFAULT_FIREWALL_COMMANDWAIT

public static final int DEFAULT_FIREWALL_COMMANDWAIT
The default time in seconds to wait for the firewall setup command to execute

See Also:
Constant Field Values

DEFAULT_QUEUE_LIMIT

public static final int DEFAULT_QUEUE_LIMIT
The default maximum queue size in use for the data queue

See Also:
Constant Field Values

QUEUE_ALGORITHM

public static final int QUEUE_ALGORITHM
The algorithm we use to remove items from the queue if it reaches its maximum size. We use a FIFO algorithm, see the uk.org.iscream.cms.util.Queue class for other options.

See Also:
Constant Field Values

_running

private boolean _running
The state if this thread


_data

private DataPanel _data
A reference to the displaying class DataPanel


_actionQueue

private Queue _actionQueue
The queue that actions are added to by other parts of the system


_myQueue

private int _myQueue
The queue number that we are reading from on the action queue


_controlLink

private Socket _controlLink
The control link socket


_dataLink

private Socket _dataLink
The data link socket


_inBound

private BufferedReader _inBound
The input for the control link


_outBound

private PrintWriter _outBound
The output for the control link


_dataInBound

private BufferedReader _dataInBound
The input for the data link


_dataOutBound

private PrintWriter _dataOutBound
The output for the data link


_dataReader

private DataReader _dataReader
A reference to the DataReader in use


_configuration

private Configuration _configuration
A reference to the system configuration component


_server

private String _server
The server we will be connecting to


_configuredServer

private String _configuredServer
The server that the config says we should connect to


_controlFirewallProcess

private TunnelProcess _controlFirewallProcess
The process used to start the firewall pipe for the control link.


_dataFirewallProcess

private TunnelProcess _dataFirewallProcess
The process used to start the firewall pipe for the data link.

Constructor Detail

ConnectionHandler

public ConnectionHandler(DataPanel data,
                         Queue actionQueue)
Constructs new data handler. Needs a reference to the data panel so that it can set it processing inBound data Also gets a reference to the queue that will be used by other areas of the system to send it actions

Parameters:
data - the DataPanel in use
actionQueue - the actionQueue for this class
Method Detail

run

public void run()
Starts this ConnectionHandler running. This basically runs until told to stop, it gets "actions" from its actionQueue and switch's on them do determine what it should do it then carries out the action For details on what each action does see the action types.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

getConfigFromServer

public String getConfigFromServer(String configName,
                                  String propertyName)
This method is called by the Configuration object when a request is made for a server property. The Configuration object is informed of the Connection Handler's whereabouts on construction of the ConnectionHandler. This implements the STARTCONFIG command in the 1.0 protocol.


shutdown

public void shutdown()
This method allows other classes to shutdown this connection handler.


shutdownDataLink

public void shutdownDataLink()
Called by the DataReader if the link is unexpectedly lost. This closes the data link.


setHostList

private boolean setHostList(String hostList)
This method performs the SETHOSTLIST command. This is run by the CONNECT command. It tells the server which hosts we are interested in, if "" is sent, this indicates we want ALL hosts.

Parameters:
hostList - the list of hosts as gained from the config
Returns:
if we succeeded in setting the host list

handleFirewall

private String handleFirewall(String server,
                              int port,
                              TunnelProcess firewallProcess)
Handles opening pipes through firewalls. It checks the configuration for various entries to set up the link or not. If a link is setup it will return the name of the new server to connect to, if a link is NOT setup, it will simply return the original server name. The name of the machine that the pipe is setup on defaults to "localhost", unless the configuration specifies otherwise. Once it has run the firewall command it then waits a set period according to the config for the firewall pipe to be set up. The firewall process should be destroyed when the link is finished with.

Parameters:
server - the name of the server to open up the pipe to
port - the port number to open up the pipe to
firewallProcess - the holder for the new firewall process
Returns:
the server to connect to, as determined by this routine

closeFirewall

private void closeFirewall(TunnelProcess firewallProcess)
Checks to see if the given firewall process has been created. If it has it calls destroy() on it.

Parameters:
firewallProcess - the process to check


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