Commit 7661e359 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Fixed and simplified logic when adding new routes. LIVE-600


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@970 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7f8fcd8d
...@@ -78,14 +78,12 @@ public interface RoutingTable { ...@@ -78,14 +78,12 @@ public interface RoutingTable {
* <p>A single access method allows you to add any of the acceptable * <p>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 * route to the table. It is expected that routes are added and removed
* on a relatively rare occassion so routing tables should be optimized * on a relatively rare occassion so routing tables should be optimized
* for lookup speed. If an existing route corresponds to the * for lookup speed.</p>
* given address, the previously registered destination object is returned.</p>
* *
* @param node The route's destination node * @param node The route's destination node
* @param destination The destination object for this route * @param destination The destination object for this route
* @return The destination object previously registered under the given address, or null if none existed
*/ */
ChannelHandler addRoute(JID node, RoutableChannelHandler destination); void addRoute(JID node, RoutableChannelHandler destination);
/** /**
* <p>Obtain a route to a packet handler for the given node.</p> * <p>Obtain a route to a packet handler for the given node.</p>
......
...@@ -11,12 +11,15 @@ ...@@ -11,12 +11,15 @@
package org.jivesoftware.messenger.spi; package org.jivesoftware.messenger.spi;
import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.messenger.*; import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import java.util.*; import java.util.Collections;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
...@@ -44,57 +47,33 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable { ...@@ -44,57 +47,33 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable {
super("Routing table"); super("Routing table");
} }
public ChannelHandler addRoute(JID node, RoutableChannelHandler destination) { public void addRoute(JID node, RoutableChannelHandler destination) {
ChannelHandler route = null;
String nodeJID = node.getNode() == null ? "" : node.getNode(); String nodeJID = node.getNode() == null ? "" : node.getNode();
String resourceJID = node.getResource() == null ? "" : node.getResource(); String resourceJID = node.getResource() == null ? "" : node.getResource();
routeLock.writeLock().lock(); routeLock.writeLock().lock();
try { try {
if (destination instanceof InternalComponentManager.RoutableComponent) { if (destination instanceof ClientSession) {
routes.put(node.getDomain(), destination);
}
else {
Object nameRoutes = routes.get(node.getDomain()); Object nameRoutes = routes.get(node.getDomain());
if (nameRoutes == null) { if (nameRoutes == null) {
routes.put(node.getDomain(), destination); nameRoutes = new Hashtable();
routes.put(node.getDomain(), nameRoutes);
} }
else if (nameRoutes instanceof Hashtable && ((Hashtable)nameRoutes).isEmpty()) { Object resourceRoutes = ((Hashtable)nameRoutes).get(nodeJID);
((Hashtable)nameRoutes).put(nodeJID, destination); if (resourceRoutes == null) {
} resourceRoutes = new Hashtable();
else { ((Hashtable)nameRoutes).put(nodeJID, resourceRoutes);
if (nameRoutes instanceof ChannelHandler) {
nameRoutes = new Hashtable();
Object item = routes.put(node.getDomain(), nameRoutes);
// Associate the previous Route withno the bare JID
((Hashtable)nameRoutes).put("", item);
}
Object resourceRoutes = ((Hashtable)nameRoutes).get(nodeJID);
if (resourceRoutes == null || resourceRoutes instanceof ChannelHandler) {
resourceRoutes = new Hashtable();
Object item = ((Hashtable)nameRoutes).put(nodeJID, resourceRoutes);
if (item instanceof ChannelHandler) {
// Associate the previous Route with the bare JID
((Hashtable)resourceRoutes).put("", item);
}
}
Object resourceRoute =
((Hashtable)resourceRoutes).put(resourceJID, destination);
if (resourceRoute != null) {
if (resourceRoute instanceof ChannelHandler) {
route = (ChannelHandler)resourceRoute;
}
}
} }
((Hashtable)resourceRoutes).put(resourceJID, destination);
}
else {
routes.put(node.getDomain(), destination);
} }
} }
finally { finally {
routeLock.writeLock().unlock(); routeLock.writeLock().unlock();
} }
return route;
} }
public RoutableChannelHandler getRoute(JID node) throws NoSuchRouteException { public RoutableChannelHandler getRoute(JID node) throws NoSuchRouteException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment