use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.
the class MetaClientCore method setZK.
private void setZK(ZooKeeperConfig zkConfig) throws IOException, KeeperException {
Lock lock;
ZooKeeperExtended _zk;
lock = acquireLockIfShared(zkConfig);
try {
if (shareZK) {
_zk = zkMap.get(zkConfig);
} else {
_zk = null;
}
if (_zk == null) {
Log.info(String.format("Getting ZooKeeperExtended for %s\n", zkConfig));
zk = ZooKeeperExtended.getZooKeeperWithRetries(zkConfig, sessionTimeout, this, connectAttempts);
Log.info(String.format("Done getting ZooKeeperExtended for %s\n", zkConfig));
if (shareZK) {
zkMap.putIfAbsent(zkConfig, zk);
}
} else {
zk = _zk;
}
} finally {
releaseLockIfShared(lock);
}
}
use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.
the class MetaClientCore method getZooKeeper.
public ZooKeeperExtended getZooKeeper(int getZKMaxAttempts, int getZKSleepUnit) throws KeeperException {
ZooKeeperExtended _zk;
int attemptIndex;
assert getZKMaxAttempts > 0;
assert getZKSleepUnit > 0;
_zk = null;
attemptIndex = 0;
while (_zk == null) {
_zk = _getZooKeeper();
if (_zk == null) {
if (attemptIndex < getZKMaxAttempts - 1) {
ThreadUtil.randomSleep(getZKSleepUnit << attemptIndex);
++attemptIndex;
} else {
Log.warning("getZooKeeper() failed after " + (attemptIndex + 1) + " attempts");
throw new OperationTimeoutException();
}
}
}
return _zk;
}
use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.
the class NodeCreationWatcherTest method main.
/**
* @param args
*/
public static void main(String[] args) {
try {
if (args.length < 2) {
System.out.println("<zkConfig> <path...>");
} else {
ZooKeeperConfig zkConfig;
NodeCreationWatcherTest wTest;
zkConfig = new ZooKeeperConfig(args[0]);
wTest = new NodeCreationWatcherTest(new ZooKeeperExtended(zkConfig, 2 * 60 * 1000, null));
for (int i = 1; i < args.length; i++) {
wTest.addWatch(args[i]);
}
Thread.sleep(60 * 60 * 1000);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.
the class SuspectsZK method writeSuspectsToZK.
public void writeSuspectsToZK(IPAndPort accuser, Set<IPAndPort> suspects) throws IOException, KeeperException {
String basePath;
ZooKeeperExtended _zk;
String path;
basePath = mc.getMetaPaths().getInstanceSuspectsPath();
_zk = mc.getZooKeeper();
path = basePath + "/" + accuser;
if (_zk.exists(path)) {
_zk.setString(path, CollectionUtil.toString(suspects, suspectsDelimiter));
} else {
_zk.createString(path, CollectionUtil.toString(suspects, suspectsDelimiter), CreateMode.EPHEMERAL);
}
}
use of com.ms.silverking.cloud.zookeeper.ZooKeeperExtended in project SilverKing by Morgan-Stanley.
the class SuspectsZK method readAccuserSuspectsFromZK.
/**
* Read accuser->suspects map from zookeeper.
* @return accuser->suspects map
* @throws KeeperException
*/
public SetMultimap<IPAndPort, IPAndPort> readAccuserSuspectsFromZK() throws KeeperException {
String basePath;
List<IPAndPort> accusers;
SetMultimap<IPAndPort, IPAndPort> accuserSuspectsMap;
ZooKeeperExtended _zk;
if (debug) {
Log.warning("in readAccuserSuspectsFromZK()");
}
basePath = mc.getMetaPaths().getInstanceSuspectsPath();
_zk = mc.getZooKeeper();
accusers = IPAndPort.list(_zk.getChildren(basePath));
accuserSuspectsMap = HashMultimap.create();
for (IPAndPort accuser : accusers) {
Set<IPAndPort> suspects;
suspects = _readSuspectsFromZK(_zk, accuser);
if (suspects != null) {
accuserSuspectsMap.putAll(accuser, suspects);
}
}
if (debug) {
Log.warning("accuserSuspectsMap.size()\t", accuserSuspectsMap.size());
Log.warning("out readAccuserSuspectsFromZK()");
}
return accuserSuspectsMap;
}
Aggregations