Search in sources :

Example 1 with Factory

use of org.apache.zookeeper.server.NIOServerCnxn.Factory in project ecf by eclipse.

the class ZooDiscoveryContainer method startStandAlone.

/**
 * Start a ZooKeeer server locally to write nodes to. Implied by
 * {@link IDiscoveryConfig#ZOODISCOVERY_FLAVOR_STANDALONE} configuration.
 *
 * @param conf
 */
void startStandAlone(final Configuration conf) {
    if (ZooDiscoveryContainer.zooKeeperServer != null && ZooDiscoveryContainer.zooKeeperServer.isRunning())
        return;
    else if (ZooDiscoveryContainer.zooKeeperServer != null && !ZooDiscoveryContainer.zooKeeperServer.isRunning())
        try {
            ZooDiscoveryContainer.zooKeeperServer.startup();
            return;
        } catch (Exception e) {
            // $NON-NLS-1$
            Logger.log(LogService.LOG_DEBUG, "Zookeeper server cannot be started! ", e);
        }
    try {
        ZooDiscoveryContainer.zooKeeperServer = new ZooKeeperServer();
        FileTxnSnapLog fileTxnSnapLog = new FileTxnSnapLog(conf.getZookeeperDataFile(), conf.getZookeeperDataFile());
        ZooDiscoveryContainer.zooKeeperServer.setTxnLogFactory(fileTxnSnapLog);
        ZooDiscoveryContainer.zooKeeperServer.setTickTime(conf.getTickTime());
        Factory cnxnFactory = new NIOServerCnxn.Factory(new InetSocketAddress(conf.getClientPort()));
        cnxnFactory.startup(ZooDiscoveryContainer.zooKeeperServer);
    } catch (Exception e) {
        Logger.log(LogService.LOG_ERROR, "Zookeeper server cannot be started! Possibly another instance is already running on the same port. ", e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Factory(org.apache.zookeeper.server.NIOServerCnxn.Factory) IOException(java.io.IOException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) FileTxnSnapLog(org.apache.zookeeper.server.persistence.FileTxnSnapLog)

Aggregations

IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Factory (org.apache.zookeeper.server.NIOServerCnxn.Factory)1 ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)1 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)1 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)1