Example usage for org.apache.zookeeper.server.quorum QuorumPeerConfig getSnapRetainCount

List of usage examples for org.apache.zookeeper.server.quorum QuorumPeerConfig getSnapRetainCount

Introduction

In this page you can find the example usage for org.apache.zookeeper.server.quorum QuorumPeerConfig getSnapRetainCount.

Prototype

public int getSnapRetainCount() 

Source Link

Usage

From source file:com.anhth12.zk.util.LocalZKServer.java

/**
 * Starts Zookeeper.//from w ww . j a  va 2 s . c o m
 *
 * @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();

    Properties properties = new Properties();
    properties.setProperty("dataDir", dataDir.toAbsolutePath().toString());
    properties.setProperty("clientPort", Integer.toString(port));
    log.info("ZK config: {}", properties);

    QuorumPeerConfig quorumConfig = new QuorumPeerConfig();
    try {
        quorumConfig.parseProperties(properties);
    } 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);
}

From source file:com.chiralBehaviors.autoconfigure.ZookeeperLauncher.java

License:Open Source License

/**
 * Copied from QuorumPeerMain because whomever wrote that crap made things
 * protected. Because freedom./*from   w  ww  .  j  a  v  a 2  s .c  om*/
 */
protected void initializeAndRun(String[] args) throws ConfigException, IOException {
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config.getDataDir(), config.getDataLogDir(),
            config.getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.getServers().size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warning("Running in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}

From source file:com.cloudera.oryx.kafka.util.LocalZKServer.java

License:Open Source License

/**
 * Starts Zookeeper.//from w w  w  .j av  a 2 s . c o  m
 *
 * @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);
}

From source file:com.glaf.cluster.catalina.session.QuorumPeerMain.java

License:Apache License

protected void initializeAndRun(String[] args) throws ConfigException, IOException {
    QuorumPeerConfig config = new QuorumPeerConfig();
    if (args.length == 1) {
        config.parse(args[0]);//from  ww w  .  ja  va  2s  .c  o  m
    }

    // Start and schedule the the purge task
    DatadirCleanupManager purgeMgr = new DatadirCleanupManager(config.getDataDir(), config.getDataLogDir(),
            config.getSnapRetainCount(), config.getPurgeInterval());
    purgeMgr.start();

    if (args.length == 1 && config.getServers().size() > 0) {
        runFromConfig(config);
    } else {
        LOG.warn("Either no config or no quorum defined in config, running " + " in standalone mode");
        // there is only server in the quorum -- run as standalone
        ZooKeeperServerMain.main(args);
    }
}