use of com.pamirs.attach.plugin.rabbitmq.consumer.admin.support.ConsumerApiResult 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.attach.plugin.rabbitmq.consumer.admin.support.ConsumerApiResult in project LinkAgent by shulieTech.
the class SimpleLocalCacheSupport method computeIfAbsent.
@Override
public ConsumerApiResult computeIfAbsent(CacheKey cacheKey, Supplier supplier) {
if (cache == null) {
synchronized (SimpleLocalCacheSupport.class) {
if (cache == null) {
renew(supplier);
}
}
}
ConsumerApiResult consumerApiResult = cache.get(cacheKey);
if (consumerApiResult == null) {
synchronized (SimpleLocalCacheSupport.class) {
renew(supplier);
consumerApiResult = cache.get(cacheKey);
}
}
return consumerApiResult;
}
use of com.pamirs.attach.plugin.rabbitmq.consumer.admin.support.ConsumerApiResult in project LinkAgent by shulieTech.
the class ZkWithIpCacheSupport method ipGroup.
private Map<String, List<ConsumerApiResult>> ipGroup(List<ConsumerApiResult> consumerApiResults) {
Map<String, List<ConsumerApiResult>> result = new HashMap<String, List<ConsumerApiResult>>();
for (ConsumerApiResult consumerApiResult : consumerApiResults) {
String ip = ((WithCacheKey) cacheKeyBuilder.build(consumerApiResult)).getConnectionLocalIp();
List<ConsumerApiResult> pieces = result.get(ip);
if (pieces == null) {
pieces = new ArrayList<ConsumerApiResult>();
result.put(ip, pieces);
}
pieces.add(consumerApiResult);
}
return result;
}
use of com.pamirs.attach.plugin.rabbitmq.consumer.admin.support.ConsumerApiResult in project LinkAgent by shulieTech.
the class ZkWithIpCacheSupport method renew.
/**
* 注意这里,不完全保证一定能拿到最新的
*/
private void renew(Supplier supplier, String connectionLocalIp) {
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(connectionLocalIp);
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.attach.plugin.rabbitmq.consumer.admin.support.ConsumerApiResult in project LinkAgent by shulieTech.
the class ZkWithIpCacheSupport method computeIfAbsent.
@Override
public ConsumerApiResult computeIfAbsent(CacheKey key, Supplier supplier) {
WithCacheKey cacheKey = (WithCacheKey) key;
if (CACHE == null) {
synchronized (ZkWithIpCacheSupport.class) {
if (CACHE == null) {
List<ConsumerApiResult> consumerApiResults = getFromZK(cacheKey.getConnectionLocalIp());
if (consumerApiResults == null) {
renew(supplier, cacheKey.getConnectionLocalIp());
return CACHE.get(cacheKey);
} else {
CACHE = group(consumerApiResults);
ConsumerApiResult consumerApiResult = CACHE.get(cacheKey);
if (consumerApiResult == null) {
renew(supplier, cacheKey.getConnectionLocalIp());
return CACHE.get(cacheKey);
} else {
return consumerApiResult;
}
}
}
}
}
ConsumerApiResult consumerApiResult = CACHE.get(cacheKey);
if (consumerApiResult == null) {
synchronized (ZkWithIpCacheSupport.class) {
renew(supplier, cacheKey.getConnectionLocalIp());
consumerApiResult = CACHE.get(cacheKey);
}
}
return consumerApiResult;
}
Aggregations