com.lyrisoft.chat.server.remote
Class ConnectionHandler

java.lang.Object
  |
  +--com.lyrisoft.chat.server.remote.ConnectionHandler
All Implemented Interfaces:
IConnectionHandler
Direct Known Subclasses:
FlashConnectionHandler

public class ConnectionHandler
extends java.lang.Object
implements IConnectionHandler

The keeper of the Socket on the server side. Spawns a thread for reading from the socket. As each line is read from the socket, the server is notified, via the IConnectionListener interface Outgoing messages are passed to the Dispatcher who queues them up


Field Summary
protected  IConnectionListener _connectionListener
           
protected  Dispatcher _dispatcher
           
protected  java.io.InputStream _inputStream
           
protected  boolean _isShutDown
           
protected  java.io.PrintWriter _out
           
protected  ReaderThread _reader
           
protected  java.net.Socket _socket
           
protected static boolean DEBUG
           
 
Constructor Summary
ConnectionHandler(java.net.Socket s, IConnectionListener listener)
          Construct a ConnectionHandler for the given socket
 
Method Summary
 ReaderThread createReader()
           
 void queueMessage(java.lang.String message)
          Queue a message headed outbound
 void sendImmediately(java.lang.String message)
          Send a message immediately.
 void setDispatcher(Dispatcher d)
           
 void setListener(IConnectionListener listener)
          Set the connection listener for this connection handler
 void shutdown(boolean notify)
          Shutdown this connection listener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_out

protected java.io.PrintWriter _out

_socket

protected java.net.Socket _socket

_reader

protected ReaderThread _reader

_inputStream

protected java.io.InputStream _inputStream

_connectionListener

protected IConnectionListener _connectionListener

_isShutDown

protected boolean _isShutDown

_dispatcher

protected Dispatcher _dispatcher

DEBUG

protected static final boolean DEBUG
Constructor Detail

ConnectionHandler

public ConnectionHandler(java.net.Socket s,
                         IConnectionListener listener)
                  throws java.io.IOException
Construct a ConnectionHandler for the given socket
Parameters:
s - the socket
listener - the object that will be notified with incoming messages
Throws:
java.io.IOException - if there is a problem reading or writing to the socket
Method Detail

setListener

public void setListener(IConnectionListener listener)
Description copied from interface: IConnectionHandler
Set the connection listener for this connection handler
Specified by:
setListener in interface IConnectionHandler

createReader

public ReaderThread createReader()

setDispatcher

public void setDispatcher(Dispatcher d)

queueMessage

public void queueMessage(java.lang.String message)
Queue a message headed outbound
Specified by:
queueMessage in interface IConnectionHandler

sendImmediately

public void sendImmediately(java.lang.String message)
Description copied from interface: IConnectionHandler
Send a message immediately.
Specified by:
sendImmediately in interface IConnectionHandler

shutdown

public void shutdown(boolean notify)
Description copied from interface: IConnectionHandler
Shutdown this connection listener. The notify parameter indicates whether or not the client (ConnectionListener) should be notified of the shutdown. Basically, notify should only be false if the client itself called us.
Specified by:
shutdown in interface IConnectionHandler
Parameters:
notify - to notify the ConnectionListener. Should be true for unexpected shutdowns (like if there is a socket error), and false otherwise (if client called this method on purpose)


Copyright © 2000-2002 Taso Lyristis