Commit bf793e63 authored by Tom Evans's avatar Tom Evans Committed by Guus der Kinderen

OF-1045: Fix NPE in cluster info page

Ensure cluster listener is properly initialized (and destroyed).
parent 14a0e405
...@@ -99,6 +99,8 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy { ...@@ -99,6 +99,8 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
private static HazelcastInstance hazelcast = null; private static HazelcastInstance hazelcast = null;
private static Cluster cluster = null; private static Cluster cluster = null;
private ClusterListener clusterListener; private ClusterListener clusterListener;
private String lifecycleListener;
private String membershipListener;
/** /**
* Keeps that running state. Initial state is stopped. * Keeps that running state. Initial state is stopped.
...@@ -141,8 +143,8 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy { ...@@ -141,8 +143,8 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
XMPPServer.getInstance().setNodeID(NodeID.getInstance(getClusterMemberID())); XMPPServer.getInstance().setNodeID(NodeID.getInstance(getClusterMemberID()));
// CacheFactory is now using clustered caches. We can add our listeners. // CacheFactory is now using clustered caches. We can add our listeners.
clusterListener = new ClusterListener(cluster); clusterListener = new ClusterListener(cluster);
hazelcast.getLifecycleService().addLifecycleListener(clusterListener); lifecycleListener = hazelcast.getLifecycleService().addLifecycleListener(clusterListener);
cluster.addMembershipListener(clusterListener); membershipListener = cluster.addMembershipListener(clusterListener);
break; break;
} catch (Exception e) { } catch (Exception e) {
if (retry < CLUSTER_STARTUP_RETRY_COUNT) { if (retry < CLUSTER_STARTUP_RETRY_COUNT) {
...@@ -172,6 +174,7 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy { ...@@ -172,6 +174,7 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
// Stop the cluster // Stop the cluster
Hazelcast.shutdownAll(); Hazelcast.shutdownAll();
cluster = null; cluster = null;
if (clusterListener != null) {
// Wait until the server has updated its internal state // Wait until the server has updated its internal state
while (!clusterListener.isDone()) { while (!clusterListener.isDone()) {
try { try {
...@@ -180,6 +183,12 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy { ...@@ -180,6 +183,12 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
// Ignore // Ignore
} }
} }
hazelcast.getLifecycleService().removeLifecycleListener(lifecycleListener);
cluster.removeMembershipListener(membershipListener);
lifecycleListener = null;
membershipListener = null;
clusterListener = null;
}
// Reset the node ID // Reset the node ID
XMPPServer.getInstance().setNodeID(null); XMPPServer.getInstance().setNodeID(null);
...@@ -225,7 +234,7 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy { ...@@ -225,7 +234,7 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
} }
public Collection<ClusterNodeInfo> getClusterNodesInfo() { public Collection<ClusterNodeInfo> getClusterNodesInfo() {
return clusterListener.getClusterNodesInfo(); return clusterListener == null ? Collections.EMPTY_LIST : clusterListener.getClusterNodesInfo();
} }
public int getMaxClusterNodes() { public int getMaxClusterNodes() {
......
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
List<ClusterNodeInfo> members = (List<ClusterNodeInfo>) CacheFactory.getClusterNodesInfo(); List<ClusterNodeInfo> members = (List<ClusterNodeInfo>) CacheFactory.getClusterNodesInfo();
Map<NodeID, NodeRuntimeStats.NodeInfo> nodeInfoMap = NodeRuntimeStats.getNodeInfo(); Map<NodeID, NodeRuntimeStats.NodeInfo> nodeInfoMap = NodeRuntimeStats.getNodeInfo();
if (members.size() > 1) {
// Sort it according to name // Sort it according to name
Collections.sort(members, new Comparator<ClusterNodeInfo>() { Collections.sort(members, new Comparator<ClusterNodeInfo>() {
public int compare(ClusterNodeInfo member1, ClusterNodeInfo member2) { public int compare(ClusterNodeInfo member1, ClusterNodeInfo member2) {
...@@ -94,11 +95,12 @@ ...@@ -94,11 +95,12 @@
return name1.toLowerCase().compareTo(name2.toLowerCase().toLowerCase()); return name1.toLowerCase().compareTo(name2.toLowerCase().toLowerCase());
} }
}); });
}
// If no UID was used, use the UID from the first member in the member list // If no UID was used, use the UID from the first member in the member list
byte[] byteArray; byte[] byteArray;
if (uid == null) { if (uid == null) {
byteArray = members.get(0).getNodeID().toByteArray(); byteArray = members.isEmpty() ? new byte[] {0} : members.get(0).getNodeID().toByteArray();
} else { } else {
byteArray = Base64.decode(uid, Base64.URL_SAFE); byteArray = Base64.decode(uid, Base64.URL_SAFE);
} }
......
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