org.kaariboga.io
Class ListenThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.kaariboga.io.ListenThread
All Implemented Interfaces:
java.lang.Runnable

public class ListenThread
extends java.lang.Thread

Listens on the specified port and spawns new threads to receive incoming messages.


Field Summary
private  KbMessageHandler messageHandler
          Handles the incoming messages
private  int port
          Port on which to listen for new messages.
private  java.util.Collection receivingThreads
          Collection of all threads currently receiving messages
private  boolean shouldLive
          Should this thread continue to live or terminate?
 
Fields inherited from class java.lang.Thread
contextClassLoader, daemon, eetop, group, inheritableThreadLocals, inheritedAccessControlContext, MAX_PRIORITY, MIN_PRIORITY, name, NORM_PRIORITY, priority, single_step, stillborn, stopThreadPermission, target, threadInitNumber, threadLocals, threadQ
 
Constructor Summary
ListenThread(KbMessageHandler handler, int port, java.util.Collection threads)
           
 
Method Summary
 void run()
          Listens on a server socket and spawns new threads to receive messages.
 void terminate()
          Terminates this thread.
 
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, exit, getContextClassLoader, getName, getPriority, getThreadGroup, init, interrupt, interrupt0, interrupted, isAlive, isDaemon, isInterrupted, isInterrupted, join, join, join, nextThreadNum, registerNatives, resume, resume0, setContextClassLoader, setDaemon, setName, setPriority, setPriority0, sleep, sleep, start, stop, stop, stop0, suspend, suspend0, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

shouldLive

private volatile boolean shouldLive
Should this thread continue to live or terminate?

messageHandler

private KbMessageHandler messageHandler
Handles the incoming messages

receivingThreads

private java.util.Collection receivingThreads
Collection of all threads currently receiving messages

port

private int port
Port on which to listen for new messages.
Constructor Detail

ListenThread

public ListenThread(KbMessageHandler handler,
                    int port,
                    java.util.Collection threads)
Parameters:
handler - A KbMessageHandler to handle incoming messages
port - The port number on which the server socket listens for messages.
threads - Collection of the threads, currently receiving messages.
Method Detail

run

public void run()
Listens on a server socket and spawns new threads to receive messages.
Overrides:
run in class java.lang.Thread

terminate

public void terminate()
Terminates this thread. This method returns before the thread has terminated. If you want to wait until the thread has terminated use something like this: listenThread.terminate(); listenThread.join();