org.xsocket
Class Dispatcher<T extends IHandle>

Package class diagram package Dispatcher
java.lang.Object
  extended by org.xsocket.Dispatcher<T>
All Implemented Interfaces:
java.io.Closeable, java.lang.Runnable, IDispatcher<T>

public class Dispatcher<T extends IHandle>
extends java.lang.Object
implements IDispatcher<T>

implementation of the IDispatcher

All dispatcher methods are thread save.


Constructor Summary
Dispatcher(IEventHandler<T> eventHandler)
          constructor
 
Method Summary
 void close()
          
 void deregister(T handle)
          deregister a handle.
 IEventHandler<T> getEventHandler()
          get the event handler of this dispatcher

.
 long getNumberOfHandledReads()
          get the number of handled reads
 long getNumberOfHandledRegistrations()
          get the number of handled registractions
 long getNumberOfHandledWrites()
          get the number of handled writes
 java.util.Set<T> getRegistered()
          return the registered handles
 boolean isOpen()
          check if this dispatcher is open
 void register(T handle, int ops)
          register a new handle.
 void run()
          
 void updateInterestSet(T handle, int ops)
          announce a write for he given handle.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Dispatcher

public Dispatcher(IEventHandler<T> eventHandler)
constructor

Parameters:
eventHandler - the assigned event handler
Method Detail

getEventHandler

public final IEventHandler<T> getEventHandler()
get the event handler of this dispatcher

. This method is thread save

Specified by:
getEventHandler in interface IDispatcher<T extends IHandle>
Returns:
the event handler

register

public void register(T handle,
                     int ops)
              throws java.io.IOException
register a new handle.

. This method is thread save

Specified by:
register in interface IDispatcher<T extends IHandle>
Parameters:
handle - the handle to register
ops - the interest set
Throws:
java.io.IOException - If some I/O error occurs

deregister

public void deregister(T handle)
                throws java.io.IOException
deregister a handle.

This method is thread save

Specified by:
deregister in interface IDispatcher<T extends IHandle>
Parameters:
handle - the handle to deregister
Throws:
java.io.IOException - If some I/O error occurs

getRegistered

public final java.util.Set<T> getRegistered()
return the registered handles

Specified by:
getRegistered in interface IDispatcher<T extends IHandle>
Returns:
a list of the registered handles

updateInterestSet

public final void updateInterestSet(T handle,
                                    int ops)
                             throws java.io.IOException
announce a write for he given handle.

This method is thread save

Specified by:
updateInterestSet in interface IDispatcher<T extends IHandle>
Parameters:
handle - the handle for the write need
ops - the interest set
Throws:
java.io.IOException - if the given hnadle is invalid

run

public final void run()

Specified by:
run in interface java.lang.Runnable

close

public void close()

Specified by:
close in interface java.io.Closeable

isOpen

public final boolean isOpen()
check if this dispatcher is open

Returns:
true, if the disptacher is open

getNumberOfHandledRegistrations

public final long getNumberOfHandledRegistrations()
get the number of handled registractions

Specified by:
getNumberOfHandledRegistrations in interface IDispatcher<T extends IHandle>
Returns:
the number of handled registractions

getNumberOfHandledReads

public final long getNumberOfHandledReads()
get the number of handled reads

Specified by:
getNumberOfHandledReads in interface IDispatcher<T extends IHandle>
Returns:
the number of handled reads

getNumberOfHandledWrites

public final long getNumberOfHandledWrites()
get the number of handled writes

Specified by:
getNumberOfHandledWrites in interface IDispatcher<T extends IHandle>
Returns:
the number of handled writes