Refine search
@Override public void remove(final String key) { try { client.delete().deletingChildrenIfNeeded().forPath(key); //CHECKSTYLE:OFF } catch (final Exception ex) { //CHECKSTYLE:ON RegExceptionHandler.handleException(ex); } }
public void deleteData(String path) throws Exception { if (zookeeperClient.checkExists().forPath(path) != null) { zookeeperClient.delete().deletingChildrenIfNeeded().forPath(path); } }
@Override public void persistEphemeral(final String key, final String value) { try { if (isExisted(key)) { client.delete().deletingChildrenIfNeeded().forPath(key); } client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(key, value.getBytes(Charsets.UTF_8)); // CHECKSTYLE:OFF } catch (final Exception ex) { // CHECKSTYLE:ON CuratorZookeeperExceptionHandler.handleException(ex); } }
/** * Delete path. * * @param path the path * @throws Exception the exception */ public void deletePath(String path) throws Exception { CuratorFramework client = getOrCreateClient(); client.start(); client.delete().deletingChildrenIfNeeded().forPath(path); client.close(); }
private void releaseLock() { try { if (zkClient.getState().equals(CuratorFrameworkState.STARTED)) { // client.setData().forPath(ZOOKEEPER_LOCK_PATH, null); if (zkClient.checkExists().forPath(schedulerId()) != null) { zkClient.delete().guaranteed().deletingChildrenIfNeeded().forPath(schedulerId()); } } } catch (Exception e) { logger.error("error release lock:" + schedulerId()); throw new RuntimeException(e); } }
@Override public void purgeLocks(String lockPathRoot) { lockPathRoot = norm(lockPathRoot); try { curator.delete().guaranteed().deletingChildrenIfNeeded().forPath(lockPathRoot); logger.info("{} purged all locks under {}", client, lockPathRoot); } catch (Exception ex) { throw new IllegalStateException("Error while " + client + " trying to purge " + lockPathRoot, ex); } }
@Override public void leave(Handler<AsyncResult<Void>> resultHandler) { vertx.executeBlocking(future -> { synchronized (ZookeeperClusterManager.this) { if (active) { active = false; try { curator.delete().deletingChildrenIfNeeded().inBackground((client, event) -> { if (event.getType() == CuratorEventType.DELETE) { if (customCuratorCluster) { future.complete(); } else { if (curator.getState() == CuratorFrameworkState.STARTED) { curator.close(); future.complete(); } } } }).forPath(ZK_PATH_CLUSTER_NODE + nodeID); AsyncMapTTLMonitor.getInstance(vertx, this).stop(); } catch (Exception e) { log.error(e); future.fail(e); } } else future.complete(); } }, resultHandler); }
public void deleteWithoutGuaranteed(String path, boolean isDeleteChildren) { try { if (!exist(path)) { return; } DeleteBuilder builder = client.delete(); if (isDeleteChildren) { builder.deletingChildrenIfNeeded().forPath(path); } else { builder.forPath(path); } } catch (Throwable e) { throw checkException(String.format("Fail to delete node of path: %s", path), e); } }
Future<V> delete(String path, V v) { Future<V> future = Future.future(); try { curator.delete().deletingChildrenIfNeeded().inBackground((client, event) -> { if (event.getType() == CuratorEventType.DELETE) { //clean parent node if doesn't have child node. String[] paths = path.split("/"); String parentNodePath = Stream.of(paths).limit(paths.length - 1).reduce((previous, current) -> previous + "/" + current).get(); curator.getChildren().inBackground((childClient, childEvent) -> { if (childEvent.getChildren().size() == 0) { curator.delete().inBackground((deleteClient, deleteEvent) -> { if (deleteEvent.getType() == CuratorEventType.DELETE) vertx.runOnContext(ea -> future.complete(v)); }).forPath(parentNodePath); } else { vertx.runOnContext(ea -> future.complete(v)); } }).forPath(parentNodePath); } }).forPath(path); } catch (Exception ex) { vertx.runOnContext(aVoid -> future.fail(ex)); } return future; } }
/** * 删除节点 递归删除子节点 * * @param path * @param version * @return */ public boolean deleteNode(String path, Integer version) { if (!ObjectUtils.allNotNull(zkClient, path)) { return Boolean.FALSE; } try { Stat stat = exists(path); if (stat != null) { if (version == null) { zkClient.delete().deletingChildrenIfNeeded().forPath(path); } else { zkClient.delete().deletingChildrenIfNeeded().withVersion(version).forPath(path); } } return Boolean.TRUE; } catch (Exception e) { log.error("delete node fail! path: {}, error: {}", path, e); } return Boolean.FALSE; }
public CompletableFuture<Void> deleteTree(final String path) { CompletableFuture<Void> result = new CompletableFuture<>(); try { client.delete() .deletingChildrenIfNeeded() .inBackground(callback(event -> result.complete(null), result::completeExceptionally, path), executor) .forPath(path); } catch (Exception e) { result.completeExceptionally(StoreException.create(StoreException.Type.UNKNOWN, e, path)); } return result; }
} else { try { DeleteBuilder delete = client.delete(); if (guaranteed) { delete.guaranteed(); .deletingChildrenIfNeeded() .inBackground((curatorFramework, curatorEvent) -> callback(context, record, resultHandler, curatorEvent))
@Override public ErrorListenerPathable<Void> inBackground(Object context) { return new ErrorListenerPathableDecorator<>(inner.inBackground(context)); }
@Override public BackgroundPathable<Void> withVersion(int version) { return inner.withVersion(version); } }
public void deleteData(String path) throws Exception { if (zookeeperClient.checkExists().forPath(path) != null) { zookeeperClient.delete().deletingChildrenIfNeeded().forPath(path); } }
@Override public void persistEphemeral(final String key, final String value) { try { if (isExisted(key)) { client.delete().deletingChildrenIfNeeded().forPath(key); } client.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath(key, value.getBytes(Charsets.UTF_8)); //CHECKSTYLE:OFF } catch (final Exception ex) { //CHECKSTYLE:ON RegExceptionHandler.handleException(ex); } }
/** * Delete path. * * @param path the path * @throws Exception the exception */ public void deletePath(String path) throws Exception { CuratorFramework client = getOrCreateClient(); client.start(); client.delete().deletingChildrenIfNeeded().forPath(path); client.close(); }
private void releaseLock() { try { if (zkClient.getState().equals(CuratorFrameworkState.STARTED)) { // client.setData().forPath(ZOOKEEPER_LOCK_PATH, null); if (zkClient.checkExists().forPath(scheduleID) != null) { zkClient.delete().guaranteed().deletingChildrenIfNeeded().forPath(scheduleID); } } } catch (Exception e) { logger.error("error release lock:" + scheduleID); throw new RuntimeException(e); } }
public void deleteRecursive(CuratorFramework zk, String path) throws Exception { String normPath = PathUtils.normalize_path(path); if (existsNode(zk, normPath, false)) { zk.delete().guaranteed().deletingChildrenIfNeeded().forPath(normPath); } }
/** * 删除节点 递归删除子节点 * * @param path * @param version * @return */ public boolean deleteNode(String path, Integer version) { if (!ObjectUtils.allNotNull(zkClient, path)) { return Boolean.FALSE; } try { Stat stat = exists(path); if (stat != null) { if (version == null) { zkClient.delete().deletingChildrenIfNeeded().forPath(path); } else { zkClient.delete().deletingChildrenIfNeeded().withVersion(version).forPath(path); } } return Boolean.TRUE; } catch (Exception e) { log.error("delete node fail! path: {}, error: {}", path, e); } return Boolean.FALSE; }