Skip to content

Commit 6db60e3

Browse files
committed
📝 Add comprehensive JavaDoc to org.restheart.configuration package of module commons
1 parent 2c5371c commit 6db60e3

File tree

10 files changed

+1484
-89
lines changed

10 files changed

+1484
-89
lines changed

commons/src/main/java/org/restheart/configuration/Configuration.java

Lines changed: 314 additions & 41 deletions
Large diffs are not rendered by default.

commons/src/main/java/org/restheart/configuration/ConfigurationException.java

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,91 @@
2020
package org.restheart.configuration;
2121

2222
/**
23-
*
23+
* Exception thrown when configuration loading or validation fails.
24+
*
25+
* <p>This exception is thrown in various scenarios:</p>
26+
* <ul>
27+
* <li>Configuration file is not found or cannot be read</li>
28+
* <li>Configuration file has invalid syntax (YAML/JSON parse errors)</li>
29+
* <li>Required configuration properties are missing</li>
30+
* <li>Configuration values are invalid or out of acceptable range</li>
31+
* <li>Override files have unsupported extensions or invalid format</li>
32+
* </ul>
33+
*
34+
* <p>The exception includes a flag {@code shouldPrintStackTrace} that indicates
35+
* whether the full stack trace should be printed. This is typically set to false
36+
* for user-friendly errors (like missing files) and true for unexpected errors
37+
* (like parse exceptions).</p>
38+
*
2439
* @author Andrea Di Cesare {@literal <andrea@softinstigate.com>}
40+
* @since 1.0
2541
*/
2642
public class ConfigurationException extends IllegalArgumentException {
2743
private static final long serialVersionUID = 1685800316196830205L;
2844
private final boolean shoudlPrintStackTrace;
2945

46+
/**
47+
* Constructs a new ConfigurationException with no message.
48+
*
49+
* <p>Stack trace printing is disabled by default for this constructor.</p>
50+
*/
3051
public ConfigurationException() {
3152
super();
3253
this.shoudlPrintStackTrace = false;
3354
}
3455

56+
/**
57+
* Constructs a new ConfigurationException with the specified message.
58+
*
59+
* <p>Stack trace printing is disabled by default for this constructor.
60+
* This is typically used for user-friendly error messages.</p>
61+
*
62+
* @param message the detail message explaining the configuration error
63+
*/
3564
public ConfigurationException(String message) {
3665
super(message);
3766
this.shoudlPrintStackTrace = false;
3867
}
3968

69+
/**
70+
* Constructs a new ConfigurationException with message and cause.
71+
*
72+
* <p>Stack trace printing is enabled by default for this constructor.
73+
* This is typically used for unexpected errors that require debugging.</p>
74+
*
75+
* @param message the detail message explaining the configuration error
76+
* @param cause the underlying cause of the configuration error
77+
*/
4078
public ConfigurationException(String message, Throwable cause) {
4179
super(message, cause);
4280
this.shoudlPrintStackTrace = true;
4381
}
4482

83+
/**
84+
* Constructs a new ConfigurationException with full control over stack trace printing.
85+
*
86+
* <p>This constructor allows explicit control over whether the stack trace
87+
* should be printed when the exception is logged. Use this when you want
88+
* to provide a cause but control the verbosity of error output.</p>
89+
*
90+
* @param message the detail message explaining the configuration error
91+
* @param cause the underlying cause of the configuration error
92+
* @param shoudlPrintStackTrace true if stack trace should be printed when logged
93+
*/
4594
public ConfigurationException(String message, Throwable cause, boolean shoudlPrintStackTrace) {
4695
super(message, cause);
4796
this.shoudlPrintStackTrace = shoudlPrintStackTrace;
4897
}
4998

99+
/**
100+
* Indicates whether the stack trace should be printed when this exception is logged.
101+
*
102+
* <p>This is used by error handlers to determine the appropriate level of
103+
* detail to show to users. User-friendly errors (like missing files) typically
104+
* return false, while unexpected errors return true.</p>
105+
*
106+
* @return true if the stack trace should be printed, false otherwise
107+
*/
50108
public boolean shoudlPrintStackTrace() {
51109
return shoudlPrintStackTrace;
52110
}

commons/src/main/java/org/restheart/configuration/CoreModule.java

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,45 @@
2626
import static org.restheart.configuration.Utils.asMap;
2727
import static org.restheart.configuration.Utils.getOrDefault;
2828

29+
/**
30+
* Core configuration module containing essential RESTHeart settings.
31+
*
32+
* <p>This record encapsulates the core configuration parameters that control
33+
* RESTHeart's fundamental behavior including plugin management, threading,
34+
* buffering, and URL handling.</p>
35+
*
36+
* <h2>Configuration Structure</h2>
37+
* <p>In the configuration file, these settings are under the {@code core} section:</p>
38+
* <pre>{@code
39+
* core:
40+
* name: "my-restheart"
41+
* plugins-directory: "./plugins"
42+
* plugins-packages:
43+
* - "org.restheart.plugins"
44+
* - "com.example.myplugins"
45+
* io-threads: 4
46+
* workers-scheduler-parallelism: 8
47+
* buffer-size: 16384
48+
* direct-buffers: true
49+
* }</pre>
50+
*
51+
* @param name the instance name for this RESTHeart server
52+
* @param pluginsDirectory path to the directory containing plugin JARs
53+
* @param pluginsPackages list of Java packages to scan for plugins
54+
* @param pluginsScanningVerbose if true, enables verbose logging during plugin scanning
55+
* @param baseUrl the base URL for this instance (optional, for URL construction)
56+
* @param ioThreads number of I/O threads (0 for automatic based on CPU cores)
57+
* @param workersSchedulerParallelism parallelism level for the workers thread pool
58+
* @param workersSchedulerMaxPoolSize maximum size of the workers thread pool
59+
* @param buffersPooling if true, enables buffer pooling for better performance
60+
* @param bufferSize size of I/O buffers in bytes
61+
* @param directBuffers if true, uses direct (off-heap) buffers
62+
* @param forceGzipEncoding if true, forces GZIP encoding for all responses
63+
* @param allowUnescapedCharsInUrl if true, allows unescaped characters in URLs
64+
*
65+
* @author Andrea Di Cesare {@literal <andrea@softinstigate.com>}
66+
* @since 1.0
67+
*/
2968
public record CoreModule(String name,
3069
String pluginsDirectory,
3170
List<String> pluginsPackages,
@@ -40,23 +79,104 @@ public record CoreModule(String name,
4079
boolean forceGzipEncoding,
4180
boolean allowUnescapedCharsInUrl) {
4281

82+
/**
83+
* Configuration key for the core section in the configuration file.
84+
*/
4385
public static final String CORE_KEY = "core";
86+
87+
/**
88+
* Configuration key for the instance name.
89+
*/
4490
public static final String INSTANCE_NAME_KEY = "name";
91+
92+
/**
93+
* Configuration key for the plugins directory path.
94+
*/
4595
public static final String PLUGINS_DIRECTORY_PATH_KEY = "plugins-directory";
96+
97+
/**
98+
* Configuration key for the list of packages to scan for plugins.
99+
*/
46100
public static final String PLUGINS_PACKAGES_KEY = "plugins-packages";
101+
102+
/**
103+
* Configuration key for enabling verbose plugin scanning output.
104+
*/
47105
public static final String PLUGINS_SCANNING_VERBOSE_KEY = "plugins-scanning-verbose";
106+
107+
/**
108+
* Configuration key for the base URL of this instance.
109+
*/
48110
public static final String BASE_URL_KEY = "base-url";
111+
112+
/**
113+
* Configuration key for the number of I/O threads.
114+
*/
49115
public static final String IO_THREADS_KEY = "io-threads";
116+
117+
/**
118+
* Configuration key for workers scheduler parallelism level.
119+
*/
50120
public static final String WORKERS_SCHEDULER_PARALLELISM_KEY ="workers-scheduler-parallelism";
121+
122+
/**
123+
* Configuration key for workers scheduler maximum pool size.
124+
*/
51125
public static final String WORKERS_SCHEDULER_MAX_POOL_SIZE_KEY = "workers-scheduler-max-pool-size";
126+
127+
/**
128+
* Configuration key for enabling buffer pooling.
129+
*/
52130
public static final String BUFFERS_POOLING_KEY = "buffers-pooling";
131+
132+
/**
133+
* Configuration key for the I/O buffer size in bytes.
134+
*/
53135
public static final String BUFFER_SIZE_KEY = "buffer-size";
136+
137+
/**
138+
* Configuration key for enabling direct (off-heap) buffers.
139+
*/
54140
public static final String DIRECT_BUFFERS_KEY = "direct-buffers";
141+
142+
/**
143+
* Configuration key for forcing GZIP encoding on responses.
144+
*/
55145
public static final String FORCE_GZIP_ENCODING_KEY = "force-gzip-encoding";
146+
147+
/**
148+
* Configuration key for allowing unescaped characters in URLs.
149+
*/
56150
public static final String ALLOW_UNESCAPED_CHARS_IN_ULR_KEY = "allow-unescaped-characters-in-url";
57151

152+
/**
153+
* Default CoreModule configuration used when no configuration is provided.
154+
*
155+
* <p>Default values:</p>
156+
* <ul>
157+
* <li>name: "default"</li>
158+
* <li>plugins-directory: "plugins"</li>
159+
* <li>plugins-packages: empty list</li>
160+
* <li>io-threads: 0 (auto-detect based on CPU cores)</li>
161+
* <li>workers-scheduler-parallelism: 0 (uses default)</li>
162+
* <li>workers-scheduler-max-pool-size: 256</li>
163+
* <li>buffer-size: 16384 bytes</li>
164+
* <li>direct-buffers: true</li>
165+
* <li>force-gzip-encoding: false</li>
166+
* <li>allow-unescaped-characters-in-url: true</li>
167+
* </ul>
168+
*/
58169
private static final CoreModule DEFAULT_CORE_MODULE = new CoreModule("default", "plugins", new ArrayList<>(), false, null, 0, 0, 256, true, 16364, true, false, true);
59170

171+
/**
172+
* Creates a CoreModule from a configuration map.
173+
*
174+
* <p>This constructor extracts core configuration values from the provided map,
175+
* using default values for any missing properties.</p>
176+
*
177+
* @param conf the configuration map containing core settings
178+
* @param silent if true, suppresses warning messages for missing optional properties
179+
*/
60180
public CoreModule(Map<String, Object> conf, boolean silent) {
61181
this(getOrDefault(conf, INSTANCE_NAME_KEY, DEFAULT_CORE_MODULE.name(), silent),
62182
getOrDefault(conf, PLUGINS_DIRECTORY_PATH_KEY, DEFAULT_CORE_MODULE.pluginsDirectory(), silent),
@@ -76,6 +196,17 @@ public CoreModule(Map<String, Object> conf, boolean silent) {
76196
getOrDefault(conf, ALLOW_UNESCAPED_CHARS_IN_ULR_KEY, DEFAULT_CORE_MODULE.allowUnescapedCharsInUrl(), true));
77197
}
78198

199+
/**
200+
* Builds a CoreModule from the main configuration map.
201+
*
202+
* <p>This method looks for the {@code core} section in the configuration map.
203+
* If found, it creates a CoreModule from that section. If not found, returns
204+
* the default CoreModule configuration.</p>
205+
*
206+
* @param conf the main configuration map
207+
* @param silent if true, suppresses warning messages for missing optional properties
208+
* @return a CoreModule instance with configuration values or defaults
209+
*/
79210
public static CoreModule build(Map<String, Object> conf, boolean silent) {
80211
var core = asMap(conf, CORE_KEY, null, silent);
81212

commons/src/main/java/org/restheart/configuration/Listener.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,82 @@
2222
import static org.restheart.configuration.Utils.findOrDefault;
2323
import java.util.Map;
2424

25+
/**
26+
* Configuration for HTTP and AJP protocol listeners.
27+
*
28+
* <p>This record represents the configuration for network listeners that handle
29+
* incoming HTTP or AJP (Apache JServ Protocol) connections. Each listener can be
30+
* independently enabled or disabled and configured with specific host and port
31+
* bindings.</p>
32+
*
33+
* <h2>Configuration Structure</h2>
34+
* <p>In the configuration file, listeners are configured as:</p>
35+
* <pre>{@code
36+
* http-listener:
37+
* enabled: true
38+
* host: "0.0.0.0"
39+
* port: 8080
40+
*
41+
* ajp-listener:
42+
* enabled: false
43+
* host: "localhost"
44+
* port: 8009
45+
* }</pre>
46+
*
47+
* <h2>Host Binding</h2>
48+
* <p>The host parameter controls which network interfaces the listener binds to:</p>
49+
* <ul>
50+
* <li>{@code "localhost"} or {@code "127.0.0.1"} - only local connections</li>
51+
* <li>{@code "0.0.0.0"} - all available interfaces (use with caution)</li>
52+
* <li>Specific IP address - binds to that interface only</li>
53+
* </ul>
54+
*
55+
* @param enabled whether this listener should be activated
56+
* @param host the hostname or IP address to bind to
57+
* @param port the port number to listen on
58+
*
59+
* @author Andrea Di Cesare {@literal <andrea@softinstigate.com>}
60+
* @since 1.0
61+
*/
2562
public record Listener(boolean enabled, String host, int port) {
63+
/**
64+
* Configuration key for the HTTP listener section.
65+
*/
2666
public static final String HTTP_LISTENER_KEY = "http-listener";
67+
68+
/**
69+
* Configuration key for the AJP listener section.
70+
*/
2771
public static final String AJP_LISTENER_KEY = "ajp-listener";
72+
73+
/**
74+
* Configuration key for enabling/disabling the listener.
75+
*/
2876
public static final String ENABLED_KEY = "enabled";
77+
78+
/**
79+
* Configuration key for the host/IP binding.
80+
*/
2981
public static final String HOST_KEY = "host";
82+
83+
/**
84+
* Configuration key for the port number.
85+
*/
3086
public static final String PORT_KEY = "port";
3187

88+
/**
89+
* Creates a Listener from a configuration map.
90+
*
91+
* <p>This constructor extracts listener configuration values from the provided map
92+
* under the specified listener key (e.g., "http-listener" or "ajp-listener").
93+
* If any values are missing, the corresponding values from the defaultValue
94+
* parameter are used.</p>
95+
*
96+
* @param conf the main configuration map
97+
* @param listenerKey the key for this listener section (e.g., "http-listener")
98+
* @param defaultValue default values to use for missing configuration
99+
* @param silent if true, suppresses warning messages for missing properties
100+
*/
32101
public Listener(Map<String, Object> conf, String listenerKey, Listener defaultValue, boolean silent) {
33102
this(findOrDefault(conf, "/" + listenerKey + "/" + ENABLED_KEY, defaultValue.enabled(), silent),
34103
findOrDefault(conf, "/" + listenerKey + "/" + HOST_KEY, defaultValue.host(), silent),

0 commit comments

Comments
 (0)