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


Java ConnectStringParser.getServerAddresses方法代码示例

本文整理汇总了Java中org.apache.zookeeper.client.ConnectStringParser.getServerAddresses方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectStringParser.getServerAddresses方法的具体用法?Java ConnectStringParser.getServerAddresses怎么用?Java ConnectStringParser.getServerAddresses使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.zookeeper.client.ConnectStringParser的用法示例。


在下文中一共展示了ConnectStringParser.getServerAddresses方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ZookeeperMonitor

import org.apache.zookeeper.client.ConnectStringParser; //导入方法依赖的package包/类
protected ZookeeperMonitor(Connection connection, String[] monitorTargets, boolean useRegExp,
    StdOutSink sink, ExecutorService executor, boolean treatFailureAsError)  {
  super(connection, monitorTargets, useRegExp, sink, executor, treatFailureAsError);
  Configuration configuration = connection.getConfiguration();
  znode =
      configuration.get(ZOOKEEPER_ZNODE_PARENT,
          DEFAULT_ZOOKEEPER_ZNODE_PARENT);
  timeout = configuration
      .getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT);
  ConnectStringParser parser =
      new ConnectStringParser(ZKConfig.getZKQuorumServersString(configuration));
  hosts = Lists.newArrayList();
  for (InetSocketAddress server : parser.getServerAddresses()) {
    hosts.add(server.toString());
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:17,代码来源:Canary.java

示例2: ZooKeeper

import org.apache.zookeeper.client.ConnectStringParser; //导入方法依赖的package包/类
/**
 * To create a ZooKeeper client object, the application needs to pass a
 * connection string containing a comma separated list of host:port pairs,
 * each corresponding to a ZooKeeper server.
 * <p>
 * Session establishment is asynchronous. This constructor will initiate
 * connection to the server and return immediately - potentially (usually)
 * before the session is fully established. The watcher argument specifies
 * the watcher that will be notified of any changes in state. This
 * notification can come at any point before or after the constructor call
 * has returned.
 * <p>
 * The instantiated ZooKeeper client object will pick an arbitrary server
 * from the connectString and attempt to connect to it. If establishment of
 * the connection fails, another server in the connect string will be tried
 * (the order is non-deterministic, as we random shuffle the list), until a
 * connection is established. The client will continue attempts until the
 * session is explicitly closed.
 * <p>
 * Added in 3.2.0: An optional "chroot" suffix may also be appended to the
 * connection string. This will run the client commands while interpreting
 * all paths relative to this root (similar to the unix chroot command).
 *
 * @param connectString
 *            comma separated host:port pairs, each corresponding to a zk
 *            server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" If
 *            the optional chroot suffix is used the example would look
 *            like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a"
 *            where the client would be rooted at "/app/a" and all paths
 *            would be relative to this root - ie getting/setting/etc...
 *            "/foo/bar" would result in operations being run on
 *            "/app/a/foo/bar" (from the server perspective).
 * @param sessionTimeout
 *            session timeout in milliseconds
 * @param watcher
 *            a watcher object which will be notified of state changes, may
 *            also be notified for node events
 * @param canBeReadOnly
 *            (added in 3.4) whether the created client is allowed to go to
 *            read-only mode in case of partitioning. Read-only mode
 *            basically means that if the client can't find any majority
 *            servers but there's partitioned server it could reach, it
 *            connects to one in read-only mode, i.e. read requests are
 *            allowed while write requests are not. It continues seeking for
 *            majority in the background.
 *
 * @throws IOException
 *             in cases of network failure
 * @throws IllegalArgumentException
 *             if an invalid chroot path is specified
 */
public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher,
        boolean canBeReadOnly)
    throws IOException
{
    LOG.info("Initiating client connection, connectString=" + connectString
            + " sessionTimeout=" + sessionTimeout + " watcher=" + watcher);

    watchManager.defaultWatcher = watcher;

    ConnectStringParser connectStringParser = new ConnectStringParser(
            connectString);
    HostProvider hostProvider = new StaticHostProvider(
            connectStringParser.getServerAddresses());
    cnxn = new ClientCnxn(connectStringParser.getChrootPath(),
            hostProvider, sessionTimeout, this, watchManager,
            getClientCnxnSocket(), canBeReadOnly);
    cnxn.start();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:70,代码来源:ZooKeeper.java

示例3: updateServerList

import org.apache.zookeeper.client.ConnectStringParser; //导入方法依赖的package包/类
/**
 * This function allows a client to update the connection string by providing 
 * a new comma separated list of host:port pairs, each corresponding to a 
 * ZooKeeper server. 
 * <p>
 * The function invokes a <a href="https://issues.apache.org/jira/browse/ZOOKEEPER-1355">
 * probabilistic load-balancing algorithm</a> which may cause the client to disconnect from 
 * its current host with the goal to achieve expected uniform number of connections per server 
 * in the new list. In case the current host to which the client is connected is not in the new
 * list this call will always cause the connection to be dropped. Otherwise, the decision
 * is based on whether the number of servers has increased or decreased and by how much.
 * For example, if the previous connection string contained 3 hosts and now the list contains
 * these 3 hosts and 2 more hosts, 40% of clients connected to each of the 3 hosts will
 * move to one of the new hosts in order to balance the load. The algorithm will disconnect 
 * from the current host with probability 0.4 and in this case cause the client to connect 
 * to one of the 2 new hosts, chosen at random.
 * <p>
 * If the connection is dropped, the client moves to a special mode "reconfigMode" where he chooses
 * a new server to connect to using the probabilistic algorithm. After finding a server,
 * or exhausting all servers in the new list after trying all of them and failing to connect,
 * the client moves back to the normal mode of operation where it will pick an arbitrary server
 * from the connectString and attempt to connect to it. If establishment of
 * the connection fails, another server in the connect string will be tried
 * (the order is non-deterministic, as we random shuffle the list), until a
 * connection is established. The client will continue attempts until the
 * session is explicitly closed (or the session is expired by the server).

 * @param connectString
 *            comma separated host:port pairs, each corresponding to a zk
 *            server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
 *            If the optional chroot suffix is used the example would look
 *            like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a"
 *            where the client would be rooted at "/app/a" and all paths
 *            would be relative to this root - ie getting/setting/etc...
 *            "/foo/bar" would result in operations being run on
 *            "/app/a/foo/bar" (from the server perspective).     
 *
 * @throws IOException in cases of network failure     
 */
public void updateServerList(String connectString) throws IOException {
    ConnectStringParser connectStringParser = new ConnectStringParser(connectString);
    Collection<InetSocketAddress> serverAddresses = connectStringParser.getServerAddresses();

    ClientCnxnSocket clientCnxnSocket = cnxn.sendThread.getClientCnxnSocket();
    InetSocketAddress currentHost = (InetSocketAddress) clientCnxnSocket.getRemoteSocketAddress();

    boolean reconfigMode = hostProvider.updateServerList(serverAddresses, currentHost);

    // cause disconnection - this will cause next to be called
    // which will in turn call nextReconfigMode
    if (reconfigMode) clientCnxnSocket.testableCloseSocket();
}
 
开发者ID:didichuxing2,项目名称:https-github.com-apache-zookeeper,代码行数:53,代码来源:ZooKeeper.java


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