use of com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator in project LinkAgent by shulieTech.
the class JedisSentinelFactory method createMediator.
@Override
public RedisClientMediator createMediator(Object obj, ShadowRedisConfig shadowConfig) {
model.cachePressureNode(shadowConfig);
RedisClientMediator mediator = null;
if (Jedis.class.isAssignableFrom(obj.getClass())) {
Object datasource = Reflect.on(obj).get("dataSource");
if (datasource != null && JedisSentinelPool.class.isAssignableFrom(datasource.getClass())) {
JedisSentinelPool pressureJedisPool = null;
String masterName = shadowConfig.getMaster();
Set nodes = new HashSet(shadowConfig.getNodeNums());
String password = shadowConfig.getPassword();
GenericObjectPoolConfig poolConfig = Reflect.on(datasource).get("poolConfig");
password = StringUtil.isEmpty(password) ? null : password;
int database = shadowConfig.getDatabase() == null ? 0 : shadowConfig.getDatabase();
pressureJedisPool = new JedisSentinelPool(masterName, nodes, poolConfig, 2000, password, database);
/* else if (StringUtil.isEmpty(password)) {
pressureJedisPool = new JedisSentinelPool(masterName, nodes, poolConfig);
} else {
pressureJedisPool = new JedisSentinelPool(masterName, nodes, poolConfig, password);
}*/
mediator = new RedisClientMediator<JedisSentinelPool>(pressureJedisPool, (JedisSentinelPool) datasource, true);
}
}
return mediator;
}
use of com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator in project LinkAgent by shulieTech.
the class LettuceFactory method dynamic.
public Object dynamic(Object object) {
Object o = connectionMap.get(object);
if (o != null) {
return o;
}
Object target = manager.removeField(object, LettuceConstants.DYNAMIC_FIELD_LETTUCE_TARGET);
String method = manager.removeField(object, LettuceConstants.DYNAMIC_FIELD_LETTUCE_METHOD);
Object[] args = manager.removeField(object, LettuceConstants.DYNAMIC_FIELD_LETTUCE_ARGS);
Object result = manager.removeField(object, LettuceConstants.DYNAMIC_FIELD_LETTUCE_RESULT);
RedisClientMediator mediator = (RedisClientMediator) getClient(target, method, args, result);
Object performanceRedisClient = mediator.getPerformanceRedisClient();
connectionMap.put(target, performanceRedisClient);
return performanceRedisClient;
}
use of com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator in project LinkAgent by shulieTech.
the class RedissonFactory method createMediator.
@Override
protected RedisClientMediator createMediator(Object obj, ShadowRedisConfig shadowRedisConfig) {
try {
Config oldConfig = null;
Config newConfig = null;
Object client = null;
Object shadowClient = null;
if (RedissonClient.class.isAssignableFrom(obj.getClass())) {
client = (RedissonClient) obj;
oldConfig = ((RedissonClient) client).getConfig();
newConfig = generate(oldConfig, shadowRedisConfig);
shadowClient = Redisson.create(newConfig);
} else if (RedissonReactiveClient.class.isAssignableFrom(obj.getClass())) {
client = (RedissonReactiveClient) obj;
oldConfig = ((RedissonReactiveClient) client).getConfig();
newConfig = generate(oldConfig, shadowRedisConfig);
shadowClient = Redisson.createReactive(newConfig);
}
RedisClientMediator mediator = new RedisClientMediator(obj, shadowClient);
putMediator(obj, mediator);
return mediator;
} catch (Throwable e) {
logger.error(Throwables.getStackTraceAsString(e));
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.RedisServer).setDetail("build redisson shadow db error.").setMessage(Throwables.getStackTraceAsString(e)).report();
}
return null;
}
use of com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator in project LinkAgent by shulieTech.
the class RedissonFactory method clean.
@Override
public void clean(ShadowRedisConfig config) {
Map<Object, RedisClientMediator<?>> mediators = getMediators();
String master = config.getMaster();
List<String> nodes = config.getNodes().contains(",") ? Arrays.asList(StringUtils.split(config.getNodes(), ",")) : Arrays.asList(config.getNodes());
nodes = new ArrayList<String>(nodes);
if (StringUtils.isNotBlank(master)) {
nodes.add(master);
}
if (mediators == null) {
return;
}
for (Map.Entry entry : mediators.entrySet()) {
RedisClientMediator value = (RedisClientMediator) entry.getValue();
if (value == null) {
continue;
}
Object performanceClient = value.getPerformanceRedisClient();
if (performanceClient == null) {
continue;
}
List<String> addrs = null;
if (performanceClient instanceof RedissonClient) {
RedissonClient client = (RedissonClient) performanceClient;
addrs = getAddr(client.getConfig());
if (equals(nodes, addrs)) {
remove(entry.getKey());
if (!client.isShutdown() && !client.isShuttingDown()) {
client.shutdown();
}
break;
}
} else if (performanceClient instanceof RedissonReactiveClient) {
RedissonReactiveClient client = (RedissonReactiveClient) performanceClient;
addrs = getAddr(client.getConfig());
if (equals(nodes, addrs)) {
remove(entry.getKey());
if (!client.isShutdown() && !client.isShuttingDown()) {
client.shutdown();
}
break;
}
} else {
logger.error("unsupported redisson client ,disable all registerd shadow server..");
// clear();
}
}
}
use of com.pamirs.attach.plugin.common.datasource.redisserver.RedisClientMediator in project LinkAgent by shulieTech.
the class LettuceFactory method createMediator.
@Override
public RedisClientMediator<AbstractRedisClient> createMediator(Object obj, ShadowRedisConfig shadowRedisConfig) {
AbstractRedisClient client = (AbstractRedisClient) obj;
RedisClientMediator<AbstractRedisClient> mediator = null;
try {
if (client instanceof RedisClusterClient) {
RedisClusterClient redisClient = (RedisClusterClient) client;
Iterable<RedisURI> redisURIS = Reflect.on(redisClient).call("getInitialUris").get();
Iterable<RedisURI> performanceRedisUris = performanceRedisUris(redisURIS, shadowRedisConfig);
// redisURIS需要修改ip:port等信息
RedisClusterClient performanceRedisClient = RedisClusterClient.create(redisClient.getResources(), performanceRedisUris);
mediator = new RedisClientMediator<AbstractRedisClient>(performanceRedisClient, client, true);
} else if (client instanceof RedisClient) {
RedisClient redisClient = (RedisClient) client;
RedisURI redisURI = Reflect.on(redisClient).get("redisURI");
// 单机redisUri,如果控制台配置多个,只取第一个node节点
RedisURI performanceRedisUri = performanceRedisUri(redisURI, shadowRedisConfig.getNodeNums(), 0, shadowRedisConfig.getDatabase(), shadowRedisConfig.getPassword());
RedisClient performanceRedisClient = RedisClient.create(redisClient.getResources(), performanceRedisUri);
mediator = new RedisClientMediator<AbstractRedisClient>(performanceRedisClient, client, true);
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.RedisServer).setErrorCode("redisServer-0001").setMessage("redis server lettuce error!").setDetail(ExceptionUtils.getStackTrace(e)).report();
}
return mediator;
}
Aggregations