org.apache.zookeeper.ZooKeeper.getSessionTimeout()方法的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(167)

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

ZooKeeper.getSessionTimeout介绍

[英]The negotiated session timeout for this ZooKeeper client instance. The value returned is not valid until the client connects to a server and may change after a re-connect. This method is NOT thread safe
[中]此ZooKeeper客户端实例的协商会话超时。在客户端连接到服务器之前,返回的值无效,重新连接后可能会更改。此方法不是线程安全的

代码示例

代码示例来源:origin: ltsopensource/light-task-scheduler

public long getSessionTimeout() {
  ZooKeeper current = zk;
  if (current != null) {
    return current.getSessionTimeout();
  }
  return -1;
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public long getSessionTimeout() {
  ZooKeeper current = zk;
  if (current != null) {
    return current.getSessionTimeout();
  }
  return -1;
}

代码示例来源:origin: apache/zookeeper

private void verifySessionTimeOut(int sessionTimeout,
    int expectedSessionTimeout, String HOSTPORT) throws IOException,
    KeeperException, InterruptedException {
  clientConnected = new CountDownLatch(1);
  ZooKeeper zk = new ZooKeeper(HOSTPORT, sessionTimeout, this);
  Assert.assertTrue("Failed to establish zkclient connection!",
      clientConnected.await(sessionTimeout, TimeUnit.MILLISECONDS));
  Assert.assertEquals("Not able to configure the sessionTimeout values",
      expectedSessionTimeout, zk.getSessionTimeout());
  zk.close();
}

代码示例来源:origin: apache/zookeeper

/**
 * String representation of this ZooKeeper client. Suitable for things
 * like logging.
 * 
 * Do NOT count on the format of this string, it may change without
 * warning.
 * 
 * @since 3.3.0
 */
@Override
public String toString() {
  States state = getState();
  return ("State:" + state.toString()
      + (state.isConnected() ?
          " Timeout:" + getSessionTimeout() + " " :
          " ")
      + cnxn);
}

代码示例来源:origin: org.apache.zookeeper/zookeeper

/**
 * String representation of this ZooKeeper client. Suitable for things
 * like logging.
 * 
 * Do NOT count on the format of this string, it may change without
 * warning.
 * 
 * @since 3.3.0
 */
@Override
public String toString() {
  States state = getState();
  return ("State:" + state.toString()
      + (state.isConnected() ?
          " Timeout:" + getSessionTimeout() + " " :
          " ")
      + cnxn);
}

代码示例来源:origin: org.apache.curator/curator-client

@Override
  public int getNegotiatedSessionTimeoutMs()
  {
    return (zooKeeperHandle != null) ? zooKeeperHandle.getSessionTimeout() : 0;
  }
};

代码示例来源:origin: com.github.ltsopensource/lts-core

public long getSessionTimeout() {
  ZooKeeper current = zk;
  if (current != null) {
    return current.getSessionTimeout();
  }
  return -1;
}

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

@Override
public int getSessionTimeout() {
  return delegate.getSessionTimeout();
}

代码示例来源:origin: com.linkedin.pegasus/d2

@Override
public int getSessionTimeout()
{
 return _zk.getSessionTimeout();
}

代码示例来源:origin: NGDATA/lilyproject

@Override
public int getSessionTimeout() {
  return delegate.getSessionTimeout();
}

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

@Override
public int getSessionTimeout() {
  return delegate.getSessionTimeout();
}

代码示例来源:origin: indeedeng/util

public int getSessionTimeout() {
  return zooKeeper.getSessionTimeout();
}

代码示例来源:origin: org.apache.bookkeeper/bookkeeper-server

@Override
public int getSessionTimeout() {
  ZooKeeper zkHandle = zk.get();
  if (null == zkHandle) {
    return super.getSessionTimeout();
  }
  return zkHandle.getSessionTimeout();
}

代码示例来源:origin: org.apache.pulsar/pulsar-proxy

@Override
public int getSessionTimeout() {
  ZooKeeper zkHandle = zk.get();
  if (null == zkHandle) {
    return super.getSessionTimeout();
  }
  return zkHandle.getSessionTimeout();
}

