Package de.stefanreiser.net.server
Class AbstractWorker
java.lang.Object
java.lang.Thread
de.stefanreiser.net.server.AbstractWorker
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
DefaultWorker
public abstract class AbstractWorker
extends java.lang.Thread
- Author:
- Stefan
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
AbstractWorker.Message
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CRLF
protected Loggable
logger
static int
SOCKET_TIMEOUT
-
Constructor Summary
Constructors Constructor Description AbstractWorker(java.net.Socket socket, Loggable logger)
-
Method Summary
Modifier and Type Method Description void
cancel()
protected void
flush()
boolean
isCanceled()
protected boolean
isLineAvailable()
abstract int
maxLineLength()
Accept lines from client up to maxLineLength() characters.protected abstract void
onThreadHasEnded()
Called when Thread.run() ends.protected AbstractWorker.Message
read()
void
run()
protected void
send(java.lang.String... msgs)
protected void
sendln(java.lang.String msg)
protected abstract void
session()
abstract java.lang.String
welcomeMessage()
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
SOCKET_TIMEOUT
public static final int SOCKET_TIMEOUT- See Also:
- Constant Field Values
-
CRLF
public static final java.lang.String CRLF- See Also:
- Constant Field Values
-
logger
-
-
Constructor Details
-
Method Details
-
run
public final void run()- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
-
read
- Returns:
- Throws:
ServerException
-
isLineAvailable
- Throws:
ServerException
-
send
- Throws:
ServerException
-
sendln
- Throws:
ServerException
-
flush
- Throws:
ServerException
-
cancel
public void cancel() -
isCanceled
public boolean isCanceled() -
onThreadHasEnded
protected abstract void onThreadHasEnded()Called when Thread.run() ends. Can be used to clean up resources. -
welcomeMessage
public abstract java.lang.String welcomeMessage() -
maxLineLength
public abstract int maxLineLength()Accept lines from client up to maxLineLength() characters.- Returns:
-
session
- Throws:
ServerException
-