本文整理匯總了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;
}
}
示例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;
}
示例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();
}
示例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);
}
}
示例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;
}
}
示例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);
}