当前位置: 首页>>代码示例>>Java>>正文


Java QuorumPeerMain类代码示例

本文整理汇总了Java中org.apache.zookeeper.server.quorum.QuorumPeerMain的典型用法代码示例。如果您正苦于以下问题:Java QuorumPeerMain类的具体用法?Java QuorumPeerMain怎么用?Java QuorumPeerMain使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


QuorumPeerMain类属于org.apache.zookeeper.server.quorum包,在下文中一共展示了QuorumPeerMain类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runZKServer

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的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

示例2: main

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    if (args == null || args.length != 1) {
        throw new IllegalArgumentException("");
    }
    int i = Integer.valueOf(args[0]);
    QuorumPeerMain.main(new String[]{SingleServerTest.class.getResource("/zoo" + i + ".cfg").getPath()});
    System.in.read();
}
 
开发者ID:txazo,项目名称:zookeeper,代码行数:9,代码来源:SingleServerTest.java

示例3: start

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的package包/类
protected static void start(String[] args, String defaultStatsPort) throws Exception {
    // Register basic JVM metrics
    DefaultExports.initialize();

    // load aspectj-weaver agent for instrumentation
    AgentLoader.loadAgentClass(Agent.class.getName(), null);

    // Start Jetty to serve stats
    int port = Integer.parseInt(System.getProperties().getProperty("stats_server_port", defaultStatsPort));

    log.info("Starting ZK stats HTTP server at port {}", port);
    InetSocketAddress httpEndpoint = InetSocketAddress.createUnresolved("0.0.0.0", port);

    Server server = new Server(httpEndpoint);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
    try {
        server.start();
    } catch (Exception e) {
        log.error("Failed to start HTTP server at port {}. Use \"-Dstats_server_port=1234\" to change port number",
                port, e);
        throw e;
    }

    // Start the regular ZooKeeper server
    QuorumPeerMain.main(args);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:30,代码来源:ZooKeeperStarter.java

示例4: startZookeeper

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的package包/类
private void startZookeeper() {
    startInNewThread(() -> {
        try {
            String zookeeperConfig = TestServerManager.class.getClassLoader().getResource("zookeeper.properties").getPath();
            logger.debug("Starting Zookeeper server using config:" + zookeeperConfig);
            QuorumPeerMain.main(new String[]{zookeeperConfig});
        } catch (RuntimeException ex) {
            logger.error("Failed to start zookeeper", ex);
            throw ex;
        }
    }, "Zookeeper");
    logger.debug("Waiting until zookeper is started");
    new ZkClient("localhost:2181").waitUntilConnected();
    logger.debug("Zookeeper started");
}
 
开发者ID:badalgeek,项目名称:EventStreamAnalytics,代码行数:16,代码来源:TestServerManager.java

示例5: runFlinkZkQuorumPeer

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的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

示例6: start

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的package包/类
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);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:39,代码来源:SolrZkServer.java

示例7: main

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的package包/类
public static void main(String[] args) {
    org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
    rootLogger.setLevel(Level.INFO);
    // Define log pattern layout
    PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd hh:mm:ss}:%p %t %c{n} - %m%n");
    // Add console appender to root logger
    rootLogger.addAppender(new ConsoleAppender(layout));
    QuorumPeerMain.main(args);
}
 
开发者ID:ShifuML,项目名称:guagua,代码行数:10,代码来源:ZooKeeperMain.java

示例8: startEmbedZooKeeper

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的package包/类
/**
 * Start embed zookeeper server in a daemon thread.
 */
public static int startEmbedZooKeeper() throws IOException {
    String zooKeeperWorkingDir = getZooKeeperWorkingDir();
    boolean isSuccessful = createFolder(zooKeeperWorkingDir);

    if(!isSuccessful) {
        zooKeeperWorkingDir = getZooKeeperWorkingDir("zookeeper_" + System.currentTimeMillis());
        createFolder(zooKeeperWorkingDir);
    }

    final String confName = zooKeeperWorkingDir + File.separator + "zoo.cfg";
    int validZkPort = getValidZooKeeperPort();

    prepZooKeeperConf(zooKeeperWorkingDir, confName, validZkPort + "");

    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            QuorumPeerMain.main(new String[] { confName });
        }
    }, "Embed ZooKeeper");

    thread.setDaemon(true);
    thread.start();

    final String cleanZkFolder = zooKeeperWorkingDir;
    // used local data should be cleaned.
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                FileUtils.deleteDirectory(new File(cleanZkFolder));
            } catch (IOException ignore) {
            }
        }
    }));

    return validZkPort;
}
 
