use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class AbstractClientInternalCacheProxy method putInternalAsync.
private Object putInternalAsync(final V value, final boolean isGet, final long start, final Data keyData, final Data valueData, ClientInvocationFuture future) {
OneShotExecutionCallback<V> oneShotExecutionCallback = null;
if (nearCache != null || statisticsEnabled) {
oneShotExecutionCallback = new OneShotExecutionCallback<V>() {
@Override
protected void onResponseInternal(V responseData) {
if (nearCache != null) {
if (cacheOnUpdate) {
storeInNearCache(keyData, valueData, value, NOT_RESERVED, cacheOnUpdate);
} else {
invalidateNearCache(keyData);
}
}
if (statisticsEnabled) {
handleStatisticsOnPut(isGet, start, responseData);
}
}
@Override
protected void onFailureInternal(Throwable t) {
}
};
}
SerializationService serializationService = clientContext.getSerializationService();
if (oneShotExecutionCallback == null) {
return new ClientDelegatingFuture<V>(future, serializationService, PUT_RESPONSE_DECODER);
}
ClientDelegatingFuture<V> delegatingFuture = new CallbackAwareClientDelegatingFuture<V>(future, serializationService, PUT_RESPONSE_DECODER, oneShotExecutionCallback);
delegatingFuture.andThenInternal(oneShotExecutionCallback, true);
return delegatingFuture;
}
use of com.hazelcast.spi.serialization.SerializationService 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.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class ClientCacheHelper method getCacheConfig.
/**
* Gets the cache configuration from the server.
*
* @param client the client instance which will send the operation to server
* @param cacheName full cache name with prefixes
* @param simpleCacheName pure cache name without any prefix
* @param <K> type of the key of the cache
* @param <V> type of the value of the cache
* @return the cache configuration if it can be found
*/
static <K, V> CacheConfig<K, V> getCacheConfig(HazelcastClientInstanceImpl client, String cacheName, String simpleCacheName) {
ClientMessage request = CacheGetConfigCodec.encodeRequest(cacheName, simpleCacheName);
try {
int partitionId = client.getClientPartitionService().getPartitionId(cacheName);
ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionId);
Future<ClientMessage> future = clientInvocation.invoke();
ClientMessage responseMessage = future.get();
SerializationService serializationService = client.getSerializationService();
return deserializeCacheConfig(client, responseMessage, serializationService, clientInvocation);
} catch (Exception e) {
throw rethrow(e);
}
}
use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class DefaultClientExtension method createNearCacheManager.
@Override
public NearCacheManager createNearCacheManager() {
SerializationService ss = client.getSerializationService();
ClientExecutionServiceImpl es = client.getExecutionService();
ClassLoader classLoader = client.getClientConfig().getClassLoader();
return new DefaultNearCacheManager(ss, es, classLoader);
}
use of com.hazelcast.spi.serialization.SerializationService 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);
}
Aggregations