org.jogre.common
Class AbstractConnectionThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.jogre.common.AbstractConnectionThread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ClientConnectionThread, ServerConnectionThread

public abstract class AbstractConnectionThread
extends Thread

Abstract connection thread which is spawned with each client. This extends a thread and stores a Socket to the client, and a BufferedReader and PrintStream which can read/write Strings to the user/server. Also the username of the client is stored in the username String.

Version:
Alpha 0.1
Author:
Bob Marks

Field Summary
protected  BufferedReader in
          Buffered input.
protected  boolean loop
          When the boolean loop becomes false the Thread finishes.
protected  PrintStream out
          PrintStream for the output.
protected  Socket socket
          Socket between the server and the user.
protected  String username
          Username of the client.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbstractConnectionThread(Socket socket)
          Constructor for a connection which takes a Socket and sends up the input and output stream.
 
Method Summary
abstract  void cleanup()
          This method is called to properly clean up after a client.
 BufferedReader getReader()
          Return the reader.
 Socket getSocket()
          Returns the Socket of this connection.
 String getUsername()
          Returns the usernam.
abstract  void parse(String messageType, String inString)
          This abstract method must be overwritten by a child which extends this class.
 void run()
          Run method - runs until an exception has occured or the loop variable becomes false.
 void send(ITransmittable transObject)
          Send a ITransmittable object to the output stream (could be server or client).
 void send(String message)
          Send a message to the output stream (could be server or client).
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, 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

socket

protected Socket socket
Socket between the server and the user.

in

protected BufferedReader in
Buffered input.

out

protected PrintStream out
PrintStream for the output.

username

protected String username
Username of the client.

loop

protected boolean loop
When the boolean loop becomes false the Thread finishes.
Constructor Detail

AbstractConnectionThread

public AbstractConnectionThread(Socket socket)
Constructor for a connection which takes a Socket and sends up the input and output stream.
Parameters:
socket -  
Method Detail

parse

public abstract void parse(String messageType,
                           String inString)
                    throws TransmissionException
This abstract method must be overwritten by a child which extends this class.
Parameters:
messageType - Header token (1st token) of String just parsed from Socket.
inString - Unparsed string.
Throws:
TransmissionException - This is thrown if there is a problem parsing the String.

cleanup

public abstract void cleanup()
This method is called to properly clean up after a client.

run

public void run()
Run method - runs until an exception has occured or the loop variable becomes false.
Overrides:
run in class Thread
See Also:
Runnable.run()

send

public void send(String message)
Send a message to the output stream (could be server or client).
Parameters:
message -  

send

public void send(ITransmittable transObject)
Send a ITransmittable object to the output stream (could be server or client).
Parameters:
transObject -  

getSocket

public Socket getSocket()
Returns the Socket of this connection.
Returns:
 

getUsername

public String getUsername()
Returns the usernam.
Returns:
 

getReader

public BufferedReader getReader()
Return the reader.
Returns: