Search in sources :

Example 6 with ZooKeeperx

use of com.alibaba.otter.shared.common.utils.zookeeper.ZooKeeperx in project otter by alibaba.

the class ArbitrateViewServiceImpl method getCanalCursor.

public PositionEventData getCanalCursor(String destination, short clientId) {
    String path = String.format(CANAL_CURSOR_PATH, destination, String.valueOf(clientId));
    try {
        IZkConnection connection = zookeeper.getConnection();
        // zkclient会将获取stat信息和正常的操作分开,使用原生的zk进行优化
        ZooKeeper orginZk = ((ZooKeeperx) connection).getZookeeper();
        Stat stat = new Stat();
        byte[] bytes = orginZk.getData(path, false, stat);
        PositionEventData eventData = new PositionEventData();
        eventData.setCreateTime(new Date(stat.getCtime()));
        eventData.setModifiedTime(new Date(stat.getMtime()));
        eventData.setPosition(new String(bytes, "UTF-8"));
        return eventData;
    } catch (Exception e) {
        return null;
    }
}
Also used : PositionEventData(com.alibaba.otter.shared.arbitrate.model.PositionEventData) ZooKeeper(org.apache.zookeeper.ZooKeeper) ProcessStat(com.alibaba.otter.shared.common.model.statistics.stage.ProcessStat) Stat(org.apache.zookeeper.data.Stat) StageStat(com.alibaba.otter.shared.common.model.statistics.stage.StageStat) IZkConnection(org.I0Itec.zkclient.IZkConnection) ZooKeeperx(com.alibaba.otter.shared.common.utils.zookeeper.ZooKeeperx) Date(java.util.Date) ArbitrateException(com.alibaba.otter.shared.arbitrate.exception.ArbitrateException) ZkException(org.I0Itec.zkclient.exception.ZkException) KeeperException(org.apache.zookeeper.KeeperException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ZooKeeperx (com.alibaba.otter.shared.common.utils.zookeeper.ZooKeeperx)6 KeeperException (org.apache.zookeeper.KeeperException)6 ZooKeeper (org.apache.zookeeper.ZooKeeper)6 IZkConnection (org.I0Itec.zkclient.IZkConnection)5 Stat (org.apache.zookeeper.data.Stat)5 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)4 ArbitrateException (com.alibaba.otter.shared.arbitrate.exception.ArbitrateException)3 ProcessStat (com.alibaba.otter.shared.common.model.statistics.stage.ProcessStat)3 StageStat (com.alibaba.otter.shared.common.model.statistics.stage.StageStat)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 WatchedEvent (org.apache.zookeeper.WatchedEvent)3 StageComparator (com.alibaba.otter.shared.arbitrate.impl.setl.helper.StageComparator)2 AsyncWatcher (com.alibaba.otter.shared.arbitrate.impl.zookeeper.AsyncWatcher)2 ZkException (org.I0Itec.zkclient.exception.ZkException)2 BaseOtterTest (com.alibaba.otter.shared.arbitrate.BaseOtterTest)1 EtlEventData (com.alibaba.otter.shared.arbitrate.model.EtlEventData)1 PositionEventData (com.alibaba.otter.shared.arbitrate.model.PositionEventData)1 ProcessNodeEventData (com.alibaba.otter.shared.arbitrate.model.ProcessNodeEventData)1 StageType (com.alibaba.otter.shared.common.model.config.enums.StageType)1 ZkClientx (com.alibaba.otter.shared.common.utils.zookeeper.ZkClientx)1