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

项目:Lagerta    文件:EmbeddedKafka.java   
private void startZookeeper() throws IOException, InterruptedException {
    File zkDir = folder.mkSubDir("embedded-zk-" + zookeeperPort);
    ServerConfig config = new ServerConfig();

    config.parse(new String[]{String.valueOf(zookeeperPort), zkDir.getAbsolutePath()});
    zookeeperThread = new Thread(() -> {
        try {
            zookeeperServer.runFromConfig(config);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    zookeeperThread.setDaemon(true);
    zookeeperThread.start();
    // Await zookeeper startup.
    zookeeperThread.join(ZOOKEEPER_AWAIT_TIME);
}
项目: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");
    }
}
项目: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");
    }
}
项目:hadoop-EAR    文件:MiniAvatarCluster.java   
private static ServerConfig createZooKeeperConf() 
  throws IOException, ConfigException {

  // create conf file
  File zkConfDir = new File(TEST_DIR);
  zkConfDir.mkdirs();
  File zkConfFile = new File(ZK_CONF_FILE);
  zkConfFile.delete();
  zkConfFile.createNewFile();

  Properties zkConfProps = new Properties();
  zkConfProps.setProperty("tickTime", "2000");
  zkConfProps.setProperty("dataDir", ZK_DATA_DIR);
  zkConfProps.setProperty("clientPort", new Integer(zkClientPort).toString());
  zkConfProps.setProperty("maxClientCnxns", "500");
  zkConfProps.store(new FileOutputStream(zkConfFile), "");

  // create config object
  ServerConfig zkConf = new ServerConfig();
  zkConf.parse(ZK_CONF_FILE);

  return zkConf;
}
项目:hadoop-EAR    文件:MiniAvatarCluster.java   
public static void createAndStartZooKeeper() 
  throws IOException, ConfigException, InterruptedException {
  logStateChange("Creating zookeeper server");
  AvatarShell.retrySleep = 1000;
  ServerConfig zkConf = createZooKeeperConf();

  zooKeeper = new ZooKeeperServer();
  FileTxnSnapLog ftxn = new 
    FileTxnSnapLog(new File(zkConf.getDataLogDir()),
                   new File(zkConf.getDataDir()));
  zooKeeper.setTxnLogFactory(ftxn);
  zooKeeper.setTickTime(zkConf.getTickTime());
  zooKeeper.setMinSessionTimeout(zkConf.getMinSessionTimeout());
  zooKeeper.setMaxSessionTimeout(zkConf.getMaxSessionTimeout());

  cnxnFactory = new NIOServerCnxnFactory();
  cnxnFactory.configure(zkConf.getClientPortAddress(),
      zkConf.getMaxClientCnxns());
  cnxnFactory.startup(zooKeeper);
  logStateChange("Creating zookeeper server - completed");
}
项目:java-dynamicconfig    文件:ZookeepersAsConfigSourceIT.java   
@Before
public void setUp() throws Exception {
    final String clientPort = "21818";
    final String dataDirectory = System.getProperty("java.io.tmpdir");
    zookeeperHost = "localhost:" + clientPort;

    ServerConfig config = new ServerConfig();
    config.parse(new String[] { clientPort, dataDirectory });

    testConfig = new BaseConfiguration();
    testConfig.setProperty("quorum", zookeeperHost);
    testConfig.setProperty("znode", "/config");
    testConfig.setProperty(APPNAME_PROPERTY, "test");
    testConfig.setProperty(ROOTCONFIG_PROPERTY, "test");

    zkServer = new ZookeeperTestUtil.ZooKeeperThread(config);
    server = new Thread(zkServer);
    server.start();

    zookeeper = connect(zookeeperHost);
}
项目:java-dynamicconfig    文件:ZookeeperAsConfigSourceDisruptedIT.java   
@Before
public void setUp() throws Exception {
    final String clientPort = "21818";
    final String dataDirectory = System.getProperty("java.io.tmpdir");
    zookeeperHost = "localhost:" + clientPort;

    ServerConfig config = new ServerConfig();
    config.parse(new String[] { clientPort, dataDirectory });

    testConfig = new BaseConfiguration();
    testConfig.setProperty("quorum", zookeeperHost);
    testConfig.setProperty("znode", "/config");
    testConfig.setProperty(APPNAME_PROPERTY, "test");
    testConfig.setProperty(ROOTCONFIG_PROPERTY, "test");

    zkServer = new ZookeeperTestUtil.ZooKeeperThread(config);
    server = new Thread(zkServer);
    server.start();

    zookeeper = connect(zookeeperHost);
}
项目:prairie    文件:ZookeeperUnit.java   
private void runFromConfig(ServerConfig config) throws IOException {
    zkServer = new ZooKeeperServer();
    try {

        txnLog = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir()));
        zkServer.setTxnLogFactory(txnLog);
        zkServer.setTickTime(config.getTickTime());
        zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
        zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
        cnxnFactory = ServerCnxnFactory.createFactory();
        cnxnFactory.configure(config.getClientPortAddress(),
                config.getMaxClientCnxns());
        cnxnFactory.startup(zkServer);
    } catch (InterruptedException e) {
        if (zkServer.isRunning()) {
            zkServer.shutdown();
        }
    }
}
项目:StreamCQL    文件:LocalTaskCommons.java   
/**
 * 启动zookeeper服务
 */
