All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.lontime.shaded.org.redisson.transaction.RedissonTransactionalMapCache Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2013-2021 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.github.lontime.shaded.org.redisson.transaction;

import com.github.lontime.shaded.org.redisson.RedissonMapCache;
import com.github.lontime.shaded.org.redisson.ScanResult;
import com.github.lontime.shaded.org.redisson.api.*;
import com.github.lontime.shaded.org.redisson.api.mapreduce.RMapReduce;
import com.github.lontime.shaded.org.redisson.client.RedisClient;
import com.github.lontime.shaded.org.redisson.client.codec.Codec;
import com.github.lontime.shaded.org.redisson.command.CommandAsyncExecutor;
import com.github.lontime.shaded.org.redisson.transaction.operation.TransactionalOperation;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 
 * @author Nikita Koksharov
 *
 * @param  key type
 * @param  value type
 */
public class RedissonTransactionalMapCache extends RedissonMapCache {

    private final BaseTransactionalMapCache transactionalMap;
    private final AtomicBoolean executed;
    
    public RedissonTransactionalMapCache(CommandAsyncExecutor commandExecutor, String name, 
            List operations, long timeout, AtomicBoolean executed, String transactionId) {
        super(null, commandExecutor, name, null, null, null);
        this.executed = executed;
        RedissonMapCache innerMap = new RedissonMapCache(null, commandExecutor, name, null, null, null);
        this.transactionalMap = new BaseTransactionalMapCache(commandExecutor, timeout, operations, innerMap, transactionId);
    }

    public RedissonTransactionalMapCache(Codec codec, CommandAsyncExecutor commandExecutor, String name,
            List operations, long timeout, AtomicBoolean executed, String transactionId) {
        super(codec, null, commandExecutor, name, null, null, null);
        this.executed = executed;
        RedissonMapCache innerMap = new RedissonMapCache(codec, null, commandExecutor, name, null, null, null);
        this.transactionalMap = new BaseTransactionalMapCache(commandExecutor, timeout, operations, innerMap, transactionId);
    }
    
    @Override
    public RFuture expireAsync(long timeToLive, TimeUnit timeUnit, String param, String... keys) {
        return transactionalMap.expireAsync(timeToLive, timeUnit, param, keys);
    }
    
    @Override
    protected RFuture expireAtAsync(long timestamp, String param, String... keys) {
        return transactionalMap.expireAtAsync(timestamp, param, keys);
    }

    @Override
    public RFuture clearExpireAsync() {
        return transactionalMap.clearExpireAsync();
    }
    
    @Override
    public RFuture moveAsync(int database) {
        throw new UnsupportedOperationException("moveAsync method is not supported in transaction");
    }
    
    @Override
    public RFuture migrateAsync(String host, int port, int database, long timeout) {
        throw new UnsupportedOperationException("migrateAsync method is not supported in transaction");
    }

    @Override
    public RFuture touchAsync() {
        checkState();
        return transactionalMap.touchAsync(commandExecutor);
    }
    
    @Override
    public RFuture isExistsAsync() {
        checkState();
        return transactionalMap.isExistsAsync();
    }
    
    @Override
    public RFuture unlinkAsync() {
        return transactionalMap.unlinkAsync(commandExecutor);
    }
    
    @Override
    public RFuture deleteAsync() {
        checkState();
        return transactionalMap.deleteAsync(commandExecutor);
    }
    
