use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class ClientHeartbeatMonitor method monitor.
private void monitor(String memberUuid, ClientEndpointImpl clientEndpoint) {
if (clientEndpoint.isFirstConnection() && ClientType.CPP.equals(clientEndpoint.getClientType())) {
return;
}
Connection connection = clientEndpoint.getConnection();
long lastTimePacketReceived = connection.lastReadTimeMillis();
long timeoutInMillis = SECONDS.toMillis(heartbeatTimeoutSeconds);
long currentTimeMillis = Clock.currentTimeMillis();
if (lastTimePacketReceived + timeoutInMillis < currentTimeMillis) {
if (memberUuid.equals(clientEngine.getOwnerUuid(clientEndpoint.getUuid()))) {
String message = "Client heartbeat is timed out, closing connection to " + connection + ". Now: " + timeToString(currentTimeMillis) + ". LastTimePacketReceived: " + timeToString(lastTimePacketReceived);
connection.close(message, null);
}
}
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class NearCachedClientMapProxy method getConnectedServerVersion.
private int getConnectedServerVersion() {
ClientContext clientContext = getClientContext();
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.nio.Connection in project hazelcast by hazelcast.
the class ClientConnectionManagerImpl method getOrConnect.
@Override
public Connection getOrConnect(Address address, boolean asOwner) throws IOException {
try {
while (true) {
Connection connection = getConnection(address, asOwner);
if (connection != null) {
return connection;
}
AuthenticationFuture firstCallback = triggerConnect(addressTranslator.translate(address), asOwner);
connection = firstCallback.get(connectionTimeout);
if (!asOwner) {
return connection;
}
if (firstCallback.authenticatedAsOwner) {
return connection;
}
}
} catch (Throwable e) {
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class ClientNonSmartListenerService method invoke.
private ClientEventRegistration invoke(ClientRegistrationKey registrationKey) throws Exception {
EventHandler handler = registrationKey.getHandler();
handler.beforeListenerRegister();
ClientMessage request = registrationKey.getCodec().encodeAddRequest(false);
ClientInvocation invocation = new ClientInvocation(client, request);
invocation.setEventHandler(handler);
ClientInvocationFuture future = invocation.invoke();
String registrationId = registrationKey.getCodec().decodeAddResponse(future.get());
handler.onListenerRegister();
Connection connection = future.getInvocation().getSendConnection();
return new ClientEventRegistration(registrationId, request.getCorrelationId(), connection, registrationKey.getCodec());
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class ClientSmartListenerService method invoke.
private void invoke(ClientRegistrationKey registrationKey, Connection connection) throws Exception {
//This method should only be called from registrationExecutor
assert (Thread.currentThread().getName().contains("eventRegistration"));
Map<Connection, ClientEventRegistration> registrationMap = registrations.get(registrationKey);
if (registrationMap.containsKey(connection)) {
return;
}
ListenerMessageCodec codec = registrationKey.getCodec();
ClientMessage request = codec.encodeAddRequest(true);
EventHandler handler = registrationKey.getHandler();
handler.beforeListenerRegister();
ClientInvocation invocation = new ClientInvocation(client, request, connection);
invocation.setEventHandler(handler);
ClientInvocationFuture future = invocation.invokeUrgent();
ClientMessage clientMessage;
try {
clientMessage = future.get();
} catch (Exception e) {
throw ExceptionUtil.rethrow(e, Exception.class);
}
String serverRegistrationId = codec.decodeAddResponse(clientMessage);
handler.onListenerRegister();
long correlationId = request.getCorrelationId();
ClientEventRegistration registration = new ClientEventRegistration(serverRegistrationId, correlationId, connection, codec);
registrationMap.put(connection, registration);
}
Aggregations