gpt4 book ai didi

com.ngdata.sep.util.zookeeper.ZooKeeperImpl类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 12:51:45 29 4
gpt4 key购买 nike

本文整理了Java中com.ngdata.sep.util.zookeeper.ZooKeeperImpl类的一些代码示例,展示了ZooKeeperImpl类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZooKeeperImpl类的具体详情如下:
包路径:com.ngdata.sep.util.zookeeper.ZooKeeperImpl
类名称:ZooKeeperImpl

ZooKeeperImpl介绍

[英]Default implementation of ZooKeeperItf.

To wait until the ZK connection is established, use ZkUtil#connect(String,int).

For a global ZK handle to be used by a ZK-dependent application, see rather org.lilyproject.util.zookeeper.StateWatchingZooKeeper.
[中]ZooKeef的默认实现。
要等待ZK连接建立,请使用ZkUtil#connect(String,int)。
有关ZK相关应用程序要使用的全局ZK句柄,请参阅。莉莉项目。util。动物园管理员。国家观察动物园管理员。

代码示例

代码示例来源:origin: NGDATA/hbase-indexer

@Override
public <T> T retryOperation(ZooKeeperOperation<T> operation) throws InterruptedException, KeeperException {
  if (isCurrentThreadEventThread()) {
    throw new RuntimeException("retryOperation should not be called from within the ZooKeeper event thread.");
  }
  int tryCount = 0;
  while (true) {
    tryCount++;
    try {
      return operation.execute();
    } catch (KeeperException.ConnectionLossException e) {
      // ok
    }
    if (tryCount > 3) {
      log.warn("ZooKeeper operation attempt " + tryCount + " failed due to connection loss.");
    }
    waitForConnection();
  }
}

代码示例来源:origin: NGDATA/hbase-indexer

private void endProcess(String message) {
  if (stopping) {
    return;
  }
  if (endProcessHook != null) {
    endProcessHook.run();
  }
  super.shutdown();
  log.error(message);
  System.err.println(message);
  System.exit(1);
}

代码示例来源:origin: NGDATA/hbase-indexer

public static ZooKeeperItf connect(String connectString, int sessionTimeout) throws ZkConnectException {
  ZooKeeperImpl zooKeeper;
  try {
    zooKeeper = new ZooKeeperImpl(connectString, sessionTimeout);
  } catch (IOException e) {
    throw new ZkConnectException("Failed to connect with Zookeeper @ '" + connectString + "'", e);
  }
  long waitUntil = System.currentTimeMillis() + sessionTimeout;
  boolean connected = (States.CONNECTED).equals(zooKeeper.getState());
  while (!connected && waitUntil > System.currentTimeMillis()) {
    try {
      Thread.sleep(100);
    } catch (InterruptedException e) {
      connected = (States.CONNECTED).equals(zooKeeper.getState());
      break;
    }
    connected = (States.CONNECTED).equals(zooKeeper.getState());
  }
  if (!connected) {
    System.out.println("Failed to connect to Zookeeper within timeout: Dumping stack: ");
    Thread.dumpStack();
    zooKeeper.close();
    throw new ZkConnectException("Failed to connect with Zookeeper @ '" + connectString +
        "' within timeout " + sessionTimeout);
  }
  return zooKeeper;
}

代码示例来源:origin: com.ngdata/hbase-sep-impl-common

@Override
public void waitForConnection() throws InterruptedException {
  if (isCurrentThreadEventThread()) {
    throw new RuntimeException("waitForConnection should not be called from within the ZooKeeper event thread.");
  }
  synchronized (connectedMonitor) {
    while (!connected && !stop) {
      connectedMonitor.wait();
    }
  }
  if (stop) {
    throw new InterruptedException("This ZooKeeper handle is shutting down.");
  }
}

代码示例来源:origin: com.ngdata/hbase-sep-impl-common

@Override
  public void process(WatchedEvent event) {
    zkEventThread = Thread.currentThread();
    if (event.getState() == Watcher.Event.KeeperState.Disconnected) {
      System.err.println("ZooKeeper disconnected at " + new Date());
      printConnectMsg = true;
    } else if (event.getState() == Event.KeeperState.Expired) {
      System.err.println("ZooKeeper session expired at " + new Date());
      printConnectMsg = true;
    } else if (event.getState() == Event.KeeperState.SyncConnected) {
      if (printConnectMsg) {
        System.out.println("ZooKeeper connected at " + new Date());
      }
    }
    setConnectedState(event);
    for (Watcher watcher : additionalDefaultWatchers) {
      watcher.process(event);
    }
  }
}