    @Override
    public RFuture putIfAbsentAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) {
        return transactionalMap.putIfAbsentAsync(key, value, ttl, ttlUnit, maxIdleTime, maxIdleUnit);
    }

    @Override
    public RFuture fastPutOperationAsync(K key, V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) {
        return transactionalMap.fastPutOperationAsync(key, value, ttl, ttlUnit, maxIdleTime, maxIdleUnit);
    }
    
    @Override
    public RFuture putOperationAsync(K key, V value, long ttlTimeout, long maxIdleTimeout, long maxIdleDelta, long ttlTimeoutDelta) {
        return transactionalMap.putOperationAsync(key, value, ttlTimeout, maxIdleTimeout, maxIdleDelta, ttlTimeoutDelta);
    }
    
    public RFuture fastPutIfAbsentAsync(final K key, final V value, long ttl, TimeUnit ttlUnit, long maxIdleTime, TimeUnit maxIdleUnit) {
        return transactionalMap.fastPutIfAbsentAsync(key, value, ttl, ttlUnit, maxIdleTime, maxIdleUnit);
    }
    
    @Override
    public RFuture remainTimeToLiveAsync() {
        throw new UnsupportedOperationException("remainTimeToLiveAsync method is not supported in transaction");
    }
    
    @Override
    public RFuture setMaxSizeAsync(int maxSize) {
        throw new UnsupportedOperationException("setMaxSize method is not supported in transaction");
    }
    
    @Override
    public RFuture trySetMaxSizeAsync(int maxSize) {
        throw new UnsupportedOperationException("trySetMaxSize method is not supported in transaction");
    }

    @Override
    public  RMapReduce mapReduce() {
        throw new UnsupportedOperationException("mapReduce method is not supported in transaction");
    }
    
    @Override
    public ScanResult> scanIterator(String name, RedisClient client,
                                                          long startPos, String pattern, int count) {
        checkState();
        return transactionalMap.scanIterator(name, client, startPos, pattern, count);
    }
    
    @Override
    public RFuture containsKeyAsync(Object key) {
        checkState();
        return transactionalMap.containsKeyAsync(key);
    }
    
    @Override
    public RFuture containsValueAsync(Object value) {
        checkState();
        return transactionalMap.containsValueAsync(value);
    }
    
    @Override
    protected RFuture addAndGetOperationAsync(K key, Number value) {
        checkState();
        return transactionalMap.addAndGetOperationAsync(key, value);
    }

    @Override
    protected RFuture fastPutIfExistsOperationAsync(K key, V value) {
        checkState();
        return transactionalMap.fastPutIfExistsOperationAsync(key, value);
    }

    @Override
    protected RFuture putIfExistsOperationAsync(K key, V value) {
        checkState();
        return transactionalMap.putIfExistsOperationAsync(key, value);
    }

    @Override
    protected RFuture putIfAbsentOperationAsync(K key, V value) {
        checkState();
        return transactionalMap.putIfAbsentOperationAsync(key, value);
    }
    
    @Override
    protected RFuture putOperationAsync(K key, V value) {
        checkState();
        return transactionalMap.putOperationAsync(key, value);
    }
    
    @Override
    protected RFuture fastPutIfAbsentOperationAsync(K key, V value) {
        checkState();
        return transactionalMap.fastPutIfAbsentOperationAsync(key, value);
    }
    
    @Override
    protected RFuture fastPutOperationAsync(K key, V value) {
        checkState();
        return transactionalMap.fastPutOperationAsync(key, value);
    }
    
    @Override
    @SuppressWarnings("unchecked")
    protected RFuture fastRemoveOperationAsync(K... keys) {
        checkState();
        return transactionalMap.fastRemoveOperationAsync(keys);
    }
    
    @Override
    public RFuture valueSizeAsync(K key) {
        checkState();
        return transactionalMap.valueSizeAsync(key);
    }
    
    @Override
    public RFuture getOperationAsync(K key) {
        checkState();
        return transactionalMap.getOperationAsync(key);
    }

    @Override
    public RFuture> readAllKeySetAsync() {
        checkState();
        return transactionalMap.readAllKeySetAsync();
    }
    
    @Override
    public RFuture>> readAllEntrySetAsync() {
        checkState();
        return transactionalMap.readAllEntrySetAsync();
    }
    
    @Override
    public RFuture> readAllValuesAsync() {
        checkState();
        return transactionalMap.readAllValuesAsync();
    }
    
    @Override
    public RFuture> readAllMapAsync() {
        checkState();
        return transactionalMap.readAllMapAsync();
    }
    
    @Override
    public RFuture> getAllOperationAsync(Set keys) {
        checkState();
        return transactionalMap.getAllOperationAsync(keys);
    }
    
    @Override
    protected RFuture removeOperationAsync(K key) {
        checkState();
        return transactionalMap.removeOperationAsync(key);
    }
    
    @Override
    protected RFuture removeOperationAsync(Object key, Object value) {
        checkState();
        return transactionalMap.removeOperationAsync(key, value);
    }
    
    @Override
    protected RFuture putAllOperationAsync(Map entries) {
        checkState();
        return transactionalMap.putAllOperationAsync(entries);
    }
    
    @Override
    protected RFuture replaceOperationAsync(K key, V oldValue, V newValue) {
        checkState();
        return transactionalMap.replaceOperationAsync(key, oldValue, newValue);
    }

    @Override
    protected RFuture replaceOperationAsync(K key, V value) {
        checkState();
        return transactionalMap.replaceOperationAsync(key, value);
    }
    
    protected void checkState() {
        if (executed.get()) {
            throw new IllegalStateException("Unable to execute operation. Transaction is in finished state!");
        }
    }
    
    @Override
    public RFuture loadAllAsync(boolean replaceExistingValues, int parallelism) {
        throw new UnsupportedOperationException("loadAll method is not supported in transaction");
    }
    
    @Override
    public RFuture loadAllAsync(Set keys, boolean replaceExistingValues, int parallelism) {
        throw new UnsupportedOperationException("loadAll method is not supported in transaction");
    }
    
    @Override
    public RLock getFairLock(K key) {
        throw new UnsupportedOperationException("getFairLock method is not supported in transaction");
    }
    
    @Override
    public RCountDownLatch getCountDownLatch(K key) {
        throw new UnsupportedOperationException("getCountDownLatch method is not supported in transaction");
    }
    
    @Override
    public RPermitExpirableSemaphore getPermitExpirableSemaphore(K key) {
        throw new UnsupportedOperationException("getPermitExpirableSemaphore method is not supported in transaction");
    }
    
    @Override
    public RSemaphore getSemaphore(K key) {
        throw new UnsupportedOperationException("getSemaphore method is not supported in transaction");
    }
    
    @Override
    public RLock getLock(K key) {
        throw new UnsupportedOperationException("getLock method is not supported in transaction");
    }
    
    @Override
    public RReadWriteLock getReadWriteLock(K key) {
        throw new UnsupportedOperationException("getReadWriteLock method is not supported in transaction");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy