Example usage for org.apache.zookeeper.server ZooKeeperServer ZooKeeperServer

List of usage examples for org.apache.zookeeper.server ZooKeeperServer ZooKeeperServer

Introduction

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

Prototype

public ZooKeeperServer(File snapDir, File logDir, int tickTime) throws IOException 

Source Link

Document

This constructor is for backward compatibility with the existing unit test code.

Usage

From source file:akka.cluster.LocalBookKeeper.java

License:Open Source License

/**
 * @param args//from   w  ww. j ava 2s.  c o  m
 */

public void runZookeeper(int maxCC) throws IOException {
    // create a ZooKeeper server(dataDir, dataLogDir, port)
    //ServerStats.registerAsConcrete();
    //ClientBase.setupTestEnv();
    ZkTmpDir = File.createTempFile("zookeeper", "test");
    ZkTmpDir.delete();
    ZkTmpDir.mkdir();

    try {
        zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort);
        serverFactory = new NIOServerCnxnFactory();
        serverFactory.configure(new InetSocketAddress(ZooKeeperDefaultPort), maxCC);
        serverFactory.startup(zks);
    } catch (Exception e) {
        // TODO Auto-generated catch block
    }

    boolean b = waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT);
}

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);/* w  w w . j  a  va2  s.  c om*/

    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);//from w  w  w .ja va  2s .c  om
    zkConnection = "localhost:" + server.getClientPort();
}

From source file:com.alibaba.jstorm.zk.Zookeeper.java

License:Apache License

public static Factory mkInprocessZookeeper(String localdir, int port) throws IOException, InterruptedException {
    LOG.info("Starting inprocess zookeeper at port " + port + " and dir " + localdir);
    File localfile = new File(localdir);
    ZooKeeperServer zk = new ZooKeeperServer(localfile, localfile, 2000);
    Factory factory = new Factory(new InetSocketAddress(port), 0);
    factory.startup(zk);//from  ww w  .  j  a  va2 s. co m
    return factory;
}

From source file:com.api6.zkclient.util.ZKServer.java

License:Apache License

private void startZooKeeperServer() {
    //???//from w  ww. j a v  a2  s  .  c  o m
    if (isPortFree(port)) {
        final File dataDir = new File(dataPath);
        final File dataLogDir = new File(logPath);
        dataDir.mkdirs();
        dataLogDir.mkdirs();
        //? zk server
        LOG.info("data dir: " + dataDir.getAbsolutePath());
        LOG.info("data log dir: " + dataLogDir.getAbsolutePath());
        LOG.info("JAAS login file: " + System.getProperty("java.security.auth.login.config", "none"));

        try {
            zooKeeperServer = new ZooKeeperServer(dataDir, dataLogDir, tickTime);
            zooKeeperServer.setMinSessionTimeout(minSessionTimeout);
            nioFactory = new NIOServerCnxnFactory();
            int maxClientConnections = 0; // 0 means unlimited
            nioFactory.configure(new InetSocketAddress(port), maxClientConnections);
            nioFactory.startup(zooKeeperServer);
        } catch (IOException e) {
            throw new ZKException("Unable to start single ZooKeeper server.", e);
        } catch (InterruptedException e) {
            throw new ZKInterruptedException(e);
        }

    } else {
        throw new IllegalStateException("Zookeeper port " + port + " was already in use.");
    }
}

From source file:com.blackberry.bdp.common.versioned.LocalZkServer.java

License:Apache License

public LocalZkServer()
        throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException,
        IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException {
    String dataDirectory = System.getProperty("java.io.tmpdir");

    dir = new File(dataDirectory, "zookeeper").getAbsoluteFile();

    while (dir.exists()) {
        LOG.info("deleting {}", dir);
        FileUtils.deleteDirectory(dir);/*from   w w w. j  a  v  a2 s  .  co m*/
    }

    server = new ZooKeeperServer(dir, dir, tickTime);

    // The class that we need changed name between CDH3 and CDH4, so let's
    // check
    // for the right version here.
    try {
        factoryClass = Class.forName("org.apache.zookeeper.server.NIOServerCnxnFactory");

        standaloneServerFactory = factoryClass.newInstance();
        Method configure = factoryClass.getMethod("configure", InetSocketAddress.class, Integer.TYPE);
        configure.invoke(standaloneServerFactory, new InetSocketAddress(clientPort), numConnections);
        Method startup = factoryClass.getMethod("startup", ZooKeeperServer.class);
        startup.invoke(standaloneServerFactory, server);

    } catch (ClassNotFoundException e) {
        LOG.info("Did not find NIOServerCnxnFactory");
        try {
            factoryClass = Class.forName("org.apache.zookeeper.server.NIOServerCnxn$Factory");

            Constructor<?> constructor = factoryClass.getConstructor(InetSocketAddress.class, Integer.TYPE);
            standaloneServerFactory = constructor.newInstance(new InetSocketAddress(clientPort),
                    numConnections);
            Method startup = factoryClass.getMethod("startup", ZooKeeperServer.class);
            startup.invoke(standaloneServerFactory, server);

        } catch (ClassNotFoundException e1) {
            LOG.info("Did not find NIOServerCnxn.Factory");
            throw new ClassNotFoundException("Can't find NIOServerCnxnFactory or NIOServerCnxn.Factory");
        }
    }
}

