Java Code Examples for org.apache.zookeeper.server.ServerConfig#parse()

The following examples show how to use org.apache.zookeeper.server.ServerConfig#parse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZkTestServer.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 2
Source File: MiniAvatarCluster.java    From RDFS with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: TestUtil.java    From feast with Apache License 2.0 5 votes vote down vote up
static void start(int zookeeperPort, String zookeeperDataDir) {
  ZooKeeperServerMain zookeeper = new ZooKeeperServerMain();
  final ServerConfig serverConfig = new ServerConfig();
  serverConfig.parse(new String[] {String.valueOf(zookeeperPort), zookeeperDataDir});
  thread =
      new Thread(
          () -> {
            try {
              zookeeper.runFromConfig(serverConfig);
            } catch (Exception e) {
              e.printStackTrace();
            }
          });
  thread.start();
}
 
Example 4
Source File: ZkS.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
public static ZooServer runZookeeperServer(String zooConfFile) {
    zkSystemProps();
    ServerConfig config = new ServerConfig();
    try { 
        config.parse(zooConfFile);
    } catch (ConfigException e) {
        FmtLog.error(LOG, "Error in Zookeeper configuration file '%s': %s", zooConfFile, e.getMessage());
        throw new IllegalArgumentException(e);
    }
    ZooServer zksm = new ZooServer(config);
    zksm.setupFromConfig();
    return zksm;
}
 
Example 5
Source File: ZkS.java    From rdf-delta with Apache License 2.0 5 votes vote down vote up
private static ZooServer runZookeeperServer(String[] args) {
    zkSystemProps();
    ServerConfig config = new ServerConfig();
    config.parse(args);
    ZooServer zksm = new ZooServer(config);
    zksm.setupFromConfig();
    return zksm;
}
 
Example 6
Source File: ZooKeeperInstance.java    From java-uniqueid with Apache License 2.0 5 votes vote down vote up
@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.");
    }
}
 
Example 7
Source File: MiniAvatarCluster.java    From RDFS with Apache License 2.0 5 votes vote down vote up
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();
  }
}
 
Example 8
Source File: ZkStarter.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@Override
public void runFromConfig(final ServerConfig config)
    throws IOException {
  ServerConfig newServerConfig = new ServerConfig() {

    public void parse(String[] args) {
      config.parse(args);
    }

    public void parse(String path)
        throws QuorumPeerConfig.ConfigException {
      config.parse(path);
    }

    public void readFrom(QuorumPeerConfig otherConfig) {
      config.readFrom(otherConfig);
    }

    public InetSocketAddress getClientPortAddress() {
      return config.getClientPortAddress();
    }

    public String getDataDir() {
      return config.getDataDir();
    }

    public String getDataLogDir() {
      return config.getDataLogDir();
    }

    public int getTickTime() {
      return config.getTickTime();
    }

    public int getMaxClientCnxns() {
      dataDir = getDataDir();
      dataLogDir = getDataLogDir();
      tickTime = getTickTime();
      minSessionTimeout = getMinSessionTimeout();
      maxSessionTimeout = getMaxSessionTimeout();
      maxClientCnxns = 0;
      return 0;
    }

    public int getMinSessionTimeout() {
      return config.getMinSessionTimeout();
    }

    public int getMaxSessionTimeout() {
      return config.getMaxSessionTimeout();
    }
  };

  newServerConfig.getMaxClientCnxns();

  super.runFromConfig(newServerConfig);
}