Java 类org.apache.zookeeper.server.ZooKeeperServerMain 实例源码

项目:https-github.com-apache-zookeeper    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException, AdminServerException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.isDistributed()) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:ZooKeeper    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:iotplatform    文件:KafkaDemoClient.java   
private static void startZkLocal() throws Exception {
    final File zkTmpDir = File.createTempFile("zookeeper", "test");
    if (zkTmpDir.delete() && zkTmpDir.mkdir()) {
        Properties zkProperties = new Properties();
        zkProperties.setProperty("dataDir", zkTmpDir.getAbsolutePath());
        zkProperties.setProperty("clientPort", String.valueOf(ZK_PORT));

        ServerConfig configuration = new ServerConfig();
        QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
        quorumConfiguration.parseProperties(zkProperties);
        configuration.readFrom(quorumConfiguration);

        new Thread() {
            public void run() {
                try {
                    new ZooKeeperServerMain().runFromConfig(configuration);
                } catch (IOException e) {
                    System.out.println("Start of Local ZooKeeper Failed");
                    e.printStackTrace(System.err);
                }
            }
        }.start();
    } else {
        System.out.println("Failed to delete or create data dir for Zookeeper");
    }
}
项目:StreamProcessingInfrastructure    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:bigstreams    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:bigstreams    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:zookeeper-src-learning    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:thingsboard    文件:KafkaDemoClient.java   
private static void startZkLocal() throws Exception {
    final File zkTmpDir = File.createTempFile("zookeeper", "test");
    if (zkTmpDir.delete() && zkTmpDir.mkdir()) {
        Properties zkProperties = new Properties();
        zkProperties.setProperty("dataDir", zkTmpDir.getAbsolutePath());
        zkProperties.setProperty("clientPort", String.valueOf(ZK_PORT));

        ServerConfig configuration = new ServerConfig();
        QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();
        quorumConfiguration.parseProperties(zkProperties);
        configuration.readFrom(quorumConfiguration);

        new Thread() {
            public void run() {
                try {
                    new ZooKeeperServerMain().runFromConfig(configuration);
                } catch (IOException e) {
                    System.out.println("Start of Local ZooKeeper Failed");
                    e.printStackTrace(System.err);
                }
            }
        }.start();
    } else {
        System.out.println("Failed to delete or create data dir for Zookeeper");
    }
}
项目:SecureKeeper    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException, AdminServerException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.isDistributed()) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:SecureKeeper    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException, AdminServerException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.isDistributed()) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:StreamBench    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:LoadBalanced_zk    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:LoadBalanced_zk    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:zookeeper.dsc    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:zookeeper-pkg    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:fuck_zookeeper    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    /**
     * 解析配置文件,默认的配置文件为上一级目录
     * config/zookeeper.properties或者config/zookeeper.cfg
     */
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }
    /**
     * 启动安排清除任务,定时清理历史数据(事务日志,以及快照数据)
     * since3.4.0
     */
    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    /**
     * 重要点
     * 解析服务器配置地址列表,判断是集群,还是单机模式
     */
    // 集群分支
    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        // 单机分支,standalone(机器里的单身狗;我就是一个孤独患者,有何不可?)
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        //骚气的代码,太露骨了!
        ZooKeeperServerMain.main(args);
    }
}
项目:ditb    文件:HQuorumPeer.java   
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
项目:herddb    文件:ZooKeeperMainWrapper.java   
public void run() throws Exception {
    pidFileLocker.lock();

    server = new ZooKeeperServerMain();
    QuorumPeerConfig qp = new QuorumPeerConfig();
    qp.parseProperties(configuration);
    ServerConfig sc = new ServerConfig();
    sc.readFrom(qp);
    server.runFromConfig(sc);

}
项目:zookeeper    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args)
    throws ConfigException, IOException
{
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        // 解析zoo.cfg配置文件
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    // 自动清理管理
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config
            .getDataDir(), config.getDataLogDir(), config
            .getSnapRetainCount(), config.getPurgeInterval());
    // 启动并调度自动清理任务
    purgeMgr.start();

    if (args.length == 1 && config.servers.size() > 0) {
        // 集群方式启动
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}
项目:HeliosStreams    文件:BaseTest.java   
/**
 * Stops the zookeeper instance listening on the passed port
 * @param port the listening port of the target zookeeper instance
 */
