Search in sources :

Example 1 with UnhandledErrorListener

use of org.apache.curator.framework.api.UnhandledErrorListener in project jstorm by alibaba.

the class Zookeeper method mkClient.

/**
     * connect ZK, register Watch/unhandle Watch
     * 
     * @return
     */
public CuratorFramework mkClient(Map conf, List<String> servers, Object port, String root, final WatcherCallBack watcher) {
    CuratorFramework fk = Utils.newCurator(conf, servers, port, root);
    fk.getCuratorListenable().addListener(new CuratorListener() {

        @Override
        public void eventReceived(CuratorFramework _fk, CuratorEvent e) throws Exception {
            if (e.getType().equals(CuratorEventType.WATCHED)) {
                WatchedEvent event = e.getWatchedEvent();
                watcher.execute(event.getState(), event.getType(), event.getPath());
            }
        }
    });
    fk.getUnhandledErrorListenable().addListener(new UnhandledErrorListener() {

        @Override
        public void unhandledError(String msg, Throwable error) {
            String errmsg = "Unrecoverable Zookeeper error, halting process: " + msg;
            LOG.error(errmsg, error);
            JStormUtils.halt_process(1, "Unrecoverable Zookeeper error");
        }
    });
    fk.start();
    return fk;
}
Also used : WatchedEvent(org.apache.zookeeper.WatchedEvent) CuratorFramework(org.apache.curator.framework.CuratorFramework) CuratorListener(org.apache.curator.framework.api.CuratorListener) CuratorEvent(org.apache.curator.framework.api.CuratorEvent) UnhandledErrorListener(org.apache.curator.framework.api.UnhandledErrorListener) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 CuratorEvent (org.apache.curator.framework.api.CuratorEvent)1 CuratorListener (org.apache.curator.framework.api.CuratorListener)1 UnhandledErrorListener (org.apache.curator.framework.api.UnhandledErrorListener)1 KeeperException (org.apache.zookeeper.KeeperException)1 WatchedEvent (org.apache.zookeeper.WatchedEvent)1