@ChannelHandler.Sharable public class Dispatcher extends io.netty.channel.SimpleChannelInboundHandler<Message>
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!
| Constructor and Description |
|---|
Dispatcher(int p2pID,
PeerBean peerBeanMaster,
int heartBeatMillis) |
| Modifier and Type | Method and Description |
|---|---|
void |
addPendingRequest(int messageId,
FutureResponse futureResponse,
int timeout,
ScheduledExecutorService scheduler)
Add a new pending request.
|
DispatchHandler |
associatedHandler(Message message)
Checks if we have a handler for the given message.
|
protected void |
channelRead0(io.netty.channel.ChannelHandlerContext ctx,
Message message) |
Map<Integer,FutureResponse> |
getPendingRequests() |
PeerBean |
peerBean() |
void |
registerIoHandler(Number160 peerId,
Number160 onBehalfOf,
DispatchHandler ioHandler,
int... names)
Registers a handler with this dispatcher.
|
void |
removeIoHandler(Number160 peerId,
Number160 onBehalfOf)
If we shutdown, we remove the handlers.
|
Map<Number320,DispatchHandler> |
searchHandler(Integer command)
May take longer..
|
DispatchHandler |
searchHandler(Number160 recipientID,
Number160 onBehalfOf,
int cmd)
Looks for a registered handler according to the given parameters.
|
Map<Integer,DispatchHandler> |
searchHandlerMap(Number160 peerId,
Number160 onBehalfOf) |
acceptInboundMessage, channelReadchannelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredhandlerAdded, handlerRemoved, isSharablepublic Dispatcher(int p2pID,
PeerBean peerBeanMaster,
int heartBeatMillis)
p2pID - the p2p ID the dispatcher is looking for in messagespeerBeanMaster - heartBeatMillis - public PeerBean peerBean()
public void registerIoHandler(Number160 peerId, Number160 onBehalfOf, DispatchHandler ioHandler, int... names)
peerId - Specifies the receiver the dispatcher filters for. This allows to use one dispatcher for several
interfaces or even nodes.onBehalfOf - The ioHandler can be registered for the own use of in behalf of another peer (e.g. in case of relay node).ioHandler - the handler which should process the given type of messagesnames - The command of the Message the given handler processes. All messages having that command will
be forwarded to the given handler.public void removeIoHandler(Number160 peerId, Number160 onBehalfOf)
peerId - The Id of the peer to remove the handlers .onBehalfOf - The ioHandler can be registered for the own use of in behalf of another peer (e.g. in case of relay node).protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx,
Message message)
throws Exception
public DispatchHandler associatedHandler(Message message)
message - the message a handler should be found forpublic DispatchHandler searchHandler(Number160 recipientID, Number160 onBehalfOf, int cmd)
recipientID - The recipient of the messageonBehalfOf - The ioHandler can be registered for the own use of in behalf of another peer (e.g. in case of relay node).cmd - The type of the message to be filteredpublic Map<Number320,DispatchHandler> searchHandler(Integer command)
command - public Map<Integer,DispatchHandler> searchHandlerMap(Number160 peerId, Number160 onBehalfOf)
peerId - The id of the peer the get the dispatcher maponBehalfOf - The ioHandler can be registered for the own use of in behalf of another peer (e.g. in case of relay node).RPC.Commands typepublic void addPendingRequest(int messageId,
FutureResponse futureResponse,
int timeout,
ScheduledExecutorService scheduler)
messageId - the message idfutureResponse - the future to respond as soon as a (satisfying) response from the slow peer
arrived.scheduler - timeout - public Map<Integer,FutureResponse> getPendingRequests()
Copyright © 2014. All rights reserved.