• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ZkInterruptedException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.I0Itec.zkclient.exception.ZkInterruptedException的典型用法代码示例。如果您正苦于以下问题:Java ZkInterruptedException类的具体用法?Java ZkInterruptedException怎么用?Java ZkInterruptedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ZkInterruptedException类属于org.I0Itec.zkclient.exception包,在下文中一共展示了ZkInterruptedException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createPersistentSequential

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
/**
 * Create a persistent Sequential node.
 * 
 * @param path
 * @param data
 * @param createParents if true all parent dirs are created as well and no {@link ZkNodeExistsException} is thrown
 * in case the path already exists
 * @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
 * @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
 * @throws ZkException if any ZooKeeper exception occurred
 * @throws RuntimeException if any other exception occurs
 */
public String createPersistentSequential(String path, Object data, boolean createParents)
                                                                                         throws ZkInterruptedException,
                                                                                         IllegalArgumentException,
                                                                                         ZkException,
                                                                                         RuntimeException {
    try {
        return create(path, data, CreateMode.PERSISTENT_SEQUENTIAL);
    } catch (ZkNoNodeException e) {
        if (!createParents) {
            throw e;
        }
        String parentDir = path.substring(0, path.lastIndexOf('/'));
        createPersistent(parentDir, createParents);
        return createPersistentSequential(path, data, createParents);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:29,代码来源:ZkClientx.java


示例2: create

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
/**
 * Create a node.
 * 
 * @param path
 * @param data
 * @param mode
 * @return create node's path
 * @throws ZkInterruptedException if operation was interrupted, or a required reconnection got interrupted
 * @throws IllegalArgumentException if called from anything except the ZooKeeper event thread
 * @throws ZkException if any ZooKeeper exception occurred
 * @throws RuntimeException if any other exception occurs
 */
public String create(final String path, Object data, final CreateMode mode) throws ZkInterruptedException,
                                                                           IllegalArgumentException, ZkException,
                                                                           RuntimeException {
    if (path == null) {
        throw new NullPointerException("path must not be null.");
    }
    final byte[] bytes = data == null ? null : serialize(data);

    return retryUntilConnected(new Callable<String>() {

        @Override
        public String call() throws Exception {
            return _connection.create(path, bytes, mode);
        }
    });
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:29,代码来源:ZkClientx.java


示例3: waitUntilExists

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
public boolean waitUntilExists(String path, TimeUnit timeUnit, long time) throws ZkInterruptedException {
    Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));
    LOG.debug("Waiting until znode '" + path + "' becomes available.");
    if (exists(path)) {
        return true;
    }
    acquireEventLock();
    try {
        while (!exists(path, true)) {
            boolean gotSignal = getEventLock().getZNodeEventCondition().awaitUntil(timeout);
            if (!gotSignal) {
                return false;
            }
        }
        return true;
    } catch (InterruptedException e) {
        throw new ZkInterruptedException(e);
    } finally {
        getEventLock().unlock();
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:22,代码来源:ZkClientx.java


示例4: waitForKeeperState

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
public boolean waitForKeeperState(KeeperState keeperState, long time, TimeUnit timeUnit)
                                                                                        throws ZkInterruptedException {
    if (_zookeeperEventThread != null && Thread.currentThread() == _zookeeperEventThread) {
        throw new IllegalArgumentException("Must not be done in the zookeeper event thread.");
    }
    Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));

    LOG.debug("Waiting for keeper state " + keeperState);
    acquireEventLock();
    try {
        boolean stillWaiting = true;
        while (_currentState != keeperState) {
            if (!stillWaiting) {
                return false;
            }
            stillWaiting = getEventLock().getStateChangedCondition().awaitUntil(timeout);
        }
        LOG.debug("State is " + _currentState);
        return true;
    } catch (InterruptedException e) {
        throw new ZkInterruptedException(e);
    } finally {
        getEventLock().unlock();
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:26,代码来源:ZkClientx.java


示例5: close

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
/**
 * Close the client.
 * 
 * @throws ZkInterruptedException
 */
public void close() throws ZkInterruptedException {
    if (_connection == null) {
        return;
    }
    LOG.debug("Closing ZkClient...");
    getEventLock().lock();
    try {
        setShutdownTrigger(true);
        _eventThread.interrupt();
        _eventThread.join(2000);
        _connection.close();
        _connection = null;
    } catch (InterruptedException e) {
        throw new ZkInterruptedException(e);
    } finally {
        getEventLock().unlock();
    }
    LOG.debug("Closing ZkClient...done");
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:25,代码来源:ZkClientx.java


示例6: isInterrupt

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
protected boolean isInterrupt(Throwable e) {
    if (!running) {
        return true;
    }

    if (e instanceof InterruptedException || e instanceof ZkInterruptedException) {
        return true;
    }

    if (ExceptionUtils.getRootCause(e) instanceof InterruptedException) {
        return true;
    }

    return false;

}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:17,代码来源:GlobalTask.java


示例7: waitUntilExists

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
public boolean waitUntilExists(String path, TimeUnit timeUnit, long time)
    throws ZkInterruptedException {
  Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));
  LOG.debug("Waiting until znode '" + path + "' becomes available.");
  if (exists(path)) {
    return true;
  }
  acquireEventLock();
  try {
    while (!exists(path, true)) {
      boolean gotSignal = getEventLock().getZNodeEventCondition().awaitUntil(timeout);
      if (!gotSignal) {
        return false;
      }
    }
    return true;
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  } finally {
    getEventLock().unlock();
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:23,代码来源:ZkClient.java


示例8: waitForKeeperState

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
public boolean waitForKeeperState(KeeperState keeperState, long time, TimeUnit timeUnit)
    throws ZkInterruptedException {
  if (_zookeeperEventThread != null && Thread.currentThread() == _zookeeperEventThread) {
    throw new IllegalArgumentException("Must not be done in the zookeeper event thread.");
  }
  Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));

  LOG.debug("Waiting for keeper state " + keeperState);
  acquireEventLock();
  try {
    boolean stillWaiting = true;
    while (_currentState != keeperState) {
      if (!stillWaiting) {
        return false;
      }
      stillWaiting = getEventLock().getStateChangedCondition().awaitUntil(timeout);
    }
    LOG.debug("State is " + _currentState);
    return true;
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  } finally {
    getEventLock().unlock();
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:26,代码来源:ZkClient.java


示例9: createPersistentSequential

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
/**
 * Create a persistent Sequential node.
 * 
 * @param path
 * @param data
 * @param createParents if true all parent dirs are created as well and no
 * {@link ZkNodeExistsException} is thrown in case the path already exists
 * @throws ZkInterruptedException if operation was interrupted, or a
 * required reconnection got interrupted
 * @throws IllegalArgumentException if called from anything except the
 * ZooKeeper event thread
 * @throws ZkException if any ZooKeeper exception occurred
 * @throws RuntimeException if any other exception occurs
 */
public String createPersistentSequential(String path, Object data, boolean createParents)
                                                                                         throws ZkInterruptedException,
                                                                                         IllegalArgumentException,
                                                                                         ZkException,
                                                                                         RuntimeException {
    try {
        return create(path, data, CreateMode.PERSISTENT_SEQUENTIAL);
    } catch (ZkNoNodeException e) {
        if (!createParents) {
            throw e;
        }
        String parentDir = path.substring(0, path.lastIndexOf('/'));
        createPersistent(parentDir, createParents);
        return createPersistentSequential(path, data, createParents);
    }
}
 
开发者ID:alibaba,项目名称:canal,代码行数:31,代码来源:ZkClientx.java


示例10: acquireEventLock

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
private void acquireEventLock() {
    try {
        getEventLock().lockInterruptibly();
    } catch (InterruptedException e) {
        throw new ZkInterruptedException(e);
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:8,代码来源:ZkClientx.java


示例11: connect

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
/**
 * Connect to ZooKeeper.
 * 
 * @param maxMsToWaitUntilConnected
 * @param watcher
 * @throws ZkInterruptedException if the connection timed out due to thread interruption
 * @throws ZkTimeoutException if the connection timed out
 * @throws IllegalStateException if the connection timed out due to thread interruption
 */
public void connect(final long maxMsToWaitUntilConnected, Watcher watcher) throws ZkInterruptedException,
                                                                          ZkTimeoutException, IllegalStateException {
    boolean started = false;
    try {
        getEventLock().lockInterruptibly();
        setShutdownTrigger(false);
        _eventThread = new ZkEventThread(_connection.getServers());
        _eventThread.start();
        _connection.connect(watcher);

        LOG.debug("Awaiting connection to Zookeeper server");
        if (!waitUntilConnected(maxMsToWaitUntilConnected, TimeUnit.MILLISECONDS)) {
            throw new ZkTimeoutException("Unable to connect to zookeeper server within timeout: "
                                         + maxMsToWaitUntilConnected);
        }
        started = true;
    } catch (InterruptedException e) {
        States state = _connection.getZookeeperState();
        throw new IllegalStateException("Not connected with zookeeper server yet. Current state is " + state);
    } finally {
        getEventLock().unlock();

        // we should close the zookeeper instance, otherwise it would keep
        // on trying to connect
        if (!started) {
            close();
        }
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:39,代码来源:ZkClientx.java


示例12: reconnect

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
private void reconnect() {
    getEventLock().lock();
    try {
        _connection.close();
        _connection.connect(this);
    } catch (InterruptedException e) {
        throw new ZkInterruptedException(e);
    } finally {
        getEventLock().unlock();
    }
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:12,代码来源:ZkClientx.java


示例13: connect

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
public void connect() throws ZkInterruptedException {
  boolean isConnected = zkClient.waitUntilConnected(connectionTimeoutMs, TimeUnit.MILLISECONDS);
  if (!isConnected) {
    if (metrics != null) {
      metrics.zkConnectionError.inc();
    }
    throw new RuntimeException("Unable to connect to Zookeeper within connectionTimeout " + connectionTimeoutMs + "ms. Shutting down!");
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:10,代码来源:ZkUtils.java


示例14: close

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
public void close() {
  try {
    if (zkUtils != null)
      zkUtils.close();
  } catch (ZkInterruptedException ex) {
    // Swallowing due to occurrence in the last stage of lifecycle(Not actionable).
    LOG.error("Exception in close(): ", ex);
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:10,代码来源:ZkCoordinationUtils.java


示例15: acquireEventLock

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
private void acquireEventLock() {
  try {
    getEventLock().lockInterruptibly();
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:8,代码来源:ZkClient.java


示例16: connect

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
/**
 * Connect to ZooKeeper.
 *
 * @param maxMsToWaitUntilConnected
 * @param watcher
 * @throws ZkInterruptedException
 *             if the connection timed out due to thread interruption
 * @throws ZkTimeoutException
 *             if the connection timed out
 * @throws IllegalStateException
 *             if the connection timed out due to thread interruption
 */
public void connect(final long maxMsToWaitUntilConnected, Watcher watcher)
    throws ZkInterruptedException, ZkTimeoutException, IllegalStateException {
  boolean started = false;
  acquireEventLock();
  try {
    setShutdownTrigger(false);
    _eventThread = new ZkEventThread(_connection.getServers());
    _eventThread.start();
    _connection.connect(watcher);

    LOG.debug("Awaiting connection to Zookeeper server");
    if (!waitUntilConnected(maxMsToWaitUntilConnected, TimeUnit.MILLISECONDS)) {
      throw new ZkTimeoutException(
          "Unable to connect to zookeeper server within timeout: " + maxMsToWaitUntilConnected);
    }
    started = true;
  } finally {
    getEventLock().unlock();

    // we should close the zookeeper instance, otherwise it would keep
    // on trying to connect
    if (!started) {
      close();
    }
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:39,代码来源:ZkClient.java


示例17: reconnect

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
private void reconnect() {
  getEventLock().lock();
  try {
    _connection.close();
    _connection.connect(this);
  } catch (InterruptedException e) {
    throw new ZkInterruptedException(e);
  } finally {
    getEventLock().unlock();
  }
}
 
开发者ID:apache,项目名称:helix,代码行数:12,代码来源:ZkClient.java


示例18: waitUntilConnected

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
public void waitUntilConnected() throws ZkInterruptedException {
    waitUntilConnected(Integer.MAX_VALUE, TimeUnit.MILLISECONDS);
}
 
开发者ID:luoyaogui,项目名称:otter-G,代码行数:4,代码来源:ZkClientx.java


示例19: createPersistent

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
@Override
public void createPersistent(String path, boolean createParents) throws ZkInterruptedException, IllegalArgumentException, ZkException, RuntimeException {
    zkClient.createPersistent(path, createParents);
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:5,代码来源:ZooKeeperClientImpl.java


示例20: createEphemeral

import org.I0Itec.zkclient.exception.ZkInterruptedException; //导入依赖的package包/类
@Override
public void createEphemeral(String path, Object data) throws ZkInterruptedException, IllegalArgumentException, ZkException, RuntimeException {
    zkClient.createEphemeral(path, data);
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:5,代码来源:ZooKeeperClientImpl.java



注:本文中的org.I0Itec.zkclient.exception.ZkInterruptedException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PDFMergerUtility类代码示例发布时间:2022-05-22
下一篇:
Java NewtCanvasAWT类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap