use of org.redisson.connection.NodeSource in project redisson by redisson.
the class CommandAsyncService method writeAsync.
@Override
public <T, R> RFuture<R> writeAsync(String key, Codec codec, RedisCommand<T> command, Object... params) {
RPromise<R> mainPromise = connectionManager.newPromise();
NodeSource source = getNodeSource(key);
async(false, source, codec, command, params, mainPromise, 0);
return mainPromise;
}
use of org.redisson.connection.NodeSource in project redisson by redisson.
the class CommandAsyncService method readAsync.
public <T, R> RFuture<R> readAsync(MasterSlaveEntry entry, Codec codec, RedisCommand<T> command, Object... params) {
RPromise<R> mainPromise = connectionManager.newPromise();
async(true, new NodeSource(entry), codec, command, params, mainPromise, 0);
return mainPromise;
}
use of org.redisson.connection.NodeSource in project redisson by redisson.
the class CommandAsyncService method getNodeSource.
private NodeSource getNodeSource(String key) {
int slot = connectionManager.calcSlot(key);
MasterSlaveEntry entry = connectionManager.getEntry(slot);
return new NodeSource(entry);
}
use of org.redisson.connection.NodeSource in project redisson by redisson.
the class CommandBatchService method executeAsync.
public RFuture<List<?>> executeAsync() {
if (executed) {
throw new IllegalStateException("Batch already executed!");
}
if (commands.isEmpty()) {
return connectionManager.newSucceededFuture(null);
}
executed = true;
RPromise<Void> voidPromise = connectionManager.newPromise();
final RPromise<List<?>> promise = connectionManager.newPromise();
voidPromise.addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
if (!future.isSuccess()) {
promise.tryFailure(future.cause());
commands = null;
return;
}
List<BatchCommandData> entries = new ArrayList<BatchCommandData>();
for (Entry e : commands.values()) {
entries.addAll(e.getCommands());
}
Collections.sort(entries);
List<Object> result = new ArrayList<Object>(entries.size());
for (BatchCommandData<?, ?> commandEntry : entries) {
Object entryResult = commandEntry.getPromise().getNow();
if (isRedissonReferenceSupportEnabled() && entryResult instanceof RedissonReference) {
result.add(redisson != null ? RedissonObjectFactory.<Object>fromReference(redisson, (RedissonReference) entryResult) : RedissonObjectFactory.<Object>fromReference(redissonReactive, (RedissonReference) entryResult));
} else {
result.add(entryResult);
}
}
promise.trySuccess(result);
commands = null;
}
});
AtomicInteger slots = new AtomicInteger(commands.size());
for (java.util.Map.Entry<MasterSlaveEntry, Entry> e : commands.entrySet()) {
execute(e.getValue(), new NodeSource(e.getKey()), voidPromise, slots, 0, false);
}
return promise;
}
use of org.redisson.connection.NodeSource in project redisson by redisson.
the class CommandBatchService method executeAsyncVoid.
private RFuture<Void> executeAsyncVoid(boolean noResult) {
if (executed) {
throw new IllegalStateException("Batch already executed!");
}
if (commands.isEmpty()) {
return connectionManager.newSucceededFuture(null);
}
if (noResult) {
for (Entry entry : commands.values()) {
RPromise<Object> s = connectionManager.newPromise();
BatchCommandData commandData = new BatchCommandData(s, null, RedisCommands.CLIENT_REPLY, new Object[] { "OFF" }, index.incrementAndGet());
entry.getCommands().addFirst(commandData);
RPromise<Object> s1 = connectionManager.newPromise();
BatchCommandData commandData1 = new BatchCommandData(s1, null, RedisCommands.CLIENT_REPLY, new Object[] { "ON" }, index.incrementAndGet());
entry.getCommands().add(commandData1);
}
}
executed = true;
RPromise<Void> voidPromise = connectionManager.newPromise();
voidPromise.addListener(new FutureListener<Void>() {
@Override
public void operationComplete(Future<Void> future) throws Exception {
commands = null;
}
});
AtomicInteger slots = new AtomicInteger(commands.size());
for (java.util.Map.Entry<MasterSlaveEntry, Entry> e : commands.entrySet()) {
execute(e.getValue(), new NodeSource(e.getKey()), voidPromise, slots, 0, true);
}
return voidPromise;
}
Aggregations