Commit 09485f10 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

nodeID is now an object instead of a byte[].

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8564 b35dd754-fafc-0310-a699-88a17e54d16e
parent cf291aff
......@@ -186,7 +186,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener
RemoteSessionLocator locator = server.getRemoteSessionLocator();
if (locator != null) {
for (Map.Entry<String, byte[]> entry : multiplexerSessionsCache.entrySet()) {
if (!Arrays.equals(server.getNodeID(), entry.getValue())) {
if (!server.getNodeID().equals(entry.getValue())) {
sessions.add(locator.getConnectionMultiplexerSession(entry.getValue(), new JID(entry.getKey())));
}
}
......@@ -216,7 +216,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener
RemoteSessionLocator locator = server.getRemoteSessionLocator();
if (locator != null) {
for (Map.Entry<String, byte[]> entry : multiplexerSessionsCache.entrySet()) {
if (!Arrays.equals(server.getNodeID(), entry.getValue())) {
if (!server.getNodeID().equals(entry.getValue())) {
JID jid = new JID(entry.getKey());
if (domain.equals(jid.getDomain())) {
sessions.add(
......@@ -250,7 +250,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener
boolean firstConnection = getConnectionMultiplexerSessions(address.getDomain()).isEmpty();
localSessionManager.getConnnectionManagerSessions().put(address.toString(), session);
// Keep track of the cluster node hosting the new CM connection
multiplexerSessionsCache.put(address.toString(), server.getNodeID());
multiplexerSessionsCache.put(address.toString(), server.getNodeID().toByteArray());
if (firstConnection) {
// Notify ConnectionMultiplexerManager that a new connection manager
// is available
......@@ -336,7 +336,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener
// Add to component session.
localSessionManager.getComponentsSessions().add(session);
// Keep track of the cluster node hosting the new external component
componentSessionsCache.put(address.toString(), server.getNodeID());
componentSessionsCache.put(address.toString(), server.getNodeID().toByteArray());
return session;
}
......@@ -390,7 +390,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener
String streamID = session.getStreamID().getID();
localSessionManager.addIncomingServerSessions(streamID, session);
// Keep track of the nodeID hosting the incoming server session
incomingServerSessionsCache.put(streamID, server.getNodeID());
incomingServerSessionsCache.put(streamID, server.getNodeID().toByteArray());
// Update list of sockets/sessions coming from the same remote hostname
Lock lock = LockManager.getLock(hostname);
try {
......@@ -870,7 +870,7 @@ public class SessionManager extends BasicModule implements ClusterEventListener
RemoteSessionLocator locator = server.getRemoteSessionLocator();
if (locator != null) {
for (Map.Entry<String, byte[]> entry : componentSessionsCache.entrySet()) {
if (!Arrays.equals(server.getNodeID(), entry.getValue())) {
if (!server.getNodeID().equals(entry.getValue())) {
sessions.add(locator.getComponentSession(entry.getValue(), new JID(entry.getKey())));
}
}
......@@ -1429,18 +1429,18 @@ public class SessionManager extends BasicModule implements ClusterEventListener
private void restoreCacheContent() {
// Add external component sessions hosted locally to the cache (using new nodeID)
for (Session session : localSessionManager.getComponentsSessions()) {
componentSessionsCache.put(session.getAddress().toString(), server.getNodeID());
componentSessionsCache.put(session.getAddress().toString(), server.getNodeID().toByteArray());
}
// Add connection multiplexer sessions hosted locally to the cache (using new nodeID)
for (String address : localSessionManager.getConnnectionManagerSessions().keySet()) {
multiplexerSessionsCache.put(address, server.getNodeID());
multiplexerSessionsCache.put(address, server.getNodeID().toByteArray());
}
// Add incoming server sessions hosted locally to the cache (using new nodeID)
for (LocalIncomingServerSession session : localSessionManager.getIncomingServerSessions()) {
String streamID = session.getStreamID().getID();
incomingServerSessionsCache.put(streamID, server.getNodeID());
incomingServerSessionsCache.put(streamID, server.getNodeID().toByteArray());
for (String hostname : session.getValidatedDomains()) {
// Update list of sockets/sessions coming from the same remote hostname
Lock lock = LockManager.getLock(hostname);
......
......@@ -16,6 +16,7 @@ import org.dom4j.io.SAXReader;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.openfire.audit.AuditManager;
import org.jivesoftware.openfire.audit.spi.AuditManagerImpl;
import org.jivesoftware.openfire.cluster.NodeID;
import org.jivesoftware.openfire.commands.AdHocCommandHandler;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.jivesoftware.openfire.container.AdminConsolePlugin;
......@@ -98,8 +99,8 @@ public class XMPPServer {
private Date startDate;
private Date stopDate;
private boolean initialized = false;
private byte[] nodeID;
private static final byte[] DEFAULT_NODE_ID = new byte[0];
private NodeID nodeID;
private static final NodeID DEFAULT_NODE_ID = new NodeID(new byte[0]);
/**
* All modules loaded by this server
......@@ -206,7 +207,7 @@ public class XMPPServer {
*
* @return an ID that uniquely identifies this server in a cluster.
*/
public byte[] getNodeID() {
public NodeID getNodeID() {
return nodeID == null ? DEFAULT_NODE_ID : nodeID;
}
......@@ -217,7 +218,7 @@ public class XMPPServer {
*
* @param nodeID an ID that uniquely identifies this server in a cluster or null if not in a cluster.
*/
public void setNodeID(byte[] nodeID) {
public void setNodeID(NodeID nodeID) {
this.nodeID = nodeID;
}
......
......@@ -58,7 +58,7 @@ public class DirectedPresence implements Externalizable {
public DirectedPresence(JID handlerJID) {
this.handler = handlerJID;
this.nodeID = XMPPServer.getInstance().getNodeID();
this.nodeID = XMPPServer.getInstance().getNodeID().toByteArray();
}
public byte[] getNodeID() {
......
......@@ -11,6 +11,7 @@
package org.jivesoftware.openfire.spi;
import org.jivesoftware.openfire.cluster.NodeID;
import org.jivesoftware.util.cache.CacheSizes;
import org.jivesoftware.util.cache.Cacheable;
import org.jivesoftware.util.cache.ExternalizableUtil;
......@@ -44,8 +45,8 @@ public class ClientRoute implements Cacheable, Externalizable {
return available;
}
public ClientRoute(byte[] nodeID, boolean available) {
this.nodeID = nodeID;
public ClientRoute(NodeID nodeID, boolean available) {
this.nodeID = nodeID.toByteArray();
this.available = available;
}
......
......@@ -15,6 +15,7 @@ import org.jivesoftware.openfire.*;
import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.cluster.ClusterEventListener;
import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.cluster.NodeID;
import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.handler.PresenceUpdateHandler;
import org.jivesoftware.openfire.server.OutgoingSessionPromise;
......@@ -61,7 +62,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
* Cache (unlimited, never expire) that holds components connected to the server.
* Key: component domain, Value: list of nodeIDs hosting the component
*/
private Cache<String, Set<byte[]>> componentsCache;
private Cache<String, Set<NodeID>> componentsCache;
/**
* Cache (unlimited, never expire) that holds sessions of user that have authenticated with the server.
* Key: full JID, Value: {nodeID, available/unavailable}
......@@ -100,7 +101,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
public void addServerRoute(JID route, LocalOutgoingServerSession destination) {
String address = destination.getAddress().getDomain();
localRoutingTable.addRoute(address, destination);
serversCache.put(address, server.getNodeID());
serversCache.put(address, server.getNodeID().toByteArray());
}
public void addComponentRoute(JID route, RoutableChannelHandler destination) {
......@@ -109,9 +110,9 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
Lock lock = LockManager.getLock(address + "rt");
try {
lock.lock();
Set<byte[]> nodes = componentsCache.get(address);
Set<NodeID> nodes = componentsCache.get(address);
if (nodes == null) {
nodes = new HashSet<byte[]>();
nodes = new HashSet<NodeID>();
}
nodes.add(server.getNodeID());
componentsCache.put(address, nodes);
......@@ -196,7 +197,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
routed = false;
}
else {
if (Arrays.equals(clientRoute.getNodeID(), server.getNodeID())) {
if (server.getNodeID().equals(clientRoute.getNodeID())) {
// This is a route to a local user hosted in this node
try {
localRoutingTable.getRoute(jid.toString()).process(packet);
......@@ -229,10 +230,10 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
}
else {
// Check if other cluster nodes are hosting this component
Set<byte[]> nodes = componentsCache.get(jid.getDomain());
Set<NodeID> nodes = componentsCache.get(jid.getDomain());
if (nodes != null) {
for (byte[] nodeID : nodes) {
if (Arrays.equals(nodeID, server.getNodeID())) {
for (NodeID nodeID : nodes) {
if (server.getNodeID().equals(nodeID)) {
// This is a route to a local component hosted in this node (route
// could have been added after our previous check)
try {
......@@ -246,7 +247,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
else {
// This is a route to a local component hosted in other node
if (remotePacketRouter != null) {
routed = remotePacketRouter.routePacket(nodeID, jid, packet);
routed = remotePacketRouter.routePacket(nodeID.toByteArray(), jid, packet);
if (routed) {
break;
}
......@@ -260,7 +261,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
// Packet sent to remote server
byte[] nodeID = serversCache.get(jid.getDomain());
if (nodeID != null) {
if (Arrays.equals(nodeID, server.getNodeID())) {
if (server.getNodeID().equals(nodeID)) {
// This is a route to a remote server connected from this node
try {
localRoutingTable.getRoute(jid.getDomain()).process(packet);
......@@ -489,14 +490,14 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
// Add sessions of non-anonymous users hosted by other cluster nodes
for (Map.Entry<String, ClientRoute> entry : usersCache.entrySet()) {
ClientRoute route = entry.getValue();
if (!Arrays.equals(route.getNodeID(), server.getNodeID())) {
if (!server.getNodeID().equals(route.getNodeID())) {
sessions.add(locator.getClientSession(route.getNodeID(), 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 (!Arrays.equals(route.getNodeID(), server.getNodeID())) {
if (!server.getNodeID().equals(route.getNodeID())) {
sessions.add(locator.getClientSession(route.getNodeID(), new JID(entry.getKey())));
}
}
......@@ -651,7 +652,7 @@ public class RoutingTableImpl extends BasicModule implements RoutingTable, Clust
Lock lock = LockManager.getLock(address + "rt");
try {
lock.lock();
Set<byte[]> nodes = componentsCache.get(address);
Set<NodeID> nodes = componentsCache.get(address);
if (nodes != null) {
removed = nodes.remove(server.getNodeID());
if (nodes.isEmpty()) {
......
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