/** * Copyright 2018 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 com.fr.third.org.redisson; import java.util.concurrent.TimeUnit; import com.fr.third.org.redisson.api.BatchResult; import com.fr.third.org.redisson.api.RAtomicDoubleAsync; import com.fr.third.org.redisson.api.RAtomicLongAsync; import com.fr.third.org.redisson.api.RBatch; import com.fr.third.org.redisson.api.RBitSetAsync; import com.fr.third.org.redisson.api.RBlockingDequeAsync; import com.fr.third.org.redisson.api.RBlockingQueueAsync; import com.fr.third.org.redisson.api.RBucketAsync; import com.fr.third.org.redisson.api.RDequeAsync; import com.fr.third.org.redisson.api.RFuture; import com.fr.third.org.redisson.api.RGeoAsync; import com.fr.third.org.redisson.api.RHyperLogLogAsync; import com.fr.third.org.redisson.api.RKeysAsync; import com.fr.third.org.redisson.api.RLexSortedSetAsync; import com.fr.third.org.redisson.api.RListAsync; import com.fr.third.org.redisson.api.RMapAsync; import com.fr.third.org.redisson.api.RMapCacheAsync; import com.fr.third.org.redisson.api.RMultimapAsync; import com.fr.third.org.redisson.api.RMultimapCacheAsync; import com.fr.third.org.redisson.api.RQueueAsync; import com.fr.third.org.redisson.api.RScoredSortedSetAsync; import com.fr.third.org.redisson.api.RScriptAsync; import com.fr.third.org.redisson.api.RSetAsync; import com.fr.third.org.redisson.api.RSetCacheAsync; import com.fr.third.org.redisson.api.RTopicAsync; import com.fr.third.org.redisson.client.codec.Codec; import com.fr.third.org.redisson.api.BatchResult; import com.fr.third.org.redisson.api.RAtomicDoubleAsync; import com.fr.third.org.redisson.api.RAtomicLongAsync; import com.fr.third.org.redisson.api.RBatch; import com.fr.third.org.redisson.api.RBitSetAsync; import com.fr.third.org.redisson.api.RBlockingDequeAsync; import com.fr.third.org.redisson.api.RBlockingQueueAsync; import com.fr.third.org.redisson.api.RBucketAsync; import com.fr.third.org.redisson.api.RDequeAsync; import com.fr.third.org.redisson.api.RFuture; import com.fr.third.org.redisson.api.RGeoAsync; import com.fr.third.org.redisson.api.RHyperLogLogAsync; import com.fr.third.org.redisson.api.RKeysAsync; import com.fr.third.org.redisson.api.RLexSortedSetAsync; import com.fr.third.org.redisson.api.RListAsync; import com.fr.third.org.redisson.api.RMapAsync; import com.fr.third.org.redisson.api.RMapCacheAsync; import com.fr.third.org.redisson.api.RMultimapAsync; import com.fr.third.org.redisson.api.RMultimapCacheAsync; import com.fr.third.org.redisson.api.RQueueAsync; import com.fr.third.org.redisson.api.RScoredSortedSetAsync; import com.fr.third.org.redisson.api.RScriptAsync; import com.fr.third.org.redisson.api.RSetAsync; import com.fr.third.org.redisson.api.RSetCacheAsync; import com.fr.third.org.redisson.api.RTopicAsync; import com.fr.third.org.redisson.client.codec.Codec; import com.fr.third.org.redisson.command.CommandBatchService; import com.fr.third.org.redisson.connection.ConnectionManager; import com.fr.third.org.redisson.eviction.EvictionScheduler; /** * * * @author Nikita Koksharov * */ public class RedissonBatch implements RBatch { private final EvictionScheduler evictionScheduler; private final CommandBatchService executorService; private long timeout; private int retryAttempts; private long retryInterval; private int syncSlaves; private long syncTimeout; private boolean skipResult; private boolean atomic; public RedissonBatch(EvictionScheduler evictionScheduler, ConnectionManager connectionManager) { this.executorService = new CommandBatchService(connectionManager); this.evictionScheduler = evictionScheduler; } @Override public RBucketAsync getBucket(String name) { return new RedissonBucket(executorService, name); } @Override public RBucketAsync getBucket(String name, Codec codec) { return new RedissonBucket(codec, executorService, name); } @Override public RHyperLogLogAsync getHyperLogLog(String name) { return new RedissonHyperLogLog(executorService, name); } @Override public RHyperLogLogAsync getHyperLogLog(String name, Codec codec) { return new RedissonHyperLogLog(codec, executorService, name); } @Override public RListAsync getList(String name) { return new RedissonList(executorService, name, null); } @Override public RListAsync getList(String name, Codec codec) { return new RedissonList(codec, executorService, name, null); } @Override public RMapAsync getMap(String name) { return new RedissonMap(executorService, name, null, null); } @Override public RMapAsync getMap(String name, Codec codec) { return new RedissonMap(codec, executorService, name, null, null); } @Override public RSetAsync getSet(String name) { return new RedissonSet(executorService, name, null); } @Override public RSetAsync getSet(String name, Codec codec) { return new RedissonSet(codec, executorService, name, null); } @Override public RTopicAsync getTopic(String name) { return new RedissonTopic(executorService, name); } @Override public RTopicAsync getTopic(String name, Codec codec) { return new RedissonTopic(codec, executorService, name); } @Override public RQueueAsync getQueue(String name) { return new RedissonQueue(executorService, name, null); } @Override public RQueueAsync getQueue(String name, Codec codec) { return new RedissonQueue(codec, executorService, name, null); } @Override public RBlockingQueueAsync getBlockingQueue(String name) { return new RedissonBlockingQueue(executorService, name, null); } @Override public RBlockingQueueAsync getBlockingQueue(String name, Codec codec) { return new RedissonBlockingQueue(codec, executorService, name, null); } @Override public RBlockingDequeAsync getBlockingDeque(String name) { return new RedissonBlockingDeque(executorService, name, null); } @Override public RBlockingDequeAsync getBlockingDeque(String name, Codec codec) { return new RedissonBlockingDeque(codec, executorService, name, null); } @Override public RDequeAsync getDeque(String name) { return new RedissonDeque(executorService, name, null); } @Override public RDequeAsync getDeque(String name, Codec codec) { return new RedissonDeque(codec, executorService, name, null); } @Override public RAtomicLongAsync getAtomicLong(String name) { return new RedissonAtomicLong(executorService, name); } @Override public RAtomicDoubleAsync getAtomicDouble(String name) { return new RedissonAtomicDouble(executorService, name); } @Override public RScoredSortedSetAsync getScoredSortedSet(String name) { return new RedissonScoredSortedSet(executorService, name, null); } @Override public RScoredSortedSetAsync getScoredSortedSet(String name, Codec codec) { return new RedissonScoredSortedSet(codec, executorService, name, null); } @Override public RLexSortedSetAsync getLexSortedSet(String name) { return new RedissonLexSortedSet(executorService, name, null); } @Override public RBitSetAsync getBitSet(String name) { return new RedissonBitSet(executorService, name); } @Override public RMapCacheAsync getMapCache(String name, Codec codec) { return new RedissonMapCache(codec, evictionScheduler, executorService, name, null, null); } @Override public RMapCacheAsync getMapCache(String name) { return new RedissonMapCache(evictionScheduler, executorService, name, null, null); } @Override public RScriptAsync getScript() { return new RedissonScript(executorService); } @Override public RKeysAsync getKeys() { return new RedissonKeys(executorService); } @Override public RSetCacheAsync getSetCache(String name) { return new RedissonSetCache(evictionScheduler, executorService, name, null); } @Override public RSetCacheAsync getSetCache(String name, Codec codec) { return new RedissonSetCache(codec, evictionScheduler, executorService, name, null); } @Override public RBatch syncSlaves(int slaves, long timeout, TimeUnit unit) { this.syncSlaves = slaves; this.syncTimeout = unit.toMillis(timeout); return this; } @Override public RBatch atomic() { this.atomic = true; return this; } @Override public RBatch skipResult() { this.skipResult = true; return this; } @Override public RBatch retryAttempts(int retryAttempts) { this.retryAttempts = retryAttempts; return this; } @Override public RBatch retryInterval(long retryInterval, TimeUnit unit) { this.retryInterval = unit.toMillis(retryInterval); return this; } @Override public RBatch timeout(long timeout, TimeUnit unit) { this.timeout = unit.toMillis(timeout); return this; } @Override public BatchResult execute() { return executorService.execute(syncSlaves, syncTimeout, skipResult, timeout, retryAttempts, retryInterval, atomic); } @Override public void executeSkipResult() { executorService.execute(syncSlaves, syncTimeout, true, timeout, retryAttempts, retryInterval, atomic); } @Override public RFuture executeSkipResultAsync() { return executorService.executeAsync(syncSlaves, syncTimeout, true, timeout, retryAttempts, retryInterval, atomic); } @Override public RFuture> executeAsync() { return executorService.executeAsync(syncSlaves, syncTimeout, skipResult, timeout, retryAttempts, retryInterval, atomic); } @Override public RMultimapAsync getSetMultimap(String name) { return new RedissonSetMultimap(executorService, name); } @Override public RMultimapAsync getSetMultimap(String name, Codec codec) { return new RedissonSetMultimap(codec, executorService, name); } @Override public RMultimapAsync getListMultimap(String name) { return new RedissonListMultimap(executorService, name); } @Override public RMultimapAsync getListMultimap(String name, Codec codec) { return new RedissonListMultimap(codec, executorService, name); } @Override public RGeoAsync getGeo(String name) { return new RedissonGeo(executorService, name, null); } @Override public RGeoAsync getGeo(String name, Codec codec) { return new RedissonGeo(codec, executorService, name, null); } @Override public RMultimapCacheAsync getSetMultimapCache(String name) { return new RedissonSetMultimapCache(evictionScheduler, executorService, name); } @Override public RMultimapCacheAsync getSetMultimapCache(String name, Codec codec) { return new RedissonSetMultimapCache(evictionScheduler, codec, executorService, name); } @Override public RMultimapCacheAsync getListMultimapCache(String name) { return new RedissonListMultimapCache(evictionScheduler, executorService, name); } @Override public RMultimapCacheAsync getListMultimapCache(String name, Codec codec) { return new RedissonListMultimapCache(evictionScheduler, codec, executorService, name); } protected void enableRedissonReferenceSupport(Redisson redisson) { this.executorService.enableRedissonReferenceSupport(redisson); } }