use of com.shulie.instrument.simulator.api.reflect.Reflect in project LinkAgent by shulieTech.
the class JedisNodesStrategy method getDb.
public Integer getDb(Object obj) {
if (!BinaryJedis.class.isAssignableFrom(obj.getClass())) {
return null;
}
try {
Reflect reflect = Reflect.on(obj);
Client client = reflect.get("client");
Reflect clientRef = Reflect.on(client);
return clientRef.get("db");
} catch (Throwable e) {
LOGGER.error("", e);
}
return null;
}
use of com.shulie.instrument.simulator.api.reflect.Reflect in project LinkAgent by shulieTech.
the class JedisSentinelNodesStrategy method match.
@Override
public List<String> match(Object obj) {
List<String> nodes = new ArrayList<String>();
String master = null;
try {
if (Jedis.class.isAssignableFrom(obj.getClass())) {
Object datasource = Reflect.on(obj).get("dataSource");
if (datasource == null || !(datasource instanceof JedisSentinelPool)) {
return Collections.emptyList();
}
HashSet masterListeners = Reflect.on(datasource).get("masterListeners");
if (CollectionUtils.isEmpty(masterListeners)) {
return nodes;
}
// masterListeners是一个内部类(JedisSentinelPool$MasterListener),不能直接访问,用反射访问
Iterator iterator = masterListeners.iterator();
while (iterator.hasNext()) {
Object next = iterator.next();
Reflect t = Reflect.on(next);
master = t.get("masterName");
String host = t.get("host");
String port = String.valueOf(t.get("port"));
nodes.add(host.concat(":").concat(port));
}
}
nodes.add(master);
} catch (Throwable e) {
LOGGER.error("", e);
}
return nodes;
}
Aggregations