net.tomp2p.connection
Class DispatcherReply

java.lang.Object
  extended by org.jboss.netty.channel.SimpleChannelHandler
      extended by net.tomp2p.connection.DispatcherReply
All Implemented Interfaces:
org.jboss.netty.channel.ChannelDownstreamHandler, org.jboss.netty.channel.ChannelHandler, org.jboss.netty.channel.ChannelUpstreamHandler

@ChannelHandler.Sharable
public class DispatcherReply
extends org.jboss.netty.channel.SimpleChannelHandler

Used to deliver incoming REQUEST messages to their specific handlers. You can register handlers using the registerIoHandler function.

You probably want to add an instance of this class to the end of a pipeline to be able to receive messages. This class is able to cover several channels but only one P2P network!

Author:
Thomas Bocek

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
org.jboss.netty.channel.ChannelHandler.Sharable
 
Constructor Summary
DispatcherReply(int p2pID, PeerBean peerBean, ConnectionConfiguration configuration, org.jboss.netty.channel.group.ChannelGroup channelGroup, PeerMap peerMap)
          Constructor
 
Method Summary
 void channelOpen(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.ChannelStateEvent e)
           
 void exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.ExceptionEvent e)
          Called if we get an exception
 void messageReceived(org.jboss.netty.channel.ChannelHandlerContext ctx, org.jboss.netty.channel.MessageEvent e)
          Called if we get a message
 void registerIoHandler(Number160 localPeerId, ReplyHandler ioHandler, Message.Command... names)
          Registers a handler with this dispatcher.
 void removeIoHandler(Number160 localPeerId)
          If we shutdown, we remove the handlers.
 
Methods inherited from class org.jboss.netty.channel.SimpleChannelHandler
bindRequested, channelBound, channelClosed, channelConnected, channelDisconnected, channelInterestChanged, channelUnbound, childChannelClosed, childChannelOpen, closeRequested, connectRequested, disconnectRequested, handleDownstream, handleUpstream, setInterestOpsRequested, unbindRequested, writeComplete, writeRequested
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DispatcherReply

public DispatcherReply(int p2pID,
                       PeerBean peerBean,
                       ConnectionConfiguration configuration,
                       org.jboss.netty.channel.group.ChannelGroup channelGroup,
                       PeerMap peerMap)
Constructor

Parameters:
p2pID - the p2p ID the dispatcher is looking for in messages
routing -
Method Detail

registerIoHandler

public void registerIoHandler(Number160 localPeerId,
                              ReplyHandler ioHandler,
                              Message.Command... names)
Registers a handler with this dispatcher. Future received messages adhering to the given parameters will be forwarded to that handler. Note that the dispatcher only handles REQUEST messages. This method is thread-safe, and uses copy on write as its expected to run this only during initialization.

Parameters:
sender - Specifies the receiver the dispatcher filters for. This allows to use one dispatcher for several interfaces or even nodes. TODO: why call it sender here if it really acts as receiver?
name - The command of the Message the given handler processes. All messages having that command will be forwarded to the given handler.
Note: If you register multiple handlers with the same command, only the last registered handler will receive these messages!
ioHandler - the handler which should process the given type of messages

removeIoHandler

public void removeIoHandler(Number160 localPeerId)
If we shutdown, we remove the handlers. This means that a server may respond that the handler is unknown.

Parameters:
id - The Id of the peer to remove the handlers.

channelOpen

public void channelOpen(org.jboss.netty.channel.ChannelHandlerContext ctx,
                        org.jboss.netty.channel.ChannelStateEvent e)
                 throws Exception
Overrides:
channelOpen in class org.jboss.netty.channel.SimpleChannelHandler
Throws:
Exception

exceptionCaught

public void exceptionCaught(org.jboss.netty.channel.ChannelHandlerContext ctx,
                            org.jboss.netty.channel.ExceptionEvent e)
Called if we get an exception

Overrides:
exceptionCaught in class org.jboss.netty.channel.SimpleChannelHandler

messageReceived

public void messageReceived(org.jboss.netty.channel.ChannelHandlerContext ctx,
                            org.jboss.netty.channel.MessageEvent e)
                     throws Exception
Called if we get a message

Overrides:
messageReceived in class org.jboss.netty.channel.SimpleChannelHandler
Throws:
Exception


Copyright © 2013. All Rights Reserved.