Class QueuedSocketWriter

java.lang.Object
java.lang.Thread
net.sf.colossus.webserver.QueuedSocketWriter
All Implemented Interfaces:
Runnable

class QueuedSocketWriter extends Thread
  • Field Details

    • LOGGER

      static final Logger LOGGER
    • MSG_EXIT_LOOP

      private static final String MSG_EXIT_LOOP
      See Also:
    • MSG_FLUSH_MSGS

      private static final String MSG_FLUSH_MSGS
      See Also:
    • queue

      private final LinkedBlockingQueue<String> queue
      The actual queue holding all messages that need to be sent. This is a concurrent-safe queue.
    • out

      The actual writer object which will send printed data over the socket.
    • flushMutex

      private final Object 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 flushed
      Set to true when flushing is completed.
    • done

      private boolean done
    • instanceIdCounter

      private static int instanceIdCounter
    • instanceId

      private final int instanceId
  • Constructor Details

  • Method Details

    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • 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

      public void sendMessage(String message)
    • readNextFromQueue

      private String 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.