@Test public void testDestroyConnection() throws Exception { HazelcastClient client = mock(HazelcastClient.class); InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 5701); final Connection connection = mock(Connection.class); final CountDownLatch latch = new CountDownLatch(2); final List<LifecycleState> lifecycleEvents = new ArrayList<LifecycleState>(); final LifecycleServiceClientImpl lifecycleService = createLifecycleServiceClientImpl(client, lifecycleEvents); ClientConfig clientConfig = new ClientConfig(); clientConfig.setCredentials(credentials).addInetSocketAddress(inetSocketAddress).setConnectionTimeout(60000); ConnectionManager connectionManager = new ConnectionManager(client, clientConfig, lifecycleService) { protected Connection getNextConnection() { latch.countDown(); return connection; } }; ClientBinder binder = mock(ClientBinder.class); connectionManager.setBinder(binder); assertEquals(connection, connectionManager.getConnection()); connectionManager.destroyConnection(connection); connectionManager.getConnection(); assertTrue(latch.await(1, TimeUnit.SECONDS)); Thread.sleep(100); assertArrayEquals(new Object[]{LifecycleState.CLIENT_CONNECTION_OPENING, LifecycleState.CLIENT_CONNECTION_LOST, LifecycleState.CLIENT_CONNECTION_OPENING}, lifecycleEvents.toArray()); }
public void destroyConnection(final Connection connection) { boolean lost = false; synchronized (this) { if (currentConnection != null && connection != null && currentConnection.getVersion() == connection.getVersion()) { logger.log(Level.WARNING, "Connection to " + currentConnection + " is lost"); while (clusterMembers.remove(currentConnection.getAddress())) ; currentConnection = null; lost = true; try { connection.close(); } catch (IOException e) { logger.log(Level.FINEST, e.getMessage(), e); } } } if (lost) { lifecycleService.fireLifecycleEvent(CLIENT_CONNECTION_LOST); } }
ConnectionManager implements MembershipListener { public void destroyConnection(final Connection connection) { boolean lost = false; synchronized (this) { if (currentConnection != null && connection != null && currentConnection.getVersion() == connection.getVersion()) { logger.log(Level.WARNING, "Connection to " + currentConnection + " is lost"); while (clusterMembers.remove(currentConnection.getAddress())) ; currentConnection = null; lost = true; try { connection.close(); } catch (IOException e) { logger.log(Level.FINEST, e.getMessage(), e); } } } if (lost) { lifecycleService.fireLifecycleEvent(CLIENT_CONNECTION_LOST); } } }
ConnectionManager implements MembershipListener { public void destroyConnection(final Connection connection) { boolean lost = false; synchronized (this) { if (currentConnection != null && connection != null && currentConnection.getVersion() == connection.getVersion()) { logger.log(Level.WARNING, "Connection to " + currentConnection + " is lost"); while (clusterMembers.remove(currentConnection.getAddress())) ; currentConnection = null; lost = true; try { connection.close(); } catch (IOException e) { logger.log(Level.FINEST, e.getMessage(), e); } } } if (lost) { lifecycleService.fireLifecycleEvent(CLIENT_CONNECTION_LOST); } } ConnectionManager(HazelcastClient client, ClientConfig config, LifecycleServiceClientImpl lifecycleService); }
ConnectionManager implements MembershipListener { public void destroyConnection(final Connection connection) { boolean lost = false; synchronized (this) { if (currentConnection != null && connection != null && currentConnection.getVersion() == connection.getVersion()) { logger.log(Level.WARNING, "Connection to " + currentConnection + " is lost"); while (clusterMembers.remove(currentConnection.getAddress())) ; currentConnection = null; lost = true; try { connection.close(); } catch (IOException e) { logger.log(Level.FINEST, e.getMessage(), e); } } } if (lost) { lifecycleService.fireLifecycleEvent(CLIENT_CONNECTION_LOST); } } ConnectionManager(HazelcastClient client, ClientConfig config, LifecycleServiceClientImpl lifecycleService); Connection getInitConnection(); Connection lookForLiveConnection(); Connection getConnection(); void destroyConnection(final Connection connection); void memberAdded(MembershipEvent membershipEvent); void memberRemoved(MembershipEvent membershipEvent); void updateMembers(); boolean shouldExecuteOnDisconnect(Connection connection); void setBinder(ClientBinder binder); void shutdown(); }
ConnectionManager implements MembershipListener { public void destroyConnection(final Connection connection) { boolean lost = false; synchronized (this) { if (currentConnection != null && connection != null && currentConnection.getVersion() == connection.getVersion()) { logger.log(Level.WARNING, "Connection to " + currentConnection + " is lost"); while (clusterMembers.remove(currentConnection.getAddress())) ; currentConnection = null; lost = true; try { connection.close(); } catch (IOException e) { logger.log(Level.FINEST, e.getMessage(), e); } } } if (lost) { lifecycleService.fireLifecycleEvent(CLIENT_CONNECTION_LOST); } } ConnectionManager(HazelcastClient client, ClientConfig config, LifecycleServiceClientImpl lifecycleService); Connection getInitConnection(); Connection lookForLiveConnection(); Connection getConnection(); void destroyConnection(final Connection connection); void memberAdded(MembershipEvent membershipEvent); void memberRemoved(MembershipEvent membershipEvent); void updateMembers(); boolean shouldExecuteOnDisconnect(Connection connection); void setBinder(ClientBinder binder); void shutdown();  }