Package io.debezium.kafka
Class ZookeeperServer
java.lang.Object
io.debezium.kafka.ZookeeperServer
A lightweight embeddable Zookeeper server useful for unit testing.
- Author:
- Randall Hauch
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Filestatic intprivate org.apache.zookeeper.server.ServerCnxnFactoryprivate Fileprivate static final org.slf4j.Loggerprivate intprivate org.apache.zookeeper.server.ZooKeeperServerprivate Fileprivate intThe basic time unit in milliseconds used by ZooKeeper. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGet the connection string.(package private) FileGet the parent directory where the server's logs are kept.intgetPort()Get the current port.(package private) FileGet the parent directory where the server's snapshots are kept.Get the parent directory where the server's logs and snapshots will be kept.intGet the basic time unit in milliseconds used by ZooKeeper.(package private) voidonEachDirectory(Consumer<File> consumer) Perform the supplied function on each directory used by this server.setPort(int port) Set the port for the server.setStateDirectory(File dataDir) Set the parent directory where the server's logs and snapshots will be kept.setTickTime(int tickTime) Set the basic time unit in milliseconds used by ZooKeeper.voidshutdown()Shutdown the embedded Zookeeper server and delete all data.voidshutdown(boolean deleteData) Shutdown the embedded Kafka server.startup()Start the embedded Zookeeper server.toString()
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
DEFAULT_TICK_TIME
public static int DEFAULT_TICK_TIME -
tickTime
private volatile int tickTimeThe basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime. -
port
private volatile int port -
factory
private volatile org.apache.zookeeper.server.ServerCnxnFactory factory -
dataDir
-
snapshotDir
-
logDir
-
server
private volatile org.apache.zookeeper.server.ZooKeeperServer server
-
-
Constructor Details
-
ZookeeperServer
public ZookeeperServer()Create a new server instance.
-
-
Method Details
-
startup
Start the embedded Zookeeper server.- Returns:
- this instance to allow chaining methods; never null
- Throws:
IOException- if there is an error during startupIllegalStateException- if the server is already running
-
shutdown
public void shutdown()Shutdown the embedded Zookeeper server and delete all data. -
shutdown
public void shutdown(boolean deleteData) Shutdown the embedded Kafka server.- Parameters:
deleteData- true if the data should be removed, or false otherwise
-
getConnection
Get the connection string. If the server is notrunningand the port is to be dynamically discovered upon startup, then this method returns "localhost:-1".- Returns:
- the connection string; never null
-
setPort
Set the port for the server.- Parameters:
port- the desired port, or-1if a random available port should be found and used- Returns:
- this instance to allow chaining methods; never null
-
setTickTime
Set the basic time unit in milliseconds used by ZooKeeper. It is used to do heartbeats and the minimum session timeout will be twice the tickTime.- Parameters:
tickTime- the desired value, or non-positive if the default ofDEFAULT_TICK_TIMEbe used- Returns:
- this instance to allow chaining methods; never null
-
getPort
public int getPort()Get the current port.- Returns:
- the port number, or
-1if the port should be discovered uponstartup()
-
getTickTime
public int getTickTime()Get the basic time unit in milliseconds used by ZooKeeper.- Returns:
- tick time; always positive
-
onEachDirectory
Perform the supplied function on each directory used by this server.- Parameters:
consumer- the consumer function; may not be null
-
getSnapshotDirectory
File getSnapshotDirectory()Get the parent directory where the server's snapshots are kept.- Returns:
- the parent directory for the server's snapshots; never null once the server is running
-
getLogDirectory
File getLogDirectory()Get the parent directory where the server's logs are kept.- Returns:
- the parent directory for the server's logs; never null once the server is running
-
getStateDirectory
Get the parent directory where the server's logs and snapshots will be kept.- Returns:
- the parent directory for the server's logs and snapshots; may be null if a temporary directory will be used
-
setStateDirectory
Set the parent directory where the server's logs and snapshots will be kept.- Parameters:
dataDir- the parent directory for the server's logs and snapshots; may be null if a temporary directory will be used- Returns:
- this instance to allow method chaining; never null
- Throws:
IllegalArgumentException- if the supplied file is not a directory or not writable
-
toString
-