# Class ControllableConnectionFactory

java.lang.Object
org.apache.zookeeper.server.ServerCnxnFactory
org.apache.zookeeper.server.NIOServerCnxnFactory
org.apache.zookeeper.server.controller.ControllableConnectionFactory

public class ControllableConnectionFactory extends NIOServerCnxnFactory
Extension of NIOServerCnxnFactory which can inject changes per controller commands. Similar extensions can implement on top of NettyServerCnxnFactory as well.

## Nested Class Summary

### Nested classes/interfaces inherited from class NIOServerCnxnFactory

`NIOServerCnxnFactory.SelectorThread`

## Field Summary

### Fields inherited from class NIOServerCnxnFactory

`maxClientCnxns, workerPool, ZOOKEEPER_NIO_DIRECT_BUFFER_BYTES, ZOOKEEPER_NIO_NUM_SELECTOR_THREADS, ZOOKEEPER_NIO_NUM_WORKER_THREADS, ZOOKEEPER_NIO_SESSIONLESS_CNXN_TIMEOUT, ZOOKEEPER_NIO_SHUTDOWN_TIMEOUT`

### Fields inherited from class ServerCnxnFactory

`cnxns, login, maxCnxns, secure, zkServer, ZOOKEEPER_MAX_CONNECTION_DEFAULT, ZOOKEEPER_SERVER_CNXN_FACTORY`

## Constructor Summary

Constructors
Constructor
Description
`ControllableConnectionFactory()`

## Method Summary

Modifier and Type
Method
Description
`protected NIOServerCnxn`
`createConnection(SocketChannel sock, SelectionKey sk, NIOServerCnxnFactory.SelectorThread selectorThread)`
`void`
`delayRequestIfNeeded()`
Called by the connection to delay processing requests from the client.
`void`
`delayResponses(long delayInMs)`
`void`
`failAllFutureRequests()`
`void`
`failFutureRequests(long requestsToFail)`
`void`
`holdAllFutureResponses()`
`void`
`holdFutureResponses(long requestsToHold)`
`void`
`resetBadBehavior()`
`boolean`
`shouldFailNextRequest()`
Check if we should fail the next incoming request.
`boolean`
`shouldSendResponse()`
Check if we should send a response to the latest processed request (true), or eat the response to mess with the client (false).

### Methods inherited from class NIOServerCnxnFactory

`closeAll, configure, dumpConnections, getAllConnectionInfo, getConnections, getDirectBuffer, getLocalAddress, getLocalPort, getMaxClientCnxnsPerHost, getSocketListenBacklog, join, reconfigure, removeCnxn, resetAllConnectionStats, setMaxClientCnxnsPerHost, shutdown, start, startup, stop, touchCnxn`

### Methods inherited from class ServerCnxnFactory

`addSession, closeSession, configure, configure, configureSaslLogin, createFactory, createFactory, createFactory, createFactory, createFactory, getMaxCnxns, getNumAliveConnections, getUserName, getZooKeeperServer, initMaxCnxns, isSecure, limitTotalNumberOfCnxns, registerConnection, removeCnxnFromSessionMap, setZooKeeperServer, startup, unregisterConnection`

### Methods inherited from class Object

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

## Constructor Details

### ControllableConnectionFactory

public ControllableConnectionFactory()

## Method Details

### createConnection

protected NIOServerCnxn createConnection(SocketChannel sock, SelectionKey sk, NIOServerCnxnFactory.SelectorThread selectorThread) throws IOException

Overrides:
  `createConnection` in class `NIOServerCnxnFactory`
Throws:
  `IOException`

### delayRequestIfNeeded

public void delayRequestIfNeeded()
Called by the connection to delay processing requests from the client.

### shouldFailNextRequest

public boolean shouldFailNextRequest()
Check if we should fail the next incoming request. If so, decrement the remaining requests to fail.

### shouldSendResponse

public boolean shouldSendResponse()
Check if we should send a response to the latest processed request (true), or eat the response to mess with the client (false). If so, decrement the remaining requests to eat.

### delayResponses

public void delayResponses(long delayInMs)

### resetBadBehavior

public void resetBadBehavior()

### failAllFutureRequests

public void failAllFutureRequests()

### failFutureRequests

public void failFutureRequests(long requestsToFail)

### holdAllFutureResponses

public void holdAllFutureResponses()

### holdFutureResponses

public void holdFutureResponses(long requestsToHold)