| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.mina.core.service.IoHandlerAdapter
org.apache.mina.handler.demux.DemuxingIoHandler
public class DemuxingIoHandler
A IoHandler that demuxes messageReceived events
 to the appropriate MessageHandler.
 
 You can freely register and deregister MessageHandlers using
 addReceivedMessageHandler(Class, MessageHandler) and
 removeReceivedMessageHandler(Class).
 
 When message is received through a call to
 messageReceived(IoSession, Object) the class of the
 message object will be used to find a MessageHandler for
 that particular message type. If no MessageHandler instance can be
 found for the immediate class (i.e. message.getClass()) the
 interfaces implemented by the immediate class will be searched in depth-first
 order. If no match can be found for any of the interfaces the search will be
 repeated recursively for the superclass of the immediate class
 (i.e. message.getClass().getSuperclass()).
 
 Consider the following type hierarchy (Cx are classes while
 Ix are interfaces):
 
     C3 - I7 - I9
      |    |   /\
      |   I8  I3 I4
      |
     C2 - I5 - I6
      |
     C1 - I1 - I2 - I4
      |         |
      |        I3
    Object
 
 When message is of type C3 this hierarchy will be
 searched in the following order:
 C3, I7, I8, I9, I3, I4, C2, I5, I6, C1, I1, I2, I3, I4, Object.
 
 
 For efficiency searches will be cached. Calls to
 addReceivedMessageHandler(Class, MessageHandler) and
 removeReceivedMessageHandler(Class) clear this cache.
 
| Constructor Summary | |
|---|---|
| DemuxingIoHandler()Creates a new instance with no registered MessageHandlers. | |
| Method Summary | ||
|---|---|---|
| 
 | addExceptionHandler(Class<E> type,
                    ExceptionHandler<? super E> handler)Registers a MessageHandlerthat receives the messages of
 the specifiedtype. | |
| 
 | addReceivedMessageHandler(Class<E> type,
                          MessageHandler<? super E> handler)Registers a MessageHandlerthat handles the received messages of
 the specifiedtype. | |
| 
 | addSentMessageHandler(Class<E> type,
                      MessageHandler<? super E> handler)Registers a MessageHandlerthat handles the sent messages of the
 specifiedtype. | |
|  void | exceptionCaught(IoSession session,
                Throwable cause)Invoked when any exception is thrown by user IoHandlerimplementation or by MINA. | |
| protected  ExceptionHandler<Throwable> | findExceptionHandler(Class<? extends Throwable> type) | |
| protected  MessageHandler<Object> | findReceivedMessageHandler(Class<?> type) | |
| protected  MessageHandler<Object> | findSentMessageHandler(Class<?> type) | |
|  Map<Class<?>,ExceptionHandler<?>> | getExceptionHandlerMap()Returns the Mapwhich contains all messageType-MessageHandlerpairs registered to this handler. | |
| 
 | getMessageHandler(Class<E> type)Returns the MessageHandlerwhich is registered to process
 the specifiedtype. | |
|  Map<Class<?>,MessageHandler<?>> | getReceivedMessageHandlerMap()Returns the Mapwhich contains all messageType-MessageHandlerpairs registered to this handler for received messages. | |
|  Map<Class<?>,MessageHandler<?>> | getSentMessageHandlerMap()Returns the Mapwhich contains all messageType-MessageHandlerpairs registered to this handler for sent messages. | |
|  void | messageReceived(IoSession session,
                Object message)Forwards the received events into the appropriate MessageHandlerwhich is registered byaddReceivedMessageHandler(Class, MessageHandler). | |
|  void | messageSent(IoSession session,
            Object message)Invoked when a message written by IoSession.write(Object)is
 sent out. | |
| 
 | removeExceptionHandler(Class<E> type)Deregisters a MessageHandlerthat receives the messages of
 the specifiedtype. | |
| 
 | removeReceivedMessageHandler(Class<E> type)Deregisters a MessageHandlerthat handles the received messages
 of the specifiedtype. | |
| 
 | removeSentMessageHandler(Class<E> type)Deregisters a MessageHandlerthat handles the sent messages of
 the specifiedtype. | |
| Methods inherited from class org.apache.mina.core.service.IoHandlerAdapter | 
|---|
| sessionClosed, sessionCreated, sessionIdle, sessionOpened | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public DemuxingIoHandler()
MessageHandlers.
| Method Detail | 
|---|
public <E> MessageHandler<? super E> addReceivedMessageHandler(Class<E> type,
                                                               MessageHandler<? super E> handler)
MessageHandler that handles the received messages of
 the specified type.
public <E> MessageHandler<? super E> removeReceivedMessageHandler(Class<E> type)
MessageHandler that handles the received messages
 of the specified type.
public <E> MessageHandler<? super E> addSentMessageHandler(Class<E> type,
                                                           MessageHandler<? super E> handler)
MessageHandler that handles the sent messages of the
 specified type.
public <E> MessageHandler<? super E> removeSentMessageHandler(Class<E> type)
MessageHandler that handles the sent messages of
 the specified type.
public <E extends Throwable> ExceptionHandler<? super E> addExceptionHandler(Class<E> type,
                                                                             ExceptionHandler<? super E> handler)
MessageHandler that receives the messages of
 the specified type.
public <E extends Throwable> ExceptionHandler<? super E> removeExceptionHandler(Class<E> type)
MessageHandler that receives the messages of
 the specified type.
public <E> MessageHandler<? super E> getMessageHandler(Class<E> type)
MessageHandler which is registered to process
 the specified type.
public Map<Class<?>,MessageHandler<?>> getReceivedMessageHandlerMap()
Map which contains all messageType-MessageHandler
 pairs registered to this handler for received messages.
public Map<Class<?>,MessageHandler<?>> getSentMessageHandlerMap()
Map which contains all messageType-MessageHandler
 pairs registered to this handler for sent messages.
public Map<Class<?>,ExceptionHandler<?>> getExceptionHandlerMap()
Map which contains all messageType-MessageHandler
 pairs registered to this handler.
public final void messageReceived(IoSession session,
                                  Object message)
                           throws Exception
MessageHandler
 which is registered by addReceivedMessageHandler(Class, MessageHandler).
messageReceived in interface IoHandlermessageReceived in class IoHandlerAdapterException
public final void messageSent(IoSession session,
                              Object message)
                       throws Exception
IoHandlerIoSession.write(Object) is
 sent out.
messageSent in interface IoHandlermessageSent in class IoHandlerAdapterException
public final void exceptionCaught(IoSession session,
                                  Throwable cause)
                           throws Exception
IoHandlerIoHandler
 implementation or by MINA.  If cause is an instance of
 IOException, MINA will close the connection automatically.
exceptionCaught in interface IoHandlerexceptionCaught in class IoHandlerAdapterExceptionprotected MessageHandler<Object> findReceivedMessageHandler(Class<?> type)
protected MessageHandler<Object> findSentMessageHandler(Class<?> type)
protected ExceptionHandler<Throwable> findExceptionHandler(Class<? extends Throwable> type)
| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||