org.apache.mina.protocol.handler
Class DemuxingProtocolHandler

java.lang.Object
  extended by org.apache.mina.protocol.ProtocolHandlerAdapter
      extended by org.apache.mina.protocol.handler.DemuxingProtocolHandler
All Implemented Interfaces:
ProtocolHandler

public class DemuxingProtocolHandler
extends ProtocolHandlerAdapter

A ProtocolHandler that demuxes messageReceived events to the appropriate MessageHandler. You can freely register and deregister MessageHandlers using addMessageHandler(Class, MessageHandler) and removeMessageHandler(Class).

Version:
$Rev: 332218 $, $Date: 2005-11-10 12:52:42 +0900 $
Author:
The Apache Directory Project

Constructor Summary
protected DemuxingProtocolHandler()
          Creates a new instance with no registered MessageHandlers.
 
Method Summary
 MessageHandler addMessageHandler(Class type, MessageHandler handler)
          Registers a MessageHandler that receives the messages of the specified type.
 MessageHandler getMessageHandler(Class type)
          Returns the MessageHandler which is registered to process the specified type.
 Map getMessageHandlerMap()
          Returns the Map which contains all messageType-MessageHandler pairs registered to this handler.
 void messageReceived(ProtocolSession session, Object message)
          Forwards the received events into the appropriate MessageHandler which is registered by addMessageHandler(Class, MessageHandler).
 MessageHandler removeMessageHandler(Class type)
          Deregisters a MessageHandler that receives the messages of the specified type.
 
Methods inherited from class org.apache.mina.protocol.ProtocolHandlerAdapter
exceptionCaught, messageSent, sessionClosed, sessionCreated, sessionIdle, sessionOpened
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DemuxingProtocolHandler

protected DemuxingProtocolHandler()
Creates a new instance with no registered MessageHandlers.

Method Detail

addMessageHandler

public MessageHandler addMessageHandler(Class type,
                                        MessageHandler handler)
Registers a MessageHandler that receives the messages of the specified type.

Returns:
the old handler if there is already a registered handler for the specified type. null otherwise.

removeMessageHandler

public MessageHandler removeMessageHandler(Class type)
Deregisters a MessageHandler that receives the messages of the specified type.

Returns:
the removed handler if successfully removed. null otherwise.

getMessageHandler

public MessageHandler getMessageHandler(Class type)
Returns the MessageHandler which is registered to process the specified type.


getMessageHandlerMap

public Map getMessageHandlerMap()
Returns the Map which contains all messageType-MessageHandler pairs registered to this handler.


messageReceived

public void messageReceived(ProtocolSession session,
                            Object message)
                     throws Exception
Forwards the received events into the appropriate MessageHandler which is registered by addMessageHandler(Class, MessageHandler).

Specified by:
messageReceived in interface ProtocolHandler
Overrides:
messageReceived in class ProtocolHandlerAdapter
Throws:
Exception


Copyright © 2004-2005 . All Rights Reserved.