Search in sources :

Example 1 with AdapterTisCoordinator

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;
}
Also used : ITISCoordinator(com.qlangtech.tis.cloud.ITISCoordinator) Stat(org.apache.zookeeper.data.Stat) AdapterTisCoordinator(com.qlangtech.tis.cloud.AdapterTisCoordinator) List(java.util.List) SQLException(java.sql.SQLException) IOException(java.io.IOException) TisException(com.qlangtech.tis.lang.TisException)

Example 2 with AdapterTisCoordinator

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;
}
Also used : Watcher(org.apache.zookeeper.Watcher) ITISCoordinator(com.qlangtech.tis.cloud.ITISCoordinator) ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) CreateMode(org.apache.zookeeper.CreateMode) AdapterTisCoordinator(com.qlangtech.tis.cloud.AdapterTisCoordinator) List(java.util.List)

Aggregations

AdapterTisCoordinator (com.qlangtech.tis.cloud.AdapterTisCoordinator)2 ITISCoordinator (com.qlangtech.tis.cloud.ITISCoordinator)2 List (java.util.List)2 Stat (org.apache.zookeeper.data.Stat)2 TisException (com.qlangtech.tis.lang.TisException)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 CreateMode (org.apache.zookeeper.CreateMode)1 Watcher (org.apache.zookeeper.Watcher)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1