LimeWire Consolidated API

com.limegroup.gnutella
Interface MessageRouter

All Superinterfaces:
Service
All Known Implementing Classes:
MessageRouterImpl, StandardMessageRouter

public interface MessageRouter
extends Service


Field Summary
static long CLEAR_TIME
           
 
Method Summary
 boolean addBypassedSource(QueryReply reply, ReplyHandler handler)
          Adds the address of handler to the BypassedResultsCache if it is likely to not be firewalled.
 boolean addBypassedSource(ReplyNumberVendorMessage reply, ReplyHandler handler)
          Adds the address of handler to the BypassedResultsCache if it can receive unsolicited udp.
 void addMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Adds the new handler as a handler in addition to other handlers.
 void addMulticastMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Adds the new handler as a handler in addition to other handlers for multicast messages.
 void addUDPMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Adds the new handler as a handler in addition to other handlers for UDP messages.
 void broadcastPingRequest(PingRequest ping)
          Broadcasts the ping request to all initialized connections, setting up the proper reply routing.
 void downloadFinished(GUID guid)
          Call this to inform us that a download is finished or whatever.
 void forwardInspectionRequestToLeaves(InspectionRequest ir)
          Forwards an inspection request to leaf connections that support it.
 void forwardQueryRequestToLeaves(QueryRequest query, ReplyHandler handler)
          Forwards the query request to any leaf connections.
 MessageHandler getMessageHandler(Class<? extends Message> clazz)
          Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.
 MessageHandler getMulticastMessageHandler(Class<? extends Message> clazz)
          Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.
 int getNumOOBToRequest(ReplyNumberVendorMessage reply)
          Returns the number of results to request from source of reply.
 long getOOBExpireTime()
          Time after which an OOB session should be expired.
 String getPingRouteTableDump()
           
 ReplyHandler getPushHandler(byte[] guid)
          Returns the push handler registered for the guid, could also be ForMeReplyHandler or any of the leaves that are push proxied.
 String getPushRouteTableDump()
           
 Set<GUESSEndpoint> getQueryLocs(GUID guid)
           
 QueryRouteTable getQueryRouteTable()
          Accessor for the most recently calculated QueryRouteTable for this node.
 String getQueryRouteTableDump()
           
 MessageHandler getUDPMessageHandler(Class<? extends Message> clazz)
          Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.
 void handleMessage(Message msg, ReplyHandler receivingConnection)
          The handler for all message types.
 void handleMulticastMessage(Message msg, InetSocketAddress addr)
          The handler for Multicast messages.
 void handleQueryReply(QueryReply queryReply, ReplyHandler handler)
          The default handler for QueryReplies.
 void handleUDPMessage(Message msg, InetSocketAddress addr)
          The handler for all message types.
 boolean isHostUnicastQueried(GUID guid, IpPort host)
          Determines if we've sent a unicast OOB query to the given host using the given query GUID.
 boolean isQueryAlive(GUID guid)
           
 void originateQueryGUID(byte[] guid)
          Routes a query GUID to yourself.
 void queryKilled(GUID guid)
          Call this to inform us that a query has been killed by a user or whatever.
 void registerMessageListener(byte[] guid, MessageListener ml)
          Adds the specified MessageListener for messages with this GUID.
 Iterable<QueryReply> responsesToQueryReplies(Response[] responses, QueryRequest queryRequest)
          Converts the passed responses to QueryReplies.
 Iterable<QueryReply> responsesToQueryReplies(Response[] responses, QueryRequest queryRequest, int replyLimit, SecurityToken token)
           
 void sendDynamicQuery(QueryRequest query)
          Generates a new dynamic query.
 boolean sendInitialQuery(QueryRequest query, RoutedConnection mc)
          Used to send the first request to a specific ultrapeer when dynamic querying.
 void sendMulticastPushRequest(PushRequest push)
          Sends a push request to the multicast network.
 void sendPingRequest(PingRequest request, RoutedConnection connection)
          Sends the ping request to the designated connection, setting up the proper reply routing.
 void sendPushRequest(PushRequest push)
          Uses the push route table to send a push request to the appropriate connection.
 void sendQueryRequest(QueryRequest request, RoutedConnection connection)
          Sends the query request to the designated connection, setting up the proper reply routing.
 void setMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Installs a MessageHandler for "regular" Messages.
 void setMulticastMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Installs a MessageHandler for Multicast Messages.
 void setUDPMessageHandler(Class<? extends Message> clazz, MessageHandler handler)
          Installs a MessageHandler for UDP Messages.
 void unregisterMessageListener(byte[] guid, MessageListener ml)
          Unregisters this MessageListener from listening to the GUID.
 
