|
|
@ -70,7 +70,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
this.options = options;
|
|
|
|
this.options = options;
|
|
|
|
if (options != null
|
|
|
|
if (options != null
|
|
|
|
&& options.getWriteMode() == WriteMode.WRITE_BEHIND
|
|
|
|
&& options.getWriteMode() == WriteMode.WRITE_BEHIND
|
|
|
|
&& options.getWriter() != null) {
|
|
|
|
&& (options.getWriter() != null || options.getWriterAsync() != null)) {
|
|
|
|
this.writeBehindService = writeBehindService;
|
|
|
|
this.writeBehindService = writeBehindService;
|
|
|
|
writeBehindTask = writeBehindService.start(name, options);
|
|
|
|
writeBehindTask = writeBehindService.start(name, options);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -94,7 +94,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
this.options = options;
|
|
|
|
this.options = options;
|
|
|
|
if (options != null
|
|
|
|
if (options != null
|
|
|
|
&& options.getWriteMode() == WriteMode.WRITE_BEHIND
|
|
|
|
&& options.getWriteMode() == WriteMode.WRITE_BEHIND
|
|
|
|
&& options.getWriter() != null) {
|
|
|
|
&& (options.getWriter() != null || options.getWriterAsync() != null)) {
|
|
|
|
this.writeBehindService = writeBehindService;
|
|
|
|
this.writeBehindService = writeBehindService;
|
|
|
|
writeBehindTask = writeBehindService.start(name, options);
|
|
|
|
writeBehindTask = writeBehindService.start(name, options);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -726,6 +726,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
|
|
CompletionStage<M> f = future.thenCompose(res -> {
|
|
|
|
CompletionStage<M> f = future.thenCompose(res -> {
|
|
|
|
if (condition.apply(res)) {
|
|
|
|
if (condition.apply(res)) {
|
|
|
|
|
|
|
|
if (options.getWriter() != null) {
|
|
|
|
CompletableFuture<M> promise = new CompletableFuture<>();
|
|
|
|
CompletableFuture<M> promise = new CompletableFuture<>();
|
|
|
|
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
|
|
|
|
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -742,6 +743,15 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return promise;
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (task instanceof MapWriterTask.Add) {
|
|
|
|
|
|
|
|
return options.getWriterAsync().write(task.getMap())
|
|
|
|
|
|
|
|
.thenApply(r -> res);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return options.getWriterAsync().delete(task.getKeys())
|
|
|
|
|
|
|
|
.thenApply(r -> res);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return CompletableFuture.completedFuture(res);
|
|
|
|
return CompletableFuture.completedFuture(res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -919,7 +929,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected boolean hasNoWriter() {
|
|
|
|
protected boolean hasNoWriter() {
|
|
|
|
return options == null || options.getWriter() == null;
|
|
|
|
return options == null || (options.getWriter() == null && options.getWriterAsync() == null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected RFuture<V> putIfAbsentOperationAsync(K key, V value) {
|
|
|
|
protected RFuture<V> putIfAbsentOperationAsync(K key, V value) {
|
|
|
@ -1190,10 +1200,6 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
throw new IllegalArgumentException("parallelism can't be lower than 1");
|
|
|
|
throw new IllegalArgumentException("parallelism can't be lower than 1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (K key : keys) {
|
|
|
|
|
|
|
|
checkKey(key);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<CompletableFuture<?>> futures = new ArrayList<>();
|
|
|
|
List<CompletableFuture<?>> futures = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Iterator<? extends K> iter = keys.iterator();
|
|
|
|
Iterator<? extends K> iter = keys.iterator();
|
|
|
@ -1203,6 +1209,9 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
K key = iter.next();
|
|
|
|
K key = iter.next();
|
|
|
|
|
|
|
|
if (key == null) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (replaceExistingValues) {
|
|
|
|
if (replaceExistingValues) {
|
|
|
|
CompletableFuture<Void> f = loadValue(iter, key, loadedEntires);
|
|
|
|
CompletableFuture<Void> f = loadValue(iter, key, loadedEntires);
|
|
|
|
futures.add(f);
|
|
|
|
futures.add(f);
|
|
|
@ -1378,6 +1387,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
|
|
|
|
|
|
|
|
return CompletableFuture.completedFuture((long) deletedKeys.size());
|
|
|
|
return CompletableFuture.completedFuture((long) deletedKeys.size());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (options.getWriter() != null) {
|
|
|
|
CompletableFuture<Long> future = new CompletableFuture<>();
|
|
|
|
CompletableFuture<Long> future = new CompletableFuture<>();
|
|
|
|
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
|
|
|
|
commandExecutor.getConnectionManager().getExecutor().execute(() -> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -1390,6 +1400,10 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return future;
|
|
|
|
return future;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return options.getWriterAsync().delete(deletedKeys)
|
|
|
|
|
|
|
|
.thenApply(r -> (long) deletedKeys.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return new CompletableFutureWrapper<>(f);
|
|
|
|
return new CompletableFutureWrapper<>(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1660,6 +1674,7 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private CompletableFuture<V> loadValue(K key, RLock lock, long threadId) {
|
|
|
|
private CompletableFuture<V> loadValue(K key, RLock lock, long threadId) {
|
|
|
|
|
|
|
|
// if (options.getLoader() != null) {
|
|
|
|
CompletableFuture<V> result = new CompletableFuture<>();
|
|
|
|
CompletableFuture<V> result = new CompletableFuture<>();
|
|
|
|
commandExecutor.getConnectionManager().getExecutor().execute(new Runnable() {
|
|
|
|
commandExecutor.getConnectionManager().getExecutor().execute(new Runnable() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -1714,6 +1729,33 @@ public class RedissonMap<K, V> extends RedissonExpirable implements RMap<K, V> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CompletionStage<V> valueFuture = options.getLoaderAsync().load(key);
|
|
|
|
|
|
|
|
// return valueFuture.handle((r, ex) -> {
|
|
|
|
|
|
|
|
// if (r == null) {
|
|
|
|
|
|
|
|
// return lock.unlockAsync(threadId);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (ex != null) {
|
|
|
|
|
|
|
|
// log.error("Unable to load value by key " + key + " for map " + getRawName(), ex);
|
|
|
|
|
|
|
|
// return lock.unlockAsync(threadId);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// return valueFuture;
|
|
|
|
|
|
|
|
// }).thenCompose(f -> f)
|
|
|
|
|
|
|
|
// .thenCompose(value -> {
|
|
|
|
|
|
|
|
// if (value != null) {
|
|
|
|
|
|
|
|
// return (CompletionStage<V>) putOperationAsync(key, (V) value).handle((r, ex) -> {
|
|
|
|
|
|
|
|
// RFuture<Void> f = lock.unlockAsync(threadId);
|
|
|
|
|
|
|
|
// if (ex != null) {
|
|
|
|
|
|
|
|
// log.error("Unable to store value by key " + key + " for map " + getRawName(), ex);
|
|
|
|
|
|
|
|
// return f;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return f.thenApply(res -> value);
|
|
|
|
|
|
|
|
// }).thenCompose(f -> f);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return CompletableFuture.completedFuture((V) value);
|
|
|
|
|
|
|
|
// }).toCompletableFuture();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
final class EntrySet extends AbstractSet<Map.Entry<K, V>> {
|
|
|
|
final class EntrySet extends AbstractSet<Map.Entry<K, V>> {
|
|
|
|