netbattle
Class MessageHandler

java.lang.Object
  extended by java.lang.Thread
      extended by netbattle.MessageHandler
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
NetClient

public abstract class MessageHandler
extends java.lang.Thread

Processes input from a socket.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.io.ObjectInputStream m_input
           
protected  java.io.ObjectOutputStream m_output
           
protected  java.net.Socket m_socket
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected MessageHandler()
          Prevents creation of MessageHandler externally.
 
Method Summary
protected abstract  void executeMessage(NetMessage msg)
          Exexcute a message.
 NetMessage getNextMessage()
          Pull a message off the queue, with the default timeout.
 NetMessage getNextMessage(int timeout)
          Pull a message off the queue, with the specified timeout.
protected abstract  void informReadError(java.lang.Throwable e)
          Inform of a read error.
protected  void informWriteError(java.io.IOException e)
          Inform of a write error.
protected  boolean isRunning()
           
 void run()
           
 void sendMessage(NetMessage message)
          Send a message.
 void sendMessage(java.lang.Runnable message)
          Send a runnable message.
protected  void stopRunning()
           
 
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

m_socket

protected java.net.Socket m_socket

m_input

protected java.io.ObjectInputStream m_input

m_output

protected java.io.ObjectOutputStream m_output
Constructor Detail

MessageHandler

protected MessageHandler()
Prevents creation of MessageHandler externally.

Method Detail

isRunning

protected boolean isRunning()

stopRunning

protected void stopRunning()

executeMessage

protected abstract void executeMessage(NetMessage msg)
Exexcute a message.


informReadError

protected abstract void informReadError(java.lang.Throwable e)
Inform of a read error.


informWriteError

protected void informWriteError(java.io.IOException e)
Inform of a write error.


sendMessage

public void sendMessage(java.lang.Runnable message)
Send a runnable message.


sendMessage

public void sendMessage(NetMessage message)
Send a message.


getNextMessage

public NetMessage getNextMessage()
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
Pull a message off the queue, with the default timeout.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

getNextMessage

public NetMessage getNextMessage(int timeout)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
Pull a message off the queue, with the specified timeout.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread