@Test public void testHeartbeatResumedEvent() throws InterruptedException { hazelcastFactory.newHazelcastInstance(); HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig()); final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance(); // make sure client is connected to instance2 String keyOwnedByInstance2 = generateKeyOwnedBy(instance2); IMap<String, String> map = client.getMap(randomString()); map.put(keyOwnedByInstance2, randomString()); HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client); ClientConnectionManager connectionManager = clientImpl.getConnectionManager(); final CountDownLatch countDownLatch = new CountDownLatch(1); connectionManager.addConnectionHeartbeatListener( new ConnectionHeartbeatListener() { @Override public void heartbeatResumed(Connection connection) { assertEquals( instance2.getCluster().getLocalMember().getAddress(), connection.getEndPoint()); countDownLatch.countDown(); } @Override public void heartbeatStopped(Connection connection) {} }); blockMessagesFromInstance(instance2, client); sleepMillis(HEARTBEAT_TIMEOUT_MILLIS * 2); unblockMessagesFromInstance(instance2, client); assertOpenEventually(countDownLatch); }
public ClientInvocationServiceSupport(HazelcastClientInstanceImpl client) { this.client = client; this.connectionManager = client.getConnectionManager(); this.executionService = client.getClientExecutionService(); connectionManager.addConnectionListener(this); connectionManager.addConnectionHeartbeatListener(this); this.partitionService = client.getClientPartitionService(); responseThread = new ResponseThread( client.getThreadGroup(), client.getName() + ".response-", client.getClientConfig().getClassLoader()); responseThread.start(); }
public ClientConnection( HazelcastClientInstanceImpl client, IOSelector in, IOSelector out, int connectionId, SocketChannelWrapper socketChannelWrapper) throws IOException { final Socket socket = socketChannelWrapper.socket(); this.connectionManager = client.getConnectionManager(); this.serializationService = client.getSerializationService(); this.lifecycleService = client.getLifecycleService(); this.socketChannelWrapper = socketChannelWrapper; this.connectionId = connectionId; this.readHandler = new ClientReadHandler(this, in, socket.getReceiveBufferSize()); this.writeHandler = new ClientWriteHandler(this, out, socket.getSendBufferSize()); }
@Test public void testHeartbeatStoppedEvent() throws InterruptedException { HazelcastInstance instance = hazelcastFactory.newHazelcastInstance(); HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig()); HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client); ClientConnectionManager connectionManager = clientImpl.getConnectionManager(); final CountDownLatch countDownLatch = new CountDownLatch(1); connectionManager.addConnectionHeartbeatListener( new ConnectionHeartbeatListener() { @Override public void heartbeatResumed(Connection connection) {} @Override public void heartbeatStopped(Connection connection) { countDownLatch.countDown(); } }); blockMessagesFromInstance(instance, client); assertOpenEventually(countDownLatch); }
private Connection getTargetOrOwnerConnection(final Address target) throws IOException { if (target == null) { throw new IOException("Not able to setup owner connection!"); } final ClientConnectionManager connectionManager = client.getConnectionManager(); Connection connection = connectionManager.getConnection(target); if (connection == null) { final Address ownerConnectionAddress = client.getClientClusterService().getOwnerConnectionAddress(); if (ownerConnectionAddress == null) { throw new IOException("Not able to setup owner connection!"); } connection = connectionManager.getConnection(ownerConnectionAddress); if (connection == null) { throw new IOException("Client is not connected to member " + target); } } return connection; }
private void unblockMessagesFromInstance(HazelcastInstance instance, HazelcastInstance client) { HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client); ClientConnectionManager connectionManager = clientImpl.getConnectionManager(); Address address = instance.getCluster().getLocalMember().getAddress(); ((TestClientRegistry.MockClientConnectionManager) connectionManager).unblock(address); }
public ClientMembershipListener(HazelcastClientInstanceImpl client) { this.client = client; connectionManager = (ClientConnectionManagerImpl) client.getConnectionManager(); partitionService = (ClientPartitionServiceImpl) client.getClientPartitionService(); clusterService = (ClientClusterServiceImpl) client.getClientClusterService(); }