Search in sources :

Example 1 with ClientConnection

use of com.hazelcast.client.impl.connection.ClientConnection in project hazelcast by hazelcast.

the class ClientTestSupport method getAllEventHandlers.

protected Map<Long, EventHandler> getAllEventHandlers(HazelcastInstance client) {
    ClientConnectionManager connectionManager = getHazelcastClientInstanceImpl(client).getConnectionManager();
    Collection<Connection> activeConnections = connectionManager.getActiveConnections();
    HashMap<Long, EventHandler> map = new HashMap<>();
    for (Connection activeConnection : activeConnections) {
        map.putAll(((ClientConnection) activeConnection).getEventHandlers());
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ClientConnection(com.hazelcast.client.impl.connection.ClientConnection) Connection(com.hazelcast.internal.nio.Connection) EventHandler(com.hazelcast.client.impl.spi.EventHandler) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager)

Example 2 with ClientConnection

use of com.hazelcast.client.impl.connection.ClientConnection in project hazelcast by hazelcast.

the class TcpClientConnectionManager method getRandomConnection.

@Override
public ClientConnection getRandomConnection() {
    // Try getting the connection from the load balancer, if smart routing is enabled
    if (isSmartRoutingEnabled) {
        Member member = loadBalancer.next();
        // Failed to get a member
        ClientConnection connection = member != null ? activeConnections.get(member.getUuid()) : null;
        if (connection != null) {
            return connection;
        }
    }
    // Otherwise iterate over connections and return the first one
    for (Map.Entry<UUID, TcpClientConnection> connectionEntry : activeConnections.entrySet()) {
        return connectionEntry.getValue();
    }
    // Failed to get a connection
    return null;
}
Also used : ClientConnection(com.hazelcast.client.impl.connection.ClientConnection) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 3 with ClientConnection

use of com.hazelcast.client.impl.connection.ClientConnection in project hazelcast by hazelcast.

the class ClientTxnProxy method invoke.

final ClientMessage invoke(ClientMessage request) {
    HazelcastClientInstanceImpl client = transactionContext.getClient();
    ClientConnection connection = transactionContext.getConnection();
    return ClientTransactionUtil.invoke(request, getName(), client, connection);
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientConnection(com.hazelcast.client.impl.connection.ClientConnection)

Example 4 with ClientConnection

use of com.hazelcast.client.impl.connection.ClientConnection in project hazelcast by hazelcast.

the class ClientTransactionManagerServiceImpl method connect.

public ClientConnection connect() throws Exception {
    ClientInvocationServiceImpl invocationService = (ClientInvocationServiceImpl) client.getInvocationService();
    long startTimeMillis = System.currentTimeMillis();
    long invocationTimeoutMillis = invocationService.getInvocationTimeoutMillis();
    ClientConfig clientConfig = client.getClientConfig();
    boolean smartRouting = clientConfig.getNetworkConfig().isSmartRouting();
    while (client.getLifecycleService().isRunning()) {
        try {
            ClientConnection connection = client.getConnectionManager().getRandomConnection();
            if (connection == null) {
                throw throwException(smartRouting);
            }
            return connection;
        } catch (Exception e) {
            if (e instanceof HazelcastClientOfflineException) {
                throw e;
            }
            if (System.currentTimeMillis() - startTimeMillis > invocationTimeoutMillis) {
                throw newOperationTimeoutException(e, invocationTimeoutMillis, startTimeMillis);
            }
        }
        Thread.sleep(invocationService.getInvocationRetryPauseMillis());
    }
    throw new HazelcastClientNotActiveException();
}
Also used : HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException) ClientConnection(com.hazelcast.client.impl.connection.ClientConnection) ClientConfig(com.hazelcast.client.config.ClientConfig) HazelcastClientOfflineException(com.hazelcast.client.HazelcastClientOfflineException) HazelcastClientOfflineException(com.hazelcast.client.HazelcastClientOfflineException) TransactionException(com.hazelcast.transaction.TransactionException) OperationTimeoutException(com.hazelcast.core.OperationTimeoutException) HazelcastClientNotActiveException(com.hazelcast.client.HazelcastClientNotActiveException)

Example 5 with ClientConnection

use of com.hazelcast.client.impl.connection.ClientConnection in project hazelcast by hazelcast.

the class ClientListenerServiceImpl method handleEventMessageOnCallingThread.

public void handleEventMessageOnCallingThread(ClientMessage clientMessage) {
    long correlationId = clientMessage.getCorrelationId();
    ClientConnection connection = (ClientConnection) clientMessage.getConnection();
    EventHandler eventHandler = connection.getEventHandler(correlationId);
    if (eventHandler == null) {
        if (logger.isFineEnabled()) {
            logger.fine("No eventHandler for callId: " + correlationId + ", event: " + clientMessage);
        }
        return;
    }
    eventHandler.handle(clientMessage);
}
Also used : EventHandler(com.hazelcast.client.impl.spi.EventHandler) ClientConnection(com.hazelcast.client.impl.connection.ClientConnection)

Aggregations

ClientConnection (com.hazelcast.client.impl.connection.ClientConnection)15 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 EventHandler (com.hazelcast.client.impl.spi.EventHandler)3 Map (java.util.Map)3 UUID (java.util.UUID)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 HazelcastClientNotActiveException (com.hazelcast.client.HazelcastClientNotActiveException)2 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)2 ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)2 Member (com.hazelcast.cluster.Member)2 Connection (com.hazelcast.internal.nio.Connection)2 QueryId (com.hazelcast.sql.impl.QueryId)2 Nonnull (javax.annotation.Nonnull)2 HazelcastClientOfflineException (com.hazelcast.client.HazelcastClientOfflineException)1 ClientConfig (com.hazelcast.client.config.ClientConfig)1 SqlExecuteCodec (com.hazelcast.client.impl.protocol.codec.SqlExecuteCodec)1 SqlFetchCodec (com.hazelcast.client.impl.protocol.codec.SqlFetchCodec)1