Search in sources :

Example 1 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class ZkWithoutIpCacheSupport method renew.

/**
 * 注意这里,不完全保证一定能拿到最新的
 */
private void renew(Supplier supplier) {
    try {
        if (lock.acquire(10, TimeUnit.MILLISECONDS)) {
            try {
                List<ConsumerApiResult> newList = supplier.get();
                if (newList == null) {
                    throw new PradarException("supplier invoke but not data return!");
                }
                CACHE = group(newList);
                putInZK(newList);
            } finally {
                lock.release();
            }
        } else {
            // 如果没获取到锁,锁一定是被其它节点获取,这里等到能获取到锁的时候,一定是zk上的数据已经更新了
            lock.acquire();
            try {
                List<ConsumerApiResult> newList = getFromZK();
                if (newList == null) {
                    throw new PradarException("get lock but zk not update! this should never happened!");
                }
                CACHE = group(newList);
            } finally {
                lock.release();
            }
        }
    } catch (Exception e) {
        throw new PradarException(e);
    }
}
Also used : PradarException(com.pamirs.pradar.exception.PradarException) ConsumerApiResult(com.pamirs.attach.plugin.rabbitmq.consumer.admin.support.ConsumerApiResult) ZipException(java.util.zip.ZipException) KeeperException(org.apache.zookeeper.KeeperException) PradarException(com.pamirs.pradar.exception.PradarException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Example 2 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class ZkWithIpCacheSupport method getFromZK.

private List<ConsumerApiResult> getFromZK(String connectionLocalIp) {
    try {
        if (zkClient.checkExists().forPath(zkIpPath(connectionLocalIp)) == null) {
            return null;
        }
        byte[] bytes = zkClient.getData().decompressed().forPath(zkIpPath(connectionLocalIp));
        logger.info("[RabbitMQ] get consumers data from zk ip total bytes(uncompressed) : {}", bytes.length);
        String jsonStr = new String(bytes, "UTF-8");
        return JSON.parseArray(jsonStr, ConsumerApiResult.class);
    } catch (KeeperException.NoNodeException e) {
        return null;
    } catch (ZipException e) {
        return null;
    } catch (Exception e) {
        throw new PradarException(e);
    }
}
Also used : PradarException(com.pamirs.pradar.exception.PradarException) ZipException(java.util.zip.ZipException) KeeperException(org.apache.zookeeper.KeeperException) ZipException(java.util.zip.ZipException) KeeperException(org.apache.zookeeper.KeeperException) PradarException(com.pamirs.pradar.exception.PradarException)

Example 3 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class ZkWithoutIpCacheSupport method putInZK.

private void putInZK(List<ConsumerApiResult> consumerApiResults) {
    try {
        String jsonStr = JSON.toJSONString(consumerApiResults);
        byte[] bytes = jsonStr.getBytes("UTF-8");
        logger.info("[RabbitMQ] put consumers data to zk all total bytes(uncompressed) : {}", bytes.length);
        zkClient.setData().forPath(zkDataPath, bytes);
    } catch (Exception e) {
        throw new PradarException(e);
    }
}
Also used : PradarException(com.pamirs.pradar.exception.PradarException) ZipException(java.util.zip.ZipException) KeeperException(org.apache.zookeeper.KeeperException) PradarException(com.pamirs.pradar.exception.PradarException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Example 4 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class ZkWithoutIpCacheSupport method getFromZK.

private List<ConsumerApiResult> getFromZK() {
    try {
        if (zkClient.checkExists().forPath(zkDataPath) == null) {
            return null;
        }
        byte[] bytes = zkClient.getData().decompressed().forPath(zkDataPath);
        logger.info("[RabbitMQ] get consumers data from zk ip total bytes(uncompressed) : {}", bytes.length);
        String jsonStr = new String(bytes, "UTF-8");
        return JSON.parseArray(jsonStr, ConsumerApiResult.class);
    } catch (KeeperException.NoNodeException e) {
        return null;
    } catch (ZipException e) {
        return null;
    } catch (Exception e) {
        throw new PradarException(e);
    }
}
Also used : PradarException(com.pamirs.pradar.exception.PradarException) ZipException(java.util.zip.ZipException) KeeperException(org.apache.zookeeper.KeeperException) ZipException(java.util.zip.ZipException) KeeperException(org.apache.zookeeper.KeeperException) PradarException(com.pamirs.pradar.exception.PradarException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException)

Example 5 with PradarException

use of com.pamirs.pradar.exception.PradarException in project LinkAgent by shulieTech.

the class SpringConsumerDecoratorMetaDataBuilder method tryBuild.

@Override
public ConsumerMetaData tryBuild(ConsumerDetail consumerDetail) {
    Consumer consumer = consumerDetail.getConsumer();
    String consumerTag = consumerDetail.getConsumerTag();
    if (!consumer.getClass().getName().equals("org.springframework.amqp.rabbit.listener.BlockingQueueConsumer$ConsumerDecorator")) {
        return null;
    }
    try {
        return highVersion(consumer, consumerTag);
    } catch (Throwable e) {
        throw new PradarException("spring rabbitmq 版本不支持!", e);
    }
}
Also used : BlockingQueueConsumer(org.springframework.amqp.rabbit.listener.BlockingQueueConsumer) Consumer(com.rabbitmq.client.Consumer) PradarException(com.pamirs.pradar.exception.PradarException)

Aggregations

PradarException (com.pamirs.pradar.exception.PradarException)46 PressureMeasureError (com.pamirs.pradar.exception.PressureMeasureError)34 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)7 ConsumeMessageContext (com.alibaba.rocketmq.client.hook.ConsumeMessageContext)6 MQTraceContext (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceContext)6 ZipException (java.util.zip.ZipException)6 ConsumeMessageContext (org.apache.rocketmq.client.hook.ConsumeMessageContext)6 KeeperException (org.apache.zookeeper.KeeperException)6 MQTraceContext (com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceContext)5 MessageExt (com.alibaba.rocketmq.common.message.MessageExt)4 MQTraceBean (com.pamirs.attach.plugin.alibaba.rocketmq.common.MQTraceBean)4 MQTraceBean (com.pamirs.attach.plugin.apache.rocketmq.common.MQTraceBean)4 InetSocketAddress (java.net.InetSocketAddress)4 MessageExt (org.apache.rocketmq.common.message.MessageExt)4 MQTraceContext (com.pamirs.attach.plugin.pulsar.common.MQTraceContext)3 ConcurrentWeakHashMap (com.shulie.instrument.simulator.message.ConcurrentWeakHashMap)3 List (java.util.List)3 Map (java.util.Map)3 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)3