Search in sources :

Example 6 with NodeSource

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;
}
Also used : NodeSource(org.redisson.connection.NodeSource)

Example 7 with NodeSource

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;
}
Also used : NodeSource(org.redisson.connection.NodeSource)

Example 8 with NodeSource

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);
}
Also used : NodeSource(org.redisson.connection.NodeSource) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry)

Example 9 with NodeSource

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;
}
Also used : RedissonReference(org.redisson.RedissonReference) BatchCommandData(org.redisson.client.protocol.BatchCommandData) RedisMovedException(org.redisson.client.RedisMovedException) RedisAskException(org.redisson.client.RedisAskException) WriteRedisConnectionException(org.redisson.client.WriteRedisConnectionException) RedisLoadingException(org.redisson.client.RedisLoadingException) RedisTryAgainException(org.redisson.client.RedisTryAgainException) RedisTimeoutException(org.redisson.client.RedisTimeoutException) NodeSource(org.redisson.connection.NodeSource) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 10 with NodeSource

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;
}
Also used : BatchCommandData(org.redisson.client.protocol.BatchCommandData) RedisMovedException(org.redisson.client.RedisMovedException) RedisAskException(org.redisson.client.RedisAskException) WriteRedisConnectionException(org.redisson.client.WriteRedisConnectionException) RedisLoadingException(org.redisson.client.RedisLoadingException) RedisTryAgainException(org.redisson.client.RedisTryAgainException) RedisTimeoutException(org.redisson.client.RedisTimeoutException) NodeSource(org.redisson.connection.NodeSource) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MasterSlaveEntry(org.redisson.connection.MasterSlaveEntry) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

NodeSource (org.redisson.connection.NodeSource)17 MasterSlaveEntry (org.redisson.connection.MasterSlaveEntry)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 RedisAskException (org.redisson.client.RedisAskException)5 RedisLoadingException (org.redisson.client.RedisLoadingException)5 RedisMovedException (org.redisson.client.RedisMovedException)5 RedisTimeoutException (org.redisson.client.RedisTimeoutException)5 RedisTryAgainException (org.redisson.client.RedisTryAgainException)5 WriteRedisConnectionException (org.redisson.client.WriteRedisConnectionException)5 ChannelFuture (io.netty.channel.ChannelFuture)4 ChannelFutureListener (io.netty.channel.ChannelFutureListener)3 Future (io.netty.util.concurrent.Future)3 FutureListener (io.netty.util.concurrent.FutureListener)3 ArrayList (java.util.ArrayList)3 RFuture (org.redisson.api.RFuture)3 Timeout (io.netty.util.Timeout)2 TimerTask (io.netty.util.TimerTask)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 RedissonShutdownException (org.redisson.RedissonShutdownException)2 RedisException (org.redisson.client.RedisException)2