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

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

Introduction

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

Prototype

public abstract int getMaxClientCnxnsPerHost();

Source Link

Document

Maximum number of connections allowed from particular host (ip)

Usage

From source file:com.palantir.curatortestrule.DefaultZooKeeperRuleConfig.java

License:Open Source License

@Override
public ServerCnxnFactory getServer(int port) {
    ZooKeeperServer zkServer = new NoJMXZooKeeperServer();

    FileTxnSnapLog ftxn;//from   w  w  w  . j av a2  s. c om
    try {
        File dataDir = Files.createTempDir();
        File snapDir = Files.createTempDir();
        if (cleanupOnExit) {
            directoriesToCleanup.add(dataDir);
            directoriesToCleanup.add(snapDir);
        }
        ftxn = new FileTxnSnapLog(dataDir, snapDir);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    zkServer.setTxnLogFactory(ftxn);

    try {
        ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
        cnxnFactory.configure(new InetSocketAddress(port), cnxnFactory.getMaxClientCnxnsPerHost());
        cnxnFactory.startup(zkServer);

        return cnxnFactory;
    } catch (IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
}