代码示例来源:origin: com.ngdata/hbase-sep-impl-common

public static ZooKeeperItf connect(String connectString, int sessionTimeout) throws ZkConnectException {
  ZooKeeperImpl zooKeeper;
  try {
    zooKeeper = new ZooKeeperImpl(connectString, sessionTimeout, new DefaultACLProvider());
  } catch (IOException e) {
    throw new ZkConnectException("Failed to connect with Zookeeper @ '" + connectString + "'", e);
  }
  long waitUntil = System.currentTimeMillis() + sessionTimeout;
  boolean connected = (States.CONNECTED).equals(zooKeeper.getState());
  while (!connected && waitUntil > System.currentTimeMillis()) {
    try {
      Thread.sleep(100);
    } catch (InterruptedException e) {
      connected = (States.CONNECTED).equals(zooKeeper.getState());
      break;
    }
    connected = (States.CONNECTED).equals(zooKeeper.getState());
  }
  if (!connected) {
    System.out.println("Failed to connect to Zookeeper within timeout: Dumping stack: ");
    Thread.dumpStack();
    zooKeeper.close();
    throw new ZkConnectException("Failed to connect with Zookeeper @ '" + connectString +
        "' within timeout " + sessionTimeout);
  }
  return zooKeeper;
}

代码示例来源:origin: NGDATA/hbase-indexer

@Override
public void waitForConnection() throws InterruptedException {
  if (isCurrentThreadEventThread()) {
    throw new RuntimeException("waitForConnection should not be called from within the ZooKeeper event thread.");
  }
  synchronized (connectedMonitor) {
    while (!connected && !stop) {
      connectedMonitor.wait();
    }
  }
  if (stop) {
    throw new InterruptedException("This ZooKeeper handle is shutting down.");
  }
}

代码示例来源:origin: NGDATA/hbase-indexer

@Override
  public void process(WatchedEvent event) {
    zkEventThread = Thread.currentThread();
    if (event.getState() == Watcher.Event.KeeperState.Disconnected) {
      System.err.println("ZooKeeper disconnected at " + new Date());
      printConnectMsg = true;
    } else if (event.getState() == Event.KeeperState.Expired) {
      System.err.println("ZooKeeper session expired at " + new Date());
      printConnectMsg = true;
    } else if (event.getState() == Event.KeeperState.SyncConnected) {
      if (printConnectMsg) {
        System.out.println("ZooKeeper connected at " + new Date());
      }
    }
    setConnectedState(event);
    for (Watcher watcher : additionalDefaultWatchers) {
      watcher.process(event);
    }
  }
}

代码示例来源:origin: com.ngdata/hbase-sep-impl-common

@Override
public <T> T retryOperation(ZooKeeperOperation<T> operation) throws InterruptedException, KeeperException {
  if (isCurrentThreadEventThread()) {
    throw new RuntimeException("retryOperation should not be called from within the ZooKeeper event thread.");
  }
  int tryCount = 0;
  while (true) {
    tryCount++;
    try {
      return operation.execute();
    } catch (KeeperException.ConnectionLossException e) {
      // ok
    }
    if (tryCount > 3) {
      log.warn("ZooKeeper operation attempt " + tryCount + " failed due to connection loss.");
    }
    waitForConnection();
  }
}

代码示例来源:origin: com.ngdata/hbase-indexer-common

private void endProcess(String message) {
  if (stopping) {
    return;
  }
  if (endProcessHook != null) {
    endProcessHook.run();
  }
  super.shutdown();
  log.error(message);
  System.err.println(message);
  System.exit(1);
}

代码示例来源:origin: NGDATA/hbase-indexer

@Override
@PreDestroy
public void shutdown() {
  super.shutdown();
  stopping = true;
  if (stateWatcherThread != null) {
    stateWatcherThread.interrupt();
  }
  close();
}

代码示例来源:origin: com.ngdata/hbase-indexer-common

@Override
@PreDestroy
public void shutdown() {
  super.shutdown();
  stopping = true;
  if (stateWatcherThread != null) {
    stateWatcherThread.interrupt();
  }
  close();
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com