org.redisson.command.CommandAsyncExecutor Java Examples

The following examples show how to use org.redisson.command.CommandAsyncExecutor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BaseTransactionalMap.java    From redisson with Apache License 2.0 6 votes vote down vote up
protected RFuture<Boolean> deleteAsync(CommandAsyncExecutor commandExecutor, TransactionalOperation operation) {
    RPromise<Boolean> result = new RedissonPromise<Boolean>();
    if (deleted != null) {
        operations.add(operation);
        result.trySuccess(!deleted);
        deleted = true;
        return result;
    }
    
    map.isExistsAsync().onComplete((res, e) -> {
        if (e != null) {
            result.tryFailure(e);
            return;
        }
        
        operations.add(operation);
        state.replaceAll((k, v) -> MapEntry.NULL);
        deleted = true;
        result.trySuccess(res);
    });
    
    return result;
}
 
Example #2
Source File: RedissonDelayedQueue.java    From redisson with Apache License 2.0 5 votes vote down vote up
protected RedissonDelayedQueue(QueueTransferService queueTransferService, Codec codec, final CommandAsyncExecutor commandExecutor, String name) {
    super(codec, commandExecutor, name);
    channelName = prefixName("redisson_delay_queue_channel", getName());
    queueName = prefixName("redisson_delay_queue", getName());
    timeoutSetName = prefixName("redisson_delay_queue_timeout", getName());
    
    QueueTransferTask task = new QueueTransferTask(commandExecutor.getConnectionManager()) {
        
        @Override
        protected RFuture<Long> pushTaskAsync() {
            return commandExecutor.evalWriteAsync(getName(), LongCodec.INSTANCE, RedisCommands.EVAL_LONG,
                    "local expiredValues = redis.call('zrangebyscore', KEYS[2], 0, ARGV[1], 'limit', 0, ARGV[2]); "
                  + "if #expiredValues > 0 then "
                      + "for i, v in ipairs(expiredValues) do "
                          + "local randomId, value = struct.unpack('dLc0', v);"
                          + "redis.call('rpush', KEYS[1], value);"
                          + "redis.call('lrem', KEYS[3], 1, v);"
                      + "end; "
                      + "redis.call('zrem', KEYS[2], unpack(expiredValues));"
                  + "end; "
                    // get startTime from scheduler queue head task
                  + "local v = redis.call('zrange', KEYS[2], 0, 0, 'WITHSCORES'); "
                  + "if v[1] ~= nil then "
                     + "return v[2]; "
                  + "end "
                  + "return nil;",
                  Arrays.<Object>asList(getName(), timeoutSetName, queueName), 
                  System.currentTimeMillis(), 100);
        }
        
        @Override
        protected RTopic getTopic() {
            return new RedissonTopic(LongCodec.INSTANCE, commandExecutor, channelName);
        }
    };
    
    queueTransferService.schedule(queueName, task);
    
    this.queueTransferService = queueTransferService;
}
 
Example #3
Source File: RedissonTransactionalMap.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransactionalMap(Codec codec, CommandAsyncExecutor commandExecutor, String name,
        List<TransactionalOperation> operations, long timeout, AtomicBoolean executed, String transactionId) {
    super(codec, commandExecutor, name, null, null, null);
    this.executed = executed;
    RedissonMap<K, V> innerMap = new RedissonMap<K, V>(codec, commandExecutor, name, null, null, null);
    this.transactionalMap = new BaseTransactionalMap<K, V>(commandExecutor, timeout, operations, innerMap, transactionId);
}
 
Example #4
Source File: EvictionTask.java    From redisson with Apache License 2.0 5 votes vote down vote up
EvictionTask(CommandAsyncExecutor executor) {
    super();
    this.executor = executor;
    this.minDelay = executor.getConnectionManager().getCfg().getMinCleanUpDelay();
    this.maxDelay = executor.getConnectionManager().getCfg().getMaxCleanUpDelay();
    this.keysLimit = executor.getConnectionManager().getCfg().getCleanUpKeysAmount();
}
 
Example #5
Source File: RedissonListMultimapCache.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonListMultimapCache(EvictionScheduler evictionScheduler, Codec codec, CommandAsyncExecutor connectionManager, String name) {
    super(codec, connectionManager, name);
    if (evictionScheduler != null) {
        evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
    }
    baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
}
 
