common
Class AbstractThread

java.lang.Object
  extended by java.lang.Thread
      extended by common.AbstractThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ClientThread, ServerThread

public abstract class AbstractThread
extends java.lang.Thread


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.lang.String player
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbstractThread(java.net.Socket connection, int initNum)
          This constructor initializes the server thread by setting up all Object I/O to be used to communicate back and forth with a client.
 
Method Summary
 void destroyThread()
          Kills this thread.
abstract  void disconnect()
          An abstract disconnect method to be filled in by the concrete server or client thread.
 int getID()
          Gets the ID of the client connected to this thread.
 java.lang.String getPlayerName()
          Returns the String representation of the Player associated with this thread.
 boolean isConnected()
          Returns whether or not this thread has an active connection.
abstract  void passData(NetworkObject incoming)
          An abstract passData method to be filled in by the concrete server or client thread.
 void run()
          Receives incoming NetworkObjects, determines if connection still exists.
 void send(NetworkObject outgoing)
          Sends a NetworkObject message to the client connected to this thread.
 void setID(int id)
          Sets the ID of the client connected by this thread to the specified ID.
 void setPlayerName(java.lang.String p)
          Sets the String representation of the Player associated with this thread.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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

player

protected java.lang.String player
Constructor Detail

AbstractThread

public AbstractThread(java.net.Socket connection,
                      int initNum)
This constructor initializes the server thread by setting up all Object I/O to be used to communicate back and forth with a client.

Parameters:
connection - - socket that is connected to a client
initNum - - the player number of the client that will be communicated with by this thread
Method Detail

send

public void send(NetworkObject outgoing)
Sends a NetworkObject message to the client connected to this thread. In the event of their disconnection, an IOException is thrown.

Parameters:
outgoing - The Network Object to be written to the ObjectOutputStream.

setID

public void setID(int id)
Sets the ID of the client connected by this thread to the specified ID.

Parameters:
id - The id number to set to this client.

getID

public int getID()
Gets the ID of the client connected to this thread.

Returns:
The ID number of the client connected to this thread.

run

public void run()
Receives incoming NetworkObjects, determines if connection still exists.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

destroyThread

public void destroyThread()
Kills this thread.


setPlayerName

public void setPlayerName(java.lang.String p)
Sets the String representation of the Player associated with this thread.

Parameters:
p - String representing the Player associated with this thread.

getPlayerName

public java.lang.String getPlayerName()
Returns the String representation of the Player associated with this thread.

Returns:
String representation of the Player associated with this thread.

isConnected

public boolean isConnected()
Returns whether or not this thread has an active connection.

Returns:
boolean

disconnect

public abstract void disconnect()
An abstract disconnect method to be filled in by the concrete server or client thread.


passData

public abstract void passData(NetworkObject incoming)
An abstract passData method to be filled in by the concrete server or client thread.

Parameters:
incoming - The NetworkObject received.