Example usage for org.apache.zookeeper.server ServerCnxnFactory createFactory

List of usage examples for org.apache.zookeeper.server ServerCnxnFactory createFactory

Introduction

In this page you can find the example usage for org.apache.zookeeper.server ServerCnxnFactory createFactory.

Prototype

public static ServerCnxnFactory createFactory(InetSocketAddress addr, int maxClientCnxns) throws IOException 

Source Link

Usage

From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationConnectionTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    int tickTime = 2000;
    int numConnections = 100;
    File dir = temp.newFolder("zkHome");

    server = new ZooKeeperServer(dir, dir, tickTime);
    ServerCnxnFactory serverFactory = ServerCnxnFactory.createFactory(0, numConnections);

    serverFactory.startup(server);/*from w ww  .  j  ava 2  s .com*/

    zkConnection = "localhost:" + server.getClientPort();
}

From source file:at.salzburgresearch.kmt.zkconfig.ZookeeperConfigurationTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    int tickTime = 2000;
    int numConnections = 100;
    File dir = temp.newFolder("zkHome");

    server = new ZooKeeperServer(dir, dir, tickTime);
    ServerCnxnFactory serverFactory = ServerCnxnFactory.createFactory(0, numConnections);

    serverFactory.startup(server);/* w ww .ja  v  a2 s. co  m*/
    zkConnection = "localhost:" + server.getClientPort();
}

From source file:com.hmaimi.jodis.ZooKeeperServerWapper.java

License:Open Source License

public void start() throws IOException, InterruptedException {
    ZooKeeperServer zkServer = new ZooKeeperServer();
    FileTxnSnapLog ftxn = new FileTxnSnapLog(new File(baseDir, "zookeeper"), new File(baseDir, "zookeeper"));
    zkServer.setTxnLogFactory(ftxn);//from ww  w  .j  av  a  2 s. co  m
    zkServer.setTickTime(1000);
    ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory(port, 100);
    cnxnFactory.startup(zkServer);
    this.cnxnFactory = cnxnFactory;
    this.zkServer = zkServer;
    this.ftxn = ftxn;
}

From source file:com.jeeconf.kafka.embedded.EmbeddedZookeeper.java

License:Apache License

public void startup() throws IOException {
    if (this.port == -1) {
        this.port = TestUtils.getAvailablePort();
    }//  w w  w . jav  a  2 s  . co m
    this.factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024);
    this.snapshotDir = TestUtils.constructTempDir("embeeded-zk/snapshot");
    this.logDir = TestUtils.constructTempDir("embeeded-zk/log");

    try {
        factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime));
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}

From source file:com.jkoolcloud.tnt4j.streams.inputs.KafkaStream.java

License:Apache License

/**
 * Starts ZooKeeper server instance./* w w  w .ja  va  2 s  .co  m*/
 *
 * @throws Exception
 *             if an error occurred wile starting ZooKeeper server
 */
protected void startZooKeeper() throws Exception {
    logger().log(OpLevel.DEBUG, StreamsResources.getString(KafkaStreamConstants.RESOURCE_BUNDLE_NAME,
            "KafkaStream.zookeeper.server.starting"));

    // ZooKeeperServerMain.main();

    ServerConfig sc = new ServerConfig();
    sc.parse(System.getProperty(ZK_PROP_FILE_KEY));

    ZooKeeperServer zkServer = new ZooKeeperServer();
    zLog = new FileTxnSnapLog(new File(sc.getDataLogDir()), new File(sc.getDataDir()));
    zkServer.setTxnLogFactory(zLog);
    zkServer.setTickTime(sc.getTickTime());
    zkServer.setMinSessionTimeout(sc.getMinSessionTimeout());
    zkServer.setMaxSessionTimeout(sc.getMaxSessionTimeout());
    zkCnxnFactory = ServerCnxnFactory.createFactory(sc.getClientPortAddress(), sc.getMaxClientCnxns());
    zkCnxnFactory.startup(zkServer);

    logger().log(OpLevel.DEBUG, StreamsResources.getString(KafkaStreamConstants.RESOURCE_BUNDLE_NAME,
            "KafkaStream.zookeeper.server.started"));
}

From source file:com.msd.gin.halyard.common.HBaseServerTestInstance.java

License:Apache License