public static void startZookeeperServer()
    throws ConfigException, IOException
{
    String classPath = ApplicationParseTest.class.getResource("/").getPath();
    String[] args = {classPath + File.separator + "zoo.cfg"};
    ServerConfig config = new ServerConfig();
    if (args.length == 1)
    {
        config.parse(args[0]);
    }
    else
    {
        config.parse(args);
    }

    LOG.info("start to startup zookeeper server");
    runFromConfig(config);
}
项目:search    文件:ZkTestServer.java   
protected void initializeAndRun(String[] args) throws ConfigException,
    IOException {
  try {
    ManagedUtil.registerLog4jMBeans();
  } catch (JMException e) {
    log.warn("Unable to register log4j JMX control", e);
  }

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

  runFromConfig(config);
}
项目:NYBC    文件:ZkTestServer.java   
protected void initializeAndRun(String[] args) throws ConfigException,
    IOException {
  try {
    ManagedUtil.registerLog4jMBeans();
  } catch (JMException e) {
    log.warn("Unable to register log4j JMX control", e);
  }

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

  runFromConfig(config);
}
项目:RDFS    文件:MiniAvatarCluster.java   
private static ServerConfig createZooKeeperConf() 
  throws IOException, ConfigException {

  // create conf file
  File zkConfDir = new File(TEST_DIR);
  zkConfDir.mkdirs();
  File zkConfFile = new File(ZK_CONF_FILE);
  zkConfFile.delete();
  zkConfFile.createNewFile();

  Properties zkConfProps = new Properties();
  zkConfProps.setProperty("tickTime", "2000");
  zkConfProps.setProperty("dataDir", ZK_DATA_DIR);
  zkConfProps.setProperty("clientPort", new Integer(zkClientPort).toString());
  zkConfProps.setProperty("maxClientCnxns", "30");
  zkConfProps.store(new FileOutputStream(zkConfFile), "");

  // create config object
  ServerConfig zkConf = new ServerConfig();
  zkConf.parse(ZK_CONF_FILE);

  return zkConf;
}
项目:RDFS    文件:MiniAvatarCluster.java   
public static void createAndStartZooKeeper() 
  throws IOException, ConfigException, InterruptedException {
  ServerConfig zkConf = createZooKeeperConf();

  zooKeeper = new ZooKeeperServer();
  FileTxnSnapLog ftxn = new 
    FileTxnSnapLog(new File(zkConf.getDataLogDir()),
                   new File(zkConf.getDataDir()));
  zooKeeper.setTxnLogFactory(ftxn);
  zooKeeper.setTickTime(zkConf.getTickTime());
  zooKeeper.setMinSessionTimeout(zkConf.getMinSessionTimeout());
  zooKeeper.setMaxSessionTimeout(zkConf.getMaxSessionTimeout());

  cnxnFactory =
    new NIOServerCnxn.Factory(zkConf.getClientPortAddress(),
                              zkConf.getMaxClientCnxns());
  cnxnFactory.startup(zooKeeper);

}
项目: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);
  }
}
项目:linden    文件:EmbeddedZooKeeper.java   
public void start() throws Exception {
  try {
    // zkDir = genZookeeperDataDir();
    zkConfig = genZookeeperConfig(zkDir);
    port = Integer.valueOf(zkConfig.getProperty("clientPort"));
    QuorumPeerConfig qpConfig = new QuorumPeerConfig();
    qpConfig.parseProperties(zkConfig);
    final ServerConfig sConfig = new ServerConfig();
    sConfig.readFrom(qpConfig);


    thread = new Thread() {

      @Override
      public void run() {
        try {
          LOGGER.info("Starting ZK server");
          runFromConfig(sConfig);
        } catch (Throwable t) {
          LOGGER.error("Failure in embedded ZooKeeper", t);
        }
      }
    };

    thread.start();
    Thread.sleep(500);
  } catch (Throwable t) {
    throw new Exception("Cannot start embedded zookeeper", t);
  }
}
项目:zookeeper-cli    文件:LocalZooKeeperServer.java   
public void start() throws IOException, ConfigException, InterruptedException {
    log.info("Starting Zookeeper on port {}", port);

    Properties properties = new Properties();
    properties.setProperty("dataDir", getDataDir().getAbsolutePath());
    properties.setProperty("clientPort", Integer.toString(getPort()));

    QuorumPeerConfig quorumConfig = new QuorumPeerConfig();
    quorumConfig.parseProperties(properties);

    cleanupManager = new DatadirCleanupManager(quorumConfig.getDataDir(), quorumConfig.getDataLogDir(),
            quorumConfig.getSnapRetainCount(), quorumConfig.getPurgeInterval());
    cleanupManager.start();

    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(quorumConfig);

    zkServer = new ZooKeeperServer();
    zkServer.setTickTime(serverConfig.getTickTime());
    zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout());
    zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout());

    transactionLog = new FileTxnSnapLog(new File(serverConfig.getDataLogDir().toString()),
            new File(serverConfig.getDataDir().toString()));
    zkServer.setTxnLogFactory(transactionLog);

    connectionFactory = ServerCnxnFactory.createFactory();
    connectionFactory.configure(serverConfig.getClientPortAddress(), serverConfig.getMaxClientCnxns());
    connectionFactory.startup(zkServer);
}
项目: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);

}
项目:HeliosStreams    文件:TestZooKeeperServer.java   
/**
     * Run from a ServerConfig.
     * @param config ServerConfig to use.
     * @throws IOException on any error
     */
    public void runFromConfig(ServerConfig config) throws IOException {
        LOG.info(">>>>> Starting Test ZooKeep Server...");
        FileTxnSnapLog txnLog = null;
        try {
            // Note that this thread isn't going to be doing anything else,
            // so rather than spawning another thread, we will just call
            // run() in this thread.
            // create a file logger url from the command line args
            zkServer = new ZooKeeperServer();

            txnLog = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(
                    config.getDataDir()));
            zkServer.setTxnLogFactory(txnLog);
            zkServer.setTickTime(config.getTickTime());
            zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
            zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
            cnxnFactory = ServerCnxnFactory.createFactory();
            cnxnFactory.configure(config.getClientPortAddress(),
                    config.getMaxClientCnxns());
            cnxnFactory.startup(zkServer);
            LOG.info("<<<<< Test ZooKeep Server Started.");
//            cnxnFactory.join();
//            if (zkServer.isRunning()) {
//                zkServer.shutdown();
//            }            
        } catch (InterruptedException e) {
            // warn, but generally this is ok
            LOG.warn("Server interrupted", e);
        } finally {
//            if (txnLog != null) {
//                txnLog.close();
//            }
        }
    }
