org.apache.zookeeper.server.ServerConfig Java Examples

The following examples show how to use org.apache.zookeeper.server.ServerConfig. 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: EmbeddedZooKeeper.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 7 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #2
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #3
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #4
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 #5
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #6
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #7
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #8
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #9
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #10
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #11
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #12
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #13
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #14
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #15
Source File: KafkaDemoClient.java    From iotplatform with Apache License 2.0 6 votes vote down vote up
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");
    }
}
 
Example #16
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #17
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #18
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #19
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #20
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #21
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #22
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #23
Source File: TestingZooKeeperMain.java    From xian with Apache License 2.0 6 votes vote down vote up
@Override
public void runFromConfig(QuorumPeerConfig config) throws Exception
{
    ServerConfig serverConfig = new ServerConfig();
    serverConfig.readFrom(config);
    latch.countDown();
    try
    {
        super.runFromConfig(serverConfig);
    }
    catch ( IOException e )
    {
        startingException.set(e);
        throw e;
    }
}
 
Example #24
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 #25
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #26
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
                + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    } catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        } else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #27
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #28
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #29
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}
 
Example #30
Source File: EmbeddedZooKeeper.java    From dubbo-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        Properties properties = new Properties();
        File file = new File(System.getProperty("java.io.tmpdir")
            + File.separator + UUID.randomUUID());
        file.deleteOnExit();
        properties.setProperty("dataDir", file.getAbsolutePath());
        properties.setProperty("clientPort", String.valueOf(clientPort));

        QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parseProperties(properties);

        zkServer = new ZooKeeperServerMain();
        ServerConfig configuration = new ServerConfig();
        configuration.readFrom(quorumPeerConfig);

        zkServer.runFromConfig(configuration);
    }
    catch (Exception e) {
        if (errorHandler != null) {
            errorHandler.handleError(e);
        }
        else {
            logger.error("Exception running embedded ZooKeeper", e);
        }
    }
}