Example #6
Source File: RedissonTransactionalSet.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransactionalSet(Codec codec, CommandAsyncExecutor commandExecutor,
        String name, List<TransactionalOperation> operations, long timeout, AtomicBoolean executed, String transactionId) {
    super(codec, commandExecutor, name, null);
    this.executed = executed;
    RedissonSet<V> innerSet = new RedissonSet<V>(codec, commandExecutor, name, null);
    this.transactionalSet = new TransactionalSet<V>(commandExecutor, timeout, operations, innerSet, transactionId);
}
 
Example #7
Source File: RedissonPatternTopic.java    From redisson with Apache License 2.0 5 votes vote down vote up
protected RedissonPatternTopic(Codec codec, CommandAsyncExecutor commandExecutor, String name) {
    this.commandExecutor = commandExecutor;
    this.name = name;
    this.channelName = new ChannelName(name);
    this.codec = codec;
    this.subscribeService = commandExecutor.getConnectionManager().getSubscribeService();
}
 
Example #8
Source File: RedissonTopic.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTopic(Codec codec, CommandAsyncExecutor commandExecutor, String name) {
    this.commandExecutor = commandExecutor;
    this.name = name;
    this.channelName = new ChannelName(name);
    this.codec = codec;
    this.subscribeService = commandExecutor.getConnectionManager().getSubscribeService();
}
 
Example #9
Source File: RedissonLock.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonLock(CommandAsyncExecutor commandExecutor, String name) {
    super(commandExecutor, name);
    this.commandExecutor = commandExecutor;
    this.id = commandExecutor.getConnectionManager().getId();
    this.internalLockLeaseTime = commandExecutor.getConnectionManager().getCfg().getLockWatchdogTimeout();
    this.entryName = id + ":" + name;
    this.pubSub = commandExecutor.getConnectionManager().getSubscribeService().getLockPubSub();
}
 
Example #10
Source File: BaseRemoteService.java    From redisson with Apache License 2.0 5 votes vote down vote up
public BaseRemoteService(Codec codec, String name, CommandAsyncExecutor commandExecutor, String executorId, ConcurrentMap<String, ResponseEntry> responses) {
    this.codec = codec;
    this.name = name;
    this.commandExecutor = commandExecutor;
    this.executorId = executorId;
    this.responses = responses;
    this.cancelRequestMapName = "{" + name + ":remote" + "}:cancel-request";
    this.cancelResponseMapName = "{" + name + ":remote" + "}:cancel-response";
    this.responseQueueName = getResponseQueueName(executorId);
}
 
Example #11
Source File: MoveOperation.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void commit(CommandAsyncExecutor commandExecutor) {
    RSet<Object> set = new RedissonSet<Object>(codec, commandExecutor, name, null);
    RSet<Object> destinationSet = new RedissonSet<Object>(codec, commandExecutor, destinationName, null);
    set.moveAsync(destinationSet.getName(), value);

    getLock(destinationSet, commandExecutor, value).unlockAsync(threadId);
    getLock(set, commandExecutor, value).unlockAsync(threadId);
}
 
Example #12
Source File: MoveOperation.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void rollback(CommandAsyncExecutor commandExecutor) {
    RSet<Object> set = new RedissonSet<Object>(codec, commandExecutor, name, null);
    RSet<Object> destinationSet = new RedissonSet<Object>(codec, commandExecutor, destinationName, null);
    
    getLock(destinationSet, commandExecutor, value).unlockAsync(threadId);
    getLock(set, commandExecutor, value).unlockAsync(threadId);
}
 
Example #13
Source File: AddCacheOperation.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void commit(CommandAsyncExecutor commandExecutor) {
    RSetCache<Object> set = new RedissonSetCache<>(codec, null, commandExecutor, name, null);
    if (timeUnit != null) {
        set.addAsync(value, ttl, timeUnit);
    } else {
        set.addAsync(value);
    }
    getLock(set, commandExecutor, value).unlockAsync(threadId);
}
 
Example #14
Source File: RedissonListMultimapCache.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonListMultimapCache(EvictionScheduler evictionScheduler, CommandAsyncExecutor connectionManager, String name) {
    super(connectionManager, name);
    if (evictionScheduler != null) {
        evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
    }
    baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
}
 
Example #15
Source File: RedissonSetMultimapCache.java    From redisson with Apache License 2.0 5 votes vote down vote up
RedissonSetMultimapCache(EvictionScheduler evictionScheduler, Codec codec, CommandAsyncExecutor connectionManager, String name) {
    super(codec, connectionManager, name);
    if (evictionScheduler != null) {
        evictionScheduler.scheduleCleanMultimap(name, getTimeoutSetName());
    }
    baseCache = new RedissonMultimapCache<K>(connectionManager, this, getTimeoutSetName(), prefix);
}
 
