org.jogre.common
Class AbstractConnectionThread

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.jogre.common.AbstractConnectionThread
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ClientConnectionThread

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.2.1
Author:
Bob Marks

Field Summary
protected  boolean connected
          All clients start initially with "connected" equal to false (although they can still recieve/transfer logon information).
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.
 void connect()
          Set boolean to specify that this client has connected sucessfully.
 Socket getSocket()
          Returns the Socket of this connection.
 String getUsername()
          Returns the username.
abstract  void parse(XMLElement message)
          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.
protected  void send(ITransmittable transObject)
          Send a ITransmittable object to the output stream (could be server or client).
 void setUsername(String username)
          Set the username.
 void stopLoop()
          Stop the loop.
 
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

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.


connected

protected boolean connected
All clients start initially with "connected" equal to false (although they can still recieve/transfer logon information).

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 - Socket connection to client / server.
Method Detail

parse

public abstract void parse(XMLElement message)
                    throws TransmissionException
This abstract method must be overwritten by a child which extends this class.

Parameters:
message - Communication as an XML object.
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.

See Also:
Runnable.run()

stopLoop

public void stopLoop()
Stop the loop.


connect

public void connect()
Set boolean to specify that this client has connected sucessfully.


send

protected 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:
Socket to server / client.

getUsername

public String getUsername()
Returns the username.

Returns:
Username of client / server who created this thread.

setUsername

public void setUsername(String username)
Set the username.

Parameters:
username - Username of client / server who created this thread.