
org.redisson.rx.RedissonBatchRx Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of redisson Show documentation
Show all versions of redisson Show documentation
Redis Java client with features of In-Memory Data Grid
/**
* Copyright (c) 2013-2019 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.rx;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.redisson.RedissonAtomicDouble;
import org.redisson.RedissonAtomicLong;
import org.redisson.RedissonBitSet;
import org.redisson.RedissonBlockingDeque;
import org.redisson.RedissonBlockingQueue;
import org.redisson.RedissonBucket;
import org.redisson.RedissonDeque;
import org.redisson.RedissonGeo;
import org.redisson.RedissonHyperLogLog;
import org.redisson.RedissonKeys;
import org.redisson.RedissonLexSortedSet;
import org.redisson.RedissonList;
import org.redisson.RedissonListMultimap;
import org.redisson.RedissonMap;
import org.redisson.RedissonMapCache;
import org.redisson.RedissonQueue;
import org.redisson.RedissonScoredSortedSet;
import org.redisson.RedissonScript;
import org.redisson.RedissonSet;
import org.redisson.RedissonSetCache;
import org.redisson.RedissonSetMultimap;
import org.redisson.RedissonStream;
import org.redisson.RedissonTopic;
import org.redisson.api.BatchOptions;
import org.redisson.api.BatchResult;
import org.redisson.api.RAtomicDoubleRx;
import org.redisson.api.RAtomicLongRx;
import org.redisson.api.RBatchRx;
import org.redisson.api.RBitSetRx;
import org.redisson.api.RBlockingDequeRx;
import org.redisson.api.RBlockingQueueRx;
import org.redisson.api.RBucketRx;
import org.redisson.api.RDequeRx;
import org.redisson.api.RFuture;
import org.redisson.api.RGeoRx;
import org.redisson.api.RHyperLogLogRx;
import org.redisson.api.RKeysRx;
import org.redisson.api.RLexSortedSetRx;
import org.redisson.api.RListMultimapRx;
import org.redisson.api.RListRx;
import org.redisson.api.RMapCache;
import org.redisson.api.RMapCacheRx;
import org.redisson.api.RMapRx;
import org.redisson.api.RQueueRx;
import org.redisson.api.RScoredSortedSetRx;
import org.redisson.api.RScriptRx;
import org.redisson.api.RSetCache;
import org.redisson.api.RSetCacheRx;
import org.redisson.api.RSetMultimapRx;
import org.redisson.api.RSetRx;
import org.redisson.api.RStreamRx;
import org.redisson.api.RTopicRx;
import org.redisson.api.RedissonRxClient;
import org.redisson.client.codec.Codec;
import org.redisson.connection.ConnectionManager;
import org.redisson.eviction.EvictionScheduler;
import io.reactivex.Flowable;
/**
*
* @author Nikita Koksharov
*
*/
public class RedissonBatchRx implements RBatchRx {
private final EvictionScheduler evictionScheduler;
private final CommandRxBatchService executorService;
private final BatchOptions options;
public RedissonBatchRx(EvictionScheduler evictionScheduler, ConnectionManager connectionManager, BatchOptions options) {
this.evictionScheduler = evictionScheduler;
this.executorService = new CommandRxBatchService(connectionManager);
this.options = options;
}
@Override
public RStreamRx getStream(String name) {
return RxProxyBuilder.create(executorService, new RedissonStream(executorService, name), RStreamRx.class);
}
@Override
public RStreamRx getStream(String name, Codec codec) {
return RxProxyBuilder.create(executorService, new RedissonStream(codec, executorService, name), RStreamRx.class);
}
@Override
public RBucketRx getBucket(String name) {
return RxProxyBuilder.create(executorService, new RedissonBucket(executorService, name), RBucketRx.class);
}
@Override
public RBucketRx getBucket(String name, Codec codec) {
return RxProxyBuilder.create(executorService, new RedissonBucket(codec, executorService, name), RBucketRx.class);
}
@Override
public RHyperLogLogRx getHyperLogLog(String name) {
return RxProxyBuilder.create(executorService, new RedissonHyperLogLog(executorService, name), RHyperLogLogRx.class);
}
@Override
public RHyperLogLogRx getHyperLogLog(String name, Codec codec) {
return RxProxyBuilder.create(executorService, new RedissonHyperLogLog(codec, executorService, name), RHyperLogLogRx.class);
}
@Override
public RListRx getList(String name) {
RedissonList list = new RedissonList(executorService, name, null);
return RxProxyBuilder.create(executorService, list,
new RedissonListRx(list), RListRx.class);
}
@Override
public RListRx getList(String name, Codec codec) {
RedissonList list = new RedissonList(codec, executorService, name, null);
return RxProxyBuilder.create(executorService, list,
new RedissonListRx(list), RListRx.class);
}
@Override
public RMapRx getMap(String name) {
RedissonMap map = new RedissonMap(executorService, name, null, null);
return RxProxyBuilder.create(executorService, map,
new RedissonMapRx(map, null), RMapRx.class);
}
@Override
public RMapRx getMap(String name, Codec codec) {
RedissonMap map = new RedissonMap(codec, executorService, name, null, null);
return RxProxyBuilder.create(executorService, map,
new RedissonMapRx(map, null), RMapRx.class);
}
@Override
public RMapCacheRx getMapCache(String name, Codec codec) {
RMapCache map = new RedissonMapCache(codec, evictionScheduler, executorService, name, null, null);
return RxProxyBuilder.create(executorService, map,
new RedissonMapCacheRx(map), RMapCacheRx.class);
}
@Override
public RMapCacheRx getMapCache(String name) {
RMapCache map = new RedissonMapCache(evictionScheduler, executorService, name, null, null);
return RxProxyBuilder.create(executorService, map,
new RedissonMapCacheRx(map), RMapCacheRx.class);
}
@Override
public RSetRx getSet(String name) {
RedissonSet set = new RedissonSet(executorService, name, null);
return RxProxyBuilder.create(executorService, set,
new RedissonSetRx(set, null), RSetRx.class);
}
@Override
public RSetRx getSet(String name, Codec codec) {
RedissonSet set = new RedissonSet(codec, executorService, name, null);
return RxProxyBuilder.create(executorService, set,
new RedissonSetRx(set, null), RSetRx.class);
}
@Override
public RTopicRx getTopic(String name) {
return RxProxyBuilder.create(executorService, new RedissonTopic(executorService, name), RTopicRx.class);
}
@Override
public RTopicRx getTopic(String name, Codec codec) {
return RxProxyBuilder.create(executorService, new RedissonTopic(codec, executorService, name), RTopicRx.class);
}
@Override
public RQueueRx getQueue(String name) {
RedissonQueue queue = new RedissonQueue(executorService, name, null);
return RxProxyBuilder.create(executorService, queue,
new RedissonListRx(queue), RQueueRx.class);
}
@Override
public RQueueRx getQueue(String name, Codec codec) {
RedissonQueue queue = new RedissonQueue(codec, executorService, name, null);
return RxProxyBuilder.create(executorService, queue,
new RedissonListRx(queue), RQueueRx.class);
}
@Override
public RBlockingQueueRx getBlockingQueue(String name) {
RedissonBlockingQueue queue = new RedissonBlockingQueue(executorService, name, null);
return RxProxyBuilder.create(executorService, queue,
new RedissonListRx(queue), RBlockingQueueRx.class);
}
@Override
public RBlockingQueueRx getBlockingQueue(String name, Codec codec) {
RedissonBlockingQueue queue = new RedissonBlockingQueue(codec, executorService, name, null);
return RxProxyBuilder.create(executorService, queue,
new RedissonListRx(queue), RBlockingQueueRx.class);
}
@Override
public RDequeRx getDeque(String name) {
RedissonDeque deque = new RedissonDeque(executorService, name, null);
return RxProxyBuilder.create(executorService, deque,
new RedissonListRx(deque), RDequeRx.class);
}
@Override
public RDequeRx getDeque(String name, Codec codec) {
RedissonDeque deque = new RedissonDeque(codec, executorService, name, null);
return RxProxyBuilder.create(executorService, deque,
new RedissonListRx(deque), RDequeRx.class);
}
@Override
public RAtomicLongRx getAtomicLong(String name) {
return RxProxyBuilder.create(executorService, new RedissonAtomicLong(executorService, name), RAtomicLongRx.class);
}
@Override
public RSetCacheRx getSetCache(String name) {
RSetCache set = new RedissonSetCache(evictionScheduler, executorService, name, null);
return RxProxyBuilder.create(executorService, set,
new RedissonSetCacheRx(set, null), RSetCacheRx.class);
}
@Override
public RSetCacheRx getSetCache(String name, Codec codec) {
RSetCache set = new RedissonSetCache(codec, evictionScheduler, executorService, name, null);
return RxProxyBuilder.create(executorService, set,
new RedissonSetCacheRx(set, null), RSetCacheRx.class);
}
@Override
public RScoredSortedSetRx getScoredSortedSet(String name) {
RedissonScoredSortedSet set = new RedissonScoredSortedSet(executorService, name, null);
return RxProxyBuilder.create(executorService, set,
new RedissonScoredSortedSetRx(set), RScoredSortedSetRx.class);
}
@Override
public RScoredSortedSetRx getScoredSortedSet(String name, Codec codec) {
RedissonScoredSortedSet set = new RedissonScoredSortedSet(codec, executorService, name, null);
return RxProxyBuilder.create(executorService, set,
new RedissonScoredSortedSetRx(set), RScoredSortedSetRx.class);
}
@Override
public RLexSortedSetRx getLexSortedSet(String name) {
RedissonLexSortedSet set = new RedissonLexSortedSet(executorService, name, null);
return RxProxyBuilder.create(executorService, set,
new RedissonLexSortedSetRx(set),
RLexSortedSetRx.class);
}
@Override
public RBitSetRx getBitSet(String name) {
return RxProxyBuilder.create(executorService, new RedissonBitSet(executorService, name), RBitSetRx.class);
}
@Override
public RScriptRx getScript() {
return RxProxyBuilder.create(executorService, new RedissonScript(executorService), RScriptRx.class);
}
@Override
public RScriptRx getScript(Codec codec) {
return RxProxyBuilder.create(executorService, new RedissonScript(executorService, codec), RScriptRx.class);
}
@Override
public RKeysRx getKeys() {
return RxProxyBuilder.create(executorService, new RedissonKeys(executorService), new RedissonKeysRx(executorService), RKeysRx.class);
}
@Override
public Flowable> execute() {
return executorService.flowable(new Callable>>() {
@Override
public RFuture> call() {
return executorService.executeAsync(options);
}
});
}
public RBatchRx atomic() {
options.atomic();
return this;
}
@Override
public RBatchRx syncSlaves(int slaves, long timeout, TimeUnit unit) {
options.syncSlaves(slaves, timeout, unit);
return this;
}
@Override
public RBatchRx skipResult() {
options.skipResult();
return this;
}
@Override
public RBatchRx retryAttempts(int retryAttempts) {
options.retryAttempts(retryAttempts);
return this;
}
@Override
public RBatchRx retryInterval(long retryInterval, TimeUnit unit) {
options.retryInterval(retryInterval, unit);
return this;
}
@Override
public RBatchRx timeout(long timeout, TimeUnit unit) {
options.responseTimeout(timeout, unit);
return this;
}
public void enableRedissonReferenceSupport(RedissonRxClient redissonRx) {
this.executorService.enableRedissonReferenceSupport(redissonRx);
}
@Override
public RGeoRx getGeo(String name) {
RedissonGeo geo = new RedissonGeo(executorService, name, null);
return RxProxyBuilder.create(executorService, geo,
new RedissonScoredSortedSetRx(geo), RGeoRx.class);
}
@Override
public RGeoRx getGeo(String name, Codec codec) {
RedissonGeo geo = new RedissonGeo(codec, executorService, name, null);
return RxProxyBuilder.create(executorService, geo,
new RedissonScoredSortedSetRx(geo), RGeoRx.class);
}
@Override
public RSetMultimapRx getSetMultimap(String name) {
return RxProxyBuilder.create(executorService, new RedissonSetMultimap(executorService, name),
new RedissonSetMultimapRx(executorService, name, null), RSetMultimapRx.class);
}
@Override
public RSetMultimapRx getSetMultimap(String name, Codec codec) {
return RxProxyBuilder.create(executorService, new RedissonSetMultimap(codec, executorService, name),
new RedissonSetMultimapRx(codec, executorService, name, null), RSetMultimapRx.class);
}
@Override
public RListMultimapRx getListMultimap(String name) {
return RxProxyBuilder.create(executorService, new RedissonListMultimap(executorService, name),
new RedissonListMultimapRx(executorService, name), RListMultimapRx.class);
}
@Override
public RListMultimapRx getListMultimap(String name, Codec codec) {
return RxProxyBuilder.create(executorService, new RedissonListMultimap(codec, executorService, name),
new RedissonListMultimapRx(codec, executorService, name), RListMultimapRx.class);
}
@Override
public RAtomicDoubleRx getAtomicDouble(String name) {
return RxProxyBuilder.create(executorService, new RedissonAtomicDouble(executorService, name), RAtomicDoubleRx.class);
}
@Override
public RBlockingDequeRx getBlockingDeque(String name) {
RedissonBlockingDeque deque = new RedissonBlockingDeque(executorService, name, null);
return RxProxyBuilder.create(executorService, deque,
new RedissonListRx(deque), RBlockingDequeRx.class);
}
@Override
public RBlockingDequeRx getBlockingDeque(String name, Codec codec) {
RedissonBlockingDeque deque = new RedissonBlockingDeque(codec, executorService, name, null);
return RxProxyBuilder.create(executorService, deque,
new RedissonListRx(deque), RBlockingDequeRx.class);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy