@@ -70,8 +70,15 @@ public static void reset() {
7070 nextServerId .set (1 );
7171 }
7272
73+ /**
74+ * Create a builder to construct {@link InstanceSpec}.
75+ */
76+ public static InstanceSpecBuilder builder () {
77+ return new InstanceSpecBuilder ();
78+ }
79+
7380 public static InstanceSpec newInstanceSpec () {
74- return new InstanceSpec ( null , - 1 , - 1 , - 1 , true , - 1 , - 1 , - 1 );
81+ return builder (). build ( );
7582 }
7683
7784 public static int getRandomPort () {
@@ -94,13 +101,16 @@ public static int getRandomPort() {
94101 }
95102
96103 /**
104+ * @deprecated Use {@link #builder()} instead.
105+ *
97106 * @param dataDirectory where to store data/logs/etc.
98107 * @param port the port to listen on - each server in the ensemble must use a unique port
99108 * @param electionPort the electionPort to listen on - each server in the ensemble must use a unique electionPort
100109 * @param quorumPort the quorumPort to listen on - each server in the ensemble must use a unique quorumPort
101110 * @param deleteDataDirectoryOnClose if true, the data directory will be deleted when {@link TestingCluster#close()} is called
102111 * @param serverId the server ID for the instance
103112 */
113+ @ Deprecated
104114 public InstanceSpec (
105115 File dataDirectory ,
106116 int port ,
@@ -112,6 +122,8 @@ public InstanceSpec(
112122 }
113123
114124 /**
125+ * @deprecated Use {@link #builder()} instead.
126+ *
115127 * @param dataDirectory where to store data/logs/etc.
116128 * @param port the port to listen on - each server in the ensemble must use a unique port
117129 * @param electionPort the electionPort to listen on - each server in the ensemble must use a unique electionPort
@@ -121,6 +133,7 @@ public InstanceSpec(
121133 * @param tickTime tickTime. Set -1 to used fault server configuration
122134 * @param maxClientCnxns max number of client connections from the same IP. Set -1 to use default server configuration
123135 */
136+ @ Deprecated
124137 public InstanceSpec (
125138 File dataDirectory ,
126139 int port ,
@@ -144,6 +157,8 @@ public InstanceSpec(
144157 }
145158
146159 /**
160+ * @deprecated Use {@link #builder()} instead.
161+ *
147162 * @param dataDirectory where to store data/logs/etc.
148163 * @param port the port to listen on - each server in the ensemble must use a unique port
149164 * @param electionPort the electionPort to listen on - each server in the ensemble must use a unique electionPort
@@ -154,6 +169,7 @@ public InstanceSpec(
154169 * @param maxClientCnxns max number of client connections from the same IP. Set -1 to use default server configuration
155170 * @param customProperties other properties to be passed to the server
156171 */
172+ @ Deprecated
157173 public InstanceSpec (
158174 File dataDirectory ,
159175 int port ,
@@ -178,6 +194,8 @@ public InstanceSpec(
178194 }
179195
180196 /**
197+ * @deprecated Use {@link #builder()} instead.
198+ *
181199 * @param dataDirectory where to store data/logs/etc.
182200 * @param port the port to listen on - each server in the ensemble must use a unique port
183201 * @param electionPort the electionPort to listen on - each server in the ensemble must use a unique electionPort
@@ -189,6 +207,7 @@ public InstanceSpec(
189207 * @param customProperties other properties to be passed to the server
190208 * @param hostname Hostname or IP if the cluster is intending to be bounded into external interfaces
191209 */
210+ @ Deprecated
192211 public InstanceSpec (
193212 File dataDirectory ,
194213 int port ,
@@ -200,6 +219,32 @@ public InstanceSpec(
200219 int maxClientCnxns ,
201220 Map <String , Object > customProperties ,
202221 String hostname ) {
222+ this (
223+ dataDirectory ,
224+ port ,
225+ electionPort ,
226+ quorumPort ,
227+ deleteDataDirectoryOnClose ,
228+ serverId ,
229+ tickTime ,
230+ maxClientCnxns ,
231+ customProperties != null ? enforceStringMap (customProperties ) : null ,
232+ hostname ,
233+ false );
234+ }
235+
236+ InstanceSpec (
237+ File dataDirectory ,
238+ int port ,
239+ int electionPort ,
240+ int quorumPort ,
241+ boolean deleteDataDirectoryOnClose ,
242+ int serverId ,
243+ int tickTime ,
244+ int maxClientCnxns ,
245+ Map <String , Object > customProperties ,
246+ String hostname ,
247+ boolean ignored ) {
203248 this .dataDirectory = (dataDirectory != null ) ? dataDirectory : DirectoryUtils .createTempDirectory ();
204249 this .port = (port >= 0 ) ? port : getRandomPort ();
205250 this .electionPort = (electionPort >= 0 ) ? electionPort : getRandomPort ();
@@ -208,9 +253,8 @@ public InstanceSpec(
208253 this .serverId = (serverId >= 0 ) ? serverId : nextServerId .getAndIncrement ();
209254 this .tickTime = (tickTime > 0 ? tickTime : -1 ); // -1 to set default value
210255 this .maxClientCnxns = (maxClientCnxns >= 0 ? maxClientCnxns : -1 ); // -1 to set default value
211- this .customProperties = customProperties != null
212- ? Collections .unmodifiableMap (enforceStringMap (customProperties ))
213- : Collections .emptyMap ();
256+ this .customProperties =
257+ customProperties != null ? Collections .unmodifiableMap (customProperties ) : Collections .emptyMap ();
214258 this .hostname = hostname == null ? localhost : hostname ;
215259 }
216260
0 commit comments