开发者ID:ShifuML,项目名称:guagua,代码行数:42,代码来源:ZooKeeperUtils.java

示例9: runZKServer

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的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

示例10: start

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的package包/类
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);
  }
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:39,代码来源:SolrZkServer.java

示例11: run

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的package包/类
@Override
public void run() {
    QuorumPeerMain.main(new String[]{MultiServerTest.class.getResource(config).getPath()});
}
 
开发者ID:txazo,项目名称:zookeeper,代码行数:5,代码来源:MultiServerTest.java

示例12: startChildZooKeeperProcess

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的package包/类
/**
 * Start embed zookeeper server in a child process.
 * 
 * @return null if start child process failed, non empty string if valid zookeeper server in child.
 */
public static String startChildZooKeeperProcess(String zkJavaOpts) throws IOException {
    // 1. prepare working dir
    String zooKeeperWorkingDir = getZooKeeperWorkingDir();
    boolean isSuccessful = createFolder(zooKeeperWorkingDir);

    if(!isSuccessful) {
        zooKeeperWorkingDir = getZooKeeperWorkingDir("zookeeper_" + System.currentTimeMillis());
        createFolder(zooKeeperWorkingDir);
    }

    // 2. prepare conf file
    final String confName = zooKeeperWorkingDir + File.separator + "zoo.cfg";
    int validZkPort = getValidZooKeeperPort();
    prepZooKeeperConf(zooKeeperWorkingDir, confName, validZkPort + "");
    // 3. prepare process buider command
    ProcessBuilder processBuilder = new ProcessBuilder();
    List<String> commandList = new ArrayList<String>();
    String javaHome = System.getProperty("java.home");
    if(javaHome == null) {
        throw new IllegalArgumentException("java.home is not set!");
    }

    commandList.add(javaHome + "/bin/java");
    String[] zkJavaOptsArray = zkJavaOpts.split(" ");
    if(zkJavaOptsArray != null) {
        commandList.addAll(Arrays.asList(zkJavaOptsArray));
    }
    commandList.add("-cp");
    commandList.add(findContainingJar(Log4jLoggerAdapter.class) + ":" + findContainingJar(Logger.class) + ":"
            + findContainingJar(org.apache.log4j.Logger.class) + ":" + findContainingJar(ZooKeeperUtils.class)
            + ":" + findContainingJar(QuorumPeerMain.class));
    commandList.add(ZooKeeperMain.class.getName());
    commandList.add(confName);
    processBuilder.command(commandList);
    File execDirectory = new File(zooKeeperWorkingDir);
    processBuilder.directory(execDirectory);
    processBuilder.redirectErrorStream(true);

    LOG.info("onlineZooKeeperServers: Attempting to start ZooKeeper server with command {} in directory {}.",
            commandList, execDirectory.toString());
    // 4. start process
    Process zkProcess = null;
    StreamCollector zkProcessCollector;
    synchronized(ZooKeeperUtils.class) {
        zkProcess = processBuilder.start();
        zkProcessCollector = new StreamCollector(zkProcess.getInputStream());
        zkProcessCollector.start();
    }
    Runtime.getRuntime().addShutdownHook(
            new Thread(new ZooKeeperShutdownHook(zkProcess, zkProcessCollector, zooKeeperWorkingDir)));
    LOG.info("onlineZooKeeperServers: Shutdown hook added.");

    // 5. check and wait for server just started.
    String hostname = getLocalHostName();
    if(isServerAlive(hostname, validZkPort)) {
        return hostname + ":" + validZkPort;
    } else {
        return null;
    }
}
 
开发者ID:ShifuML,项目名称:guagua,代码行数:66,代码来源:ZooKeeperUtils.java

示例13: startCluster

import org.apache.zookeeper.server.quorum.QuorumPeerMain; //导入依赖的package包/类
/**
 * 通过官方的QuorumPeerMain启动类启动真集群模式
 * 会执行quorumPeer.join();
 * 需要在不同的服务器上执行
 * @param config
 * @throws IOException
 * @throws AdminServer.AdminServerException
 */
public void startCluster(QuorumPeerConfig config) throws IOException, AdminServer.AdminServerException {
	QuorumPeerMain main = new QuorumPeerMain();
	main.runFromConfig(config);
}
 
开发者ID:all4you,项目名称:redant,代码行数:13,代码来源:ZkServer.java


注:本文中的org.apache.zookeeper.server.quorum.QuorumPeerMain类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。