Search in sources :

Example 6 with Reflect

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;
}
Also used : BinaryJedis(redis.clients.jedis.BinaryJedis) Reflect(com.shulie.instrument.simulator.api.reflect.Reflect) Client(redis.clients.jedis.Client)

Example 7 with Reflect

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;
}
Also used : Reflect(com.shulie.instrument.simulator.api.reflect.Reflect) JedisSentinelPool(redis.clients.jedis.JedisSentinelPool)

Aggregations

Reflect (com.shulie.instrument.simulator.api.reflect.Reflect)7 Attachment (com.pamirs.attach.plugin.dynamic.Attachment)2 RedisTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate)2 Set (java.util.Set)2 BinaryJedis (redis.clients.jedis.BinaryJedis)2 Client (redis.clients.jedis.Client)2 AbstractTemplate (com.pamirs.attach.plugin.dynamic.template.AbstractTemplate)1 RedissionSentinelTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissionSentinelTemplate)1 RedissionSingleTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissionSingleTemplate)1 RedissonMasterSlaveTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissonMasterSlaveTemplate)1 RedissonReplicatedTemplate (com.pamirs.attach.plugin.dynamic.template.RedisTemplate.RedissonReplicatedTemplate)1 PradarException (com.pamirs.pradar.exception.PradarException)1 ExecutionCall (com.pamirs.pradar.internal.config.ExecutionCall)1 MatchConfig (com.pamirs.pradar.internal.config.MatchConfig)1 JsonMockStrategy (com.pamirs.pradar.pressurement.mock.JsonMockStrategy)1 ProcessControlException (com.shulie.instrument.simulator.api.ProcessControlException)1 ReflectException (com.shulie.instrument.simulator.api.reflect.ReflectException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1