private void register() { state = State.IN_PROGRESS; zkNodePath = null; // Register for election final String path = String.format("%s/%s-", zkFolderPath, guid); LOG.debug("Registering for election {} with path {}", zkFolderPath, path); OperationFuture<String> createFuture = zkClient.create(path, getNodeData(), CreateMode.EPHEMERAL_SEQUENTIAL, true); Futures.addCallback(createFuture, new FutureCallback<String>() { @Override public void onSuccess(String result) { LOG.debug("Created zk node {}", result); zkNodePath = result; if (state == State.CANCELLED) { // If cancel was called after create(), but before callback trigger, delete the node created. deleteNode(); } else { runElection(); } } @Override public void onFailure(Throwable t) { LOG.error("Got exception during node creation for folder {}", path, t); // The node may created successfully on server and then server crash, // which client might receive failure instead. // Not checking for cancel here, as we don't know the zkNodePath. // Needs to rely on runElection to handle cancel. runElection(); } }, executor); }
private void register() { state = State.IN_PROGRESS; zkNodePath = null; // Register for election final String path = String.format("%s/%s-", zkFolderPath, guid); LOG.debug("Registering for election {} with path {}", zkFolderPath, path); OperationFuture<String> createFuture = zkClient.create(path, getNodeData(), CreateMode.EPHEMERAL_SEQUENTIAL, true); Futures.addCallback(createFuture, new FutureCallback<String>() { @Override public void onSuccess(String result) { LOG.debug("Created zk node {}", result); zkNodePath = result; if (state == State.CANCELLED) { // If cancel was called after create(), but before callback trigger, delete the node created. deleteNode(); } else { runElection(); } } @Override public void onFailure(Throwable t) { LOG.error("Got exception during node creation for folder {}", path, t); // The node may created successfully on server and then server crash, // which client might receive failure instead. // Not checking for cancel here, as we don't know the zkNodePath. // Needs to rely on runElection to handle cancel. runElection(); } }, executor); }