use of com.hazelcast.internal.cluster.ClusterVersionListener in project hazelcast by hazelcast.
the class DefaultNodeExtension method registerListener.
@Override
public boolean registerListener(Object listener) {
if (listener instanceof HazelcastInstanceAware) {
((HazelcastInstanceAware) listener).setHazelcastInstance(node.hazelcastInstance);
}
if (listener instanceof ClusterVersionListener) {
ClusterVersionListener clusterVersionListener = (ClusterVersionListener) listener;
clusterVersionListeners.add(clusterVersionListener);
// on registration, invoke once the listening method so version is properly initialized on the listener
clusterVersionListener.onClusterVersionChange(getClusterOrNodeVersion());
return true;
}
return false;
}
use of com.hazelcast.internal.cluster.ClusterVersionListener in project hazelcast by hazelcast.
the class DefaultNodeExtensionTest method test_clusterVersionListener_invokedWithOverriddenPropertyValue_whenClusterVersionIsNull.
@Test
public void test_clusterVersionListener_invokedWithOverriddenPropertyValue_whenClusterVersionIsNull() throws UnknownHostException, NoSuchFieldException, IllegalAccessException {
// override initial cluster version
System.setProperty(GroupProperty.INIT_CLUSTER_VERSION.getName(), "2.1.7");
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean failed = new AtomicBoolean(false);
ClusterVersionListener listener = new ClusterVersionListener() {
@Override
public void onClusterVersionChange(Version newVersion) {
if (!newVersion.equals(Version.of("2.1.7"))) {
failed.set(true);
}
latch.countDown();
}
};
makeClusterVersionUnknownAndVerifyListener(latch, failed, listener);
System.clearProperty(GroupProperty.INIT_CLUSTER_VERSION.getName());
}
use of com.hazelcast.internal.cluster.ClusterVersionListener in project hazelcast by hazelcast.
the class DefaultNodeExtensionTest method test_clusterVersionListener_invokedOnRegistration.
@Test
public void test_clusterVersionListener_invokedOnRegistration() throws UnknownHostException {
final CountDownLatch latch = new CountDownLatch(1);
ClusterVersionListener listener = new ClusterVersionListener() {
@Override
public void onClusterVersionChange(Version newVersion) {
latch.countDown();
}
};
assertTrue(nodeExtension.registerListener(listener));
assertOpenEventually(latch);
}
use of com.hazelcast.internal.cluster.ClusterVersionListener in project hazelcast by hazelcast.
the class DefaultNodeExtension method onClusterVersionChange.
@Override
public void onClusterVersionChange(Version newVersion) {
systemLogger.info("Cluster version set to " + newVersion);
ServiceManager serviceManager = node.getNodeEngine().getServiceManager();
List<ClusterVersionListener> listeners = serviceManager.getServices(ClusterVersionListener.class);
for (ClusterVersionListener listener : listeners) {
listener.onClusterVersionChange(newVersion);
}
// also trigger cluster version change on explicitly registered listeners
for (ClusterVersionListener listener : clusterVersionListeners) {
listener.onClusterVersionChange(newVersion);
}
}
use of com.hazelcast.internal.cluster.ClusterVersionListener in project hazelcast by hazelcast.
the class DefaultNodeExtensionTest method test_clusterVersionListener_invokedWithNodeCodebaseVersion_whenClusterVersionIsNull.
@Test
public void test_clusterVersionListener_invokedWithNodeCodebaseVersion_whenClusterVersionIsNull() throws UnknownHostException, NoSuchFieldException, IllegalAccessException {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicBoolean failed = new AtomicBoolean(false);
ClusterVersionListener listener = new ClusterVersionListener() {
@Override
public void onClusterVersionChange(Version newVersion) {
if (!newVersion.equals(node.getVersion().asVersion())) {
failed.set(true);
}
latch.countDown();
}
};
makeClusterVersionUnknownAndVerifyListener(latch, failed, listener);
}
Aggregations