gpt4 book ai didi

com.alibaba.otter.shared.common.utils.zookeeper.ZkClientx类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 11:22:46 28 4
gpt4 key购买 nike

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

ZkClientx介绍

[英]使用自定义的ZooKeeperx for zk connection
[中]使用自定义的zk连接用ZooKeeperx

代码示例

代码示例来源:origin: com.alibaba.otter/shared.common

public ZkClientx apply(String servers) {
    return new ZkClientx(servers);
  }
});

代码示例来源:origin: com.alibaba.otter/shared.arbitrate

public static void destory() {
  for (ZkClientx zkClient : clients.values()) {
    zkClient.close();
  }
}

代码示例来源:origin: com.alibaba.otter/shared.common

/**
 * Create a persistent Sequential node.
 * 
 * @param path
 * @param data
 * @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown
 * in case the path already exists
 * @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
 * @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
 * @throws ZkException if any ZooKeeper exception occurred
 * @throws RuntimeException if any other exception occurs
 */
public void createPersistent(String path, Object data, boolean createParents) throws ZkInterruptedException,
                                       IllegalArgumentException, ZkException,
                                       RuntimeException {
  try {
    create(path, data, CreateMode.PERSISTENT);
  } catch (ZkNodeExistsException e) {
    if (!createParents) {
      throw e;
    }
  } catch (ZkNoNodeException e) {
    if (!createParents) {
      throw e;
    }
    String parentDir = path.substring(0, path.lastIndexOf('/'));
    createPersistent(parentDir, createParents);
    createPersistent(path, data, createParents);
  }
}

代码示例来源:origin: com.alibaba.otter/shared.common

@Override
  public List<String> call() throws Exception {
    exists(path, true);
    try {
      return getChildren(path, true);
    } catch (ZkNoNodeException e) {
      // ignore, the "exists" watch will listen for the parent node to appear
    }
    return null;
  }
});

代码示例来源:origin: com.alibaba.otter/shared.common

@SuppressWarnings("unchecked")
public <T extends Object> T readData(String path, Stat stat) {
  return (T) readData(path, stat, hasListeners(path));
}

代码示例来源:origin: com.alibaba.otter/shared.common

public boolean exists(final String path) {
  return exists(path, hasListeners(path));
}

代码示例来源:origin: com.alibaba.otter/shared.arbitrate