项目: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);
  }
}
项目:hadoop-EAR    文件:MiniAvatarCluster.java   
private static ServerConfig getZooKeeperConf() throws Exception {
  if (new File(ZK_CONF_FILE).exists()) {
    ServerConfig zkConf = new ServerConfig();
    zkConf.parse(ZK_CONF_FILE);

    return zkConf;
  } else {
    return createZooKeeperConf();
  }
}
项目: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();
                    }
                }
            }
        }

    }
项目:java-uniqueid    文件:ZooKeeperInstance.java   
@Override
public void before() throws Throwable {
    tempFolder = createTempDir();
    String zookeeperHost = "localhost:" + serverPort;
    ServerConfig config = new ServerConfig();
    config.parse(new String[]{serverPort, tempFolder.getAbsolutePath()});

    zkThread = new ZooKeeperThread(config);
    new Thread(zkThread).start();

    final CountDownLatch latch = new CountDownLatch(1);

    // Connect to the quorum and wait for the successful connection callback.
    zookeeper = new ZooKeeper(zookeeperHost, (int) TimeUnit.SECONDS.toMillis(10), watchedEvent -> {
        if (watchedEvent.getState() == Watcher.Event.KeeperState.SyncConnected) {
            // Signal that the Zookeeper connection is established.
            latch.countDown();
        }
    });

    // Wait for the connection to be established.
    boolean successfullyConnected = latch.await(12, TimeUnit.SECONDS);
    if (!successfullyConnected) {
        tempFolder.delete();
        throw new Exception("Could not start a local ZooKeeper quorum for testing.");
    }
}
项目:zookeeper-maven-plugin    文件:ZooKeeperLauncher.java   
public RunServer(File zooCfg) {
  config = new ServerConfig();
  try {
    config.parse(zooCfg.getAbsolutePath());
  } catch (ConfigException e) {
    throw new IllegalArgumentException("Bad configuration file", e);
  }
}
项目:StreamCQL    文件:LocalTaskCommons.java   
/**
 * Run from a ServerConfig.
 *
 */
