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