當前位置: 首頁>>代碼示例>>Java>>正文


Java KeeperException.code方法代碼示例

本文整理匯總了Java中org.apache.zookeeper.KeeperException.code方法的典型用法代碼示例。如果您正苦於以下問題:Java KeeperException.code方法的具體用法?Java KeeperException.code怎麽用?Java KeeperException.code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.zookeeper.KeeperException的用法示例。


在下文中一共展示了KeeperException.code方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getActiveData

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
 * get data set by the active leader
 * 
 * @return data set by the active instance
 * @throws ActiveNotFoundException
 *           when there is no active leader
 * @throws KeeperException
 *           other zookeeper operation errors
 * @throws InterruptedException
 * @throws IOException
 *           when ZooKeeper connection could not be established
 */
public synchronized byte[] getActiveData() throws ActiveNotFoundException,
    KeeperException, InterruptedException, IOException {
  try {
    if (zkClient == null) {
      createConnection();
    }
    Stat stat = new Stat();
    return getDataWithRetries(zkLockFilePath, false, stat);
  } catch(KeeperException e) {
    Code code = e.code();
    if (isNodeDoesNotExist(code)) {
      // handle the commonly expected cases that make sense for us
      throw new ActiveNotFoundException();
    } else {
      throw e;
    }
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:31,代碼來源:ActiveStandbyElector.java

示例2: grabTicket

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
static boolean grabTicket(ZooKeeper zookeeper, String lockNode,
                          String ticket) throws InterruptedException, KeeperException {
    try {
        zookeeper.create(lockNode + "/" + ticket, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE,
            CreateMode.EPHEMERAL);
    } catch (KeeperException e) {
        if (e.code() == KeeperException.Code.NODEEXISTS) {
            logger.debug("Failed to claim ticket {}.", ticket);
            return false;
        } else {
            throw e;
        }
    }
    logger.debug("Claimed ticket {}.", ticket);
    return true;
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:17,代碼來源:ResourceClaim.java

示例3: multi

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
 * Run multiple operations in a transactional manner. Retry before throwing exception
 */
public List<OpResult> multi(Iterable<Op> ops)
throws KeeperException, InterruptedException {
  TraceScope traceScope = null;
  try {
    traceScope = Trace.startSpan("RecoverableZookeeper.multi");
    RetryCounter retryCounter = retryCounterFactory.create();
    Iterable<Op> multiOps = prepareZKMulti(ops);
    while (true) {
      try {
        return checkZk().multi(multiOps);
      } catch (KeeperException e) {
        switch (e.code()) {
          case CONNECTIONLOSS:
          case SESSIONEXPIRED:
          case OPERATIONTIMEOUT:
            retryOrThrow(retryCounter, e, "multi");
            break;

          default:
            throw e;
        }
      }
      retryCounter.sleepUntilNextRetry();
  }
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:32,代碼來源:RecoverableZooKeeper.java

示例4: getData

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
 * getData is an idempotent operation. Retry before throwing exception
 * @return Data
 */
public byte[] getData(String path, Watcher watcher, Stat stat)
throws KeeperException, InterruptedException {
  TraceScope traceScope = null;
  try {
    traceScope = Trace.startSpan("RecoverableZookeeper.getData");
    RetryCounter retryCounter = retryCounterFactory.create();
    while (true) {
      try {
        byte[] revData = checkZk().getData(path, watcher, stat);
        return this.removeMetaData(revData);
      } catch (KeeperException e) {
        switch (e.code()) {
          case CONNECTIONLOSS:
          case SESSIONEXPIRED:
          case OPERATIONTIMEOUT:
            retryOrThrow(retryCounter, e, "getData");
            break;

          default:
            throw e;
        }
      }
      retryCounter.sleepUntilNextRetry();
    }
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:33,代碼來源:RecoverableZooKeeper.java

示例5: getChildren

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
 * getChildren is an idempotent operation. Retry before throwing exception
 * @return List of children znodes
 */
public List<String> getChildren(String path, boolean watch)
throws KeeperException, InterruptedException {
  TraceScope traceScope = null;
  try {
    traceScope = Trace.startSpan("RecoverableZookeeper.getChildren");
    RetryCounter retryCounter = retryCounterFactory.create();
    while (true) {
      try {
        return checkZk().getChildren(path, watch);
      } catch (KeeperException e) {
        switch (e.code()) {
          case CONNECTIONLOSS:
          case SESSIONEXPIRED:
          case OPERATIONTIMEOUT:
            retryOrThrow(retryCounter, e, "getChildren");
            break;

          default:
            throw e;
        }
      }
      retryCounter.sleepUntilNextRetry();
    }
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:32,代碼來源:RecoverableZooKeeper.java

示例6: createIfNotThere

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
static void createIfNotThere(ZooKeeper zookeeper, String znode) throws KeeperException,
                                                                InterruptedException {
    try {
        create(zookeeper, znode);
    } catch (KeeperException e) {
        if (e.code() != KeeperException.Code.NODEEXISTS) {
            throw e;
        }
    }
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:11,代碼來源:ZooKeeperHelper.java

示例7: releaseTicket

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
static void releaseTicket(ZooKeeper zookeeper, String lockNode,
                          String ticket) throws KeeperException, InterruptedException {

    logger.debug("Releasing ticket {}.", ticket);
    try {
        zookeeper.delete(lockNode + "/" + ticket, -1);
    } catch (KeeperException e) {
        if (e.code() != KeeperException.Code.NONODE) {
            // If it the node is already gone, than that is fine, otherwise:
            throw e;
        }
    }
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:14,代碼來源:ResourceClaim.java

示例8: checkException

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
private static ZkException checkException(String defaultMessage, Throwable e) {
    if (e instanceof KeeperException) {
        KeeperException zkException = (KeeperException) e;

        if (zkException.code() == KeeperException.Code.NONODE) {
            return new NotExitException(defaultMessage, e);
        }

        if (zkException.code() == KeeperException.Code.BADVERSION) {
            return new BadVersion(e);
        }
    }

    return new ZkException(defaultMessage, e);
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:16,代碼來源:ZKClient.java

示例9: createSequential

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
private String createSequential(String path, byte[] data,
    List<ACL> acl, CreateMode createMode)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  boolean first = true;
  String newPath = path+this.identifier;
  while (true) {
    try {
      if (!first) {
        // Check if we succeeded on a previous attempt
        String previousResult = findPreviousSequentialNode(newPath);
        if (previousResult != null) {
          return previousResult;
        }
      }
      first = false;
      return checkZk().create(newPath, data, acl, createMode);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "create");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:33,代碼來源:RecoverableZooKeeper.java

示例10: create

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
public static ZkException create(KeeperException e) {
    switch (e.code()) {
    // case DATAINCONSISTENCY:
    // return new DataInconsistencyException();
    // case CONNECTIONLOSS:
    // return new ConnectionLossException();
    case NONODE:
        return new ZkNoNodeException(e);
        // case NOAUTH:
        // return new ZkNoAuthException();
    case BADVERSION:
        return new ZkBadVersionException(e);
        // case NOCHILDRENFOREPHEMERALS:
        // return new NoChildrenForEphemeralsException();
    case NODEEXISTS:
        return new ZkNodeExistsException(e);
        // case INVALIDACL:
        // return new ZkInvalidACLException();
        // case AUTHFAILED:
        // return new AuthFailedException();
        // case NOTEMPTY:
        // return new NotEmptyException();
        // case SESSIONEXPIRED:
        // return new SessionExpiredException();
        // case INVALIDCALLBACK:
        // return new InvalidCallbackException();

    default:
        return new ZkException(e);
    }
}
 
開發者ID:tiglabs,項目名稱:jsf-core,代碼行數:32,代碼來源:ZkException.java

示例11: getAcl

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
 * getAcl is an idempotent operation. Retry before throwing exception
 * @return list of ACLs
 */
public List<ACL> getAcl(String path, Stat stat)
throws KeeperException, InterruptedException {
  TraceScope traceScope = null;
  try {
    traceScope = Trace.startSpan("RecoverableZookeeper.getAcl");
    RetryCounter retryCounter = retryCounterFactory.create();
    while (true) {
      try {
        return checkZk().getACL(path, stat);
      } catch (KeeperException e) {
        switch (e.code()) {
          case CONNECTIONLOSS:
          case SESSIONEXPIRED:
          case OPERATIONTIMEOUT:
            retryOrThrow(retryCounter, e, "getAcl");
            break;

          default:
            throw e;
        }
      }
      retryCounter.sleepUntilNextRetry();
    }
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:32,代碼來源:RecoverableZooKeeper.java

示例12: delete

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
 * delete is an idempotent operation. Retry before throwing exception.
 * This function will not throw NoNodeException if the path does not
 * exist.
 */
public void delete(String path, int version)
throws InterruptedException, KeeperException {
  TraceScope traceScope = null;
  try {
    traceScope = Trace.startSpan("RecoverableZookeeper.delete");
    RetryCounter retryCounter = retryCounterFactory.create();
    boolean isRetry = false; // False for first attempt, true for all retries.
    while (true) {
      try {
        checkZk().delete(path, version);
        return;
      } catch (KeeperException e) {
        switch (e.code()) {
          case NONODE:
            if (isRetry) {
              LOG.debug("Node " + path + " already deleted. Assuming a " +
                  "previous attempt succeeded.");
              return;
            }
            LOG.debug("Node " + path + " already deleted, retry=" + isRetry);
            throw e;

          case CONNECTIONLOSS:
          case SESSIONEXPIRED:
          case OPERATIONTIMEOUT:
            retryOrThrow(retryCounter, e, "delete");
            break;

          default:
            throw e;
        }
      }
      retryCounter.sleepUntilNextRetry();
      isRetry = true;
    }
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:45,代碼來源:RecoverableZooKeeper.java

示例13: setAcl

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
/**
 * setAcl is an idempotent operation. Retry before throwing exception
 * @return list of ACLs
 */
public Stat setAcl(String path, List<ACL> acls, int version)
throws KeeperException, InterruptedException {
  TraceScope traceScope = null;
  try {
    traceScope = Trace.startSpan("RecoverableZookeeper.setAcl");
    RetryCounter retryCounter = retryCounterFactory.create();
    while (true) {
      try {
        return checkZk().setACL(path, acls, version);
      } catch (KeeperException e) {
        switch (e.code()) {
          case CONNECTIONLOSS:
          case SESSIONEXPIRED:
          case OPERATIONTIMEOUT:
            retryOrThrow(retryCounter, e, "setAcl");
            break;

          default:
            throw e;
        }
      }
      retryCounter.sleepUntilNextRetry();
    }
  } finally {
    if (traceScope != null) traceScope.close();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:32,代碼來源:RecoverableZooKeeper.java

示例14: toResponse

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
public Response toResponse(KeeperException e) {
    Response.Status status;
    String message;

    String path = e.getPath();

    switch(e.code()) {
    case AUTHFAILED:
        status = Response.Status.UNAUTHORIZED;
        message = path + " not authorized";
        break;
    case BADARGUMENTS:
        status = Response.Status.BAD_REQUEST;
        message = path + " bad arguments";
        break;
    case BADVERSION:
        status = Response.Status.PRECONDITION_FAILED;
        message = path + " bad version";
        break;
    case INVALIDACL:
        status = Response.Status.BAD_REQUEST;
        message = path + " invalid acl";
        break;
    case NODEEXISTS:
        status = Response.Status.CONFLICT;
        message = path + " already exists";
        break;
    case NONODE:
        status = Response.Status.NOT_FOUND;
        message = path + " not found";
        break;
    case NOTEMPTY:
        status = Response.Status.CONFLICT;
        message = path + " not empty";
        break;
    default:
        status = Response.Status.fromStatusCode(502); // bad gateway
        message = "Error processing request for " + path
            + " : " + e.getMessage();
    }

    return Response.status(status).entity(
            new ZError(ui.getRequestUri().toString(), message)).build();
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:45,代碼來源:KeeperExceptionMapper.java

示例15: claimResource

import org.apache.zookeeper.KeeperException; //導入方法依賴的package包/類
int claimResource(ZooKeeper zookeeper, String poolNode, int poolSize) throws KeeperException,
                                                                      InterruptedException {

    logger.debug("Trying to claim a resource.");
    List<String> claimedResources = zookeeper.getChildren(poolNode, false);
    if (claimedResources.size() >= poolSize) {
        logger.debug("No resources available at the moment (pool size: {}), waiting.",
            poolSize);
        final CountDownLatch latch = new CountDownLatch(1);
        zookeeper.getChildren(poolNode, event -> latch.countDown());
        latch.await();
        return claimResource(zookeeper, poolNode, poolSize);
    }

    for (int i = 0; i < poolSize; i++) {
        String resourcePath = Integer.toString(i);
        if (!claimedResources.contains(resourcePath)) {
            String node;
            try {
                logger.debug("Trying to claim seemingly available resource {}.", resourcePath);
                node = zookeeper.create(poolNode + "/" + resourcePath, new byte[0],
                    ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL);
            } catch (KeeperException e) {
                if (e.code() == KeeperException.Code.NODEEXISTS) {
                    continue;
                } else {
                    throw e;
                }
            }

            zookeeper.exists(node, event -> {
                if (event.getType() == EventType.NodeDeleted) {
                    logger.debug("Resource-claim node unexpectedly deleted ({})", resource);
                    close(true);
                }
            });

            logger.debug("Successfully claimed resource {}.", resourcePath);
            return i;
        }
    }

    return claimResource(zookeeper, poolNode, poolSize);
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:45,代碼來源:ResourceClaim.java


注:本文中的org.apache.zookeeper.KeeperException.code方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。