Search in sources :

Example 26 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class TcpClientConnectionManager method shutdown.

public synchronized void shutdown() {
    if (!isAlive.compareAndSet(true, false)) {
        return;
    }
    executor.shutdownNow();
    ClientExecutionServiceImpl.awaitExecutorTermination("cluster", executor, logger);
    for (Connection connection : activeConnections.values()) {
        connection.close("Hazelcast client is shutting down", null);
    }
    stopNetworking();
    connectionListeners.clear();
    clusterDiscoveryService.current().destroy();
}
Also used : Connection(com.hazelcast.internal.nio.Connection) ClientConnection(com.hazelcast.client.impl.connection.ClientConnection)

Example 27 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class ClusterViewListenerService method sendToListeningEndpoints.

private void sendToListeningEndpoints(ClientMessage clientMessage) {
    for (Map.Entry<ClientEndpoint, Long> entry : clusterListeningEndpoints.entrySet()) {
        Long correlationId = entry.getValue();
        // share the partition and membership table, copy only initial frame
        ClientMessage message = clientMessage.copyWithNewCorrelationId(correlationId);
        ClientEndpoint clientEndpoint = entry.getKey();
        Connection connection = clientEndpoint.getConnection();
        write(message, connection);
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Connection(com.hazelcast.internal.nio.Connection) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HashMap(java.util.HashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 28 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class SqlClientExecuteCloseRaceTest method testCloseExecute.

@Test
public void testCloseExecute() {
    QueryId queryId = QueryId.create(UUID.randomUUID());
    // Send "close"
    Connection connection = clientService.getQueryConnection();
    ClientMessage closeRequest = SqlCloseCodec.encodeRequest(queryId);
    clientService.invokeOnConnection(connection, closeRequest);
    assertEquals(1, memberService.getInternalService().getClientStateRegistry().getCursorCount());
    // Send "execute"
    ClientMessage executeResponse = sendExecuteRequest(connection, queryId);
    assertEquals(0, memberService.getInternalService().getClientStateRegistry().getCursorCount());
    checkExecuteResponse(executeResponse, false);
}
Also used : QueryId(com.hazelcast.sql.impl.QueryId) Connection(com.hazelcast.internal.nio.Connection) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 29 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class SqlClientExecuteCloseRaceTest method testClose.

@Test
public void testClose() {
    QueryId queryId = QueryId.create(UUID.randomUUID());
    // Send "close"
    Connection connection = clientService.getQueryConnection();
    ClientMessage closeRequest = SqlCloseCodec.encodeRequest(queryId);
    clientService.invokeOnConnection(connection, closeRequest);
    // Make sure that we observed the cancel request.
    assertEquals(1, memberService.getInternalService().getClientStateRegistry().getCursorCount());
    // Wait for it to disappear.
    memberService.getInternalService().getClientStateRegistry().setClosedCursorCleanupTimeoutSeconds(1L);
    assertTrueEventually(() -> assertEquals(0, memberService.getInternalService().getClientStateRegistry().getCursorCount()));
}
Also used : QueryId(com.hazelcast.sql.impl.QueryId) Connection(com.hazelcast.internal.nio.Connection) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 30 with Connection

use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.

the class ClientHeartbeatTest method testConnectionClosed_whenHeartbeatStopped.

@Test
public void testConnectionClosed_whenHeartbeatStopped() {
    hazelcastFactory.newHazelcastInstance();
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    final ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    makeSureConnectedToServers(client, 2);
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    connectionManager.addConnectionListener(new ConnectionListener() {

        @Override
        public void connectionAdded(Connection connection) {
        }

        @Override
        public void connectionRemoved(Connection connection) {
            countDownLatch.countDown();
        }
    });
    blockMessagesFromInstance(instance, client);
    assertOpenEventually(countDownLatch);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Connection(com.hazelcast.internal.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ConnectionListener(com.hazelcast.internal.nio.ConnectionListener) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Connection (com.hazelcast.internal.nio.Connection)41 Test (org.junit.Test)14 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)8 ServerConnection (com.hazelcast.internal.server.ServerConnection)7 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)7 ClientConnection (com.hazelcast.client.impl.connection.ClientConnection)6 Address (com.hazelcast.cluster.Address)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)5 Member (com.hazelcast.cluster.Member)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)5 ConnectionListener (com.hazelcast.internal.nio.ConnectionListener)5 ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)4 ILogger (com.hazelcast.logging.ILogger)4 QueryId (com.hazelcast.sql.impl.QueryId)4 Map (java.util.Map)4 UUID (java.util.UUID)4 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)3 TargetDisconnectedException (com.hazelcast.spi.exception.TargetDisconnectedException)3 IOException (java.io.IOException)3