public void decExchangeRef(Exchange exchange) {
String exchangeFullName = exchange.toString();
String refRoot = "/exchange/" + exchangeFullName;
ArrayList<ZNode> refList = allExchangeRefs.get(exchangeFullName);
ZNode refNode = null;
refNode = refList.get(0);
String refPath = refNode.getPath();
try {
refNode.delete();
logger.info("refNode " + refPath + " deleted");
}
catch(CODIException.NoNode e) {
logger.info("refNode " + refPath + " disappeared, ignore it");
}
catch(Exception e) {
logger.error(e.getMessage(), e);
}
refList.remove(0);
try {
if(hasReference(exchange))
return;
logger.info("decExchangeRef(): no reference, check exchange " + exchangeFullName);
ZNode exNode = new ZNode(refRoot);
ZooKeeperInfo.Exchange.Builder builder = ZooKeeperInfo.Exchange.newBuilder();
TextFormat.merge(new String(exNode.getContent()), builder);
String broker = builder.build().getHost();
if(!isExchangeInUse(broker, exchange)) {
logger.info("decExchangeRef(): no other client and pending message, remove exchange");
exNode.delete();
}
}
catch(Exception e) {
logger.error(e.getMessage(), e);
}