代码示例来源:origin: org.pongasoft/org.linkedin.zookeeper-impl

@Override
public int getSessionTimeout()
{
 return getZk().getSessionTimeout();
}

代码示例来源:origin: griddynamics/jagger

@Override
public int getSessionTimeout() {
  return getDelegate().getSessionTimeout();
}

代码示例来源:origin: org.apache.hadoop/zookeeper

/**
 * String representation of this ZooKeeper client. Suitable for things
 * like logging.
 * 
 * Do NOT count on the format of this string, it may change without
 * warning.
 * 
 * @since 3.3.0
 */
@Override
public String toString() {
  States state = getState();
  return ("State:" + state.toString()
      + (state == States.CONNECTED ?
          " Timeout:" + getSessionTimeout() + " " :
          " ")
      + cnxn);
}

代码示例来源:origin: apache/helix

protected void simulateSessionExpiry(ZkConnection zkConnection) throws IOException,
  InterruptedException {
 ZooKeeper oldZookeeper = zkConnection.getZookeeper();
 LOG.info("Old sessionId = " + oldZookeeper.getSessionId());
 Watcher watcher = new Watcher() {
  @Override
  public void process(WatchedEvent event) {
   LOG.info("In New connection, process event:" + event);
  }
 };
 ZooKeeper newZookeeper =
   new ZooKeeper(zkConnection.getServers(), oldZookeeper.getSessionTimeout(), watcher,
     oldZookeeper.getSessionId(), oldZookeeper.getSessionPasswd());
 LOG.info("New sessionId = " + newZookeeper.getSessionId());
 // Thread.sleep(3000);
 newZookeeper.close();
 Thread.sleep(10000);
 oldZookeeper = zkConnection.getZookeeper();
 LOG.info("After session expiry sessionId = " + oldZookeeper.getSessionId());
}

代码示例来源:origin: caskdata/tephra

private void expireZkSession(ZKClientService zkClientService) throws Exception {
 ZooKeeper zooKeeper = zkClientService.getZooKeeperSupplier().get();
 final SettableFuture<?> connectFuture = SettableFuture.create();
 Watcher watcher = new Watcher() {
  @Override
  public void process(WatchedEvent event) {
   if (event.getState() == Event.KeeperState.SyncConnected) {
    connectFuture.set(null);
   }
  }
 };
 // Create another Zookeeper session with the same sessionId so that the original one expires.
 final ZooKeeper dupZookeeper =
  new ZooKeeper(zkClientService.getConnectString(), zooKeeper.getSessionTimeout(), watcher,
         zooKeeper.getSessionId(), zooKeeper.getSessionPasswd());
 connectFuture.get(30, TimeUnit.SECONDS);
 Assert.assertEquals("Failed to re-create current session", dupZookeeper.getState(), ZooKeeper.States.CONNECTED);
 dupZookeeper.close();
}

代码示例来源:origin: apache/helix

/**
 * expire zk session asynchronously
 * @param client
 * @throws Exception
 */
public static void asyncExpireSession(HelixZkClient client) throws Exception {
 final ZkClient zkClient = (ZkClient) client;
 ZkConnection connection = ((ZkConnection) zkClient.getConnection());
 ZooKeeper curZookeeper = connection.getZookeeper();
 LOG.info("Before expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
 Watcher watcher = new Watcher() {
  @Override
  public void process(WatchedEvent event) {
   LOG.info("Process watchEvent: " + event);
  }
 };
 final ZooKeeper dupZookeeper =
   new ZooKeeper(connection.getServers(), curZookeeper.getSessionTimeout(), watcher,
     curZookeeper.getSessionId(), curZookeeper.getSessionPasswd());
 // wait until connected, then close
 while (dupZookeeper.getState() != States.CONNECTED) {
  Thread.sleep(10);
 }
 dupZookeeper.close();
 connection = (ZkConnection) zkClient.getConnection();
 curZookeeper = connection.getZookeeper();
 // System.err.println("zk: " + oldZookeeper);
 LOG.info("After expiry. sessionId: " + Long.toHexString(curZookeeper.getSessionId()));
}

相关文章