gpt4 book ai didi

org.apache.twill.zookeeper.ZKClient.create()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-14 02:08:49 27 4
gpt4 key购买 nike

本文整理了Java中org.apache.twill.zookeeper.ZKClient.create()方法的一些代码示例,展示了ZKClient.create()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZKClient.create()方法的具体详情如下:
包路径:org.apache.twill.zookeeper.ZKClient
类名称:ZKClient
方法名:create

ZKClient.create介绍

[英]Creates a path in zookeeper. Same as calling #create(String,byte[],org.apache.zookeeper.CreateMode,boolean).
[中]在zookeeper中创建路径。与调用#create(字符串,字节[],org.apache.zookeeper.CreateMode,布尔值)相同。

代码示例

代码示例来源:origin: apache/twill

@Override
public OperationFuture<String> create(String path, @Nullable byte[] data,
                   CreateMode createMode, boolean createParent, Iterable<ACL> acl) {
 return delegate.create(path, data, createMode, createParent, acl);
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

@Override
public OperationFuture<String> create(String path, @Nullable byte[] data,
                   CreateMode createMode, boolean createParent, Iterable<ACL> acl) {
 return delegate.create(path, data, createMode, createParent, acl);
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

public OperationFuture<String> create(String path, @Nullable byte[] data,
                   CreateMode createMode, boolean createParent, Iterable<ACL> acl) {
 return client.create(path, data, createMode, createParent, acl);
}

代码示例来源:origin: apache/twill

public OperationFuture<String> create(String path, @Nullable byte[] data,
                   CreateMode createMode, boolean createParent, Iterable<ACL> acl) {
 return client.create(path, data, createMode, createParent, acl);
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

/**
 * Private helper method to create a ZK node based on the parameter. The result of the creation is always
 * communicate via the provided {@link FutureCallback}.
 */
private static void createNode(ZKClient zkClient, String path, @Nullable byte[] data,
                CreateMode createMode, boolean createParent,
                Iterable<ACL> acls, FutureCallback<String> callback) {
 Futures.addCallback(zkClient.create(path, data, createMode, createParent, acls),
           callback, Threads.SAME_THREAD_EXECUTOR);
}

代码示例来源:origin: apache/twill

/**
 * Private helper method to create a ZK node based on the parameter. The result of the creation is always
 * communicate via the provided {@link FutureCallback}.
 */
private static void createNode(ZKClient zkClient, String path, @Nullable byte[] data,
                CreateMode createMode, boolean createParent,
                Iterable<ACL> acls, FutureCallback<String> callback) {
 Futures.addCallback(zkClient.create(path, data, createMode, createParent, acls),
           callback, Threads.SAME_THREAD_EXECUTOR);
}

代码示例来源:origin: caskdata/coopr

/**
 * Acts as {@link ZKClient#create(String, byte[], org.apache.zookeeper.CreateMode, boolean)
 * create(path, null, CreateMode.PERSISTENT, true)} if node doesn't exist. Otherwise has no affect.
 * In latter case sets {@code null} in returned future.
 */
public static ListenableFuture<String> ensureExists(final ZKClient zkClient,
                          final String path) {
 final SettableFuture<String> resultFuture = SettableFuture.create();
 OperationFuture<String> createFuture = zkClient.create(path, null, CreateMode.PERSISTENT, true);
 Futures.addCallback(createFuture, new FutureCallback<String>() {
  @Override
  public void onSuccess(String result) {
   resultFuture.set(result);
  }
  @Override
  public void onFailure(Throwable t) {
   if (causedBy(t, KeeperException.NodeExistsException.class)) {
    resultFuture.set(path);
   } else {
    resultFuture.setException(t);
   }
  }
 });
 return resultFuture;
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

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);
}

代码示例来源:origin: caskdata/coopr

public T put(String key, T value) {
 Map<String, T> current = Maps.newHashMap(currentView.get());
 T result = current.put(key, value);
 currentView.set(ImmutableMap.<String, T>builder().putAll(current).build());
 // Note: we do delete and add new node with new data VS createOrSet() to avoid attaching watchers to every node
 String itemNodePath = getItemNodePath(key);
 Futures.getUnchecked(ZKClientExt.delete(zkClient, itemNodePath, true));
 Futures.getUnchecked(zkClient.create(itemNodePath, serializer.serialize(value), CreateMode.PERSISTENT));
 return result;
}

代码示例来源:origin: apache/twill

private OperationFuture<String> doRegister(Discoverable discoverable) {
 byte[] discoverableBytes = DiscoverableAdapter.encode(discoverable);
 return zkClient.create(getNodePath(discoverable), discoverableBytes, CreateMode.EPHEMERAL, true);
}

代码示例来源:origin: org.apache.twill/twill-discovery-core

private OperationFuture<String> doRegister(Discoverable discoverable) {
 byte[] discoverableBytes = DiscoverableAdapter.encode(discoverable);
 return zkClient.create(getNodePath(discoverable), discoverableBytes, CreateMode.EPHEMERAL, true);
}

代码示例来源:origin: org.apache.twill/twill-zookeeper

@Override
public OperationFuture<String> create(String path, @Nullable byte[] data,
                   CreateMode createMode, boolean createParent, Iterable<ACL> acl) {
 return relayPath(delegate.create(getNamespacedPath(path), data, createMode, createParent, acl),
          this.<String>createFuture(path));
}

代码示例来源:origin: caskdata/coopr

private T putInternal(String key, T value) {
 Map<String, T> current = Maps.newHashMap(currentView);
 T result = current.put(key, value);
 currentView = ImmutableMap.<String, T>builder().putAll(current).build();
 String itemNodePath = getItemNodePath(key);
 // Note: we do delete and add new node with new data VS createOrSet() so that cversion of children change (we depend
 //       on it when checking if the current in-memory view is stale)
 Futures.getUnchecked(ZKClientExt.delete(zkClient, itemNodePath, true));
 Futures.getUnchecked(zkClient.create(itemNodePath, serializer.serialize(value), CreateMode.PERSISTENT, true));
 return result;
}

代码示例来源:origin: apache/twill

@Override
public OperationFuture<String> create(String path, @Nullable byte[] data,
                   CreateMode createMode, boolean createParent, Iterable<ACL> acl) {
 return relayPath(delegate.create(getNamespacedPath(path), data, createMode, createParent, acl),
          this.<String>createFuture(path));
}

代码示例来源:origin: org.apache.twill/twill-yarn

@Override
protected void startUp() throws Exception {
 LOG.info("Creating container ZK path: {}{}", zkClient.getConnectString(), path);
 ZKOperations.ignoreError(zkClient.create(path, null, CreateMode.PERSISTENT),
              KeeperException.NodeExistsException.class, null).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}

代码示例来源:origin: apache/twill

@Override
protected void startUp() throws Exception {
 LOG.info("Creating container ZK path: {}{}", zkClient.getConnectString(), path);
 ZKOperations.ignoreError(zkClient.create(path, null, CreateMode.PERSISTENT),
              KeeperException.NodeExistsException.class, null).get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}

代码示例来源:origin: cdapio/cdap

public void init() throws InterruptedException {
 this.watcher = new ZKWatcher();
 try {
  LOG.info("Initializing SharedResourceCache.  Checking for parent znode {}", parentZnode);
  if (zookeeper.exists(parentZnode).get() == null) {
   // may be created in parallel by another instance
   // Also the child nodes are secure even without adding any ACLs to parent node.
   ZKOperations.ignoreError(zookeeper.create(parentZnode, null, CreateMode.PERSISTENT),
                KeeperException.NodeExistsException.class, null).get();
  }
 } catch (ExecutionException ee) {
  // recheck if already created
  throw Throwables.propagate(ee.getCause());
 }
 this.resources = reloadAll();
 listeners.notifyUpdate();
}

代码示例来源:origin: caskdata/coopr

private void initializeCounter(Type type) {
  Stat stat = Futures.getUnchecked(zkClient.exists(type.path));
  if (stat == null) {
   Futures.getUnchecked(zkClient.create(type.path, Longs.toByteArray(startId), CreateMode.PERSISTENT, true));
  }
 }
}

代码示例来源:origin: apache/twill

@Override
protected void doStart() throws Exception {
 LOG.info("Start application master with spec: {}",
  TwillRuntimeSpecificationAdapter.create().toJson(twillRuntimeSpec));
 // initialize the event handler, if it fails, it will fail the application.
 eventHandler.initialize(new BasicEventHandlerContext(twillRuntimeSpec));
 // call event handler started.
 eventHandler.started();
 instanceChangeExecutor = Executors.newSingleThreadExecutor(Threads.createDaemonThreadFactory("instanceChanger"));
 // Creates ZK path for runnable. It's ok if the path already exists.
 // That's for the case when the AM get killed and restarted
 ZKOperations.ignoreError(
  zkClient.create("/" + runId.getId() + "/runnables", null, CreateMode.PERSISTENT),
  KeeperException.NodeExistsException.class, null)
  .get();
 runningContainers.addWatcher(Constants.DISCOVERY_PATH_PREFIX);
 runnableContainerRequests = initContainerRequests();
}

代码示例来源:origin: org.apache.twill/twill-yarn

@Override
protected void doStart() throws Exception {
 LOG.info("Start application master with spec: {}",
  TwillRuntimeSpecificationAdapter.create().toJson(twillRuntimeSpec));
 // initialize the event handler, if it fails, it will fail the application.
 eventHandler.initialize(new BasicEventHandlerContext(twillRuntimeSpec));
 // call event handler started.
 eventHandler.started();
 instanceChangeExecutor = Executors.newSingleThreadExecutor(Threads.createDaemonThreadFactory("instanceChanger"));
 // Creates ZK path for runnable. It's ok if the path already exists.
 // That's for the case when the AM get killed and restarted
 ZKOperations.ignoreError(
  zkClient.create("/" + runId.getId() + "/runnables", null, CreateMode.PERSISTENT),
  KeeperException.NodeExistsException.class, null)
  .get();
 runningContainers.addWatcher(Constants.DISCOVERY_PATH_PREFIX);
 runnableContainerRequests = initContainerRequests();
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com