当前位置: 首页>>代码示例>>Java>>正文


Java KeeperException.create方法代码示例

本文整理汇总了Java中org.apache.zookeeper.KeeperException.create方法的典型用法代码示例。如果您正苦于以下问题:Java KeeperException.create方法的具体用法?Java KeeperException.create怎么用?Java KeeperException.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.zookeeper.KeeperException的用法示例。


在下文中一共展示了KeeperException.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: waitForZKConnectionEvent

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
 * Waits for the next event from ZooKeeper to arrive.
 * 
 * @param connectionTimeoutMs zookeeper connection timeout in milliseconds
 * @throws KeeperException if the connection attempt times out. This will
 * be a ZooKeeper ConnectionLoss exception code.
 * @throws IOException if interrupted while connecting to ZooKeeper
 */
private void waitForZKConnectionEvent(int connectionTimeoutMs)
    throws KeeperException, IOException {
  try {
    if (!hasReceivedEvent.await(connectionTimeoutMs, TimeUnit.MILLISECONDS)) {
      LOG.error("Connection timed out: couldn't connect to ZooKeeper in "
          + connectionTimeoutMs + " milliseconds");
      zk.close();
      throw KeeperException.create(Code.CONNECTIONLOSS);
    }
  } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    throw new IOException(
        "Interrupted when connecting to zookeeper server", e);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:ActiveStandbyElector.java

示例2: createAndWatch

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
 * Creates the specified node with the specified data and watches it.
 *
 * <p>Throws an exception if the node already exists.
 *
 * <p>The node created is persistent and open access.
 *
 * <p>Returns the version number of the created node if successful.
 *
 * @param zkw zk reference
 * @param znode path of node to create
 * @param data data of node to create
 * @return version of node created
 * @throws KeeperException if unexpected zookeeper exception
 * @throws KeeperException.NodeExistsException if node already exists
 */
public static int createAndWatch(ZooKeeperWatcher zkw,
    String znode, byte [] data)
throws KeeperException, KeeperException.NodeExistsException {
  try {
    zkw.getRecoverableZooKeeper().create(znode, data, createACL(zkw, znode),
        CreateMode.PERSISTENT);
    Stat stat = zkw.getRecoverableZooKeeper().exists(znode, zkw);
    if (stat == null){
      // Likely a race condition. Someone deleted the znode.
      throw KeeperException.create(KeeperException.Code.SYSTEMERROR,
          "ZK.exists returned null (i.e.: znode does not exist) for znode=" + znode);
    }
   return stat.getVersion();
  } catch (InterruptedException e) {
    zkw.interruptedException(e);
    return -1;
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:35,代码来源:ZKUtil.java

示例3: multi

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
private List<OpResult> multi(ZooKeeper zk, Iterable<Op> ops)
throws KeeperException, InterruptedException {
    if (useAsync) {
        final MultiResult res = new MultiResult();
        zk.multi(ops, new MultiCallback() {
            @Override
            public void processResult(int rc, String path, Object ctx,
                                      List<OpResult> opResults) {
                synchronized (res) {
                    res.rc = rc;
                    res.results = opResults;
                    res.finished = true;
                    res.notifyAll();
                }
            }
        }, null);
        synchronized (res) {
            while (!res.finished) {
                res.wait();
            }
        }
        if (KeeperException.Code.OK.intValue() != res.rc) {
            KeeperException ke = KeeperException.create(KeeperException.Code.get(res.rc));
            throw ke;
        }
        return res.results;
    } else {
        return zk.multi(ops);
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:31,代码来源:MultiTransactionTest.java

示例4: commit

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
private List<OpResult> commit(Transaction txn)
throws KeeperException, InterruptedException {
    if (useAsync) {
        final MultiResult res = new MultiResult();
        txn.commit(new MultiCallback() {
            @Override
            public void processResult(int rc, String path, Object ctx,
                                      List<OpResult> opResults) {
                synchronized (res) {
                    res.rc = rc;
                    res.results = opResults;
                    res.finished = true;
                    res.notifyAll();
                }
            }
        }, null);
        synchronized (res) {
            while (!res.finished) {
                res.wait();
            }
        }
        if (KeeperException.Code.OK.intValue() != res.rc) {
            KeeperException ke = KeeperException.create(KeeperException.Code.get(res.rc));
            throw ke;
        }
        return res.results;
    } else {
        return txn.commit();
    }
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:31,代码来源:MultiTransactionTest.java

示例5: reconfigure

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
 * Reconfigure - add/remove servers. Return the new configuration.
 * @param joiningServers
 *                a comma separated list of servers being added (incremental reconfiguration)
 * @param leavingServers
 *                a comma separated list of servers being removed (incremental reconfiguration)
 * @param newMembers
 *                a comma separated list of new membership (non-incremental reconfiguration)
 * @param fromConfig
 *                version of the current configuration
 *                (optional - causes reconfiguration to throw an exception if configuration is no longer current)
 * @param stat the stat of /zookeeper/config znode will be copied to this
 *             parameter if not null.
 * @return new configuration
 * @throws InterruptedException If the server transaction is interrupted.
 * @throws KeeperException If the server signals an error with a non-zero error code.
 */
public byte[] reconfigure(String joiningServers, String leavingServers,
                          String newMembers, long fromConfig, Stat stat) throws KeeperException, InterruptedException {
    RequestHeader h = new RequestHeader();
    h.setType(ZooDefs.OpCode.reconfig);
    ReconfigRequest request = new ReconfigRequest(joiningServers, leavingServers, newMembers, fromConfig);
    GetDataResponse response = new GetDataResponse();
    ReplyHeader r = cnxn.submitRequest(h, request, response, null);
    if (r.getErr() != 0) {
        throw KeeperException.create(KeeperException.Code.get(r.getErr()), "");
    }
    if (stat != null) {
        DataTree.copyStat(response.getStat(), stat);
    }
    return response.getData();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:33,代码来源:ZooKeeperAdmin.java

示例6: deleteNode

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
 * Deletes an existing unassigned node that is in the specified state for the
 * specified region.
 *
 * <p>If a node does not already exist for this region, a
 * {@link org.apache.zookeeper.KeeperException.NoNodeException} will be thrown.
 *
 * <p>No watcher is set whether this succeeds or not.
 *
 * <p>Returns false if the node was not in the proper state but did exist.
 *
 * <p>This method is used when a region finishes opening/closing.
 * The Master acknowledges completion
 * of the specified regions transition to being closed/opened.
 *
 * @param zkw zk reference
 * @param encodedRegionName region to be deleted from zk
 * @param expectedState state region must be in for delete to complete
 * @param serverName the expected region transition target server name
 * @param expectedVersion of the znode that is to be deleted.
 *        If expectedVersion need not be compared while deleting the znode
 *        pass -1
 * @throws KeeperException if unexpected zookeeper exception
 * @throws KeeperException.NoNodeException if node does not exist
 */
public static boolean deleteNode(ZooKeeperWatcher zkw, String encodedRegionName,
    EventType expectedState, ServerName serverName, int expectedVersion)
throws KeeperException, KeeperException.NoNodeException {
  if (LOG.isTraceEnabled()) {
    LOG.trace(zkw.prefix("Deleting existing unassigned " +
      "node " + encodedRegionName + " in expected state " + expectedState));
  }
  String node = getNodeName(zkw, encodedRegionName);
  zkw.sync(node);
  Stat stat = new Stat();
  byte [] bytes = ZKUtil.getDataNoWatch(zkw, node, stat);
  if (bytes == null) {
    // If it came back null, node does not exist.
    throw KeeperException.create(Code.NONODE);
  }
  RegionTransition rt = getRegionTransition(bytes);
  EventType et = rt.getEventType();
  if (!et.equals(expectedState)) {
    LOG.warn(zkw.prefix("Attempting to delete unassigned node " + encodedRegionName + " in " +
      expectedState + " state but node is in " + et + " state"));
    return false;
  }
  // Verify the server transition happens on is not changed
  if (serverName != null && !rt.getServerName().equals(serverName)) {
    LOG.warn(zkw.prefix("Attempting to delete unassigned node " + encodedRegionName
      + " with target " + serverName + " but node has " + rt.getServerName()));
    return false;
  }
  if (expectedVersion != -1
      && stat.getVersion() != expectedVersion) {
    LOG.warn("The node " + encodedRegionName + " we are trying to delete is not" +
      " the expected one. Got a version mismatch");
    return false;
  }
  if(!ZKUtil.deleteNode(zkw, node, stat.getVersion())) {
    LOG.warn(zkw.prefix("Attempting to delete " +
        "unassigned node " + encodedRegionName + " in " + expectedState +
        " state but after verifying state, we got a version mismatch"));
    return false;
  }
  LOG.debug(zkw.prefix("Deleted unassigned node " +
      encodedRegionName + " in expected state " + expectedState));
  return true;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:70,代码来源:ZKAssign.java


注:本文中的org.apache.zookeeper.KeeperException.create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。