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 {
private static HazelcastInstance hazelcast = null;
private static Cluster cluster = null;
private ClusterListener clusterListener;
private String lifecycleListener;
private String membershipListener;
/**
* Keeps that running state. Initial state is stopped.
......@@ -141,8 +143,8 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
XMPPServer.getInstance().setNodeID(NodeID.getInstance(getClusterMemberID()));
// CacheFactory is now using clustered caches. We can add our listeners.
clusterListener = new ClusterListener(cluster);
hazelcast.getLifecycleService().addLifecycleListener(clusterListener);
cluster.addMembershipListener(clusterListener);
lifecycleListener = hazelcast.getLifecycleService().addLifecycleListener(clusterListener);
membershipListener = cluster.addMembershipListener(clusterListener);
break;
} catch (Exception e) {
if (retry < CLUSTER_STARTUP_RETRY_COUNT) {
......@@ -172,13 +174,20 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
// Stop the cluster
Hazelcast.shutdownAll();
cluster = null;
// Wait until the server has updated its internal state
while (!clusterListener.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// Ignore
}
if (clusterListener != null) {
// Wait until the server has updated its internal state
while (!clusterListener.isDone()) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// Ignore
}
}
hazelcast.getLifecycleService().removeLifecycleListener(lifecycleListener);
cluster.removeMembershipListener(membershipListener);
lifecycleListener = null;
membershipListener = null;
clusterListener = null;
}
// Reset the node ID
XMPPServer.getInstance().setNodeID(null);
......@@ -225,7 +234,7 @@ public class ClusteredCacheFactory implements CacheFactoryStrategy {
}
public Collection<ClusterNodeInfo> getClusterNodesInfo() {
return clusterListener.getClusterNodesInfo();
return clusterListener == null ? Collections.EMPTY_LIST : clusterListener.getClusterNodesInfo();
}
public int getMaxClusterNodes() {
......
......@@ -86,19 +86,21 @@
List<ClusterNodeInfo> members = (List<ClusterNodeInfo>) CacheFactory.getClusterNodesInfo();
Map<NodeID, NodeRuntimeStats.NodeInfo> nodeInfoMap = NodeRuntimeStats.getNodeInfo();
// Sort it according to name
Collections.sort(members, new Comparator<ClusterNodeInfo>() {
public int compare(ClusterNodeInfo member1, ClusterNodeInfo member2) {
String name1 = member1.getHostName() + " (" + member1.getNodeID() + ")";
String name2 = member2.getHostName() + " (" + member2.getNodeID() + ")";
return name1.toLowerCase().compareTo(name2.toLowerCase().toLowerCase());
}
});
if (members.size() > 1) {
// Sort it according to name
Collections.sort(members, new Comparator<ClusterNodeInfo>() {
public int compare(ClusterNodeInfo member1, ClusterNodeInfo member2) {
String name1 = member1.getHostName() + " (" + member1.getNodeID() + ")";
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
byte[] byteArray;
if (uid == null) {
byteArray = members.get(0).getNodeID().toByteArray();
byteArray = members.isEmpty() ? new byte[] {0} : members.get(0).getNodeID().toByteArray();
} else {
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