当前位置: 首页>>代码示例>>Java>>正文


Java ZkInterruptedException类代码示例

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


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


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