Example #16
Source File: BucketTrySetOperation.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void commit(CommandAsyncExecutor commandExecutor) {
    RedissonBucket<V> bucket = new RedissonBucket<V>(codec, commandExecutor, name);
    if (timeToLive != 0) {
        bucket.trySetAsync((V) value, timeToLive, timeUnit);
    } else {
        bucket.trySetAsync((V) value);
    }
    RedissonLock lock = new RedissonTransactionalLock(commandExecutor, lockName, transactionId);
    lock.unlockAsync();
}
 
Example #17
Source File: MapCacheEvictionTask.java    From redisson with Apache License 2.0 5 votes vote down vote up
public MapCacheEvictionTask(String name, String timeoutSetName, String maxIdleSetName, 
        String expiredChannelName, String lastAccessTimeSetName, CommandAsyncExecutor executor) {
    super(executor);
    this.name = name;
    this.timeoutSetName = timeoutSetName;
    this.maxIdleSetName = maxIdleSetName;
    this.expiredChannelName = expiredChannelName;
    this.lastAccessTimeSetName = lastAccessTimeSetName;
    this.executeTaskOnceLatchName = RedissonObject.prefixName("redisson__execute_task_once_latch", name);
}
 
Example #18
Source File: BucketCompareAndSetOperation.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void commit(CommandAsyncExecutor commandExecutor) {
    RedissonBucket<V> bucket = new RedissonBucket<V>(codec, commandExecutor, name);
    bucket.compareAndSetAsync(expected, value);
    RedissonLock lock = new RedissonTransactionalLock(commandExecutor, lockName, transactionId);
    lock.unlockAsync();
}
 
Example #19
Source File: RedissonSetCache.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonSetCache(EvictionScheduler evictionScheduler, CommandAsyncExecutor commandExecutor, String name, RedissonClient redisson) {
    super(commandExecutor, name);
    if (evictionScheduler != null) {
        evictionScheduler.schedule(getName(), 0);
    }
    this.evictionScheduler = evictionScheduler;
    this.redisson = redisson;
}
 
Example #20
Source File: TouchOperation.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
public void commit(CommandAsyncExecutor commandExecutor) {
    RKeys keys = new RedissonKeys(commandExecutor);
    keys.touchAsync(getName());
    RedissonLock lock = new RedissonLock(commandExecutor, lockName);
    lock.unlockAsync();
}
 
Example #21
Source File: RedissonBaseAdder.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonBaseAdder(CommandAsyncExecutor connectionManager, String name, RedissonClient redisson) {
    super(connectionManager, name);
    
    topic = redisson.getTopic(suffixName(getName(), "topic"), LongCodec.INSTANCE);
    semaphore = redisson.getSemaphore(suffixName(getName(), "semaphore"));
    listenerId = topic.addListener(Long.class, new MessageListener<Long>() {
        
        @Override
        public void onMessage(CharSequence channel, Long msg) {
            if (msg == SUM_MSG) {
                RFuture<T> addAndGetFuture = addAndGetAsync();
                addAndGetFuture.onComplete((res, e) -> {
                    if (e != null) {
                        log.error("Can't increase sum", e);
                        return;
                    }
                    
                    semaphore.releaseAsync().onComplete((r, ex) -> {
                        if (ex != null) {
                            log.error("Can't release semaphore", ex);
                            return;
                        }
                    });
                });
            }
            
            if (msg == CLEAR_MSG) {
                doReset();
                semaphore.releaseAsync().onComplete((res, e) -> {
                    if (e != null) {
                        log.error("Can't release semaphore", e);
                    }
                });
            }
        }

    });
    
}
 
Example #22
Source File: BaseTransactionalSet.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RFuture<Boolean> touchAsync(CommandAsyncExecutor commandExecutor) {
    RPromise<Boolean> result = new RedissonPromise<Boolean>();
    if (deleted != null && deleted) {
        operations.add(new TouchOperation(name));
        result.trySuccess(false);
        return result;
    }
    
    set.isExistsAsync().onComplete((exists, e) -> {
        if (e != null) {
            result.tryFailure(e);
            return;
        }
        
        operations.add(new TouchOperation(name));
        if (!exists) {
            for (Object value : state.values()) {
                if (value != NULL) {
                    exists = true;
                    break;
                }
            }
        }
        result.trySuccess(exists);
    });
            
    return result;
}
 
