Search in sources :

Example 1 with ClusterVersionListener

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;
}
Also used : HazelcastInstanceAware(com.hazelcast.core.HazelcastInstanceAware) ClusterVersionListener(com.hazelcast.internal.cluster.ClusterVersionListener)

Example 2 with ClusterVersionListener

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterVersionListener(com.hazelcast.internal.cluster.ClusterVersionListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with ClusterVersionListener

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);
}
Also used : Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterVersionListener(com.hazelcast.internal.cluster.ClusterVersionListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ClusterVersionListener

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);
    }
}
Also used : ServiceManager(com.hazelcast.spi.impl.servicemanager.ServiceManager) ClusterVersionListener(com.hazelcast.internal.cluster.ClusterVersionListener)

Example 5 with ClusterVersionListener

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Version(com.hazelcast.version.Version) MemberVersion(com.hazelcast.version.MemberVersion) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterVersionListener(com.hazelcast.internal.cluster.ClusterVersionListener) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ClusterVersionListener (com.hazelcast.internal.cluster.ClusterVersionListener)5 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 QuickTest (com.hazelcast.test.annotation.QuickTest)3 MemberVersion (com.hazelcast.version.MemberVersion)3 Version (com.hazelcast.version.Version)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 HazelcastInstanceAware (com.hazelcast.core.HazelcastInstanceAware)1 ServiceManager (com.hazelcast.spi.impl.servicemanager.ServiceManager)1