net.gleamynode.netty2
Class OrderedEventDispatcher

java.lang.Object
  extended by net.gleamynode.netty2.AbstractThreadPooledEventDispatcher
      extended by net.gleamynode.netty2.OrderedEventDispatcher
All Implemented Interfaces:
EventDispatcher, EventDispatcherMBean, OrderedEventDispatcherMBean, ThreadPooledEventDispatcher, ThreadPooledEventDispatcherMBean

public class OrderedEventDispatcher
extends AbstractThreadPooledEventDispatcher
implements ThreadPooledEventDispatcher, OrderedEventDispatcherMBean

A thread-pooled EventDispatcherthat the events for the same session occurs in the same order it was generated actually. It has synchronization overhead compared to SimpleEventDispatcher, but it will be more useful in most situations. See SimpleEventDispatcherfor its shortness.

Please note that OrderedEventDispatcherdoes not guarantee read and write events are fired in order, but it does guarantee that the same type of events will be fired in order:

  • Case 1: 'messageReceived' for the response message is fired before 'messageSent' for the request message is.)
  • Case 2: 'messageSent' or 'exceptionCaught' event is fired after 'connectionClosed' is fired.
  • I can't find any easy way to order read and write events for now.

    Set thread pool size (AbstractThreadPooledEventDispatcher.setThreadPoolSize(int)) and call AbstractThreadPooledEventDispatcher.start()to activate this event dispatcher.

    Please note that dispatcher threads will not terminate even if AbstractThreadPooledEventDispatcher.stop()is invoked if there are any remaining events to process for this event dispatcher. They will be terminated when JVM exits because they are daemon threads.

    Version:
    $Rev: 4 $, $Date: 2005-04-18 12:04:09 +0900 $
    Author:
    Trustin Lee (http://gleamynode.net/dev/)

    Nested Class Summary
     
    Nested classes/interfaces inherited from class net.gleamynode.netty2.AbstractThreadPooledEventDispatcher
    AbstractThreadPooledEventDispatcher.AbstractWorker
     
    Field Summary
     
    Fields inherited from class net.gleamynode.netty2.AbstractThreadPooledEventDispatcher
    workers
     
    Constructor Summary
    OrderedEventDispatcher()
              Creates a new instance.
     
    Method Summary
     void fire(Event event)
              Fires the specified session event.
     int getWaitingEventSize()
              Returns the number of session events that are still not dispatched to SessionListeners.
    protected  AbstractThreadPooledEventDispatcher.AbstractWorker newWorker()
               
    protected  AbstractThreadPooledEventDispatcher.AbstractWorker removeWorker()
               
     
    Methods inherited from class net.gleamynode.netty2.AbstractThreadPooledEventDispatcher
    flush, getThreadNamePrefix, getThreadPoolSize, getThreadPriority, isStarted, setThreadNamePrefix, setThreadPoolSize, setThreadPriority, start, stop
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    OrderedEventDispatcher

    public OrderedEventDispatcher()
    Creates a new instance.

    Method Detail

    getWaitingEventSize

    public int getWaitingEventSize()
    Description copied from interface: EventDispatcher
    Returns the number of session events that are still not dispatched to SessionListeners.

    Specified by:
    getWaitingEventSize in interface EventDispatcher
    Specified by:
    getWaitingEventSize in interface EventDispatcherMBean
    See Also:
    EventDispatcher.getWaitingEventSize()

    newWorker

    protected AbstractThreadPooledEventDispatcher.AbstractWorker newWorker()
    Specified by:
    newWorker in class AbstractThreadPooledEventDispatcher

    removeWorker

    protected AbstractThreadPooledEventDispatcher.AbstractWorker removeWorker()
    Specified by:
    removeWorker in class AbstractThreadPooledEventDispatcher

    fire

    public void fire(Event event)
    Description copied from interface: EventDispatcher
    Fires the specified session event.

    Specified by:
    fire in interface EventDispatcher


    Copyright © 2004-2008 Trustin Lee. All Rights Reserved.