From source file:com.blackberry.bdp.test.utils.LocalZkServer.java

License:Apache License

public LocalZkServer()
        throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException,
        IllegalArgumentException, InvocationTargetException, ClassNotFoundException, IOException {
    String dataDirectory = System.getProperty("java.io.tmpdir");

    dir = new File(dataDirectory, "zookeeper").getAbsoluteFile();

    while (dir.exists()) {
        LOG.info("deleting {}", dir);
        FileUtils.deleteDirectory(dir);/* ww w  .j  a  va2  s . c  om*/
    }

    server = new ZooKeeperServer(dir, dir, tickTime);

    // The class that we need changed name between CDH3 and CDH4, so let's check
    // for the right version here.
    try {
        factoryClass = Class.forName("org.apache.zookeeper.server.NIOServerCnxnFactory");

        standaloneServerFactory = factoryClass.newInstance();
        Method configure = factoryClass.getMethod("configure", InetSocketAddress.class, Integer.TYPE);
        configure.invoke(standaloneServerFactory, new InetSocketAddress(clientPort), numConnections);
        Method startup = factoryClass.getMethod("startup", ZooKeeperServer.class);
        startup.invoke(standaloneServerFactory, server);

    } catch (ClassNotFoundException e) {
        LOG.info("Did not find NIOServerCnxnFactory");
        try {
            factoryClass = Class.forName("org.apache.zookeeper.server.NIOServerCnxn$Factory");

            Constructor<?> constructor = factoryClass.getConstructor(InetSocketAddress.class, Integer.TYPE);
            standaloneServerFactory = constructor.newInstance(new InetSocketAddress(clientPort),
                    numConnections);
            Method startup = factoryClass.getMethod("startup", ZooKeeperServer.class);
            startup.invoke(standaloneServerFactory, server);

        } catch (ClassNotFoundException e1) {
            LOG.info("Did not find NIOServerCnxn.Factory");
            throw new ClassNotFoundException("Can't find NIOServerCnxnFactory or NIOServerCnxn.Factory");
        }
    }
}

From source file:com.consol.citrus.zookeeper.server.ZooServer.java

License:Apache License

/**
 * Gets the value of the zooKeeperServer property.
 *
 * @return the zooKeeperServer/* ww  w.  j a v  a 2 s.  c o m*/
 */
public ZooKeeperServer getZooKeeperServer() {
    if (zooKeeperServer == null) {
        String dataDirectory = System.getProperty("java.io.tmpdir");
        File dir = new File(dataDirectory, "zookeeper").getAbsoluteFile();
        try {
            zooKeeperServer = new ZooKeeperServer(dir, dir, 2000);
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to create default zoo keepers server", e);
        }
    }

    return zooKeeperServer;
}

From source file:com.datatorrent.contrib.hbase.HBaseTestHelper.java

License:Open Source License

private static void startZooKeeperServer() throws IOException, InterruptedException {
    String zooLocation = System.getProperty("java.io.tmpdir");
    File zooFile = new File(zooLocation, "zookeeper-malhartest");
    ZooKeeperServer zooKeeper = new ZooKeeperServer(zooFile, zooFile, 2000);

    NIOServerCnxnFactory serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(new InetSocketAddress(2181), 10);
    serverFactory.startup(zooKeeper);//from   w w w. ja v a  2  s . c o m
}

From source file:com.datatorrent.contrib.kafka.KafkaInputOperatorTest.java

License:Open Source License

public void startZookeeper() {
    if (!useZookeeper) { // Do not use zookeeper for simpleconsumer
        return;/*from  ww w  .j  a  v  a 2 s.  c  om*/
    }

    try {
        int clientPort = 2182;
        int numConnections = 5000;
        int tickTime = 2000;
        File dir = new File(zklogdir);

        ZooKeeperServer zserver = new ZooKeeperServer(dir, dir, tickTime);
        standaloneServerFactory = new NIOServerCnxnFactory();
        standaloneServerFactory.configure(new InetSocketAddress(clientPort), numConnections);
        standaloneServerFactory.startup(zserver); // start the zookeeper server.
    } catch (InterruptedException ex) {
        logger.debug(ex.getLocalizedMessage());
    } catch (IOException ex) {
        logger.debug(ex.getLocalizedMessage());
    }
}