Class QueuedSocketWriter
java.lang.Object
java.lang.Thread
net.sf.colossus.webserver.QueuedSocketWriter
- All Implemented Interfaces:
Runnable
-
Nested Class Summary
Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanSet to true when flushing is completed.private final ObjectSending thread that requests the flushing, waits on this mutex until notified that the flush was completed (boolean 'flushed' below set to true).private final intprivate static int(package private) static final Loggerprivate static final Stringprivate static final String(package private) PrintWriterThe actual writer object which will send printed data over the socket.private final LinkedBlockingQueue<String> The actual queue holding all messages that need to be sent.Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidEnqueues a flush marker and waits on the mutex until the flushing of all messages enqueued prior to the marker have been sent.private StringWe use no timeout while waiting for next message in the queue.voidrun()voidsendMessage(String message) voidMethods inherited from class Thread
activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, threadId, toString, yield
-
Field Details
-
LOGGER
-
MSG_EXIT_LOOP
- See Also:
-
MSG_FLUSH_MSGS
- See Also:
-
queue
The actual queue holding all messages that need to be sent. This is a concurrent-safe queue. -
out
PrintWriter outThe actual writer object which will send printed data over the socket. -
flushMutex
Sending thread that requests the flushing, waits on this mutex until notified that the flush was completed (boolean 'flushed' below set to true). -
flushed
private boolean flushedSet to true when flushing is completed. -
done
private boolean done -
instanceIdCounter
private static int instanceIdCounter -
instanceId
private final int instanceId
-
-
Constructor Details
-
QueuedSocketWriter
- Throws:
IOException
-
-
Method Details
-
run
-
flushMessages
public void flushMessages()Enqueues a flush marker and waits on the mutex until the flushing of all messages enqueued prior to the marker have been sent. (this does at the moment not imply that the client has received them (not to mention even has processed them). -
stopWriter
public void stopWriter() -
sendMessage
-
readNextFromQueue
We use no timeout while waiting for next message in the queue. To get it out of the loop, we enqueue a special marker (MSG_EXIT_LOOP).- Returns:
- String containing the next message to write.
-