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


Java KeeperException.BadVersionException方法代码示例

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


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

示例1: setDataWithVersion

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
 * CAS更新指定节点数据内容
 * @param path  节点path
 * @param payload  数据内容
 * @param version 版本号
 * @return
 * @throws Exception
 */
@Override
public int setDataWithVersion(String path, byte[] payload, int version) throws Exception {
    try {
        Stat stat = null;
        if (version != -1) {
            stat = client.setData().withVersion(version).forPath(path, payload);
        } else {
            stat = client.setData().forPath(path, payload);
        }
        if (stat != null) {
            //logger.info("CAS设置数据成功,path:" + path );
            return stat.getVersion();
        } else {
            logger.error("CAS设置数据失败,path:" + path);
            return -1;
        }
    } catch (KeeperException.BadVersionException ex) {
        logger.error("CAS设置数据失败,path:" + path);
        return -1;
    }

}
 
开发者ID:BriData,项目名称:DBus,代码行数:31,代码来源:ZkService.java

示例2: checkAndIncVersion

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
private static int checkAndIncVersion(int currentVersion, int expectedVersion, String path)
        throws KeeperException.BadVersionException {
    if (expectedVersion != -1 && expectedVersion != currentVersion) {
        throw new KeeperException.BadVersionException(path);
    }
    return currentVersion + 1;
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:8,代码来源:PrepRequestProcessor.java

示例3: getMessage

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
private static String getMessage(Throwable cause) {
    if (cause instanceof  KeeperException) {
        KeeperException keeperException = (KeeperException) cause;
        if (keeperException instanceof KeeperException.NoNodeException) {
            return "Node does not exist: " + keeperException.getPath();
        } else if (keeperException instanceof KeeperException.NoChildrenForEphemeralsException) {
            return "Ephemerals cannot have children: " + keeperException.getPath();
        } else if (keeperException instanceof KeeperException.NodeExistsException) {
            return "Node already exists: " + keeperException.getPath();
        } else if (keeperException instanceof KeeperException.NotEmptyException) {
            return "Node not empty: " + keeperException.getPath();
        } else if (keeperException instanceof KeeperException.NotReadOnlyException) {
            return "Not a read-only call: " + keeperException.getPath();
        } else if (keeperException instanceof KeeperException.InvalidACLException) {
            return "Acl is not valid : " + keeperException.getPath();
        } else if (keeperException instanceof KeeperException.NoAuthException) {
            return "Authentication is not valid : " + keeperException.getPath();
        } else if (keeperException instanceof KeeperException.BadArgumentsException) {
            return "Arguments are not valid : " + keeperException.getPath();
        } else if (keeperException instanceof KeeperException.BadVersionException) {
            return "version No is not valid : " + keeperException.getPath();
        } else if (keeperException instanceof KeeperException.ReconfigInProgress) {
            return "Another reconfiguration is in progress -- concurrent " +
                    "reconfigs not supported (yet)";
        } else if (keeperException instanceof KeeperException.NewConfigNoQuorum) {
            return "No quorum of new config is connected and " +
                    "up-to-date with the leader of last commmitted config - try invoking reconfiguration after " +
                    "new servers are connected and synced";
        }
    }
    return cause.getMessage();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:33,代码来源:CliWrapperException.java

示例4: pushToZK

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
 * Pushes proposed data to ZooKeeper.  If a different server pushes its data
 * first, it gives up.
 * @param newSecret The new secret to use
 * @param currentSecret The current secret
 * @param previousSecret  The previous secret
 */
private synchronized void pushToZK(byte[] newSecret, byte[] currentSecret,
        byte[] previousSecret) {
  byte[] bytes = generateZKData(newSecret, currentSecret, previousSecret);
  try {
    client.setData().withVersion(zkVersion).forPath(path, bytes);
  } catch (KeeperException.BadVersionException bve) {
    LOG.debug("Unable to push to znode; another server already did it");
  } catch (Exception ex) {
    LOG.error("An unexpected exception occured pushing data to ZooKeeper",
            ex);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:ZKSignerSecretProvider.java

示例5: deleteNode

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
/**
 * Delete the specified node with the specified version.  Sets no watches.
 * Throws all exceptions.
 */
public static boolean deleteNode(ZooKeeperWatcher zkw, String node,
    int version)
throws KeeperException {
  try {
    zkw.getRecoverableZooKeeper().delete(node, version);
    return true;
  } catch(KeeperException.BadVersionException bve) {
    return false;
  } catch(InterruptedException ie) {
    zkw.interruptedException(ie);
    return false;
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:18,代码来源:ZKUtil.java

示例6: testRemoveAddOne

import org.apache.zookeeper.KeeperException; //导入方法依赖的package包/类
@Test
public void testRemoveAddOne() throws Exception {
    qu = new QuorumUtil(1); // create 3 servers
    qu.disableJMXTest = true;
    qu.startAll();
    ZooKeeper[] zkArr = createHandles(qu);
    ZooKeeperAdmin[] zkAdminArr = createAdminHandles(qu);

    List<String> leavingServers = new ArrayList<String>();
    List<String> joiningServers = new ArrayList<String>();

    int leaderIndex = getLeaderId(qu);

    // during first iteration, leavingIndex will correspond to a follower
    // during second iteration leavingIndex will be the index of the leader
    int leavingIndex = (leaderIndex == 1) ? 2 : 1;

    for (int i = 0; i < 2; i++) {
        // some of the operations will be executed by a client connected to
        // the removed server
        // while others are invoked by a client connected to some other
        // server.
        // when we're removing the leader, zk1 will be the client connected
        // to removed server
        ZooKeeper zk1 = (leavingIndex == leaderIndex) ? zkArr[leaderIndex]
                : zkArr[(leaderIndex % qu.ALL) + 1];
        ZooKeeper zk2 = (leavingIndex == leaderIndex) ? zkArr[(leaderIndex % qu.ALL) + 1]
                : zkArr[leaderIndex];
        ZooKeeperAdmin zkAdmin1 = (leavingIndex == leaderIndex) ? zkAdminArr[leaderIndex]
                : zkAdminArr[(leaderIndex % qu.ALL) + 1];
        ZooKeeperAdmin zkAdmin2 = (leavingIndex == leaderIndex) ? zkAdminArr[(leaderIndex % qu.ALL) + 1]
                : zkAdminArr[leaderIndex];

        leavingServers.add(Integer.toString(leavingIndex));

        // remember this server so we can add it back later
        joiningServers.add("server."
                + leavingIndex
                + "=localhost:"
                + qu.getPeer(leavingIndex).peer.getQuorumAddress()
                        .getPort()
                + ":"
                + qu.getPeer(leavingIndex).peer.getElectionAddress()
                        .getPort() + ":participant;localhost:"
                + qu.getPeer(leavingIndex).peer.getClientPort());

        String configStr = reconfig(zkAdmin1, null, leavingServers, null, -1);
        testServerHasConfig(zk2, null, leavingServers);
        testNormalOperation(zk2, zk1);

        QuorumVerifier qv = qu.getPeer(1).peer.configFromString(configStr);
        long version = qv.getVersion();

        // checks that conditioning on version works properly
        try {
            reconfig(zkAdmin2, joiningServers, null, null, version + 1);
            Assert.fail("reconfig succeeded even though version condition was incorrect!");
        } catch (KeeperException.BadVersionException e) {

        }

        reconfig(zkAdmin2, joiningServers, null, null, version);

        testNormalOperation(zk1, zk2);
        testServerHasConfig(zk1, joiningServers, null);

        // second iteration of the loop will remove the leader
        // and add it back (as follower)
        leavingIndex = leaderIndex = getLeaderId(qu);
        leavingServers.clear();
        joiningServers.clear();
    }

    closeAllHandles(zkArr, zkAdminArr);
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:76,代码来源:ReconfigTest.java


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