예제 #1
0
  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);
    }
  }
예제 #2
0
 public Map<Long, QuorumPeer.QuorumServer> getServers() {
   return zkProps.getServers();
 }