public static void stopZooKeeper(final int port) {
    final ZooKeeperServerMain zoo = zooKeeperServers.remove(port);
    if(zoo!=null) {
        PrivateAccessor.invoke(zoo, "shutdown");
    }
}
项目:flink    文件:FlinkZooKeeperQuorumPeer.java   
/**
 * Runs a ZooKeeper {@link QuorumPeer} if further peers are configured or a single
 * {@link ZooKeeperServer} if no further peers are configured.
 *
 * @param zkConfigFile ZooKeeper config file 'zoo.cfg'
 * @param peerId       ID for the 'myid' file
 */
public static void runFlinkZkQuorumPeer(String zkConfigFile, int peerId) throws Exception {

    Properties zkProps = new Properties();

    try (InputStream inStream = new FileInputStream(new File(zkConfigFile))) {
        zkProps.load(inStream);
    }

    LOG.info("Configuration: " + zkProps);

    // Set defaults for required properties
    setRequiredProperties(zkProps);

    // Write peer id to myid file
    writeMyIdToDataDir(zkProps, peerId);

    // The myid file needs to be written before creating the instance. Otherwise, this
    // will fail.
    QuorumPeerConfig conf = new QuorumPeerConfig();
    conf.parseProperties(zkProps);

    if (conf.isDistributed()) {
        // Run quorum peer
        LOG.info("Running distributed ZooKeeper quorum peer (total peers: {}).",
                conf.getServers().size());

        QuorumPeerMain qp = new QuorumPeerMain();
        qp.runFromConfig(conf);
    }
    else {
        // Run standalone
        LOG.info("Running standalone ZooKeeper quorum peer.");

        ZooKeeperServerMain zk = new ZooKeeperServerMain();
        ServerConfig sc = new ServerConfig();
        sc.readFrom(conf);
        zk.runFromConfig(sc);
    }
}
项目:LCIndex-HBase-0.94.16    文件:HQuorumPeer.java   
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
项目:majordodo    文件:TestingZookeeperServerEmbedded.java   
public void start() throws Exception {

        mainsingle = new ZooKeeperServerMain();

        thread = new Thread("zkservermainrunner") {
            @Override
            public void run() {
                try {
                    ServerConfig cc = new ServerConfig();
                    cc.readFrom(config);
                    mainsingle.runFromConfig(cc);
                    System.out.println("ZK server died");
                } catch (Throwable t) {
                    t.printStackTrace();
                }
            }
        };
        thread.start();

        this.cnxnFactory = getServerConnectionFactory();
        if (cnxnFactory != null) {
            final ZooKeeperServer zkServer = getZooKeeperServer(cnxnFactory);
            if (zkServer != null) {
                synchronized (zkServer) {
                    if (!zkServer.isRunning()) {
                        zkServer.wait();
                    }
                }
            }
        }

    }
