use of org.redisson.RedissonMap in project redisson by redisson.
the class BaseTransactionalMap method getAllOperationAsync.
protected RFuture<Map<K, V>> getAllOperationAsync(Set<K> keys) {
RPromise<Map<K, V>> result = new RedissonPromise<>();
Set<K> keysToLoad = new HashSet<K>();
Map<K, V> map = new HashMap<K, V>();
for (K key : keys) {
HashValue keyHash = toKeyHash(key);
MapEntry entry = state.get(keyHash);
if (entry != null) {
if (entry != MapEntry.NULL) {
map.put(key, (V) entry.getValue());
}
} else {
keysToLoad.add(key);
}
}
if (keysToLoad.isEmpty()) {
return RedissonPromise.newSucceededFuture(map);
}
RFuture<Map<K, V>> future = ((RedissonMap<K, V>) this.map).getAllOperationAsync(keysToLoad);
future.onComplete((res, e) -> {
if (e != null) {
result.tryFailure(e);
return;
}
map.putAll(res);
result.trySuccess(map);
});
return result;
}
use of org.redisson.RedissonMap in project redisson by redisson.
the class AsyncRemoteProxy method cancelExecution.
private void cancelExecution(RemoteInvocationOptions optionsCopy, boolean mayInterruptIfRunning, RemotePromise<Object> remotePromise, String cancelRequestMapName) {
RMap<String, RemoteServiceCancelRequest> canceledRequests = new RedissonMap<>(new CompositeCodec(StringCodec.INSTANCE, codec, codec), commandExecutor, cancelRequestMapName, null, null, null);
canceledRequests.fastPutAsync(remotePromise.getRequestId().toString(), new RemoteServiceCancelRequest(mayInterruptIfRunning, false));
canceledRequests.expireAsync(60, TimeUnit.SECONDS);
// subscribe for async result if it's not expected before
if (!optionsCopy.isResultExpected()) {
RemoteInvocationOptions options = new RemoteInvocationOptions(optionsCopy);
options.expectResultWithin(60, TimeUnit.SECONDS);
CompletionStage<RRemoteServiceResponse> responseFuture = pollResponse(options.getExecutionTimeoutInMillis(), remotePromise.getRequestId(), false);
awaitResultAsync(options, remotePromise, responseFuture);
}
}
use of org.redisson.RedissonMap in project redisson by redisson.
the class BaseTransactionalMap method getOperationAsync.
protected RFuture<V> getOperationAsync(K key) {
HashValue keyHash = toKeyHash(key);
MapEntry entry = state.get(keyHash);
if (entry != null) {
if (entry == MapEntry.NULL) {
return RedissonPromise.newSucceededFuture(null);
} else {
return RedissonPromise.newSucceededFuture((V) entry.getValue());
}
}
return ((RedissonMap<K, V>) map).getOperationAsync(key);
}
use of org.redisson.RedissonMap in project redisson by redisson.
the class LiveObjectInterceptor method intercept.
@RuntimeType
public Object intercept(@Origin Method method, @AllArguments Object[] args, @This Object me, @FieldValue("liveObjectId") Object id, @FieldProxy("liveObjectId") Setter idSetter, @FieldProxy("liveObjectId") Getter idGetter, @FieldValue("liveObjectLiveMap") RMap<String, ?> map, @FieldProxy("liveObjectLiveMap") Setter mapSetter, @FieldProxy("liveObjectLiveMap") Getter mapGetter) throws Throwable {
if ("setLiveObjectId".equals(method.getName())) {
if (args[0].getClass().isArray()) {
throw new UnsupportedOperationException("RId value cannot be an array.");
}
// TODO: distributed locking maybe required.
String idKey = getMapKey(args[0]);
if (map != null) {
if (((RedissonObject) map).getRawName().equals(idKey)) {
return null;
}
try {
map.rename(getMapKey(args[0]));
} catch (RedisException e) {
if (e.getMessage() == null || !e.getMessage().startsWith("ERR no such key")) {
throw e;
}
// key may already renamed by others.
}
}
RMap<Object, Object> liveMap = new RedissonMap<Object, Object>(namingScheme.getCodec(), commandExecutor, idKey, null, null, null);
mapSetter.setValue(liveMap);
return null;
}
if ("getLiveObjectId".equals(method.getName())) {
if (map == null) {
return null;
}
return namingScheme.resolveId(((RedissonObject) map).getRawName());
}
if ("delete".equals(method.getName())) {
CommandBatchService ce;
if (commandExecutor instanceof CommandBatchService) {
ce = (CommandBatchService) commandExecutor;
} else {
ce = new CommandBatchService(commandExecutor);
}
Object idd = ((RLiveObject) me).getLiveObjectId();
RFuture<Long> deleteFuture = service.delete(idd, me.getClass().getSuperclass(), namingScheme, ce);
ce.execute();
return deleteFuture.getNow() > 0;
}
try {
return method.invoke(map, args);
} catch (InvocationTargetException e) {
throw e.getCause();
}
}
Aggregations