com.github.lontime.extredisson.NotifyInstance 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.notify.DefaultNotifyProvider;
import com.github.lontime.extredisson.notify.NotifyProvider;
/**
* NotifyInstance.
* @author lontime
* @since 1.0
*/
public class NotifyInstance {
private static Holder globalHolder = new Holder<>();
private static final Object globalLock = new Object();
public static NotifyProvider get() {
if (null == globalHolder.get()) {
synchronized (globalLock) {
if (null == globalHolder.get()) {
globalHolder.set(DefaultNotifyProvider.create());
}
}
}
return globalHolder.get();
}
public static NotifyProvider set(NotifyProvider custom) {
synchronized (globalLock) {
final NotifyProvider 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 globalHolder.get();
}
}