项目:majordodo    文件:TestingZookeeperServerEmbedded.java   
private ServerCnxnFactory getServerConnectionFactory() throws Exception {
    Field cnxnFactoryField = ZooKeeperServerMain.class.getDeclaredField("cnxnFactory");
    cnxnFactoryField.setAccessible(true);
    ServerCnxnFactory cnxnFactory;

    // Wait until the cnxnFactory field is non-null or up to 1s, whichever comes first.
    long startTime = System.currentTimeMillis();
    do {
        cnxnFactory = (ServerCnxnFactory) cnxnFactoryField.get(mainsingle);
    } while ((cnxnFactory == null) && ((System.currentTimeMillis() - startTime) < 10000));

    return cnxnFactory;
}
项目:ACaZoo    文件:ZooStandalone.java   
@Override
public void init() {

    LOG.info("ZooStandalone init called!");

    @SuppressWarnings("unused")
    ZooStandalone zoo = new ZooStandalone();
    System.setProperty("jute.maxbuffer", "104857600");

    String[] args = ZooArguments;
    QuorumPeerConfig config = new QuorumPeerConfig();

    if (args.length == 1) {
        try {
            config.parse(args[0]);
        } catch (ConfigException e) {
            LOG.error("Error parsing configuration file!");
        }
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(
            config.getDataDir(), config.getDataLogDir(),
            config.getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();
    LOG.info("No quorum defined in config, running "
            + " in standalone mode");
    ZooKeeperServerMain.main(args);

}
项目:ACaZoo    文件:QuorumPeerMain.java   
protected void initializeAndRun(String[] args) throws ConfigException,
        IOException {

    /*
     * pgaref
     */
    args = ZooArguments;
    QuorumPeerConfig config = new QuorumPeerConfig();
    Thread mymod = new Thread(new Myclass(1));

    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(
            config.getDataDir(), config.getDataLogDir(),
            config.getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();
    mymod.start();
    if (args.length == 1 && config.servers.size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running "
                + " in standalone mode");
        // there is only server in the quorum -- run as standalone

        ZooKeeperServerMain.main(args);

    }
    mymod.start();
}
项目:pbase    文件:HQuorumPeer.java   
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
项目:search    文件:SolrZkServer.java   
public void start() {
  if (zkRun == null) return;

  zkThread = new Thread() {
    @Override
    public void run() {
      try {
        if (zkProps.getServers().size() > 1) {
          QuorumPeerMain zkServer = new QuorumPeerMain();
          zkServer.runFromConfig(zkProps);
        } else {
          ServerConfig sc = new ServerConfig();
          sc.readFrom(zkProps);
          ZooKeeperServerMain zkServer = new ZooKeeperServerMain();
          zkServer.runFromConfig(sc);
        }
        log.info("ZooKeeper Server exited.");
      } catch (Exception e) {
        log.error("ZooKeeper Server ERROR", e);
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
      }
    }
  };

  if (zkProps.getServers().size() > 1) {
    log.info("STARTING EMBEDDED ENSEMBLE ZOOKEEPER SERVER at port " + zkProps.getClientPortAddress().getPort());
  } else {
    log.info("STARTING EMBEDDED STANDALONE ZOOKEEPER SERVER at port " + zkProps.getClientPortAddress().getPort());
  }

  zkThread.setDaemon(true);
  zkThread.start();
  try {
    Thread.sleep(500); // pause for ZooKeeper to start
  } catch (Exception e) {
    log.error("STARTING ZOOKEEPER", e);
  }
}
项目:HIndex    文件:HQuorumPeer.java   
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
项目:blazingcache    文件:TestingZookeeperServerEmbedded.java   
public void start() throws Exception {

        mainsingle = new ZooKeeperServerMain();

        thread = new Thread("zkservermainrunner") {
            @Override
            public void run() {
                try {
                    ServerConfig cc = new ServerConfig();
                    cc.readFrom(config);
                    mainsingle.runFromConfig(cc);
                    System.out.println("ZK server died");
                } catch (Throwable t) {
                    t.printStackTrace();
                }
            }
        };
        thread.start();

        this.cnxnFactory = getServerConnectionFactory();
        if (cnxnFactory != null) {
            final ZooKeeperServer zkServer = getZooKeeperServer(cnxnFactory);
            if (zkServer != null) {
                synchronized (zkServer) {
                    if (!zkServer.isRunning()) {
                        zkServer.wait();
                    }
                }
            }
        }

    }
项目:blazingcache    文件:TestingZookeeperServerEmbedded.java   
private ServerCnxnFactory getServerConnectionFactory() throws Exception {
    Field cnxnFactoryField = ZooKeeperServerMain.class.getDeclaredField("cnxnFactory");
    cnxnFactoryField.setAccessible(true);
    ServerCnxnFactory cnxnFactory;

    // Wait until the cnxnFactory field is non-null or up to 1s, whichever comes first.
    long startTime = System.currentTimeMillis();
    do {
        cnxnFactory = (ServerCnxnFactory) cnxnFactoryField.get(mainsingle);
    } while ((cnxnFactory == null) && ((System.currentTimeMillis() - startTime) < 10000));

    return cnxnFactory;
}
项目:IRIndex    文件:HQuorumPeer.java   
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
项目:JMXMPAgent    文件:BaseTest.java   
/**
 * Stops the zookeeper instance listening on the passed port
 * @param port the listening port of the target zookeeper instance
 */
public static void stopZooKeeper(final int port) {
    final ZooKeeperServerMain zoo = zooKeeperServers.remove(port);
    if(zoo!=null) {
        PrivateAccessor.invoke(zoo, "shutdown");
    }
}
项目:hbase    文件:HQuorumPeer.java   
private static void runZKServer(QuorumPeerConfig zkConfig)
        throws UnknownHostException, IOException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
项目:RStore    文件:HQuorumPeer.java   
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
项目:PyroDB    文件:HQuorumPeer.java   
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
项目:lizard    文件:LzBuildZk.java   
/** Run a full Zookeepr here */
public static void zookeeper(int port, String zkConfDir) {
    FmtLog.info(logConf, "Start Zookeeper %s : %d", zkConfDir, port) ;
    ServerConfig config = new ServerConfig();
    config.parse(new String[] {Integer.toString(port), zkConfDir}) ;
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    L.async(()-> {
        try { zk.runFromConfig(config) ; }
        catch (Exception e) { FmtLog.warn(logConf, "Failed to run zookeeper: "+e.getMessage(), e); }
    }) ;
}
项目:NYBC    文件:SolrZkServer.java   
public void start() {
  if (zkRun == null) return;

  zkThread = new Thread() {
    @Override
    public void run() {
      try {
        if (zkProps.getServers().size() > 1) {
          QuorumPeerMain zkServer = new QuorumPeerMain();
          zkServer.runFromConfig(zkProps);
        } else {
          ServerConfig sc = new ServerConfig();
          sc.readFrom(zkProps);
          ZooKeeperServerMain zkServer = new ZooKeeperServerMain();
          zkServer.runFromConfig(sc);
        }
        log.info("ZooKeeper Server exited.");
      } catch (Throwable e) {
        log.error("ZooKeeper Server ERROR", e);
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
      }
    }
  };

  if (zkProps.getServers().size() > 1) {
    log.info("STARTING EMBEDDED ENSEMBLE ZOOKEEPER SERVER at port " + zkProps.getClientPortAddress().getPort());
  } else {
    log.info("STARTING EMBEDDED STANDALONE ZOOKEEPER SERVER at port " + zkProps.getClientPortAddress().getPort());
  }

  zkThread.setDaemon(true);
  zkThread.start();
  try {
    Thread.sleep(500); // pause for ZooKeeper to start
  } catch (Exception e) {
    log.error("STARTING ZOOKEEPER", e);
  }
}
项目:c5    文件:HQuorumPeer.java   
private static void runZKServer(QuorumPeerConfig zkConfig) throws UnknownHostException, IOException {
  if (zkConfig.isDistributed()) {
    QuorumPeerMain qp = new QuorumPeerMain();
    qp.runFromConfig(zkConfig);
  } else {
    ZooKeeperServerMain zk = new ZooKeeperServerMain();
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(zkConfig);
    zk.runFromConfig(serverConfig);
  }
}
项目:search-core    文件:SolrZkServer.java   
public void start() {
  if (zkRun == null) return;

  zkThread = new Thread() {
    @Override
    public void run() {
      try {
        if (zkProps.getServers().size() > 1) {
          QuorumPeerMain zkServer = new QuorumPeerMain();
          zkServer.runFromConfig(zkProps);
        } else {
          ServerConfig sc = new ServerConfig();
          sc.readFrom(zkProps);
          ZooKeeperServerMain zkServer = new ZooKeeperServerMain();
          zkServer.runFromConfig(sc);
        }
        log.info("ZooKeeper Server exited.");
      } catch (Throwable e) {
        log.error("ZooKeeper Server ERROR", e);
        throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
      }
    }
  };

  if (zkProps.getServers().size() > 1) {
    log.info("STARTING EMBEDDED ENSEMBLE ZOOKEEPER SERVER at port " + zkProps.getClientPortAddress().getPort());
  } else {
    log.info("STARTING EMBEDDED STANDALONE ZOOKEEPER SERVER at port " + zkProps.getClientPortAddress().getPort());
  }

  zkThread.setDaemon(true);
  zkThread.start();
  try {
    Thread.sleep(500); // pause for ZooKeeper to start
  } catch (Exception e) {
    log.error("STARTING ZOOKEEPER", e);
  }
}