List of usage examples for org.apache.zookeeper.server.quorum QuorumPeer QuorumPeer
public QuorumPeer(Map<Long, QuorumServer> quorumPeers, File snapDir, File logDir, int clientPort, int electionAlg, long myid, int tickTime, int initLimit, int syncLimit, int connectToLearnerMasterLimit) throws IOException
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 w w.j ava 2 s .c om*/ * @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; } }