2121import java .io .File ;
2222import java .io .FileInputStream ;
2323import java .io .IOException ;
24+ import java .nio .file .Path ;
2425import java .util .HashMap ;
2526import java .util .Map ;
2627import java .util .Map .Entry ;
2728import java .util .Properties ;
2829import org .apache .zookeeper .Environment ;
29- import org .apache .zookeeper .server .quorum .QuorumPeerConfig . ConfigException ;
30+ import org .apache .zookeeper .server .quorum .QuorumPeerConfig ;
3031import org .apache .zookeeper .server .util .VerifyingFileFactory ;
3132import org .slf4j .Logger ;
3233import org .slf4j .LoggerFactory ;
@@ -62,29 +63,50 @@ public ZKConfig() {
6263 }
6364
6465 /**
66+ * <p><b>Use {@link ZKConfig#ZKConfig(Path configPath)} instead.</b>
67+ *
68+ * <p><b>The signature of this method will be changed to throw {@link ConfigException}
69+ * instead of {@link QuorumPeerConfig.ConfigException} in future release.</b>
70+ *
6571 * @param configPath
6672 * Configuration file path
6773 * @throws ConfigException
6874 * if failed to load configuration properties
6975 */
70-
71- public ZKConfig (String configPath ) throws ConfigException {
76+ @ Deprecated
77+ public ZKConfig (String configPath ) throws QuorumPeerConfig . ConfigException {
7278 this (new File (configPath ));
7379 }
7480
7581 /**
82+ * <p><b>Use {@link ZKConfig#ZKConfig(Path configPath)} instead.</b>
83+ *
84+ * <p><b>The signature of this method will be changed to throw {@link ConfigException}
85+ * instead of {@link QuorumPeerConfig.ConfigException} in future release.</b>
7686 *
7787 * @param configFile
7888 * Configuration file
7989 * @throws ConfigException
8090 * if failed to load configuration properties
8191 */
82- public ZKConfig (File configFile ) throws ConfigException {
92+ @ Deprecated
93+ public ZKConfig (File configFile ) throws QuorumPeerConfig .ConfigException {
8394 this ();
8495 addConfiguration (configFile );
8596 LOG .info ("ZK Config {}" , this .properties );
8697 }
8798
99+ /**
100+ * Constructs a {@link ZKConfig} with properties from file.
101+ *
102+ * @param configPath path to configuration file
103+ * @throws ConfigException
104+ */
105+ @ SuppressWarnings ("deprecation" )
106+ public ZKConfig (Path configPath ) throws ConfigException {
107+ this (configPath .toFile ());
108+ }
109+
88110 private void init () {
89111 /**
90112 * backward compatibility for all currently available client properties
@@ -191,10 +213,27 @@ public void setProperty(String key, String value) {
191213 * Add a configuration resource. The properties form this configuration will
192214 * overwrite corresponding already loaded property and system property
193215 *
216+ * @param configPath path to Configuration file.
217+ */
218+ @ SuppressWarnings ("deprecation" )
219+ public void addConfiguration (Path configPath ) throws ConfigException {
220+ addConfiguration (configPath .toFile ());
221+ }
222+
223+ /**
224+ * <p><b>Use {@link #addConfiguration(Path)} instead.</b></p>
225+ *
226+ * <p><b>The signature of this method will be changed to throw {@link ConfigException}
227+ * instead of {@link QuorumPeerConfig.ConfigException} in future release.</b>
228+ *
229+ * <p>Add a configuration resource. The properties form this configuration will
230+ * overwrite corresponding already loaded property and system property
231+ *
194232 * @param configFile
195233 * Configuration file.
196234 */
197- public void addConfiguration (File configFile ) throws ConfigException {
235+ @ Deprecated
236+ public void addConfiguration (File configFile ) throws QuorumPeerConfig .ConfigException {
198237 LOG .info ("Reading configuration from: {}" , configFile .getAbsolutePath ());
199238 try {
200239 configFile = (new VerifyingFileFactory .Builder (LOG ).warnForRelativePath ()
@@ -210,18 +249,24 @@ public void addConfiguration(File configFile) throws ConfigException {
210249 parseProperties (cfg );
211250 } catch (IOException | IllegalArgumentException e ) {
212251 LOG .error ("Error while configuration from: {}" , configFile .getAbsolutePath (), e );
213- throw new ConfigException ("Error while processing " + configFile .getAbsolutePath (), e );
252+ throw new QuorumPeerConfig . ConfigException ("Error while processing " + configFile .getAbsolutePath (), e );
214253 }
215254 }
216255
217256 /**
218- * Add a configuration resource. The properties form this configuration will
257+ * <p><b>Use {@link #addConfiguration(Path)} instead.</b></p>
258+ *
259+ * <p><b>The signature of this method will be changed to throw {@link ConfigException}
260+ * instead of {@link QuorumPeerConfig.ConfigException} in future release.</b>
261+ *
262+ * <p>Add a configuration resource. The properties form this configuration will
219263 * overwrite corresponding already loaded property and system property
220264 *
221265 * @param configPath
222266 * Configuration file path.
223267 */
224- public void addConfiguration (String configPath ) throws ConfigException {
268+ @ Deprecated
269+ public void addConfiguration (String configPath ) throws QuorumPeerConfig .ConfigException {
225270 addConfiguration (new File (configPath ));
226271 }
227272
0 commit comments