Search in sources :

Example 1 with ClientListenerService

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

the class ClientInvocationServiceImpl method addBackupListener.

public void addBackupListener() {
    if (isBackupAckToClientEnabled) {
        ClientListenerService listenerService = client.getListenerService();
        listenerService.registerListener(BACKUP_LISTENER, new BackupEventHandler());
    }
}
Also used : ClientListenerService(com.hazelcast.client.impl.spi.ClientListenerService)

Example 2 with ClientListenerService

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

the class ClientHeartbeatTest method testAddingListenerToNewConnectionFailedBecauseOfHeartbeat.

@Test
public void testAddingListenerToNewConnectionFailedBecauseOfHeartbeat() throws Exception {
    hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
    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().addConnectionListener(new ConnectionListener() {

        @Override
        public void connectionAdded(Connection connection) {
        }

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

        AtomicInteger count = new AtomicInteger(0);

        @Override
        public void handle(Object event) {
        }

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

        @Override
        public void onListenerRegister(Connection connection) {
            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.impl.spi.ClientListenerService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Connection(com.hazelcast.internal.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) EventHandler(com.hazelcast.client.impl.spi.EventHandler) ConnectionListener(com.hazelcast.internal.nio.ConnectionListener) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ClientListenerService (com.hazelcast.client.impl.spi.ClientListenerService)2 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)1 EventHandler (com.hazelcast.client.impl.spi.EventHandler)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 Connection (com.hazelcast.internal.nio.Connection)1 ConnectionListener (com.hazelcast.internal.nio.ConnectionListener)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)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