@@ -54,15 +54,12 @@ public static enum HookMode {
54
54
CONCURRENT_MODE
55
55
}
56
56
57
- private InternalCRIUSupport internalCRIUSupport ;
58
-
59
57
/**
60
- * Constructs a new {@code CRIUSupport}.
58
+ * A singleton {@code CRIUSupport} instance .
61
59
*
62
60
* The default CRIU dump options are:
63
61
* <p>
64
- * {@code imageDir} = imageDir, the directory where the images are to be
65
- * created.
62
+ * {@code imageDir} = CWD, current Java process working directory.
66
63
* <p>
67
64
* {@code leaveRunning} = false
68
65
* <p>
@@ -79,6 +76,30 @@ public static enum HookMode {
79
76
* {@code ghostFileLimit} = 1 MB
80
77
* <p>
81
78
* {@code workDir} = imageDir, the directory where the images are to be created.
79
+ */
80
+ private static final CRIUSupport singletonCRIUSupport = new CRIUSupport ();
81
+
82
+ private static final InternalCRIUSupport singletonInternalCRIUSupport = InternalCRIUSupport
83
+ .getInternalCRIUSupport ();
84
+
85
+ // no public construtors
86
+ private CRIUSupport () {
87
+ }
88
+
89
+ /**
90
+ * Returns the singleton CRIUSupport object.
91
+ *
92
+ * Most methods of class {@code CRIUSupport} are instance methods and must be
93
+ * invoked via this object.
94
+ *
95
+ * @return the singleton {@code CRIUSupport} object
96
+ */
97
+ public static CRIUSupport getCRIUSupport () {
98
+ return singletonCRIUSupport ;
99
+ }
100
+
101
+ /**
102
+ * Constructs a new {@code CRIUSupport}.
82
103
*
83
104
* @param imageDir the directory that will hold the dump files as a
84
105
* java.nio.file.Path
@@ -89,8 +110,9 @@ public static enum HookMode {
89
110
/*[ENDIF] JAVA_SPEC_VERSION < 24
90
111
* @throws IllegalArgumentException if imageDir is not a valid directory
91
112
*/
113
+ @ Deprecated (forRemoval =true )
92
114
public CRIUSupport (Path imageDir ) {
93
- internalCRIUSupport = new InternalCRIUSupport ( imageDir );
115
+ System . err . println ( "WARNING: CRIUSupport(imageDir) constructor is deprecated, please use CRIUSupport.getCRIUSupport() and setImageDir( imageDir)" ); //$NON-NLS-1$
94
116
}
95
117
96
118
/**
@@ -146,7 +168,7 @@ public static String getErrorMessage() {
146
168
* @throws IllegalArgumentException if imageDir is not a valid directory
147
169
*/
148
170
public CRIUSupport setImageDir (Path imageDir ) {
149
- internalCRIUSupport = internalCRIUSupport .setImageDir (imageDir );
171
+ singletonInternalCRIUSupport .setImageDir (imageDir );
150
172
return this ;
151
173
}
152
174
@@ -159,7 +181,7 @@ public CRIUSupport setImageDir(Path imageDir) {
159
181
* @return this
160
182
*/
161
183
public CRIUSupport setLeaveRunning (boolean leaveRunning ) {
162
- internalCRIUSupport = internalCRIUSupport .setLeaveRunning (leaveRunning );
184
+ singletonInternalCRIUSupport .setLeaveRunning (leaveRunning );
163
185
return this ;
164
186
}
165
187
@@ -172,7 +194,7 @@ public CRIUSupport setLeaveRunning(boolean leaveRunning) {
172
194
* @return this
173
195
*/
174
196
public CRIUSupport setShellJob (boolean shellJob ) {
175
- internalCRIUSupport = internalCRIUSupport .setShellJob (shellJob );
197
+ singletonInternalCRIUSupport .setShellJob (shellJob );
176
198
return this ;
177
199
}
178
200
@@ -185,7 +207,7 @@ public CRIUSupport setShellJob(boolean shellJob) {
185
207
* @return this
186
208
*/
187
209
public CRIUSupport setExtUnixSupport (boolean extUnixSupport ) {
188
- internalCRIUSupport = internalCRIUSupport .setExtUnixSupport (extUnixSupport );
210
+ singletonInternalCRIUSupport .setExtUnixSupport (extUnixSupport );
189
211
return this ;
190
212
}
191
213
@@ -205,7 +227,7 @@ public CRIUSupport setExtUnixSupport(boolean extUnixSupport) {
205
227
* @throws IllegalArgumentException if logLevel is not valid
206
228
*/
207
229
public CRIUSupport setLogLevel (int logLevel ) {
208
- internalCRIUSupport = internalCRIUSupport .setLogLevel (logLevel );
230
+ singletonInternalCRIUSupport .setLogLevel (logLevel );
209
231
return this ;
210
232
}
211
233
@@ -220,7 +242,7 @@ public CRIUSupport setLogLevel(int logLevel) {
220
242
* @throws IllegalArgumentException if logFile is null or a path
221
243
*/
222
244
public CRIUSupport setLogFile (String logFile ) {
223
- internalCRIUSupport = internalCRIUSupport .setLogFile (logFile );
245
+ singletonInternalCRIUSupport .setLogFile (logFile );
224
246
return this ;
225
247
}
226
248
@@ -233,7 +255,7 @@ public CRIUSupport setLogFile(String logFile) {
233
255
* @return this
234
256
*/
235
257
public CRIUSupport setFileLocks (boolean fileLocks ) {
236
- internalCRIUSupport = internalCRIUSupport .setFileLocks (fileLocks );
258
+ singletonInternalCRIUSupport .setFileLocks (fileLocks );
237
259
return this ;
238
260
}
239
261
@@ -246,7 +268,7 @@ public CRIUSupport setFileLocks(boolean fileLocks) {
246
268
* @return this
247
269
*/
248
270
public CRIUSupport setTCPEstablished (boolean tcpEstablished ) {
249
- internalCRIUSupport = internalCRIUSupport .setTCPEstablished (tcpEstablished );
271
+ singletonInternalCRIUSupport .setTCPEstablished (tcpEstablished );
250
272
return this ;
251
273
}
252
274
@@ -259,7 +281,7 @@ public CRIUSupport setTCPEstablished(boolean tcpEstablished) {
259
281
* @return this
260
282
*/
261
283
public CRIUSupport setAutoDedup (boolean autoDedup ) {
262
- internalCRIUSupport = internalCRIUSupport .setAutoDedup (autoDedup );
284
+ singletonInternalCRIUSupport .setAutoDedup (autoDedup );
263
285
return this ;
264
286
}
265
287
@@ -272,7 +294,7 @@ public CRIUSupport setAutoDedup(boolean autoDedup) {
272
294
* @return this
273
295
*/
274
296
public CRIUSupport setTrackMemory (boolean trackMemory ) {
275
- internalCRIUSupport = internalCRIUSupport .setTrackMemory (trackMemory );
297
+ singletonInternalCRIUSupport .setTrackMemory (trackMemory );
276
298
return this ;
277
299
}
278
300
@@ -290,7 +312,7 @@ public CRIUSupport setTrackMemory(boolean trackMemory) {
290
312
* @throws IllegalArgumentException if workDir is not a valid directory
291
313
*/
292
314
public CRIUSupport setWorkDir (Path workDir ) {
293
- internalCRIUSupport = internalCRIUSupport .setWorkDir (workDir );
315
+ singletonInternalCRIUSupport .setWorkDir (workDir );
294
316
return this ;
295
317
}
296
318
@@ -303,7 +325,7 @@ public CRIUSupport setWorkDir(Path workDir) {
303
325
* @return this
304
326
*/
305
327
public CRIUSupport setUnprivileged (boolean unprivileged ) {
306
- internalCRIUSupport = internalCRIUSupport .setUnprivileged (unprivileged );
328
+ singletonInternalCRIUSupport .setUnprivileged (unprivileged );
307
329
return this ;
308
330
}
309
331
@@ -318,7 +340,7 @@ public CRIUSupport setUnprivileged(boolean unprivileged) {
318
340
* @throws UnsupportedOperationException if file limit is greater than 2^32 - 1 or negative.
319
341
*/
320
342
public CRIUSupport setGhostFileLimit (long limit ) {
321
- internalCRIUSupport = internalCRIUSupport .setGhostFileLimit (limit );
343
+ singletonInternalCRIUSupport .setGhostFileLimit (limit );
322
344
return this ;
323
345
}
324
346
@@ -331,7 +353,7 @@ public CRIUSupport setGhostFileLimit(long limit) {
331
353
* @return this
332
354
*/
333
355
public CRIUSupport setTCPClose (boolean tcpClose ) {
334
- internalCRIUSupport = internalCRIUSupport .setTCPClose (tcpClose );
356
+ singletonInternalCRIUSupport .setTCPClose (tcpClose );
335
357
return this ;
336
358
}
337
359
@@ -344,7 +366,7 @@ public CRIUSupport setTCPClose(boolean tcpClose) {
344
366
* @return this
345
367
*/
346
368
public CRIUSupport setTCPSkipInFlight (boolean tcpSkipInFlight ) {
347
- internalCRIUSupport = internalCRIUSupport .setTCPSkipInFlight (tcpSkipInFlight );
369
+ singletonInternalCRIUSupport .setTCPSkipInFlight (tcpSkipInFlight );
348
370
return this ;
349
371
}
350
372
@@ -365,7 +387,7 @@ public CRIUSupport setTCPSkipInFlight(boolean tcpSkipInFlight) {
365
387
* @return this
366
388
*/
367
389
public CRIUSupport registerRestoreEnvFile (Path envFile ) {
368
- internalCRIUSupport = internalCRIUSupport .registerRestoreEnvFile (envFile );
390
+ singletonInternalCRIUSupport .registerRestoreEnvFile (envFile );
369
391
return this ;
370
392
}
371
393
@@ -381,7 +403,7 @@ public CRIUSupport registerRestoreEnvFile(Path envFile) {
381
403
* @return this
382
404
*/
383
405
public CRIUSupport registerRestoreOptionsFile (Path optionsFile ) {
384
- internalCRIUSupport = internalCRIUSupport .registerRestoreOptionsFile (optionsFile );
406
+ singletonInternalCRIUSupport .registerRestoreOptionsFile (optionsFile );
385
407
return this ;
386
408
}
387
409
@@ -402,7 +424,7 @@ public CRIUSupport registerRestoreOptionsFile(Path optionsFile) {
402
424
*/
403
425
public CRIUSupport registerPostRestoreHook (Runnable hook ) {
404
426
try {
405
- internalCRIUSupport = internalCRIUSupport .registerPostRestoreHook (hook );
427
+ singletonInternalCRIUSupport .registerPostRestoreHook (hook );
406
428
} catch (openj9 .internal .criu .JVMCheckpointException jce ) {
407
429
throw new JVMCheckpointException (jce .getMessage (), 0 , jce );
408
430
} catch (openj9 .internal .criu .JVMRestoreException jre ) {
@@ -455,7 +477,7 @@ public CRIUSupport registerPostRestoreHook(Runnable hook, HookMode mode, int pri
455
477
internalMode = InternalCRIUSupport .HookMode .CONCURRENT_MODE ;
456
478
}
457
479
try {
458
- internalCRIUSupport = internalCRIUSupport .registerPostRestoreHook (hook , internalMode , priority );
480
+ singletonInternalCRIUSupport .registerPostRestoreHook (hook , internalMode , priority );
459
481
} catch (openj9 .internal .criu .JVMCheckpointException jce ) {
460
482
throw new JVMCheckpointException (jce .getMessage (), 0 , jce );
461
483
} catch (openj9 .internal .criu .JVMRestoreException jre ) {
@@ -482,7 +504,7 @@ public CRIUSupport registerPostRestoreHook(Runnable hook, HookMode mode, int pri
482
504
*/
483
505
public CRIUSupport registerPreCheckpointHook (Runnable hook ) {
484
506
try {
485
- internalCRIUSupport = internalCRIUSupport .registerPreCheckpointHook (hook );
507
+ singletonInternalCRIUSupport .registerPreCheckpointHook (hook );
486
508
} catch (openj9 .internal .criu .JVMCheckpointException jce ) {
487
509
throw new JVMCheckpointException (jce .getMessage (), 0 , jce );
488
510
} catch (openj9 .internal .criu .JVMRestoreException jre ) {
@@ -535,7 +557,7 @@ public CRIUSupport registerPreCheckpointHook(Runnable hook, HookMode mode, int p
535
557
internalMode = InternalCRIUSupport .HookMode .CONCURRENT_MODE ;
536
558
}
537
559
try {
538
- internalCRIUSupport = internalCRIUSupport .registerPreCheckpointHook (hook , internalMode , priority );
560
+ singletonInternalCRIUSupport .registerPreCheckpointHook (hook , internalMode , priority );
539
561
} catch (openj9 .internal .criu .JVMCheckpointException jce ) {
540
562
throw new JVMCheckpointException (jce .getMessage (), 0 , jce );
541
563
} catch (openj9 .internal .criu .JVMRestoreException jre ) {
@@ -559,7 +581,7 @@ public CRIUSupport registerPreCheckpointHook(Runnable hook, HookMode mode, int p
559
581
public synchronized void checkpointJVM () {
560
582
if (isCRIUSupportEnabled ()) {
561
583
try {
562
- internalCRIUSupport .checkpointJVM ();
584
+ singletonInternalCRIUSupport .checkpointJVM ();
563
585
} catch (openj9 .internal .criu .JVMCheckpointException jce ) {
564
586
throw new JVMCheckpointException (jce .getMessage (), 0 , jce );
565
587
} catch (openj9 .internal .criu .JVMRestoreException jre ) {
0 commit comments