Search in sources :

Example 1 with ClientListenerService

use of com.hazelcast.client.spi.ClientListenerService in project hazelcast by hazelcast.

the class ClientCacheProxy method deregisterCacheEntryListener.

@Override
public void deregisterCacheEntryListener(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) {
    if (cacheEntryListenerConfiguration == null) {
        throw new NullPointerException("CacheEntryListenerConfiguration can't be null");
    }
    final String regId = getListenerIdLocal(cacheEntryListenerConfiguration);
    if (regId == null) {
        return;
    }
    ClientListenerService listenerService = clientContext.getListenerService();
    boolean isDeregistered = listenerService.deregisterListener(regId);
    if (isDeregistered) {
        removeListenerLocally(cacheEntryListenerConfiguration);
        cacheConfig.removeCacheEntryListenerConfiguration(cacheEntryListenerConfiguration);
        updateCacheListenerConfigOnOtherNodes(cacheEntryListenerConfiguration, false);
    }
}
Also used : ClientListenerService(com.hazelcast.client.spi.ClientListenerService)

Example 2 with ClientListenerService

use of com.hazelcast.client.spi.ClientListenerService in project hazelcast by hazelcast.

the class ClientHeartbeatTest method testAddingListenerToNewConnectionFailedBecauseOfHeartbeat.

@Test
public void testAddingListenerToNewConnectionFailedBecauseOfHeartbeat() throws Exception {
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientProperty.HEARTBEAT_TIMEOUT.getName(), "4000");
    clientConfig.setProperty(ClientProperty.HEARTBEAT_INTERVAL.getName(), "1000");
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    final ClientListenerService clientListenerService = clientInstanceImpl.getListenerService();
    final CountDownLatch blockIncoming = new CountDownLatch(1);
    final CountDownLatch heartbeatStopped = new CountDownLatch(1);
    final CountDownLatch onListenerRegister = new CountDownLatch(2);
    clientInstanceImpl.getConnectionManager().addConnectionHeartbeatListener(new ConnectionHeartbeatListener() {

        @Override
        public void heartbeatResumed(Connection connection) {
        }

        @Override
        public void heartbeatStopped(Connection connection) {
            heartbeatStopped.countDown();
        }
    });
    clientListenerService.registerListener(createPartitionLostListenerCodec(), new EventHandler() {

        AtomicInteger count = new AtomicInteger(0);

        @Override
        public void handle(Object event) {
        }

        @Override
        public void beforeListenerRegister() {
            if (count.incrementAndGet() == 2) {
                try {
                    blockIncoming.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void onListenerRegister() {
            onListenerRegister.countDown();
        }
    });
    HazelcastInstance hazelcastInstance2 = hazelcastFactory.newHazelcastInstance();
    assertSizeEventually(2, clientInstanceImpl.getConnectionManager().getActiveConnections());
    blockMessagesFromInstance(hazelcastInstance2, client);
    assertOpenEventually(heartbeatStopped);
    blockIncoming.countDown();
    unblockMessagesFromInstance(hazelcastInstance2, client);
    assertOpenEventually(onListenerRegister);
}
Also used : ClientListenerService(com.hazelcast.client.spi.ClientListenerService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Connection(com.hazelcast.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) EventHandler(com.hazelcast.client.spi.EventHandler) ConnectionHeartbeatListener(com.hazelcast.client.spi.impl.ConnectionHeartbeatListener) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with ClientListenerService

use of com.hazelcast.client.spi.ClientListenerService in project hazelcast by hazelcast.

the class AbstractClientInternalCacheProxy method registerInvalidationListener.

private void registerInvalidationListener() {
    if (nearCache == null || !nearCache.isInvalidatedOnChange()) {
        return;
    }
    ListenerMessageCodec listenerCodec = createInvalidationListenerCodec();
    ClientListenerService listenerService = clientContext.getListenerService();
    EventHandler eventHandler = createInvalidationEventHandler();
    nearCacheMembershipRegistrationId = listenerService.registerListener(listenerCodec, eventHandler);
}
Also used : ClientListenerService(com.hazelcast.client.spi.ClientListenerService) ListenerMessageCodec(com.hazelcast.client.spi.impl.ListenerMessageCodec) EventHandler(com.hazelcast.client.spi.EventHandler)

Aggregations

ClientListenerService (com.hazelcast.client.spi.ClientListenerService)3 EventHandler (com.hazelcast.client.spi.EventHandler)2 ClientConfig (com.hazelcast.client.config.ClientConfig)1 HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)1 ConnectionHeartbeatListener (com.hazelcast.client.spi.impl.ConnectionHeartbeatListener)1 ListenerMessageCodec (com.hazelcast.client.spi.impl.ListenerMessageCodec)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Connection (com.hazelcast.nio.Connection)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1