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


Java ServerConfig類代碼示例

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


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

示例1: startZookeeper

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

示例2: 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

示例3: createZooKeeperConf

import org.apache.zookeeper.server.ServerConfig; //導入依賴的package包/類
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;
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:24,代碼來源:MiniAvatarCluster.java

示例4: createAndStartZooKeeper

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

示例5: setUp

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

示例6: runFromConfig

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

示例7: startZookeeperServer

import org.apache.zookeeper.server.ServerConfig; //導入依賴的package包/類
/**
 * 啟動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);
}
 
開發者ID:HuaweiBigData,項目名稱:StreamCQL,代碼行數:22,代碼來源:LocalTaskCommons.java

示例8: initializeAndRun

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

示例9: createZooKeeperConf

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

示例10: createAndStartZooKeeper

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

}
 
開發者ID:iVCE,項目名稱:RDFS,代碼行數:20,代碼來源:MiniAvatarCluster.java

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: runFromConfig

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


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