# Class ServerCnxnFactory

java.lang.Object
org.apache.zookeeper.server.ServerCnxnFactory

Direct Known Subclasses:
  `NettyServerCnxnFactory, NIOServerCnxnFactory`

public abstract class ServerCnxnFactory extends Object

## Field Summary

Fields
Modifier and Type
Field
Description
`protected final Set<ServerCnxn>`
`cnxns`
`Login`
`login`
`protected int`
`maxCnxns`
`protected boolean`
`secure`
`protected ZooKeeperServer`
`zkServer`
`static final int`
`ZOOKEEPER_MAX_CONNECTION_DEFAULT`
`static final String`
`ZOOKEEPER_SERVER_CNXN_FACTORY`

## Constructor Summary

Constructors
Constructor
Description
`ServerCnxnFactory()`

## Method Summary

Modifier and Type
Method
Description
`void`
`addSession(long sessionId, ServerCnxn cnxn)`
`abstract void`
`closeAll(ServerCnxn.DisconnectReason reason)`
`boolean`
`closeSession(long sessionId, ServerCnxn.DisconnectReason reason)`
`void`
`configure(InetSocketAddress addr, int maxcc)`
`void`
`configure(InetSocketAddress addr, int maxcc, int backlog)`
`abstract void`
`configure(InetSocketAddress addr, int maxcc, int backlog, boolean secure)`
`protected void`
`configureSaslLogin()`
Initialize the server SASL if specified.
`static ServerCnxnFactory`
`createFactory()`
`static ServerCnxnFactory`
`createFactory(int clientPort, int maxClientCnxns)`
`static ServerCnxnFactory`
`createFactory(int clientPort, int maxClientCnxns, int backlog)`
`static ServerCnxnFactory`
`createFactory(InetSocketAddress addr, int maxClientCnxns)`
`static ServerCnxnFactory`
`createFactory(InetSocketAddress addr, int maxClientCnxns, int backlog)`
`abstract Iterable<Map<String,Object>>`
`getAllConnectionInfo(boolean brief)`
`abstract Iterable<ServerCnxn>`
`getConnections()`
`abstract InetSocketAddress`
`getLocalAddress()`
`abstract int`
`getLocalPort()`
`abstract int`
`getMaxClientCnxnsPerHost()`
Maximum number of connections allowed from particular host (ip)
`int`
`getMaxCnxns()`
Maximum number of connections allowed in the ZooKeeper system
`int`
`getNumAliveConnections()`
`abstract int`
`getSocketListenBacklog()`
The maximum queue length of the ZooKeeper server's socket
`static String`
`getUserName()`
User who has started the ZooKeeper server user, it will be the logged-in user.
`final ZooKeeperServer`
`getZooKeeperServer()`
`protected void`
`initMaxCnxns()`
`boolean`
`isSecure()`
`abstract void`
`join()`
`protected boolean`
`limitTotalNumberOfCnxns()`
Ensure total number of connections are less than the maxCnxns
`abstract void`
`reconfigure(InetSocketAddress addr)`
`void`
`registerConnection(ServerCnxn serverCnxn)`
`void`
`removeCnxnFromSessionMap(ServerCnxn cnxn)`
`abstract void`
`resetAllConnectionStats()`
`abstract void`
`setMaxClientCnxnsPerHost(int max)`
Maximum number of connections allowed from particular host (ip)
`final void`
`setZooKeeperServer(ZooKeeperServer zks)`
`abstract void`
`shutdown()`
`abstract void`
`start()`
`void`
`startup(ZooKeeperServer zkServer)`
`abstract void`
`startup(ZooKeeperServer zkServer, boolean startServer)`
`void`
`unregisterConnection(ServerCnxn serverCnxn)`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### ZOOKEEPER_SERVER_CNXN_FACTORY

public static final String ZOOKEEPER_SERVER_CNXN_FACTORY

See Also:
  - Constant Field Values

### ZOOKEEPER_MAX_CONNECTION_DEFAULT

public static final int ZOOKEEPER_MAX_CONNECTION_DEFAULT

See Also:
  - Constant Field Values

### secure

protected boolean secure

### maxCnxns

protected int maxCnxns

### login

public Login login

### zkServer

protected ZooKeeperServer zkServer

