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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations