You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
373 lines
12 KiB
373 lines
12 KiB
7 years ago
|
/**
|
||
7 years ago
|
* Copyright 2018 Nikita Koksharov
|
||
7 years ago
|
*
|
||
|
* 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.
|
||
|
*/
|
||
7 years ago
|
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;
|
||
7 years ago
|
|
||
|
/**
|
||
|
*
|
||
|
*
|
||
|
* @author Nikita Koksharov
|
||
|
*
|
||
|
*/
|
||
|
public class RedissonBatch implements RBatch {
|
||
|
|
||
|
private final EvictionScheduler evictionScheduler;
|
||
|
private final CommandBatchService executorService;
|
||
|
|
||
7 years ago
|
private long timeout;
|
||
|
private int retryAttempts;
|
||
|
private long retryInterval;
|
||
|
|
||
|
private int syncSlaves;
|
||
|
private long syncTimeout;
|
||
|
private boolean skipResult;
|
||
|
private boolean atomic;
|
||
|
|
||
7 years ago
|
public RedissonBatch(EvictionScheduler evictionScheduler, ConnectionManager connectionManager) {
|
||
|
this.executorService = new CommandBatchService(connectionManager);
|
||
|
this.evictionScheduler = evictionScheduler;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RBucketAsync<V> getBucket(String name) {
|
||
|
return new RedissonBucket<V>(executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RBucketAsync<V> getBucket(String name, Codec codec) {
|
||
|
return new RedissonBucket<V>(codec, executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RHyperLogLogAsync<V> getHyperLogLog(String name) {
|
||
|
return new RedissonHyperLogLog<V>(executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RHyperLogLogAsync<V> getHyperLogLog(String name, Codec codec) {
|
||
|
return new RedissonHyperLogLog<V>(codec, executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RListAsync<V> getList(String name) {
|
||
7 years ago
|
return new RedissonList<V>(executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RListAsync<V> getList(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonList<V>(codec, executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMapAsync<K, V> getMap(String name) {
|
||
7 years ago
|
return new RedissonMap<K, V>(executorService, name, null, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMapAsync<K, V> getMap(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonMap<K, V>(codec, executorService, name, null, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RSetAsync<V> getSet(String name) {
|
||
7 years ago
|
return new RedissonSet<V>(executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RSetAsync<V> getSet(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonSet<V>(codec, executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <M> RTopicAsync<M> getTopic(String name) {
|
||
|
return new RedissonTopic<M>(executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <M> RTopicAsync<M> getTopic(String name, Codec codec) {
|
||
|
return new RedissonTopic<M>(codec, executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RQueueAsync<V> getQueue(String name) {
|
||
7 years ago
|
return new RedissonQueue<V>(executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RQueueAsync<V> getQueue(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonQueue<V>(codec, executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RBlockingQueueAsync<V> getBlockingQueue(String name) {
|
||
7 years ago
|
return new RedissonBlockingQueue<V>(executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RBlockingQueueAsync<V> getBlockingQueue(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonBlockingQueue<V>(codec, executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RBlockingDequeAsync<V> getBlockingDeque(String name) {
|
||
7 years ago
|
return new RedissonBlockingDeque<V>(executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RBlockingDequeAsync<V> getBlockingDeque(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonBlockingDeque<V>(codec, executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RDequeAsync<V> getDeque(String name) {
|
||
7 years ago
|
return new RedissonDeque<V>(executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RDequeAsync<V> getDeque(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonDeque<V>(codec, executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public RAtomicLongAsync getAtomicLong(String name) {
|
||
|
return new RedissonAtomicLong(executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public RAtomicDoubleAsync getAtomicDouble(String name) {
|
||
|
return new RedissonAtomicDouble(executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RScoredSortedSetAsync<V> getScoredSortedSet(String name) {
|
||
7 years ago
|
return new RedissonScoredSortedSet<V>(executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RScoredSortedSetAsync<V> getScoredSortedSet(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonScoredSortedSet<V>(codec, executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public RLexSortedSetAsync getLexSortedSet(String name) {
|
||
7 years ago
|
return new RedissonLexSortedSet(executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public RBitSetAsync getBitSet(String name) {
|
||
|
return new RedissonBitSet(executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMapCacheAsync<K, V> getMapCache(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonMapCache<K, V>(codec, evictionScheduler, executorService, name, null, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMapCacheAsync<K, V> getMapCache(String name) {
|
||
7 years ago
|
return new RedissonMapCache<K, V>(evictionScheduler, executorService, name, null, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public RScriptAsync getScript() {
|
||
|
return new RedissonScript(executorService);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public RKeysAsync getKeys() {
|
||
|
return new RedissonKeys(executorService);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RSetCacheAsync<V> getSetCache(String name) {
|
||
7 years ago
|
return new RedissonSetCache<V>(evictionScheduler, executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RSetCacheAsync<V> getSetCache(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonSetCache<V>(codec, evictionScheduler, executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
7 years ago
|
public RBatch syncSlaves(int slaves, long timeout, TimeUnit unit) {
|
||
|
this.syncSlaves = slaves;
|
||
|
this.syncTimeout = unit.toMillis(timeout);
|
||
|
return this;
|
||
7 years ago
|
}
|
||
7 years ago
|
|
||
7 years ago
|
@Override
|
||
7 years ago
|
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);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
@Override
|
||
|
public void executeSkipResult() {
|
||
|
executorService.execute(syncSlaves, syncTimeout, true, timeout, retryAttempts, retryInterval, atomic);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public RFuture<Void> executeSkipResultAsync() {
|
||
|
return executorService.executeAsync(syncSlaves, syncTimeout, true, timeout, retryAttempts, retryInterval, atomic);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public RFuture<BatchResult<?>> executeAsync() {
|
||
|
return executorService.executeAsync(syncSlaves, syncTimeout, skipResult, timeout, retryAttempts, retryInterval, atomic);
|
||
|
}
|
||
|
|
||
7 years ago
|
@Override
|
||
|
public <K, V> RMultimapAsync<K, V> getSetMultimap(String name) {
|
||
|
return new RedissonSetMultimap<K, V>(executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMultimapAsync<K, V> getSetMultimap(String name, Codec codec) {
|
||
|
return new RedissonSetMultimap<K, V>(codec, executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMultimapAsync<K, V> getListMultimap(String name) {
|
||
|
return new RedissonListMultimap<K, V>(executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMultimapAsync<K, V> getListMultimap(String name, Codec codec) {
|
||
|
return new RedissonListMultimap<K, V>(codec, executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RGeoAsync<V> getGeo(String name) {
|
||
7 years ago
|
return new RedissonGeo<V>(executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <V> RGeoAsync<V> getGeo(String name, Codec codec) {
|
||
7 years ago
|
return new RedissonGeo<V>(codec, executorService, name, null);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMultimapCacheAsync<K, V> getSetMultimapCache(String name) {
|
||
|
return new RedissonSetMultimapCache<K, V>(evictionScheduler, executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMultimapCacheAsync<K, V> getSetMultimapCache(String name, Codec codec) {
|
||
|
return new RedissonSetMultimapCache<K, V>(evictionScheduler, codec, executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMultimapCacheAsync<K, V> getListMultimapCache(String name) {
|
||
|
return new RedissonListMultimapCache<K, V>(evictionScheduler, executorService, name);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public <K, V> RMultimapCacheAsync<K, V> getListMultimapCache(String name, Codec codec) {
|
||
|
return new RedissonListMultimapCache<K, V>(evictionScheduler, codec, executorService, name);
|
||
|
}
|
||
|
|
||
7 years ago
|
protected void enableRedissonReferenceSupport(Redisson redisson) {
|
||
|
this.executorService.enableRedissonReferenceSupport(redisson);
|
||
|
}
|
||
7 years ago
|
|
||
|
}
|