Methods inherited from interface org.limewire.lifecycle.Service
getServiceName, initialize, start, stop
 

Field Detail

CLEAR_TIME

static final long CLEAR_TIME
See Also:
Constant Field Values
Method Detail

setMessageHandler

void setMessageHandler(Class<? extends Message> clazz,
                       MessageHandler handler)
Installs a MessageHandler for "regular" Messages.

Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

addMessageHandler

void addMessageHandler(Class<? extends Message> clazz,
                       MessageHandler handler)
Adds the new handler as a handler in addition to other handlers.

Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

getMessageHandler

MessageHandler getMessageHandler(Class<? extends Message> clazz)
Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.


setUDPMessageHandler

void setUDPMessageHandler(Class<? extends Message> clazz,
                          MessageHandler handler)
Installs a MessageHandler for UDP Messages.

Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

addUDPMessageHandler

void addUDPMessageHandler(Class<? extends Message> clazz,
                          MessageHandler handler)
Adds the new handler as a handler in addition to other handlers for UDP messages.

Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

getUDPMessageHandler

MessageHandler getUDPMessageHandler(Class<? extends Message> clazz)
Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.


setMulticastMessageHandler

void setMulticastMessageHandler(Class<? extends Message> clazz,
                                MessageHandler handler)
Installs a MessageHandler for Multicast Messages.

Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

addMulticastMessageHandler

void addMulticastMessageHandler(Class<? extends Message> clazz,
                                MessageHandler handler)
Adds the new handler as a handler in addition to other handlers for multicast messages.

Parameters:
clazz - The Class of the Message
handler - The Handler of the Message

getMulticastMessageHandler

MessageHandler getMulticastMessageHandler(Class<? extends Message> clazz)
Returns a MessageHandler for the specified Message Class or null if no such MessageHandler exists.


originateQueryGUID

void originateQueryGUID(byte[] guid)
Routes a query GUID to yourself.


queryKilled

void queryKilled(GUID guid)
                 throws IllegalArgumentException
Call this to inform us that a query has been killed by a user or whatever. Useful for purging unneeded info.
Callers of this should make sure that they have purged the guid from their tables.

Throws:
IllegalArgumentException - if the guid is null

downloadFinished

void downloadFinished(GUID guid)
                      throws IllegalArgumentException
Call this to inform us that a download is finished or whatever. Useful for purging unneeded info.
If the caller is a Downloader, please be sure to clear yourself from the active and waiting lists in DownloadManager.

Throws:
IllegalArgumentException - if the guid is null

getQueryLocs

Set<GUESSEndpoint> getQueryLocs(GUID guid)
Parameters:
guid - the guid of the query you want endpoints for.

getPingRouteTableDump

String getPingRouteTableDump()

getQueryRouteTableDump

String getQueryRouteTableDump()

getPushRouteTableDump

String getPushRouteTableDump()

handleMessage

void handleMessage(Message msg,
                   ReplyHandler receivingConnection)
The handler for all message types. Processes a message based on the message type.

Parameters:
m - the Message instance to route appropriately
receivingConnection - the ReplyHandler over which the message was received

handleUDPMessage

void handleUDPMessage(Message msg,
                      InetSocketAddress addr)
The handler for all message types. Processes a message based on the message type.

Parameters:
msg - the Message received
addr - the InetSocketAddress containing the IP and port of the client node

handleMulticastMessage

void handleMulticastMessage(Message msg,
                            InetSocketAddress addr)
The handler for Multicast messages. Processes a message based on the message type.

Parameters:
msg - the Message recieved.
addr - the InetSocketAddress containing the IP and port of the client node.

addBypassedSource

boolean addBypassedSource(ReplyNumberVendorMessage reply,
                          ReplyHandler handler)
Adds the address of handler to the BypassedResultsCache if it can receive unsolicited udp.

Returns:
true if successfully added to the bypassed results cache

addBypassedSource

boolean addBypassedSource(QueryReply reply,
                          ReplyHandler handler)
Adds the address of handler to the BypassedResultsCache if it is likely to not be firewalled.


getNumOOBToRequest

int getNumOOBToRequest(ReplyNumberVendorMessage reply)
Returns the number of results to request from source of reply.

Returns:
-1 if no results are desired

isQueryAlive

