use of com.hazelcast.client.connection.ClientConnectionManager in project hazelcast by hazelcast.
the class AbstractClientInternalCacheProxy method getConnectedServerVersion.
private int getConnectedServerVersion() {
ClientContext clientContext = getContext();
ClientClusterService clusterService = clientContext.getClusterService();
Address ownerConnectionAddress = clusterService.getOwnerConnectionAddress();
HazelcastClientInstanceImpl client = getClient();
ClientConnectionManager connectionManager = client.getConnectionManager();
Connection connection = connectionManager.getConnection(ownerConnectionAddress);
if (connection == null) {
logger.warning(format("No owner connection is available, " + "near cached cache %s will be started in legacy mode", name));
return UNKNOWN_HAZELCAST_VERSION;
}
return ((ClientConnection) connection).getConnectedServerVersion();
}
use of com.hazelcast.client.connection.ClientConnectionManager in project hazelcast by hazelcast.
the class ClientConnectionTest method destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce.
@Test
public void destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce() {
HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
HazelcastInstance client = hazelcastFactory.newHazelcastClient();
HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
final CountingConnectionRemoveListener listener = new CountingConnectionRemoveListener();
connectionManager.addConnectionListener(listener);
final Address serverAddress = new Address(server.getCluster().getLocalMember().getSocketAddress());
final Connection connectionToServer = connectionManager.getConnection(serverAddress);
final CountDownLatch isConnected = new CountDownLatch(1);
clientImpl.getLifecycleService().addLifecycleListener(new LifecycleListener() {
@Override
public void stateChanged(LifecycleEvent event) {
if (LifecycleEvent.LifecycleState.CLIENT_CONNECTED == event.getState()) {
isConnected.countDown();
}
}
});
connectionToServer.close(null, null);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(isConnected.await(5, TimeUnit.SECONDS));
}
});
connectionToServer.close(null, null);
assertEquals("connection removed should be called only once", 1, listener.count.get());
}
use of com.hazelcast.client.connection.ClientConnectionManager in project hazelcast by hazelcast.
the class ClientHeartbeatTest method testHeartbeatStoppedEvent.
@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);
}
use of com.hazelcast.client.connection.ClientConnectionManager in project hazelcast by hazelcast.
the class ClientHeartbeatTest method testHeartbeatResumedEvent.
@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);
final 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) {
}
});
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertNotNull(connectionManager.getConnection(instance2.getCluster().getLocalMember().getAddress()));
}
});
blockMessagesFromInstance(instance2, client);
sleepMillis(HEARTBEAT_TIMEOUT_MILLIS * 2);
unblockMessagesFromInstance(instance2, client);
assertOpenEventually(countDownLatch);
}
use of com.hazelcast.client.connection.ClientConnectionManager in project hazelcast by hazelcast.
the class ClientTestSupport method unblockMessagesToInstance.
/**
* Unblocks outgoing messages from client to given instance
*/
protected void unblockMessagesToInstance(HazelcastInstance instance, HazelcastInstance client) {
HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
Address address = instance.getCluster().getLocalMember().getAddress();
((TestClientRegistry.MockClientConnectionManager) connectionManager).unblockTo(address);
}
Aggregations