claimOrChoose();
return;
}
if (rc != Code.OK.intValue()) {
KeeperException e = ZkUtils.logErrorAndCreateZKException("Could not read ownership for topic: "
+ topic.toStringUtf8(), path, rc);
cb.operationFailed(ctx, new PubSubException.ServiceDownException(e));
return;
}
// successfully did a read
HedwigSocketAddress owner = new HedwigSocketAddress(new String(data));
if (!owner.equals(addr)) {
if (logger.isDebugEnabled()) {
logger.debug("topic: " + topic.toStringUtf8() + " belongs to someone else: " + owner);
}
cb.operationFinished(ctx, owner);
return;
}
logger.info("Discovered stale self-node for topic: " + topic.toStringUtf8() + ", will delete it");
// we must have previously failed and left a
// residual ephemeral node here, so we must
// delete it (clean it up) and then
// re-create/re-acquire the topic.
zk.delete(hubPath, stat.getVersion(), new VoidCallback() {
@Override
public void processResult(int rc, String path, Object ctx) {
if (Code.OK.intValue() == rc || Code.NONODE.intValue() == rc) {
claimOrChoose();
} else {
KeeperException e = ZkUtils.logErrorAndCreateZKException(
"Could not delete self node for topic: " + topic.toStringUtf8(), path, rc);
cb.operationFailed(ctx, new PubSubException.ServiceDownException(e));
}
}
}, ctx);