### cnxns

protected final Set<ServerCnxn> cnxns

## Constructor Details

### ServerCnxnFactory

public ServerCnxnFactory()

## Method Details

### addSession

public void addSession(long sessionId, ServerCnxn cnxn)

### removeCnxnFromSessionMap

public void removeCnxnFromSessionMap(ServerCnxn cnxn)

### closeSession

public boolean closeSession(long sessionId, ServerCnxn.DisconnectReason reason)

Returns:
  true if the cnxn that contains the sessionId exists in this ServerCnxnFactory and it's closed. Otherwise false.

### getLocalPort

public abstract int getLocalPort()

### getConnections

public abstract Iterable<ServerCnxn> getConnections()

### getNumAliveConnections

public int getNumAliveConnections()

### getZooKeeperServer

public final ZooKeeperServer getZooKeeperServer()

### configure

public void configure(InetSocketAddress addr, int maxcc) throws IOException

Throws:
  `IOException`

### configure

public void configure(InetSocketAddress addr, int maxcc, int backlog) throws IOException

Throws:
  `IOException`

### configure

public abstract void configure(InetSocketAddress addr, int maxcc, int backlog, boolean secure) throws IOException

Throws:
  `IOException`

### reconfigure

public abstract void reconfigure(InetSocketAddress addr)

### getMaxClientCnxnsPerHost

public abstract int getMaxClientCnxnsPerHost()
Maximum number of connections allowed from particular host (ip)

### setMaxClientCnxnsPerHost

public abstract void setMaxClientCnxnsPerHost(int max)
Maximum number of connections allowed from particular host (ip)

### isSecure

public boolean isSecure()

### startup

public void startup(ZooKeeperServer zkServer) throws IOException, InterruptedException

Throws:
  `IOException`
  `InterruptedException`

### startup

public abstract void startup(ZooKeeperServer zkServer, boolean startServer) throws IOException, InterruptedException

Throws:
  `IOException`
  `InterruptedException`

### getSocketListenBacklog

public abstract int getSocketListenBacklog()
The maximum queue length of the ZooKeeper server's socket

### join

public abstract void join() throws InterruptedException

Throws:
  `InterruptedException`

### shutdown

public abstract void shutdown()

### start

public abstract void start()

### setZooKeeperServer

public final void setZooKeeperServer(ZooKeeperServer zks)

### closeAll

public abstract void closeAll(ServerCnxn.DisconnectReason reason)

### createFactory

public static ServerCnxnFactory createFactory() throws IOException

Throws:
  `IOException`

### createFactory

public static ServerCnxnFactory createFactory(int clientPort, int maxClientCnxns) throws IOException

Throws:
  `IOException`

### createFactory

public static ServerCnxnFactory createFactory(int clientPort, int maxClientCnxns, int backlog) throws IOException

Throws:
  `IOException`

### createFactory

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

Throws:
  `IOException`

### createFactory

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

Throws:
  `IOException`

### getLocalAddress

public abstract InetSocketAddress getLocalAddress()

### resetAllConnectionStats

public abstract void resetAllConnectionStats()

### getAllConnectionInfo

public abstract Iterable<Map<String,Object>> getAllConnectionInfo(boolean brief)

### unregisterConnection

public void unregisterConnection(ServerCnxn serverCnxn)

### registerConnection

public void registerConnection(ServerCnxn serverCnxn)

### configureSaslLogin

protected void configureSaslLogin() throws IOException
Initialize the server SASL if specified. If the user has specified a "ZooKeeperServer.LOGIN_CONTEXT_NAME_KEY" or a jaas.conf using "java.security.auth.login.config" the authentication is required and an exception is raised. Otherwise no authentication is configured and no exception is raised.

Throws:
  `IOException` - if jaas.conf is missing or there's an error in it.

### getUserName

public static String getUserName()
User who has started the ZooKeeper server user, it will be the logged-in user. If no user logged-in then system user

### getMaxCnxns

public int getMaxCnxns()
Maximum number of connections allowed in the ZooKeeper system

### initMaxCnxns

protected void initMaxCnxns()

### limitTotalNumberOfCnxns

protected boolean limitTotalNumberOfCnxns()
Ensure total number of connections are less than the maxCnxns