use of com.hazelcast.client.impl.HazelcastClientInstanceImpl 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.impl.HazelcastClientInstanceImpl 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.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientAddressCancellableDelegatingFuture method invokeCancelRequest.
private boolean invokeCancelRequest(boolean mayInterruptIfRunning) throws InterruptedException {
waitForRequestToBeSend();
ClientInvocation clientInvocation;
final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) context.getHazelcastInstance();
ClientMessage request = ExecutorServiceCancelOnAddressCodec.encodeRequest(uuid, target, mayInterruptIfRunning);
clientInvocation = new ClientInvocation(client, request, target);
try {
ClientInvocationFuture f = clientInvocation.invoke();
return ExecutorServiceCancelOnAddressCodec.decodeResponse(f.get()).response;
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.
the class ClientCacheClearTest method registerInvalidationListener.
private void registerInvalidationListener(EventHandler handler, String nameWithPrefix) {
ListenerMessageCodec listenerCodec = createInvalidationListenerCodec(nameWithPrefix);
HazelcastClientProxy hzClient = (HazelcastClientProxy) client;
final HazelcastClientInstanceImpl clientInstance = hzClient.client;
clientInstance.getListenerService().registerListener(listenerCodec, handler);
}
use of com.hazelcast.client.impl.HazelcastClientInstanceImpl 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);
}
Aggregations