Commit ee9d5150 authored by Dave Cridland's avatar Dave Cridland

Merge pull request #523 from tevans/OF-1045

OF-1045: Fix NPE in cluster info page
parents 73b5e68f 35403147
...@@ -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,13 +174,20 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy { ...@@ -172,13 +174,20 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
// Stop the cluster // Stop the cluster
Hazelcast.shutdownAll(); Hazelcast.shutdownAll();
cluster = null; cluster = null;
// Wait until the server has updated its internal state if (clusterListener != null) {
while (!clusterListener.isDone()) { // Wait until the server has updated its internal state
try { while (!clusterListener.isDone()) {
Thread.sleep(100); try {
} catch (InterruptedException e) { Thread.sleep(100);
// Ignore } catch (InterruptedException e) {
} // 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,19 +86,21 @@ ...@@ -86,19 +86,21 @@
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();
// Sort it according to name if (members.size() > 1) {
Collections.sort(members, new Comparator<ClusterNodeInfo>() { // Sort it according to name
public int compare(ClusterNodeInfo member1, ClusterNodeInfo member2) { Collections.sort(members, new Comparator<ClusterNodeInfo>() {
String name1 = member1.getHostName() + " (" + member1.getNodeID() + ")"; public int compare(ClusterNodeInfo member1, ClusterNodeInfo member2) {
String name2 = member2.getHostName() + " (" + member2.getNodeID() + ")"; String name1 = member1.getHostName() + " (" + member1.getNodeID() + ")";
return name1.toLowerCase().compareTo(name2.toLowerCase().toLowerCase()); String name2 = member2.getHostName() + " (" + member2.getNodeID() + ")";
} 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