|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.grizzly.comet.concurrent.DefaultConcurrentCometHandler<E>
public abstract class DefaultConcurrentCometHandler<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 .
Field Summary | |
---|---|
protected E |
attachment
|
protected static Logger |
logger
|
protected 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 Summary | |
---|---|
DefaultConcurrentCometHandler()
|
|
DefaultConcurrentCometHandler(int messageQueueLimit)
|
Method Summary | |
---|---|
void |
attach(E attachment)
Attach an intance of E to this class. |
E |
attachment()
returns the attachment |
void |
enqueueEvent(CometEvent event)
Queues event if another thread is currently working on this handler. |
void |
onInterrupt(CometEvent event)
Receive CometEvent notification when the underlying
tcp communication is resumed by Grizzly. |
void |
onQueueFull(CometEvent event)
called in synchronized context. |
void |
onTerminate(CometEvent event)
Receive CometEvent notification when the response
is resumed by a CometHandler or by the CometContext |
protected void |
terminate()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.sun.grizzly.comet.CometHandler |
---|
onEvent, onInitialize |
Field Detail |
---|
protected static final Logger logger
protected final Queue<CometEvent> messageQueue
protected E attachment
Constructor Detail |
---|
public DefaultConcurrentCometHandler()
public DefaultConcurrentCometHandler(int messageQueueLimit)
messageQueueLimit
- Method Detail |
---|
public void enqueueEvent(CometEvent event)
public void onQueueFull(CometEvent event)
event
- CometEvent
public E attachment()
public void attach(E attachment)
CometHandler
attach
in interface CometHandler<E>
public void onInterrupt(CometEvent event) throws IOException
CometEvent
notification when the underlying
tcp communication is resumed by Grizzly. This happens
when the CometContext.setExpirationDelay(long)
expires or when
the remote client close the connection.
onInterrupt
in interface CometHandler<E>
IOException
public void onTerminate(CometEvent event) throws IOException
CometEvent
notification when the response
is resumed by a CometHandler
or by the CometContext
onTerminate
in interface CometHandler<E>
IOException
protected void terminate()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |