public abstract class Handler extends Thread
ReceiverServer is stored
to pipe error messages to its ReceiverServer.processError(stella.ErrorEvent) method.
A handler always runs as a thread because it handles the whole
communication between server and client which is normally a time-consuming
process. It does not start automatically. After the communication is
complete the close() method should be called to allow necessary
cleanup, i.e. closing of the streams and the client socket.
To avoid cpu-starvation due to low priority, the priority of the handler thread can be specified after construct using the Thread's setPriority method. Otherwise the default priority is used.
This class is defined abstract due to its (protected) runProtocol()
method.
Concrete implementations should follow these prescriptions.
ReceiverServer.processError(stella.ErrorEvent) for reporting
any errors.close() method should terminate the protocol.runProtocol() returns. It must be
performed by explicetly calling close(). Thread.State, Thread.UncaughtExceptionHandler| Modifier and Type | Field and Description |
|---|---|
private Socket |
client
The client socket this handler is connected to.
|
private static long |
ID
A session ID.
|
protected InputStream |
in
The input stream associated with this handler's client socket.
|
protected OutputStream |
out
The output stream associated with this handler's client socket.
|
protected ErrorProcessing |
spawner
The reference to the spawning server.
|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Modifier | Constructor and Description |
|---|---|
protected |
Handler(ErrorProcessing spawn,
Socket connect,
ThreadGroup group,
String name)
Constructs a new handler.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
close()
Closes the input and output streams and the associated socket.
|
void |
init()
Initializes this handler.
|
private static long |
nextID()
Returns the next session ID.
|
void |
run()
The rudimentary run method.
|
protected abstract void |
runProtocol()
The protocol implementation.
|
activeCount, checkAccess, clone, 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, yieldprivate Socket client
protected InputStream in
protected OutputStream out
protected ErrorProcessing spawner
private static long ID
protected Handler(ErrorProcessing spawn, Socket connect, ThreadGroup group, String name)
spawn - The spawning server used for error processing.connect - The socket this handler is conneted to.group - The thread group the handler should run in.name - The handlers thread-name.private static long nextID()
public void init()
protected void close()
public void run()
runProtocol()
method. Protocolls that want automatic closing of the socket must call
the close() method explicetly.protected abstract void runProtocol()
ReceiverServer.processError(stella.ErrorEvent) for reporting
any errors.close() method should terminate the protocol.
runProtocol() returns.