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

org.zodiac.autoconfigure.redis.RedisLockAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.redis;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.redis.condition.ConditionalOnRedisEnabled;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.redis.redisson.RedissonClientBuilder;
import org.zodiac.redis.redisson.RedissonInfo;

@SpringBootConfiguration
@ConditionalOnRedisEnabled
@ConditionalOnProperty(value = SystemPropertiesConstants.Zodiac.SPRING_REDIS_LOCK_ENABLED, havingValue = "true")
@ConditionalOnClass(value = {org.redisson.api.RedissonClient.class, org.redisson.spring.data.connection.RedissonConnectionFactory.class})
public class RedisLockAutoConfiguration {

    private final ApplicationContext applicationContext;
    private final RedisCacheCloudProperties redisCacheCloudProperties;

    public RedisLockAutoConfiguration(ApplicationContext applicationContext, RedisCacheCloudProperties redisCacheCloudProperties) {
        this.applicationContext = applicationContext;
        this.redisCacheCloudProperties = redisCacheCloudProperties;
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.redis.lock.RedisLockClient redisLockClient(ObjectProvider redissonClientProvider) {
        org.redisson.api.RedissonClient client = redissonClientProvider.getIfAvailable();
        if (null == client) {
            client= createRedissonClient(redisCacheCloudProperties);
        }
        return new org.zodiac.redis.lock.RedisLockClientImpl(client);
    }

    @Bean
    @ConditionalOnMissingBean
    protected org.zodiac.redis.lock.RedisLockAspect redisLockAspect(org.zodiac.redis.lock.RedisLockClient redisLockClient) {
        return new org.zodiac.redis.lock.RedisLockAspect(redisLockClient);
    }

    private org.redisson.api.RedissonClient createRedissonClient(RedisCacheCloudProperties redisConfigProperties) {
        RedisCacheCloudRedissonProperties redisRedissonConfigProperties = (RedisCacheCloudRedissonProperties)redisConfigProperties;
        RedissonInfo redissonInfo = redisRedissonConfigProperties.getRedisson();
        return new RedissonClientBuilder(redisRedissonConfigProperties.getLock().getClientName(), redissonInfo, applicationContext).build();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy