當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerConfig.readFrom方法代碼示例

本文整理匯總了Java中org.apache.zookeeper.server.ServerConfig.readFrom方法的典型用法代碼示例。如果您正苦於以下問題:Java ServerConfig.readFrom方法的具體用法?Java ServerConfig.readFrom怎麽用?Java ServerConfig.readFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.zookeeper.server.ServerConfig的用法示例。


在下文中一共展示了ServerConfig.readFrom方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: startZkLocal

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
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");
    }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:27,代碼來源:KafkaDemoClient.java

示例2: runZKServer

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
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);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:12,代碼來源:HQuorumPeer.java

示例3: start

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
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);
  }
}
 
開發者ID:XiaoMi,項目名稱:linden,代碼行數:31,代碼來源:EmbeddedZooKeeper.java

示例4: start

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
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);
}
 
開發者ID:mosuka,項目名稱:zookeeper-cli,代碼行數:31,代碼來源:LocalZooKeeperServer.java

示例5: run

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
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);

}
 
開發者ID:diennea,項目名稱:herddb,代碼行數:12,代碼來源:ZooKeeperMainWrapper.java

示例6: runFlinkZkQuorumPeer

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
/**
 * 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);
	}
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:47,代碼來源:FlinkZooKeeperQuorumPeer.java

示例7: TestZkServer

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
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);
}
 
開發者ID:adobe-research,項目名稱:cross-preferences,代碼行數:10,代碼來源:TestZkServer.java

示例8: runZKServer

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
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);
  }
}
 
開發者ID:apache,項目名稱:hbase,代碼行數:13,代碼來源:HQuorumPeer.java

示例9: start

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
/**
 * Starts Zookeeper.
 *
 * @throws IOException if an error occurs during initialization
 * @throws InterruptedException if an error occurs during initialization
 */
public synchronized void start() throws IOException, InterruptedException {
  log.info("Starting Zookeeper on port {}", port);

  dataDir = Files.createTempDirectory(LocalZKServer.class.getSimpleName());
  dataDir.toFile().deleteOnExit();

  QuorumPeerConfig quorumConfig = new QuorumPeerConfig();
  try {
    quorumConfig.parseProperties(ConfigUtils.keyValueToProperties(
        "dataDir", dataDir.toAbsolutePath(),
        "clientPort", port
    ));
  } catch (QuorumPeerConfig.ConfigException e) {
    throw new IllegalArgumentException(e);
  }

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

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

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

  // These two ServerConfig methods returned String in 3.4.x and File in 3.5.x
  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);
}
 
開發者ID:oncewang,項目名稱:oryx2,代碼行數:47,代碼來源:LocalZKServer.java

示例10: init

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
public void init() throws Exception {
  logger.info("Starting Zookeeper");

  final Properties startupProperties = new Properties();
  final File dir = new File(storageDir, "zookeeper");
  startupProperties.put("dataDir", dir.toString());
  final ServerConfig configuration = new ServerConfig();
  final QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig();

  while (true) {
    startupProperties.put("clientPort", port);
    quorumConfiguration.parseProperties(startupProperties);
    configuration.readFrom(quorumConfiguration);
    this.zkEmbeddedServer = new ZkEmbeddedServer(configuration);
    this.zkThread = new Thread(zkEmbeddedServer, "[email protected]" + port);
    zkThread.start();
    // wait for zk server to start cleanly, max wait half a sec
    int maxWait = ZK_SERVER_STARTUP_TIME;
    while (zkEmbeddedServer.error == null && maxWait > 0) {
      try {
        Thread.currentThread().sleep(100);
      } catch (InterruptedException ite) {
        break;
      }
      maxWait -= 100;
    }
    if (zkEmbeddedServer.error != null) {
      zkEmbeddedServer.shutDown();
      zkThread.join();
      if (autoPort && zkEmbeddedServer.error instanceof BindException) {
        logger.info("ZooKeeper failed to start on port {}, trying next port {}", port, port + 1);
        port++;
      } else {
        logger.error("ZooKeeper startup failed", zkEmbeddedServer.error);
        Throwables.propagate(zkEmbeddedServer.error);
        break;
      }
    } else {
      break;
    }
  }

  logger.info("Zookeeper is up at localhost:{}", port);
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:45,代碼來源:ZkServer.java

示例11: startup

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
public void startup() throws IOException {
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(config);
    runFromConfig(serverConfig);
}
 
開發者ID:apache,項目名稱:aries-rsa,代碼行數:6,代碼來源:ZookeeperStarter.java

示例12: getServerConfig

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
private ServerConfig getServerConfig(QuorumPeerConfig peerConfig) {
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(peerConfig);
    LOGGER.info("Created zookeeper server configuration: {}", serverConfig);
    return serverConfig;
}
 
開發者ID:fabric8io,項目名稱:jube,代碼行數:7,代碼來源:ZooKeeperServerFactory.java

示例13: start

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
public void start() throws Exception {
  ServerConfig config = new ServerConfig();
  config.readFrom(qConfig);;
  runFromConfig(config);
}
 
開發者ID:DemandCube,項目名稱:NeverwinterDP-Commons,代碼行數:6,代碼來源:ZookeeperClusterService.java

示例14: runFromConfig

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
@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);
}
 
開發者ID:linkedin,項目名稱:pinot,代碼行數:57,代碼來源:ZkStarter.java

示例15: run

import org.apache.zookeeper.server.ServerConfig; //導入方法依賴的package包/類
/**
 * Attempts to run the vertex internally in the current JVM, reading and
 * writing to an in-memory graph. Will start its own zookeeper
 * instance.
 *
 * @param <I> Vertex ID
 * @param <V> Vertex Value
 * @param <E> Edge Value
 * @param conf GiraphClasses specifying which types to use
 * @param graph input graph
 * @return iterable output data
 * @throws Exception if anything goes wrong
 */
public static <I extends WritableComparable,
  V extends Writable,
  E extends Writable> TestGraph<I, V, E> run(
    GiraphConfiguration conf,
    TestGraph<I, V, E> graph) throws Exception {
  File tmpDir = null;
  try {
    // Prepare temporary folders
    tmpDir = FileUtils.createTestDir(conf.getComputationName());

    File zkDir = FileUtils.createTempDir(tmpDir, "_bspZooKeeper");
    File zkMgrDir = FileUtils.createTempDir(tmpDir, "_defaultZkManagerDir");
    File checkpointsDir = FileUtils.createTempDir(tmpDir, "_checkpoints");

    conf.setVertexInputFormatClass(InMemoryVertexInputFormat.class);

    // Create and configure the job to run the vertex
    GiraphJob job = new GiraphJob(conf, conf.getComputationName());

    InMemoryVertexInputFormat.setGraph(graph);

    conf.setWorkerConfiguration(1, 1, 100.0f);
    GiraphConstants.SPLIT_MASTER_WORKER.set(conf, false);
    GiraphConstants.LOCAL_TEST_MODE.set(conf, true);
    conf.set(GiraphConstants.ZOOKEEPER_LIST, "localhost:" +
        String.valueOf(LOCAL_ZOOKEEPER_PORT));

    conf.set(GiraphConstants.ZOOKEEPER_DIR, zkDir.toString());
    GiraphConstants.ZOOKEEPER_MANAGER_DIRECTORY.set(conf,
        zkMgrDir.toString());
    GiraphConstants.CHECKPOINT_DIRECTORY.set(conf, checkpointsDir.toString());

    // Configure a local zookeeper instance
    Properties zkProperties = configLocalZooKeeper(zkDir);

    QuorumPeerConfig qpConfig = new QuorumPeerConfig();
    qpConfig.parseProperties(zkProperties);

    // Create and run the zookeeper instance
    final InternalZooKeeper zookeeper = new InternalZooKeeper();
    final ServerConfig zkConfig = new ServerConfig();
    zkConfig.readFrom(qpConfig);

    ExecutorService executorService = Executors.newSingleThreadExecutor();
    executorService.execute(new Runnable() {
      @Override
      public void run() {
        try {
          zookeeper.runFromConfig(zkConfig);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
    });
    try {
      job.run(true);
    } finally {
      executorService.shutdown();
      zookeeper.end();
    }
    return graph;
  } finally {
    FileUtils.delete(tmpDir);
  }
}
 
開發者ID:renato2099,項目名稱:giraph-gora,代碼行數:79,代碼來源:InternalVertexRunner.java


注:本文中的org.apache.zookeeper.server.ServerConfig.readFrom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。