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 {
*/
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>
* if none was found. When running inside of a cluster and a remote node is hosting
......
......@@ -11,6 +11,7 @@
package org.jivesoftware.openfire.spi;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.cluster.NodeID;
import org.jivesoftware.util.cache.CacheSizes;
import org.jivesoftware.util.cache.Cacheable;
......@@ -29,14 +30,14 @@ import java.io.ObjectOutput;
*/
public class ClientRoute implements Cacheable, Externalizable {
private byte[] nodeID;
private NodeID nodeID;
private boolean available;
public ClientRoute() {
}
public byte[] getNodeID() {
public NodeID getNodeID() {
return nodeID;
}
......@@ -46,7 +47,7 @@ public class ClientRoute implements Cacheable, Externalizable {
}
public ClientRoute(NodeID nodeID, boolean available) {
this.nodeID = nodeID.toByteArray();
this.nodeID = nodeID;
this.available = available;
}
......@@ -55,18 +56,26 @@ public class ClientRoute implements Cacheable, Externalizable {
// of each field.
int size = 0;
size += CacheSizes.sizeOfObject(); // overhead of object
size += nodeID.length; // Node ID
size += nodeID.toByteArray().length; // Node ID
size += CacheSizes.sizeOfBoolean(); // available
return size;
}
public void writeExternal(ObjectOutput out) throws IOException {
ExternalizableUtil.getInstance().writeByteArray(out, nodeID);
ExternalizableUtil.getInstance().writeByteArray(out, nodeID.toByteArray());
ExternalizableUtil.getInstance().writeBoolean(out, available);
}
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);
}
}
......@@ -209,7 +209,8 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
else {
// This is a route to a local user hosted in other node
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
route = anonymousUsersCache.get(jid.toString());
}
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
for (Map.Entry<String, ClientRoute> entry : usersCache.entrySet()) {
ClientRoute route = entry.getValue();
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
for (Map.Entry<String, ClientRoute> entry : anonymousUsersCache.entrySet()) {
ClientRoute route = entry.getValue();
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
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) {
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