Example #23
Source File: RedissonTransactionalSetCache.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransactionalSetCache(CommandAsyncExecutor commandExecutor, String name,
        List<TransactionalOperation> operations, long timeout, AtomicBoolean executed, String transactionId) {
    super(null, commandExecutor, name, null);
    this.executed = executed;
    RedissonSetCache<V> innerSet = new RedissonSetCache<V>(null, commandExecutor, name, null);
    this.transactionalSet = new TransactionalSetCache<V>(commandExecutor, timeout, operations, innerSet, transactionId);
}
 
Example #24
Source File: RedissonTransactionalSetCache.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransactionalSetCache(Codec codec, CommandAsyncExecutor commandExecutor, String name,
        List<TransactionalOperation> operations, long timeout, AtomicBoolean executed, String transactionId) {
    super(null, commandExecutor, name, null);
    this.executed = executed;
    RedissonSetCache<V> innerSet = new RedissonSetCache<V>(codec, null, commandExecutor, name, null);
    this.transactionalSet = new TransactionalSetCache<V>(commandExecutor, timeout, operations, innerSet, transactionId);
}
 
Example #25
Source File: RedissonTransaction.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransaction(CommandAsyncExecutor commandExecutor, TransactionOptions options,
        List<TransactionalOperation> operations, Set<String> localCaches) {
    super();
    this.commandExecutor = commandExecutor;
    this.options = options;
    this.operations = operations;
    this.localCaches = localCaches;
}
 
Example #26
Source File: RedissonTransactionalBuckets.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransactionalBuckets(CommandAsyncExecutor commandExecutor, 
        long timeout, List<TransactionalOperation> operations, AtomicBoolean executed, String transactionId) {
    super(commandExecutor);
    
    this.timeout = timeout;
    this.operations = operations;
    this.executed = executed;
    this.transactionId = transactionId;
}
 
Example #27
Source File: BaseTransactionalMap.java    From redisson with Apache License 2.0 5 votes vote down vote up
public BaseTransactionalMap(CommandAsyncExecutor commandExecutor, long timeout, List<TransactionalOperation> operations, RMap<K, V> map, String transactionId) {
    super();
    this.timeout = timeout;
    this.operations = operations;
    this.map = map;
    this.commandExecutor = commandExecutor;
    this.transactionId = transactionId;
}
 
Example #28
Source File: BaseTransactionalMap.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RFuture<Boolean> touchAsync(CommandAsyncExecutor commandExecutor) {
    RPromise<Boolean> result = new RedissonPromise<Boolean>();
    if (deleted != null && deleted) {
        operations.add(new TouchOperation(map.getName()));
        result.trySuccess(false);
        return result;
    }
    
    map.isExistsAsync().onComplete((exists, e) -> {
        if (e != null) {
            result.tryFailure(e);
            return;
        }
        
        operations.add(new TouchOperation(map.getName()));
        if (!exists) {
            for (MapEntry entry : state.values()) {
                if (entry != MapEntry.NULL) {
                    exists = true;
                    break;
                }
            }
        }
        result.trySuccess(exists);
    });
    return result;
}
 
Example #29
Source File: RedissonTransferQueue.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonTransferQueue(CommandAsyncExecutor commandExecutor, String name, RRemoteService remoteService) {
    super(commandExecutor, name);
    service = remoteService.get(TransferQueueServiceAsync.class, RemoteInvocationOptions.defaults().noAck());
    this.remoteService = remoteService;

    queueName = ((RedissonRemoteService) remoteService).getRequestQueueName(TransferQueueService.class);
    mapName = ((RedissonRemoteService) remoteService).getRequestTasksMapName(TransferQueueService.class);
}
 
Example #30
Source File: RedissonMapCache.java    From redisson with Apache License 2.0 5 votes vote down vote up
public RedissonMapCache(Codec codec, EvictionScheduler evictionScheduler, CommandAsyncExecutor commandExecutor,
                        String name, RedissonClient redisson, MapOptions<K, V> options, WriteBehindService writeBehindService) {
    super(codec, commandExecutor, name, redisson, options, writeBehindService);
    if (evictionScheduler != null) {
        evictionScheduler.schedule(getName(), getTimeoutSetName(), getIdleSetName(), getExpiredChannelName(), getLastAccessTimeSetName());
    }
    this.evictionScheduler = evictionScheduler;
}