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

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

Introduction

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

Prototype

public void parse(String path) throws ConfigException 

Source Link

Document

Parse a ZooKeeper configuration file

Usage

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.// www .j a v  a 2 s . c o m
 */
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.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   www  .ja va 2  s.  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);
    }
}

From source file:org.eclipse.ecf.provider.zookeeper.core.ZooDiscoveryContainer.java

License:Open Source License

/**
 * Start a local ZooKeeer server to write nodes to. It plays as a peer
 * within a replicated servers configuration. Implied by
 * {@link IDiscoveryConfig#ZOODISCOVERY_FLAVOR_REPLICATED} configuration.
 * // w ww  . j  a  v a  2s .  c  o m
 * @param conf
 */
void startQuorumPeer(final Configuration conf) {
    if (this.quorumPeer != null && this.quorumPeer.isAlive()) {
        return;
    } else if (this.quorumPeer != null && !this.quorumPeer.isAlive()) {
        this.quorumPeer.start();
        return;
    }
    try {
        final QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
        quorumPeerConfig.parse(conf.getConfFile());
        QuorumPeer.Factory qpFactory = new QuorumPeer.Factory() {
            public QuorumPeer create(NIOServerCnxn.Factory cnxnFactory) throws IOException {
                ServerConfig serverConfig = new ServerConfig();
                serverConfig.readFrom(quorumPeerConfig);
                QuorumPeer peer = new QuorumPeer(quorumPeerConfig.getServers(),
                        new File(serverConfig.getDataDir()), new File(serverConfig.getDataLogDir()),
                        quorumPeerConfig.getElectionAlg(), quorumPeerConfig.getServerId(),
                        quorumPeerConfig.getTickTime(), quorumPeerConfig.getInitLimit(),
                        quorumPeerConfig.getSyncLimit(), cnxnFactory, quorumPeerConfig.getQuorumVerifier());
                ZooDiscoveryContainer.this.quorumPeer = peer;
                return peer;
            }

            public NIOServerCnxn.Factory createConnectionFactory() throws IOException {
                return new NIOServerCnxn.Factory(quorumPeerConfig.getClientPortAddress());
            }
        };
        quorumPeer = qpFactory.create(qpFactory.createConnectionFactory());
        quorumPeer.start();
        quorumPeer.setDaemon(true);
        isQuorumPeerReady = true;
    } catch (Exception e) {
        Logger.log(LogService.LOG_ERROR, "Zookeeper quorum cannot be started! ", e); //$NON-NLS-1$
        isQuorumPeerReady = false;
    }
}