Class DefaultConcurrentCometHandler<E>

java.lang.Object
org.glassfish.grizzly.comet.concurrent.DefaultConcurrentCometHandler<E>
All Implemented Interfaces:
CometHandler<E>

public abstract class DefaultConcurrentCometHandler<E> extends Object implements CometHandler<E>
We queue events in each CometHandler to lower the probability that slow or massive IO for one CometHandler severely delays events to others.

only streaming mode can benefit from buffering messages like this.
only 1 thread at a time is allowed to do IO, other threads put events in the queue and return to the thread pool.

a thread initially calls enqueueEvent and stay there until there are no more events in the queue, calling the onEVent method in synchronized context for each Event.

on IOE in onEvent we terminate.
we have a limit, to keep memory usage under control.

if queue limit is reached onQueueFull is called, and then we terminate.


whats not optimal is that a worker thread is sticky to the client depending upon available events in the handlers local queue, that can in theory allow a few clients to block all threads for extended time.
that effect can make this implementation unusable depending on the scenario, its not a perfect design be any means.
The potential improvement is that only 1 worker thread is tied up to a client instead of several being blocked by synchronized io wait for one CometHandler .
Author:
Gustav Trede
  • Field Details

    • messageQueue

      protected final Queue<CometEvent> messageQueue
      todo replace with non array copying list for non resizing add situations, using internal index to keep track of state , not a linked list, it has too much overhead and eats memory.
  • Constructor Details

    • DefaultConcurrentCometHandler

      public DefaultConcurrentCometHandler(CometContext<E> context, org.glassfish.grizzly.http.server.Response response)
    • DefaultConcurrentCometHandler

      public DefaultConcurrentCometHandler(int messageQueueLimit)
      Parameters:
      messageQueueLimit -
  • Method Details