protected <T> ICompletableFuture<T> getAndRemoveAsyncInternal( K key, boolean withCompletionEvent, boolean async) { final long start = System.nanoTime(); ensureOpen(); validateNotNull(key); CacheProxyUtil.validateConfiguredTypes(cacheConfig, key); final Data keyData = toData(key); final int completionId = withCompletionEvent ? nextCompletionId() : -1; ClientMessage request = CacheGetAndRemoveCodec.encodeRequest(nameWithPrefix, keyData, completionId); ClientInvocationFuture future; try { future = invoke(request, keyData, completionId); invalidateNearCache(keyData); } catch (Exception e) { throw ExceptionUtil.rethrow(e); } ClientDelegatingFuture delegatingFuture = new ClientDelegatingFuture<T>( future, clientContext.getSerializationService(), getAndRemoveResponseDecoder); if (async && statisticsEnabled) { delegatingFuture.andThen( new ExecutionCallback<Object>() { public void onResponse(Object responseData) { Object response = clientContext.getSerializationService().toObject(responseData); handleStatisticsOnRemove(true, start, response); } public void onFailure(Throwable t) {} }); } return delegatingFuture; }
protected Object putIfAbsentInternal( final K key, final V value, final ExpiryPolicy expiryPolicy, final boolean withCompletionEvent, final boolean async) { final long start = System.nanoTime(); ensureOpen(); validateNotNull(key, value); CacheProxyUtil.validateConfiguredTypes(cacheConfig, key, value); final Data keyData = toData(key); final Data valueData = toData(value); final Data expiryPolicyData = toData(expiryPolicy); final int completionId = withCompletionEvent ? nextCompletionId() : -1; ClientMessage request = CachePutIfAbsentCodec.encodeRequest( nameWithPrefix, keyData, valueData, expiryPolicyData, completionId); ClientInvocationFuture future; try { future = invoke(request, keyData, completionId); } catch (Exception e) { throw ExceptionUtil.rethrow(e); } ClientDelegatingFuture delegatingFuture = new ClientDelegatingFuture<Boolean>( future, clientContext.getSerializationService(), putIfAbsentResponseDecoder); if (!async) { try { Object response = delegatingFuture.get(); if (nearCache != null) { if (cacheOnUpdate) { storeInNearCache(keyData, valueData, value); } else { invalidateNearCache(keyData); } } if (statisticsEnabled) { handleStatisticsOnPutIfAbsent(start, (Boolean) response); } return response; } catch (Throwable e) { throw ExceptionUtil.rethrowAllowedTypeFirst(e, CacheException.class); } } else { if (nearCache != null || statisticsEnabled) { delegatingFuture.andThen( new ExecutionCallback<Object>() { @Override public void onResponse(Object responseData) { if (nearCache != null) { if (cacheOnUpdate) { storeInNearCache(keyData, valueData, value); } else { invalidateNearCache(keyData); } } if (statisticsEnabled) { Object response = clientContext.getSerializationService().toObject(responseData); handleStatisticsOnPutIfAbsent(start, (Boolean) response); } } @Override public void onFailure(Throwable t) {} }); } return delegatingFuture; } }