Wildfire 3.2.4 Javadoc

org.jivesoftware.wildfire.spi
Class RoutingTableImpl

java.lang.Object
  extended by org.jivesoftware.wildfire.container.BasicModule
      extended by org.jivesoftware.wildfire.spi.RoutingTableImpl
All Implemented Interfaces:
Module, RoutingTable

public class RoutingTableImpl
extends BasicModule
implements RoutingTable

Uses simple Maps for table storage.

Leaves in the tree are indicated by a PacketHandler, while branches are stored in Maps. Traverse the tree according to an XMPPAddress' fields (host -> name -> resource) and when you hit a PacketHandler, you have found the handler for that node and all sub-nodes.

Author:
Iain Shigeoka

Constructor Summary
RoutingTableImpl()
           
 
Method Summary
 void addRoute(JID node, RoutableChannelHandler destination)
          Add a route to the routing table.
 ChannelHandler getBestRoute(JID node)
          Obtain a route to a handler at the given node falling back to a user branch if no resource leaf exists.
 RoutableChannelHandler getRoute(JID node)
          Obtain a route to a packet handler for the given node.
 List<ChannelHandler> getRoutes(JID node)
          Obtain all child routes for the given node.
 void initialize(XMPPServer server)
          Initializes the basic module.
 ChannelHandler removeRoute(JID node)
          Remove a route from the routing table.
 void start()
          Starts the basic module.
 
Methods inherited from class org.jivesoftware.wildfire.container.BasicModule
destroy, getName, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RoutingTableImpl

public RoutingTableImpl()
Method Detail

addRoute

public void addRoute(JID node,
                     RoutableChannelHandler destination)
Description copied from interface: RoutingTable

Add a route to the routing table.

A single access method allows you to add any of the acceptable route to the table. It is expected that routes are added and removed on a relatively rare occassion so routing tables should be optimized for lookup speed.

Specified by:
addRoute in interface RoutingTable
Parameters:
node - The route's destination node
destination - The destination object for this route

getRoute

public RoutableChannelHandler getRoute(JID node)
Description copied from interface: RoutingTable

Obtain a route to a packet handler for the given node.

If a route doesn't exist, the method returns null.

Specified by:
getRoute in interface RoutingTable
Parameters:
node - The address we want a route to
Returns:
The handler corresponding to the route, or null indicating no route exists

getRoutes

public List<ChannelHandler> getRoutes(JID node)
Description copied from interface: RoutingTable

Obtain all child routes for the given node.

See the class documentation for the matching algorithm of child routes for any given node. If a route doesn't exist, the method returns an empty iterator (not null).

Specified by:
getRoutes in interface RoutingTable
Parameters:
node - The address we want a route to
Returns:
An iterator over all applicable routes

getBestRoute

public ChannelHandler getBestRoute(JID node)
Description copied from interface: RoutingTable

Obtain a route to a handler at the given node falling back to a user branch if no resource leaf exists.

Matching differs slightly from getRoute() which does matching according to the general matching algorithm described in the class notes. This method searches using the standard matching rules, and if that does not find a match and the address name component is not null, or empty, searches again with the resource set to null (wild card). This is essentially a convenience for falling back to the best route to a user node when a specific resource is not available.

For example, consider we're searching for a route to user@server.com/work. There is no route to that resource but a session is available at user@server.com/home. The routing table will contain entries for user@server.com and user@server.com/home. getBestLocalRoute() will first do a search for user@server.com/work and not find a match. It will then do another search on user@server.com and find the alias for the session user@server.com/home (the alias must be maintained by the session manager for the highest priority resource for any given user). In most cases, the caller doesn't care as long as they get a legitimate route to the user, so this behavior is 'better' than the exact matching used in getLocalRoute().

However, it is important to note that sometimes you don't want the best route to a node. In the previous example, if the packet is an error packet, it is probably only relevant to the sending session. If a route to that particular session can't be found, the error should not be sent to another session logged into the account.

If a route doesn't exist, the method returns null.

Specified by:
getBestRoute in interface RoutingTable
Parameters:
node - The address we want a route to
Returns:
The Session corresponding to the route, or null indicating no route exists

removeRoute

public ChannelHandler removeRoute(JID node)
Description copied from interface: RoutingTable

Remove a route from the routing table.

If a route doesn't exist, the method returns null.

Specified by:
removeRoute in interface RoutingTable
Parameters:
node - The address we want a route to
Returns:
The destination object previously registered under the given address, or null if none existed

initialize

public void initialize(XMPPServer server)
Description copied from class: BasicModule

Initializes the basic module.

Inheriting classes that choose to override this method MUST call this initialize() method before accessing BasicModule resources.

Specified by:
initialize in interface Module
Overrides:
initialize in class BasicModule
Parameters:
server - the server hosting this module.

start

public void start()
           throws IllegalStateException
Description copied from class: BasicModule

Starts the basic module.

Inheriting classes that choose to override this method MUST call this start() method before accessing BasicModule resources.

Specified by:
start in interface Module
Overrides:
start in class BasicModule
Throws:
IllegalStateException - If start is called before initialize successfully returns

Wildfire 3.2.4 Javadoc

Copyright © 2003-2007 Jive Software.