-
-
Notifications
You must be signed in to change notification settings - Fork 940
Expand file tree
/
Copy pathCheckpointMain.java
More file actions
89 lines (71 loc) · 2.58 KB
/
CheckpointMain.java
File metadata and controls
89 lines (71 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package org.jruby.main;
import com.headius.options.Option;
import org.crac.CheckpointException;
import org.crac.Context;
import org.crac.Core;
import org.crac.Resource;
import org.crac.RestoreException;
import org.jruby.Ruby;
import org.jruby.RubyInstanceConfig;
import org.jruby.exceptions.RaiseException;
import org.jruby.util.cli.Options;
import java.io.InputStream;
import static org.jruby.main.Main.handleRaiseException;
public class CheckpointMain extends PrebootMain {
public static void main(String[] args) {
preboot(new CheckpointMain(), args);
}
protected String[] warmup(String[] args) {
Ruby ruby = Ruby.newInstance();
ruby.evalScriptlet("1 + 1");
Ruby.clearGlobalRuntime();
return args;
}
protected RubyInstanceConfig prepareConfig(String[] args) {
RubyInstanceConfig config = super.prepareConfig(args);
if (args.length > 0) {
config.processArguments(args);
}
return config;
}
protected Ruby prepareRuntime(RubyInstanceConfig config, String[] args) {
Ruby ruby = super.prepareRuntime(config, args);
// If more arguments were provided, run them as normal before checkpointing
if (args.length > 0) {
InputStream in = config.getScriptSource();
String filename = config.displayedFileName();
try {
if (in == null || config.getShouldCheckSyntax()) {
// ignore if there's no code to run
} else {
// proceed to run the script
ruby.runFromMain(in, filename);
}
} catch (RaiseException rj) {
handleRaiseException(rj);
}
}
return ruby;
}
@Override
protected void endPreboot(RubyInstanceConfig config, Ruby ruby, String[] args) {
super.endPreboot(config, ruby, args);
try {
Core.getGlobalContext().register(new JRubyContext());
Core.checkpointRestore();
} catch (CheckpointException | RestoreException e) {
e.printStackTrace();
System.exit(1);
}
}
private static class JRubyContext extends Context<Resource> {
@Override
public void beforeCheckpoint(Context<? extends Resource> context) throws CheckpointException {}
@Override
public void afterRestore(Context<? extends Resource> context) throws RestoreException {
Options.PROPERTIES.forEach(Option::reload);
}
@Override
public void register(Resource resource) {}
}
}