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

com.github.lontime.extredisson.RedissonInstance Maven / Gradle / Ivy

The newest version!
package com.github.lontime.extredisson;

import com.github.lontime.base.commonj.utils.Holder;
import com.github.lontime.base.logging.GLogger;
import com.github.lontime.extredisson.provider.DefaultProvider;
import com.github.lontime.extredisson.provider.Provider;

/**
 * RedissonInstance.
 * @author lontime
 * @since 1.0
 */
public class RedissonInstance {

    private static Holder globalHolder = new Holder<>();
    private static final Object globalLock = new Object();

    public static Provider get() {
        if (null == globalHolder.get()) {
            synchronized (globalLock) {
                if (null == globalHolder.get()) {
                    globalHolder.set(DefaultProvider.create());
                }
            }
        }
        return globalHolder.get();
    }

    public static Provider set(DefaultProvider custom) {
        synchronized (globalLock) {
            final Provider provider = globalHolder.get();
            if (null != provider) {
                if (provider.equals(custom)) {
                    return provider;
                }
                GLogger.defaults().infov("close {0} now {1}", provider.getName(), custom.getName());
                provider.close();
            }
            globalHolder.set(custom);
        }
        return get();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy