Commit 05ed8916 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

More refactoring work.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8639 b35dd754-fafc-0310-a699-88a17e54d16e
parent 650daf5d
...@@ -233,14 +233,6 @@ public interface RoutingTable { ...@@ -233,14 +233,6 @@ public interface RoutingTable {
*/ */
Collection<ClientSession> getClientsRoutes(boolean onlyLocal); Collection<ClientSession> getClientsRoutes(boolean onlyLocal);
/**
* Returns the ID of the node that is hosting the specified client session.
*
* @param jid the address of the specified client session.
* @return the ID of the node that is hosting the specified client session or null if not found.
*/
byte[] getNodeIDForClientRoute(JID jid);
/** /**
* Returns the outgoing server session associated to the specified XMPP address or <tt>null</tt> * Returns the outgoing server session associated to the specified XMPP address or <tt>null</tt>
* if none was found. When running inside of a cluster and a remote node is hosting * if none was found. When running inside of a cluster and a remote node is hosting
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
package org.jivesoftware.openfire.spi; package org.jivesoftware.openfire.spi;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.cluster.NodeID; import org.jivesoftware.openfire.cluster.NodeID;
import org.jivesoftware.util.cache.CacheSizes; import org.jivesoftware.util.cache.CacheSizes;
import org.jivesoftware.util.cache.Cacheable; import org.jivesoftware.util.cache.Cacheable;
...@@ -29,14 +30,14 @@ import java.io.ObjectOutput; ...@@ -29,14 +30,14 @@ import java.io.ObjectOutput;
*/ */
public class ClientRoute implements Cacheable, Externalizable { public class ClientRoute implements Cacheable, Externalizable {
private byte[] nodeID; private NodeID nodeID;
private boolean available; private boolean available;
public ClientRoute() { public ClientRoute() {
} }
public byte[] getNodeID() { public NodeID getNodeID() {
return nodeID; return nodeID;
} }
...@@ -46,7 +47,7 @@ public class ClientRoute implements Cacheable, Externalizable { ...@@ -46,7 +47,7 @@ public class ClientRoute implements Cacheable, Externalizable {
} }
public ClientRoute(NodeID nodeID, boolean available) { public ClientRoute(NodeID nodeID, boolean available) {
this.nodeID = nodeID.toByteArray(); this.nodeID = nodeID;
this.available = available; this.available = available;
} }
...@@ -55,18 +56,26 @@ public class ClientRoute implements Cacheable, Externalizable { ...@@ -55,18 +56,26 @@ public class ClientRoute implements Cacheable, Externalizable {
// of each field. // of each field.
int size = 0; int size = 0;
size += CacheSizes.sizeOfObject(); // overhead of object size += CacheSizes.sizeOfObject(); // overhead of object
size += nodeID.length; // Node ID size += nodeID.toByteArray().length; // Node ID
size += CacheSizes.sizeOfBoolean(); // available size += CacheSizes.sizeOfBoolean(); // available
return size; return size;
} }
public void writeExternal(ObjectOutput out) throws IOException { public void writeExternal(ObjectOutput out) throws IOException {
ExternalizableUtil.getInstance().writeByteArray(out, nodeID); ExternalizableUtil.getInstance().writeByteArray(out, nodeID.toByteArray());
ExternalizableUtil.getInstance().writeBoolean(out, available); ExternalizableUtil.getInstance().writeBoolean(out, available);
} }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
nodeID = ExternalizableUtil.getInstance().readByteArray(in); byte[] bytes = ExternalizableUtil.getInstance().readByteArray(in);
// Retrieve the NodeID but try to use the singleton instance
if (XMPPServer.getInstance().getNodeID().equals(bytes)) {
nodeID = XMPPServer.getInstance().getNodeID();
}
else {
// TODO Keep singleton instances in NodeID
nodeID = new NodeID(bytes);
}
available = ExternalizableUtil.getInstance().readBoolean(in); available = ExternalizableUtil.getInstance().readBoolean(in);
} }
} }
...@@ -209,7 +209,8 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -209,7 +209,8 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
else { else {
// This is a route to a local user hosted in other node // This is a route to a local user hosted in other node
if (remotePacketRouter != null) { if (remotePacketRouter != null) {
routed = remotePacketRouter.routePacket(clientRoute.getNodeID(), jid, packet); routed = remotePacketRouter
.routePacket(clientRoute.getNodeID().toByteArray(), jid, packet);
} }
} }
} }
...@@ -473,7 +474,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -473,7 +474,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
route = anonymousUsersCache.get(jid.toString()); route = anonymousUsersCache.get(jid.toString());
} }
if (route != null) { if (route != null) {
session = locator.getClientSession(route.getNodeID(), jid); session = locator.getClientSession(route.getNodeID().toByteArray(), jid);
} }
} }
} }
...@@ -491,14 +492,14 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -491,14 +492,14 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
for (Map.Entry<String, ClientRoute> entry : usersCache.entrySet()) { for (Map.Entry<String, ClientRoute> entry : usersCache.entrySet()) {
ClientRoute route = entry.getValue(); ClientRoute route = entry.getValue();
if (!server.getNodeID().equals(route.getNodeID())) { if (!server.getNodeID().equals(route.getNodeID())) {
sessions.add(locator.getClientSession(route.getNodeID(), new JID(entry.getKey()))); sessions.add(locator.getClientSession(route.getNodeID().toByteArray(), new JID(entry.getKey())));
} }
} }
// Add sessions of anonymous users hosted by other cluster nodes // Add sessions of anonymous users hosted by other cluster nodes
for (Map.Entry<String, ClientRoute> entry : anonymousUsersCache.entrySet()) { for (Map.Entry<String, ClientRoute> entry : anonymousUsersCache.entrySet()) {
ClientRoute route = entry.getValue(); ClientRoute route = entry.getValue();
if (!server.getNodeID().equals(route.getNodeID())) { if (!server.getNodeID().equals(route.getNodeID())) {
sessions.add(locator.getClientSession(route.getNodeID(), new JID(entry.getKey()))); sessions.add(locator.getClientSession(route.getNodeID().toByteArray(), new JID(entry.getKey())));
} }
} }
} }
...@@ -531,17 +532,6 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust ...@@ -531,17 +532,6 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
return usersCache.containsKey(jid.toString()) || isAnonymousRoute(jid); return usersCache.containsKey(jid.toString()) || isAnonymousRoute(jid);
} }
public byte[] getNodeIDForClientRoute(JID jid) {
ClientRoute clientRoute = usersCache.get(jid.toString());
if (clientRoute == null) {
clientRoute = anonymousUsersCache.get(jid.toString());
}
if (clientRoute != null) {
return clientRoute.getNodeID();
}
return null;
}
public boolean isAnonymousRoute(JID jid) { public boolean isAnonymousRoute(JID jid) {
return anonymousUsersCache.containsKey(jid.toString()); return anonymousUsersCache.containsKey(jid.toString());
} }
......
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