use of com.qlangtech.tis.cloud.AdapterTisCoordinator in project tis by qlangtech.
the class SysInitializeAction method getCoordinator.
private static ITISCoordinator getCoordinator(ZooKeeper zooKeeper) throws Exception {
ITISCoordinator coordinator = null;
coordinator = new AdapterTisCoordinator() {
@Override
public List<String> getChildren(String zkPath, Watcher watcher, boolean b) {
try {
return zooKeeper.getChildren(zkPath, watcher);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public boolean exists(String path, boolean watch) {
try {
return zooKeeper.exists(path, watch) != null;
} catch (Exception e) {
throw new RuntimeException(path, e);
}
}
@Override
public void create(String path, byte[] data, boolean persistent, boolean sequential) {
CreateMode createMode = null;
if (persistent) {
createMode = sequential ? CreateMode.PERSISTENT_SEQUENTIAL : CreateMode.PERSISTENT;
} else {
createMode = sequential ? CreateMode.EPHEMERAL_SEQUENTIAL : CreateMode.EPHEMERAL;
}
try {
zooKeeper.create(path, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode);
} catch (Exception e) {
throw new RuntimeException("path:" + path, e);
}
}
@Override
public byte[] getData(String zkPath, Watcher o, Stat stat, boolean b) {
try {
return zooKeeper.getData(zkPath, o, stat);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
return coordinator;
}
use of com.qlangtech.tis.cloud.AdapterTisCoordinator in project tis by qlangtech.
the class DataXJobConsumer method getCoordinator.
private static ITISCoordinator getCoordinator(String zkAddress, CuratorFramework curatorClient) throws Exception {
ITISCoordinator coordinator = null;
final ZooKeeper zooKeeper = curatorClient.getZookeeperClient().getZooKeeper();
coordinator = new AdapterTisCoordinator() {
@Override
public List<String> getChildren(String zkPath, Watcher watcher, boolean b) {
try {
return zooKeeper.getChildren(zkPath, watcher);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
public boolean exists(String path, boolean watch) {
try {
Stat exists = zooKeeper.exists(path, false);
return exists != null;
} catch (Exception e) {
throw new RuntimeException("path:" + path, e);
}
}
@Override
public void create(String path, byte[] data, boolean persistent, boolean sequential) {
CreateMode createMode = null;
if (persistent) {
createMode = sequential ? CreateMode.PERSISTENT_SEQUENTIAL : CreateMode.PERSISTENT;
} else {
createMode = sequential ? CreateMode.EPHEMERAL_SEQUENTIAL : CreateMode.EPHEMERAL;
}
try {
zooKeeper.create(path, data, ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode);
} catch (Exception e) {
throw new RuntimeException("path:" + path, e);
}
}
@Override
public byte[] getData(String zkPath, Watcher o, Stat stat, boolean b) {
try {
return zooKeeper.getData(zkPath, o, stat);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
logger.info("create TIS new zookeeper instance with ,system zkHost:{}", Config.getZKHost());
// }
return coordinator;
}
Aggregations