use of com.pamirs.pradar.internal.config.ShadowRedisConfig in project LinkAgent by shulieTech.
the class LettuceMasterSlaveFactory method create.
private RedisClientMediator<?> create(Advice advice) {
ShadowRedisConfig shadowRedisConfig = serverMatch.getConfig(advice);
if (null == shadowRedisConfig) {
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.RedisServer).setErrorCode("redisServer-0001").setMessage("没有配置影子Redis Server").setDetail("没有配置影子Redis Server").report();
// 抛出相关异常信息
throw new PressureMeasureError("not found redis shadow server config error.");
}
validationConfig(shadowRedisConfig);
RedisClientMediator mediator = createMediator(advice, shadowRedisConfig);
putMediator(advice.getReturnObj(), mediator);
return mediator;
}
use of com.pamirs.pradar.internal.config.ShadowRedisConfig in project LinkAgent by shulieTech.
the class RedisShadowServerConfig method compareIsChangeAndSet.
@Override
public Boolean compareIsChangeAndSet(ApplicationConfig applicationConfig, Map<String, ShadowRedisConfig> newConfig) {
Map<String, ShadowRedisConfig> old = GlobalConfig.getInstance().getShadowRedisConfigs();
if (old.size() == 0 && newConfig.size() == 0) {
return Boolean.FALSE;
} else if (old.size() == 0 && newConfig.size() != 0) {
GlobalConfig.getInstance().setShadowRedisConfigs(newConfig);
applicationConfig.setShadowRedisConfigs(newConfig);
return Boolean.TRUE;
} else if (old.size() != 0 && newConfig.size() == 0) {
GlobalConfig.getInstance().setShadowRedisConfigs(newConfig);
applicationConfig.setShadowRedisConfigs(newConfig);
for (Map.Entry<String, ShadowRedisConfig> entry : old.entrySet()) {
ShadowRedisConfig oldValue = entry.getValue();
ShadowRedisServerDisableEvent event = new ShadowRedisServerDisableEvent(Collections.singletonList(oldValue));
EventRouter.router().publish(event);
}
return Boolean.TRUE;
} else if (old.size() != 0 && newConfig.size() != 0) {
Boolean change = false;
if (old.size() != newConfig.size()) {
change = true;
}
List<ShadowRedisConfig> removeKeys = new ArrayList<ShadowRedisConfig>();
for (Map.Entry entry : old.entrySet()) {
String oldKey = String.valueOf(entry.getKey());
ShadowRedisConfig oldValue = (ShadowRedisConfig) entry.getValue();
if (!newConfig.containsKey(oldKey)) {
change = true;
removeKeys.add(oldValue);
} else if (newConfig.containsKey(oldKey)) {
if (!oldValue.equals(newConfig.get(oldKey))) {
removeKeys.add(oldValue);
change = true;
}
}
}
if (removeKeys.size() > 0) {
EventRouter.router().publish(new ShadowRedisServerDisableEvent(removeKeys));
}
if (change) {
GlobalConfig.getInstance().setShadowRedisConfigs(newConfig);
applicationConfig.setShadowRedisConfigs(newConfig);
return Boolean.TRUE;
}
return Boolean.FALSE;
}
return Boolean.FALSE;
}
Aggregations