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;
}
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;
}
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);
}
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();
}
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);
}
Aggregations