byte[] bytes = zookeeper.readData(mainStemPath, true);
if (bytes == null) {
  return;
  List<String> currentProcesses = zookeeper.getChildren(path);
  size = ArbitrateConfigUtils.getParallelism(getPipelineId()) - currentProcesses.size();
  if (size > 0) {// 创建一个节点
    nodeData.setNid(ArbitrateConfigUtils.getCurrentNid());
    byte[] nodeBytes = JsonUtils.marshalToByte(nodeData);
    String processPath = zookeeper.create(path + "/", nodeBytes, CreateMode.PERSISTENT_SEQUENTIAL);

代码示例来源:origin: com.alibaba.otter/shared.common

public boolean deleteRecursive(String path) {
  List<String> children;
  try {
    children = getChildren(path, false);
  } catch (ZkNoNodeException e) {
    return true;
  }
  for (String subPath : children) {
    if (!deleteRecursive(path + "/" + subPath)) {
      return false;
    }
  }
  return delete(path);
}

代码示例来源:origin: com.alibaba.otter/shared.common

public <T extends Object> T readData(String path, boolean returnNullIfPathNotExists) {
  T data = null;
  try {
    data = (T) readData(path, null);
  } catch (ZkNoNodeException e) {
    if (!returnNullIfPathNotExists) {
      throw e;
    }
  }
  return data;
}

代码示例来源:origin: com.alibaba.otter/shared.common

/**
 * Create a persistent Sequential node.
 * 
 * @param path
 * @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown
 * in case the path already exists
 * @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
 * @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
 * @throws ZkException if any ZooKeeper exception occurred
 * @throws RuntimeException if any other exception occurs
 */
public String createPersistentSequential(String path, boolean createParents) throws ZkInterruptedException,
                                      IllegalArgumentException, ZkException,
                                      RuntimeException {
  try {
    return create(path, null, CreateMode.PERSISTENT_SEQUENTIAL);
  } catch (ZkNoNodeException e) {
    if (!createParents) {
      throw e;
    }
    String parentDir = path.substring(0, path.lastIndexOf('/'));
    createPersistent(parentDir, createParents);
    return createPersistentSequential(path, createParents);
  }
}

代码示例来源:origin: com.alibaba.otter/shared.common

/**
 * Create an ephemeral node.
 * 
 * @param path
 * @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
 * @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
 * @throws ZkException if any ZooKeeper exception occurred
 * @throws RuntimeException if any other exception occurs
 */
public void createEphemeral(final String path) throws ZkInterruptedException, IllegalArgumentException,
                       ZkException, RuntimeException {
  create(path, null, CreateMode.EPHEMERAL);
}

代码示例来源:origin: com.alibaba.otter/shared.arbitrate

byte[] data = zookeeper.readData(path);
  return JsonUtils.unmarshalFromByte(data, EtlEventData.class);// 反序列化并返回
} catch (ZkNoNodeException e) {
zookeeper.delete(path);
return await(pipelineId);// 出现rollback情况,递归调用重新获取一次,当前的processId可丢弃

代码示例来源:origin: com.alibaba.otter/shared.arbitrate

public NodeMonitor(){
  childListener = new IZkChildListener() {
    public void handleChildChange(String parentPath, List<String> currentChilds) throws Exception {
      if (currentChilds != null) {
        initNodes(currentChilds);
      }
    }
  };
  List<String> childs = zookeeper.subscribeChildChanges(ArbitrateConstants.NODE_NID_ROOT, childListener);
  if (childs == null) {//如果为null,代表系统节点为初始化
    try {
      zookeeper.createPersistent(ArbitrateConstants.NODE_NID_ROOT, true);
    } catch (ZkNodeExistsException e) {
      //ignore 
    }
    childs = zookeeper.getChildren(ArbitrateConstants.NODE_NID_ROOT);
  }
  initNodes(childs);
  // syncNodes();// 开始监视node节点的变化
  MonitorScheduler.register(this);
}

代码示例来源:origin: com.alibaba.otter/shared.arbitrate

/**
 * 释放锁对象
 */
public void unlock() throws KeeperException {
  if (id != null) {
    zookeeper.delete(root + "/" + id);
    id = null;
    idName = null;
  } else {
    // do nothing
  }
}

代码示例来源:origin: com.alibaba.otter/shared.common

/**
 * Counts number of children for the given path.
 * 
 * @param path
 * @return number of children or 0 if path does not exist.
 */
public int countChildren(String path) {
  try {
    return getChildren(path).size();
  } catch (ZkNoNodeException e) {
    return 0;
  }
}

代码示例来源:origin: com.alibaba.otter/shared.common

/**
 * Updates data of an existing znode. The current content of the znode is passed to the {@link DataUpdater} that is
 * passed into this method, which returns the new content. The new content is only written back to ZooKeeper if
 * nobody has modified the given znode in between. If a concurrent change has been detected the new data of the
 * znode is passed to the updater once again until the new contents can be successfully written back to ZooKeeper.
 * 
 * @param <T>
 * @param path The path of the znode.
 * @param updater Updater that creates the new contents.
 */
public <T extends Object> void updateDataSerialized(String path, DataUpdater<T> updater) {
  Stat stat = new Stat();
  boolean retry;
  do {
    retry = false;
    try {
      T oldData = (T) readData(path, stat);
      T newData = updater.update(oldData);
      writeData(path, newData, stat.getVersion());
    } catch (ZkBadVersionException e) {
      retry = true;
    }
  } while (retry);
}

代码示例来源:origin: com.alibaba.otter/shared.common

boolean started = false;
try {
  getEventLock().lockInterruptibly();
  setShutdownTrigger(false);
  _eventThread = new ZkEventThread(_connection.getServers());
  _eventThread.start();
  if (!waitUntilConnected(maxMsToWaitUntilConnected, TimeUnit.MILLISECONDS)) {
    throw new ZkTimeoutException("Unable to connect to zookeeper server within timeout: "
                   + maxMsToWaitUntilConnected);
  throw new IllegalStateException("Not connected with zookeeper server yet. Current state is " + state);
} finally {
  getEventLock().unlock();
    close();

代码示例来源:origin: com.alibaba.otter/shared.arbitrate

String prefix = "x-" + sessionId + "-";
String path = zookeeper.create(root + "/" + prefix, data, CreateMode.EPHEMERAL_SEQUENTIAL);
int index = path.lastIndexOf("/");
id = StringUtils.substring(path, index + 1);
List<String> names = zookeeper.getChildren(root);
if (names.isEmpty()) {
  logger.warn("lock lost with scene:empty list, id[] and node[]", id, idName);
    lastChildId = lastChildName.getName();
    IZkConnection connection = zookeeper.getConnection();

代码示例来源:origin: com.alibaba.otter/shared.common

@Override
  public void run() throws Exception {
    // reinstall watch
    exists(path, true);
    try {
      Object data = readData(path, null, true);
      listener.handleDataChange(path, data);
    } catch (ZkNoNodeException e) {
      listener.handleDataDeleted(path);
    }
  }
});

代码示例来源:origin: com.alibaba.otter/shared.common

public void writeData(String path, Object object) {
  writeData(path, object, -1);
}

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