public static synchronized Configuration getInstanceConfig() throws Exception {
    if (conf == null) {
        File zooRoot = File.createTempFile("hbase-zookeeper", "");
        zooRoot.delete();/*from ww w  .  j  a v  a 2  s .c o  m*/
        ZooKeeperServer zookeper = new ZooKeeperServer(zooRoot, zooRoot, 2000);
        ServerCnxnFactory factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", 0),
                5000);
        factory.startup(zookeper);

        YarnConfiguration yconf = new YarnConfiguration();
        String argLine = System.getProperty("argLine");
        if (argLine != null) {
            yconf.set("yarn.app.mapreduce.am.command-opts", argLine.replace("jacoco.exec", "jacocoMR.exec"));
        }
        yconf.setBoolean(MRConfig.MAPREDUCE_MINICLUSTER_CONTROL_RESOURCE_MONITORING, false);
        yconf.setClass(YarnConfiguration.RM_SCHEDULER, FifoScheduler.class, ResourceScheduler.class);
        MiniMRYarnCluster miniCluster = new MiniMRYarnCluster("testCluster");
        miniCluster.init(yconf);
        yconf.setBoolean(MRJobConfig.JOB_UBERTASK_ENABLE, true);
        miniCluster.start();

        File hbaseRoot = File.createTempFile("hbase-root", "");
        hbaseRoot.delete();
        conf = HBaseConfiguration.create(miniCluster.getConfig());
        conf.set(HConstants.HBASE_DIR, hbaseRoot.toURI().toURL().toString());
        conf.setInt(HConstants.ZOOKEEPER_CLIENT_PORT, factory.getLocalPort());
        conf.set("hbase.master.hostname", "localhost");
        conf.set("hbase.regionserver.hostname", "localhost");
        conf.setInt("hbase.master.info.port", -1);
        conf.set("hbase.fs.tmp.dir", new File(System.getProperty("java.io.tmpdir")).toURI().toURL().toString());
        LocalHBaseCluster cluster = new LocalHBaseCluster(conf);
        cluster.startup();
    }
    return conf;
}

From source file:io.debezium.kafka.ZookeeperServer.java

License:Apache License

/**
 * Start the embedded Zookeeper server.// ww w.  ja  v  a2  s . c  om
 * 
 * @return this instance to allow chaining methods; never null
 * @throws IOException if there is an error during startup
 * @throws IllegalStateException if the server is already running
 */
public synchronized ZookeeperServer startup() throws IOException {
    if (factory != null)
        throw new IllegalStateException("" + this + " is already running");

    if (this.port == -1)
        this.port = IoUtil.getAvailablePort();
    this.factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024);
    if (this.dataDir == null) {
        try {
            File temp = File.createTempFile("kafka", "suffix");
            this.dataDir = temp.getParentFile();
            temp.delete();
        } catch (IOException e) {
            throw new RuntimeException("Unable to create temporary directory", e);
        }
    }
    this.snapshotDir = new File(this.dataDir, "snapshot");
    this.logDir = new File(this.dataDir, "log");
    this.snapshotDir.mkdirs();
    this.logDir.mkdirs();

    try {
        server = new ZooKeeperServer(snapshotDir, logDir, tickTime);
        factory.startup(server);
        return this;
    } catch (InterruptedException e) {
        factory = null;
        Thread.interrupted();
        throw new IOException(e);
    }
}

From source file:org.apache.hadoop.ha.ClientBaseWithFixes.java

License:Apache License

static ServerCnxnFactory createNewServerInstance(File dataDir, ServerCnxnFactory factory, String hostPort,
        int maxCnxns) throws IOException, InterruptedException {
    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = getPort(hostPort);
    if (factory == null) {
        factory = ServerCnxnFactory.createFactory(PORT, maxCnxns);
    }//from w  w  w.  ja  va2  s . c  om
    factory.startup(zks);
    Assert.assertTrue("waiting for server up",
            ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT, CONNECTION_TIMEOUT));

    return factory;
}

From source file:org.debezium.kafka.ZookeeperServer.java

License:Apache License

/**
 * Start the embedded Zookeeper server.//  ww  w.ja  v  a 2 s.  co m
 * 
 * @return this instance to allow chaining methods; never null
 * @throws IOException if there is an error during startup
 * @throws IllegalStateException if the server is already running
 */
public synchronized ZookeeperServer startup() throws IOException {
    if (factory != null)
        throw new IllegalStateException("" + this + " is already running");

    if (this.port == -1)
        this.port = IoUtil.getAvailablePort();
    this.factory = ServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024);
    if (this.dataDir == null) {
        try {
            File temp = File.createTempFile("kafka", "suffix");
            this.dataDir = temp.getParentFile();
            temp.delete();
        } catch (IOException e) {
            throw new RuntimeException("Unable to create temporary directory", e);
        }
    }
    this.snapshotDir = new File(this.dataDir, "snapshot");
    this.logDir = new File(this.dataDir, "log");
    this.snapshotDir.mkdirs();
    this.logDir.mkdirs();

    try {
        factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime));
        return this;
    } catch (InterruptedException e) {
        factory = null;
        Thread.interrupted();
        throw new IOException(e);
    }
}

From source file:org.jboss.as.zookeeper.ZooKeeperService.java

License:Open Source License

@Override
public synchronized void start(final StartContext context) throws StartException {
    File dir = new File(dataDir).getAbsoluteFile();

    try {//w w w .ja  v a2s. c o m
        System.setProperty("zookeeper.sasl.serverconfig", "zookeeper");
        System.setProperty("zookeeper.SASLAuthenticationProvider.superPassword", "redhat2015!");
        System.setProperty("zookeeper.sasl.client", "false");

        zooKeeperServer = new ZooKeeperServer(dir, dir, (int) tickTime);
        ServerCnxnFactory serverCnxnFactory = ServerCnxnFactory
                .createFactory(binding.getValue().getSocketAddress(), 5);
        zooKeeperServer.setServerCnxnFactory(serverCnxnFactory);

        context.asynchronous();
        executor.getValue().execute(new ZooKeeperServerRunner(zooKeeperServer, context));
    } catch (IOException e) {
        context.failed(new StartException(e));
    }
}