帆软使用的第三方框架。
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.
 
 

372 lines
12 KiB

/**
* 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 <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) {
return new RedissonList<V>(executorService, name, null);
}
@Override
public <V> RListAsync<V> getList(String name, Codec codec) {
return new RedissonList<V>(codec, executorService, name, null);
}
@Override
public <K, V> RMapAsync<K, V> getMap(String name) {
return new RedissonMap<K, V>(executorService, name, null, null);
}
@Override
public <K, V> RMapAsync<K, V> getMap(String name, Codec codec) {
return new RedissonMap<K, V>(codec, executorService, name, null, null);
}
@Override
public <V> RSetAsync<V> getSet(String name) {
return new RedissonSet<V>(executorService, name, null);
}
@Override
public <V> RSetAsync<V> getSet(String name, Codec codec) {
return new RedissonSet<V>(codec, executorService, name, null);
}
@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) {
return new RedissonQueue<V>(executorService, name, null);
}
@Override
public <V> RQueueAsync<V> getQueue(String name, Codec codec) {
return new RedissonQueue<V>(codec, executorService, name, null);
}
@Override
public <V> RBlockingQueueAsync<V> getBlockingQueue(String name) {
return new RedissonBlockingQueue<V>(executorService, name, null);
}
@Override
public <V> RBlockingQueueAsync<V> getBlockingQueue(String name, Codec codec) {
return new RedissonBlockingQueue<V>(codec, executorService, name, null);
}
@Override
public <V> RBlockingDequeAsync<V> getBlockingDeque(String name) {
return new RedissonBlockingDeque<V>(executorService, name, null);
}
@Override
public <V> RBlockingDequeAsync<V> getBlockingDeque(String name, Codec codec) {
return new RedissonBlockingDeque<V>(codec, executorService, name, null);
}
@Override
public <V> RDequeAsync<V> getDeque(String name) {
return new RedissonDeque<V>(executorService, name, null);
}
@Override
public <V> RDequeAsync<V> getDeque(String name, Codec codec) {
return new RedissonDeque<V>(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 <V> RScoredSortedSetAsync<V> getScoredSortedSet(String name) {
return new RedissonScoredSortedSet<V>(executorService, name, null);
}
@Override
public <V> RScoredSortedSetAsync<V> getScoredSortedSet(String name, Codec codec) {
return new RedissonScoredSortedSet<V>(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 <K, V> RMapCacheAsync<K, V> getMapCache(String name, Codec codec) {
return new RedissonMapCache<K, V>(codec, evictionScheduler, executorService, name, null, null);
}
@Override
public <K, V> RMapCacheAsync<K, V> getMapCache(String name) {
return new RedissonMapCache<K, V>(evictionScheduler, executorService, name, null, null);
}
@Override
public RScriptAsync getScript() {
return new RedissonScript(executorService);
}
@Override
public RKeysAsync getKeys() {
return new RedissonKeys(executorService);
}
@Override
public <V> RSetCacheAsync<V> getSetCache(String name) {
return new RedissonSetCache<V>(evictionScheduler, executorService, name, null);
}
@Override
public <V> RSetCacheAsync<V> getSetCache(String name, Codec codec) {
return new RedissonSetCache<V>(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<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);
}
@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) {
return new RedissonGeo<V>(executorService, name, null);
}
@Override
public <V> RGeoAsync<V> getGeo(String name, Codec codec) {
return new RedissonGeo<V>(codec, executorService, name, null);
}
@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);
}
protected void enableRedissonReferenceSupport(Redisson redisson) {
this.executorService.enableRedissonReferenceSupport(redisson);
}
}