private static void runFromConfig(ServerConfig config)
    throws IOException
{
    LOG.info("Starting server");
    String newDataDir = LocalTaskCommons.setDir(ZKDATA);
    String newLogDir = LocalTaskCommons.setDir(ZKLOG);

    try
    {
        removeZKTmpDir(newDataDir, newLogDir);
        ZooKeeperServer zkServer = new ZooKeeperServer();
        FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(newLogDir), new File(newDataDir));
        zkServer.setTxnLogFactory(ftxn);
        zkServer.setTickTime(config.getTickTime());
        zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
        zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
        cnxnFactory = ServerCnxnFactory.createFactory();
        cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
        cnxnFactory.startup(zkServer);
    }
    catch (InterruptedException e)
    {
        // warn, but generally this is ok
        LOG.warn("Server interrupted", e);
    }
}
项目: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    文件:ZkTestServer.java   
/**
 * Run from a ServerConfig.
 * @param config ServerConfig to use.
 * @throws IOException If there is a low-level I/O error.
 */
public void runFromConfig(ServerConfig config) throws IOException {
  log.info("Starting server");
  try {
    // Note that this thread isn't going to be doing anything else,
    // so rather than spawning another thread, we will just call
    // run() in this thread.
    // create a file logger url from the command line args
    zooKeeperServer = new ZooKeeperServer();

    FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(
        config.getDataLogDir()), new File(config.getDataDir()));
    zooKeeperServer.setTxnLogFactory(ftxn);
    zooKeeperServer.setTickTime(config.getTickTime());
    zooKeeperServer.setMinSessionTimeout(config.getMinSessionTimeout());
    zooKeeperServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
    cnxnFactory = ServerCnxnFactory.createFactory();
    cnxnFactory.configure(config.getClientPortAddress(),
        config.getMaxClientCnxns());
    cnxnFactory.startup(zooKeeperServer);
    cnxnFactory.join();
   // if (zooKeeperServer.isRunning()) {
      zkServer.shutdown();
   // }
  } catch (InterruptedException e) {
    // warn, but generally this is ok
    log.warn("Server interrupted", e);
  }
}
项目: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);
  }
}
项目:cross-preferences    文件:TestZkServer.java   
public TestZkServer() throws IOException, ConfigException {
    final Properties props = new Properties();
    props.setProperty("clientPort", String.valueOf(PORT));
    props.setProperty("dataDir", Files.createTempDirectory("zk").toString());
    final QuorumPeerConfig quorumConfig = new QuorumPeerConfig();
    quorumConfig.parseProperties(props);
    config = new ServerConfig();
    config.readFrom(quorumConfig);
}
项目: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();
                    }
                }
            }
        }

    }
