use of com.hazelcast.client.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.
the class ClientConnectionManagerImpl method authenticate.
private void authenticate(final Address target, final ClientConnection connection, final boolean asOwner, final AuthenticationFuture callback) {
SerializationService ss = client.getSerializationService();
final ClientClusterServiceImpl clusterService = (ClientClusterServiceImpl) client.getClientClusterService();
final ClientPrincipal principal = clusterService.getPrincipal();
byte serializationVersion = ((InternalSerializationService) client.getSerializationService()).getVersion();
String uuid = null;
String ownerUuid = null;
if (principal != null) {
uuid = principal.getUuid();
ownerUuid = principal.getOwnerUuid();
}
ClientMessage clientMessage = encodeAuthenticationRequest(asOwner, ss, serializationVersion, uuid, ownerUuid);
ClientInvocation clientInvocation = new ClientInvocation(client, clientMessage, connection);
ClientInvocationFuture future = clientInvocation.invokeUrgent();
if (asOwner && clientInvocation.getSendConnection() != null) {
correlationIddOfLastAuthentication.set(clientInvocation.getClientMessage().getCorrelationId());
}
future.andThen(new ExecutionCallback<ClientMessage>() {
@Override
public void onResponse(ClientMessage response) {
ClientAuthenticationCodec.ResponseParameters result = ClientAuthenticationCodec.decodeResponse(response);
AuthenticationStatus authenticationStatus = AuthenticationStatus.getById(result.status);
switch(authenticationStatus) {
case AUTHENTICATED:
connection.setConnectedServerVersion(result.serverHazelcastVersion);
connection.setRemoteEndpoint(result.address);
if (asOwner) {
if (!(correlationIddOfLastAuthentication.get() == response.getCorrelationId())) {
//if not same, client already gave up on this and send another authentication.
onFailure(new AuthenticationException("Owner authentication response from address " + target + " is late. Dropping the response. Principal : " + principal));
return;
}
connection.setIsAuthenticatedAsOwner();
ClientPrincipal principal = new ClientPrincipal(result.uuid, result.ownerUuid);
clusterService.setPrincipal(principal);
clusterService.setOwnerConnectionAddress(connection.getEndPoint());
logger.info("Setting " + connection + " as owner with principal " + principal);
}
onAuthenticated(target, connection);
callback.onSuccess(connection, asOwner);
break;
case CREDENTIALS_FAILED:
onFailure(new AuthenticationException("Invalid credentials! Principal: " + principal));
break;
default:
onFailure(new AuthenticationException("Authentication status code not supported. status: " + authenticationStatus));
}
}
@Override
public void onFailure(Throwable t) {
onAuthenticationFailed(target, connection, t);
callback.onFailure(t);
}
});
}
use of com.hazelcast.client.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.
the class ClientDurableExecutorServiceProxy method submitToPartition.
private <T> DurableExecutorServiceFuture<T> submitToPartition(Callable<T> task, int partitionId, T result) {
checkNotNull(task, "task should not be null");
SerializationService serService = getSerializationService();
ClientMessage request = DurableExecutorSubmitToPartitionCodec.encodeRequest(name, serService.toData(task));
int sequence;
try {
ClientMessage response = invokeOnPartition(request, partitionId);
sequence = DurableExecutorSubmitToPartitionCodec.decodeResponse(response).response;
} catch (Throwable t) {
return new ClientDurableExecutorServiceCompletedFuture<T>(t, getUserExecutor());
}
ClientMessage clientMessage = DurableExecutorRetrieveResultCodec.encodeRequest(name, sequence);
ClientInvocationFuture future = new ClientInvocation(getClient(), clientMessage, partitionId).invoke();
long taskId = Bits.combineToLong(partitionId, sequence);
return new ClientDurableExecutorServiceDelegatingFuture<T>(future, serService, RETRIEVE_RESPONSE_DECODER, result, taskId);
}
use of com.hazelcast.client.spi.impl.ClientInvocationFuture 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.client.spi.impl.ClientInvocationFuture 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);
}
use of com.hazelcast.client.spi.impl.ClientInvocationFuture in project hazelcast by hazelcast.
the class ClientCancellableDelegatingFuture method waitForRequestToBeSend.
protected void waitForRequestToBeSend() throws InterruptedException {
ICompletableFuture future = getFuture();
ClientInvocationFuture clientCallFuture = (ClientInvocationFuture) future;
clientCallFuture.getInvocation().getSendConnectionOrWait();
}
Aggregations