boolean isQueryAlive(GUID guid)
Returns:
true if there is still a route for this reply

isHostUnicastQueried

boolean isHostUnicastQueried(GUID guid,
                             IpPort host)
Determines if we've sent a unicast OOB query to the given host using the given query GUID.


sendPingRequest

void sendPingRequest(PingRequest request,
                     RoutedConnection connection)
Sends the ping request to the designated connection, setting up the proper reply routing.


sendQueryRequest

void sendQueryRequest(QueryRequest request,
                      RoutedConnection connection)
Sends the query request to the designated connection, setting up the proper reply routing.


broadcastPingRequest

void broadcastPingRequest(PingRequest ping)
Broadcasts the ping request to all initialized connections, setting up the proper reply routing.


sendDynamicQuery

void sendDynamicQuery(QueryRequest query)
Generates a new dynamic query. This method is used to send a new dynamic query from this host (the user initiated this query directly, so it's replies are intended for this node).

Parameters:
query - the QueryRequest instance that generates queries for this dynamic query

forwardQueryRequestToLeaves

void forwardQueryRequestToLeaves(QueryRequest query,
                                 ReplyHandler handler)
Forwards the query request to any leaf connections.

Parameters:
request - the query to forward
handler - the ReplyHandler that responds to the request appropriately
manager - the ConnectionManager that provides access to any leaf connections that we should forward to

sendInitialQuery

boolean sendInitialQuery(QueryRequest query,
                         RoutedConnection mc)
Used to send the first request to a specific ultrapeer when dynamic querying.

Parameters:
request - The query to send.
mc - The RoutedConnection to send the query along
Returns:
false if the query was not sent, true if so

handleQueryReply

void handleQueryReply(QueryReply queryReply,
                      ReplyHandler handler)
The default handler for QueryReplies. This implementation uses the query route table to route a query reply. If an appropriate route doesn't exist, records the error statistics. On sucessful routing, the QueryReply count is incremented.

Override as desired, but you probably want to call super.handleQueryReply if you do. This is public for testing purposes.


sendPushRequest

void sendPushRequest(PushRequest push)
                     throws IOException
Uses the push route table to send a push request to the appropriate connection. Since this is used for PushRequests orginating here, no stats are updated.

Throws:
IOException - if no appropriate route exists.

sendMulticastPushRequest

void sendMulticastPushRequest(PushRequest push)
Sends a push request to the multicast network. No lookups are performed in the push route table, because the message will always be broadcast to everyone.


responsesToQueryReplies

Iterable<QueryReply> responsesToQueryReplies(Response[] responses,
                                             QueryRequest queryRequest)
Converts the passed responses to QueryReplies. Each QueryReply can accomodate atmost 255 responses. Not all the responses may get included in QueryReplies in case the query request came from a far away host.

NOTE: This method doesnt have any side effect, and does not modify the state of this object

Parameters:
responses - The responses to be converted
queryRequest - The query request corresponding to which we are generating query replies.
Returns:
Iterable of QueryReply

responsesToQueryReplies

Iterable<QueryReply> responsesToQueryReplies(Response[] responses,
                                             QueryRequest queryRequest,
                                             int replyLimit,
                                             SecurityToken token)

getQueryRouteTable

QueryRouteTable getQueryRouteTable()
Accessor for the most recently calculated QueryRouteTable for this node. If this node is an Ultrapeer, the table will include all data for leaf nodes in addition to data for this node's files.

Returns:
the QueryRouteTable for this node

registerMessageListener

void registerMessageListener(byte[] guid,
                             MessageListener ml)
Adds the specified MessageListener for messages with this GUID. You must manually unregister the listener. This works by replacing the necessary maps & lists, so that notifying doesn't have to hold any locks.


unregisterMessageListener

void unregisterMessageListener(byte[] guid,
                               MessageListener ml)
Unregisters this MessageListener from listening to the GUID. This works by replacing the necessary maps & lists so that notifying doesn't have to hold any locks.


forwardInspectionRequestToLeaves

void forwardInspectionRequestToLeaves(InspectionRequest ir)
Forwards an inspection request to leaf connections that support it.


getOOBExpireTime

long getOOBExpireTime()
Time after which an OOB session should be expired.

Returns:

getPushHandler

ReplyHandler getPushHandler(byte[] guid)
Returns the push handler registered for the guid, could also be ForMeReplyHandler or any of the leaves that are push proxied.

Parameters:
guid - the client guid
Returns:
null if no reply handler is registered for the guid

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.