|
|
package com.yohoufo.user.component;
|
|
|
|
|
|
import com.google.common.cache.Cache;
|
|
|
import com.google.common.cache.CacheBuilder;
|
|
|
import com.yoho.core.cache.LocalCache;
|
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.core.config.ZKConfigWriter;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.concurrent.Callable;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -20,25 +25,32 @@ public class CertPhotoSwitchComponent { |
|
|
@Autowired
|
|
|
private ConfigReader configReader;
|
|
|
|
|
|
@Autowired
|
|
|
private ZKConfigWriter zkConfigWriter;
|
|
|
|
|
|
//缓存
|
|
|
private LocalCache localCache_switch = new LocalCache();
|
|
|
private static final String SWITCH_CACHE_KEY = "certPhotoSwitchCacheKey";
|
|
|
private Cache<String,Boolean> localCache = CacheBuilder.newBuilder().maximumSize(10).expireAfterWrite(2, TimeUnit.MINUTES).build();
|
|
|
private final String SWITCH_CACHE_KEY = "certPhotoSwitchCacheKey";
|
|
|
private final String zkValue = "ufo.order.certPhotoSwitchCacheKey";
|
|
|
private Boolean defaultSwitch = Boolean.TRUE;
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
private void init() {
|
|
|
localCache_switch.init(SWITCH_CACHE_KEY, 1, TimeUnit.MINUTES, (String s, Object o) -> {
|
|
|
logger.info("StoreSellerServiceImpl init certPhotoSwitchCacheKey s = {}, o = {}", s, o);
|
|
|
return configReader.getBoolean("ufo.order.certPhotoSwitchCacheKey",defaultSwitch);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
public boolean getCertPhotoSwitch(){
|
|
|
Object value=localCache_switch.get(SWITCH_CACHE_KEY);
|
|
|
if(null == value) {
|
|
|
try{
|
|
|
return localCache.get(SWITCH_CACHE_KEY, new Callable<Boolean>() {
|
|
|
@Override
|
|
|
public Boolean call() throws Exception {
|
|
|
return configReader.getBoolean(zkValue,defaultSwitch);
|
|
|
}
|
|
|
});
|
|
|
}catch (ExecutionException e){
|
|
|
logger.warn("StoreSellerServiceImpl getCertPhotoSwitch error ", e);
|
|
|
return defaultSwitch;
|
|
|
}
|
|
|
return (Boolean) value;
|
|
|
}
|
|
|
|
|
|
public void writeZkValueToFalse(){
|
|
|
logger.info("StoreSellerServiceImpl writeZkValueToFalse");
|
|
|
zkConfigWriter.setConfig(zkValue,"false");
|
|
|
localCache.invalidate(SWITCH_CACHE_KEY);
|
|
|
}
|
|
|
} |
...
|
...
|
|