26
26
import static org .restheart .configuration .Utils .asMap ;
27
27
import static org .restheart .configuration .Utils .getOrDefault ;
28
28
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
+ */
29
68
public record CoreModule (String name ,
30
69
String pluginsDirectory ,
31
70
List <String > pluginsPackages ,
@@ -40,23 +79,104 @@ public record CoreModule(String name,
40
79
boolean forceGzipEncoding ,
41
80
boolean allowUnescapedCharsInUrl ) {
42
81
82
+ /**
83
+ * Configuration key for the core section in the configuration file.
84
+ */
43
85
public static final String CORE_KEY = "core" ;
86
+
87
+ /**
88
+ * Configuration key for the instance name.
89
+ */
44
90
public static final String INSTANCE_NAME_KEY = "name" ;
91
+
92
+ /**
93
+ * Configuration key for the plugins directory path.
94
+ */
45
95
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
+ */
46
100
public static final String PLUGINS_PACKAGES_KEY = "plugins-packages" ;
101
+
102
+ /**
103
+ * Configuration key for enabling verbose plugin scanning output.
104
+ */
47
105
public static final String PLUGINS_SCANNING_VERBOSE_KEY = "plugins-scanning-verbose" ;
106
+
107
+ /**
108
+ * Configuration key for the base URL of this instance.
109
+ */
48
110
public static final String BASE_URL_KEY = "base-url" ;
111
+
112
+ /**
113
+ * Configuration key for the number of I/O threads.
114
+ */
49
115
public static final String IO_THREADS_KEY = "io-threads" ;
116
+
117
+ /**
118
+ * Configuration key for workers scheduler parallelism level.
119
+ */
50
120
public static final String WORKERS_SCHEDULER_PARALLELISM_KEY ="workers-scheduler-parallelism" ;
121
+
122
+ /**
123
+ * Configuration key for workers scheduler maximum pool size.
124
+ */
51
125
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
+ */
52
130
public static final String BUFFERS_POOLING_KEY = "buffers-pooling" ;
131
+
132
+ /**
133
+ * Configuration key for the I/O buffer size in bytes.
134
+ */
53
135
public static final String BUFFER_SIZE_KEY = "buffer-size" ;
136
+
137
+ /**
138
+ * Configuration key for enabling direct (off-heap) buffers.
139
+ */
54
140
public static final String DIRECT_BUFFERS_KEY = "direct-buffers" ;
141
+
142
+ /**
143
+ * Configuration key for forcing GZIP encoding on responses.
144
+ */
55
145
public static final String FORCE_GZIP_ENCODING_KEY = "force-gzip-encoding" ;
146
+
147
+ /**
148
+ * Configuration key for allowing unescaped characters in URLs.
149
+ */
56
150
public static final String ALLOW_UNESCAPED_CHARS_IN_ULR_KEY = "allow-unescaped-characters-in-url" ;
57
151
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
+ */
58
169
private static final CoreModule DEFAULT_CORE_MODULE = new CoreModule ("default" , "plugins" , new ArrayList <>(), false , null , 0 , 0 , 256 , true , 16364 , true , false , true );
59
170
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
+ */
60
180
public CoreModule (Map <String , Object > conf , boolean silent ) {
61
181
this (getOrDefault (conf , INSTANCE_NAME_KEY , DEFAULT_CORE_MODULE .name (), silent ),
62
182
getOrDefault (conf , PLUGINS_DIRECTORY_PATH_KEY , DEFAULT_CORE_MODULE .pluginsDirectory (), silent ),
@@ -76,6 +196,17 @@ public CoreModule(Map<String, Object> conf, boolean silent) {
76
196
getOrDefault (conf , ALLOW_UNESCAPED_CHARS_IN_ULR_KEY , DEFAULT_CORE_MODULE .allowUnescapedCharsInUrl (), true ));
77
197
}
78
198
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
+ */
79
210
public static CoreModule build (Map <String , Object > conf , boolean silent ) {
80
211
var core = asMap (conf , CORE_KEY , null , silent );
81
212
0 commit comments