@Test public void testGetConnection() 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); connectionManager.getConnection(); assertEquals(connection, connectionManager.getConnection()); verify(binder).bind(connection, credentials); assertEquals(connection, connectionManager.getConnection()); assertEquals(1, latch.getCount()); Thread.sleep(100); assertArrayEquals(new Object[]{LifecycleState.CLIENT_CONNECTION_OPENING}, lifecycleEvents.toArray()); }
public Connection getConnection() throws IOException { if (currentConnection == null && running && !lookingForLiveConnection) { boolean restored = false; synchronized (this) { if (currentConnection == null) { Connection connection = searchForAvailableConnection(); if (connection != null) { logger.log(Level.FINE, "Client is connecting to " + connection); try { bindConnection(connection); currentConnection = connection; } catch (Throwable e) { closeConnection(connection); logger.log(Level.WARNING, "got an exception on getConnection:" + e.getMessage(), e); } } restored = currentConnection != null; } } if (restored) { notifyConnectionIsRestored(); } } return currentConnection; }
ConnectionManager implements MembershipListener { public Connection getConnection() throws IOException { if (currentConnection == null && running && !lookingForLiveConnection) { boolean restored = false; synchronized (this) { if (currentConnection == null) { Connection connection = searchForAvailableConnection(); if (connection != null) { logger.log(Level.FINE, "Client is connecting to " + connection); try { bindConnection(connection); currentConnection = connection; } catch (Throwable e) { closeConnection(connection); logger.log(Level.WARNING, "got an exception on getConnection:" + e.getMessage(), e); } } restored = currentConnection != null; } } if (restored) { notifyConnectionIsRestored(); } } return currentConnection; } }
ConnectionManager implements MembershipListener { public Connection getConnection() throws IOException { if (currentConnection == null && running && !lookingForLiveConnection) { boolean restored = false; synchronized (this) { if (currentConnection == null) { Connection connection = searchForAvailableConnection(); if (connection != null) { logger.log(Level.FINE, "Client is connecting to " + connection); try { bindConnection(connection); currentConnection = connection; } catch (Throwable e) { closeConnection(connection); logger.log(Level.WARNING, "got an exception on getConnection:" + e.getMessage(), e); } } restored = currentConnection != null; } } if (restored) { notifyConnectionIsRestored(); } } return currentConnection; } ConnectionManager(HazelcastClient client, ClientConfig config, LifecycleServiceClientImpl lifecycleService); }
ConnectionManager implements MembershipListener { public Connection getConnection() throws IOException { if (currentConnection == null && running && !lookingForLiveConnection) { boolean restored = false; synchronized (this) { if (currentConnection == null) { Connection connection = searchForAvailableConnection(); if (connection != null) { logger.log(Level.FINE, "Client is connecting to " + connection); try { bindConnection(connection); currentConnection = connection; } catch (Throwable e) { closeConnection(connection); logger.log(Level.WARNING, "got an exception on getConnection:" + e.getMessage(), e); } } restored = currentConnection != null; } } if (restored) { notifyConnectionIsRestored(); } } return currentConnection; } 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 Connection getConnection() throws IOException { if (currentConnection == null && running && !lookingForLiveConnection) { boolean restored = false; synchronized (this) { if (currentConnection == null) { Connection connection = searchForAvailableConnection(); if (connection != null) { logger.log(Level.FINE, "Client is connecting to " + connection); try { bindConnection(connection); currentConnection = connection; } catch (Throwable e) { closeConnection(connection); logger.log(Level.WARNING, "got an exception on getConnection:" + e.getMessage(), e); } } restored = currentConnection != null; } } if (restored) { notifyConnectionIsRestored(); } } return currentConnection; } 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();  }