项目: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);
  }
}
项目:jube    文件:ZooKeeperServerFactory.java   
public ZooKeeperServerFactory(QuorumPeerConfig config) throws IOException, InterruptedException {
    LOGGER.info("Creating zookeeper server with: {}", config);
    ServerConfig serverConfig = getServerConfig(config);
    ZooKeeperServer zkServer = new ZooKeeperServer();
    FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(serverConfig.getDataLogDir()), new File(serverConfig.getDataDir()));
    zkServer.setTxnLogFactory(ftxn);
    zkServer.setTickTime(serverConfig.getTickTime());
    zkServer.setMinSessionTimeout(serverConfig.getMinSessionTimeout());
    zkServer.setMaxSessionTimeout(serverConfig.getMaxSessionTimeout());
    NIOServerCnxnFactory cnxnFactory = new NIOServerCnxnFactory() {
        protected void configureSaslLogin() throws IOException {
        }
    };
    InetSocketAddress clientPortAddress = serverConfig.getClientPortAddress();
    cnxnFactory.configure(clientPortAddress, serverConfig.getMaxClientCnxns());
    updateZooKeeperURL(cnxnFactory.getLocalAddress(), cnxnFactory.getLocalPort());

    try {
        LOGGER.debug("Starting ZooKeeper server on address %s", serverConfig.getClientPortAddress());
        cnxnFactory.startup(zkServer);
        LOGGER.debug("Started ZooKeeper server");
    } catch (Exception e) {
        LOGGER.warn(String.format("Failed to start ZooKeeper server, reason : %s", e));
        cnxnFactory.shutdown();
        throw e;
    }
}
项目: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);
  }
}
项目:flume2storm    文件:ZkTestServer.java   
/**
 * Starts the test ZooKeeper server
 */
public void start() {
  if (started) {
    LOG.debug("Already started");
    return;
  }
  try {
    LOG.debug("Starting...");
    ServerConfig config = new ServerConfig();
    config.parse(new String[] { port.toString(), ZK_DIR.getCanonicalPath(), ticktime.toString() });

    zkServer = new ZooKeeperServer();

    FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(config.getDataLogDir()), new File(config.getDataDir()));
    zkServer.setTxnLogFactory(ftxn);
    zkServer.setTickTime(config.getTickTime());
    zkServer.setMinSessionTimeout(config.getMinSessionTimeout());
    zkServer.setMaxSessionTimeout(config.getMaxSessionTimeout());

    cnxnFactory = ServerCnxnFactory.createFactory();
    cnxnFactory.configure(config.getClientPortAddress(), config.getMaxClientCnxns());
    cnxnFactory.startup(zkServer);
    started = true;
    LOG.info("Started, {}", getConnectString());
  } catch (Exception e) {
    LOG.error("Failed to start: " + e.getMessage(), e);
  }
}
项目: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    文件:ZkTestServer.java   
/**
 * Run from a ServerConfig.
 * @param config ServerConfig to use.
 * @throws IOException If there is a low-level I/O error.
 */
public void runFromConfig(ServerConfig config) throws IOException {
  log.info("Starting server");
  try {
    // Note that this thread isn't going to be doing anything else,
    // so rather than spawning another thread, we will just call
    // run() in this thread.
    // create a file logger url from the command line args
    zooKeeperServer = new ZooKeeperServer();

    FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(
        config.getDataLogDir()), new File(config.getDataDir()));
    zooKeeperServer.setTxnLogFactory(ftxn);
    zooKeeperServer.setTickTime(config.getTickTime());
    zooKeeperServer.setMinSessionTimeout(config.getMinSessionTimeout());
    zooKeeperServer.setMaxSessionTimeout(config.getMaxSessionTimeout());
    cnxnFactory = ServerCnxnFactory.createFactory();
    cnxnFactory.configure(config.getClientPortAddress(),
        config.getMaxClientCnxns());
    cnxnFactory.startup(zooKeeperServer);
    cnxnFactory.join();
    if (zooKeeperServer.isRunning()) {
      zkServer.shutdown();
    }
  } catch (InterruptedException e) {
    // warn, but generally this is ok
    log.warn("Server interrupted", 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);
  }
}