Skip to content

Commit c24e28b

Browse files
committed
JShellAPI updated with the new sysout char limit config
1 parent a2b862b commit c24e28b

4 files changed

Lines changed: 10 additions & 5 deletions

File tree

JShellAPI/src/main/java/org/togetherjava/jshellapi/Config.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public record Config(
77
long regularSessionTimeoutSeconds,
88
long oneTimeSessionTimeoutSeconds,
99
long evalTimeoutSeconds,
10+
int sysOutCharLimit,
1011
long maxAliveSessions,
1112
int dockerMaxRamMegaBytes,
1213
double dockerCPUsUsage,
@@ -15,6 +16,7 @@ public record Config(
1516
if(regularSessionTimeoutSeconds <= 0) throw new RuntimeException("Invalid value " + regularSessionTimeoutSeconds);
1617
if(oneTimeSessionTimeoutSeconds <= 0) throw new RuntimeException("Invalid value " + oneTimeSessionTimeoutSeconds);
1718
if(evalTimeoutSeconds <= 0) throw new RuntimeException("Invalid value " + evalTimeoutSeconds);
19+
if(sysOutCharLimit <= 0) throw new RuntimeException("Invalid value " + sysOutCharLimit);
1820
if(maxAliveSessions <= 0) throw new RuntimeException("Invalid value " + maxAliveSessions);
1921
if(dockerMaxRamMegaBytes <= 0) throw new RuntimeException("Invalid value " + dockerMaxRamMegaBytes);
2022
if(dockerCPUsUsage <= 0) throw new RuntimeException("Invalid value " + dockerCPUsUsage);

JShellAPI/src/main/java/org/togetherjava/jshellapi/service/JShellService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class JShellService implements Closeable {
2727
private final boolean renewable;
2828
private boolean doingOperation;
2929

30-
public JShellService(JShellSessionService sessionService, String id, long timeout, boolean renewable, long evalTimeout, int maxMemory, double cpus, String startupScript) throws DockerException {
30+
public JShellService(JShellSessionService sessionService, String id, long timeout, boolean renewable, long evalTimeout, int sysOutCharLimit, int maxMemory, double cpus, String startupScript) throws DockerException {
3131
this.sessionService = sessionService;
3232
this.id = id;
3333
this.timeout = timeout;
@@ -53,6 +53,7 @@ public JShellService(JShellSessionService sessionService, String id, long timeou
5353
"--cpus=" + cpus,
5454
"--name", containerName(),
5555
"-e", "\"evalTimeoutSeconds=%d\"".formatted(evalTimeout),
56+
"-e", "\"sysOutCharLimit=%d\"".formatted(sysOutCharLimit),
5657
"togetherjava.org:5001/togetherjava/jshellwrapper:master")
5758
.directory(new File(".."))
5859
.redirectError(errorLogs.toFile())

JShellAPI/src/main/java/org/togetherjava/jshellapi/service/JShellSessionService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public boolean hasSession(String id) {
4949

5050
public JShellService session(String id, @Nullable StartupScriptId startupScriptId) throws DockerException {
5151
if(!hasSession(id)) {
52-
return createSession(id, config.regularSessionTimeoutSeconds(), true, config.evalTimeoutSeconds(), startupScriptId);
52+
return createSession(id, config.regularSessionTimeoutSeconds(), true, config.evalTimeoutSeconds(), config.sysOutCharLimit(), startupScriptId);
5353
}
5454
return jshellSessions.get(id);
5555
}
5656
public JShellService session(@Nullable StartupScriptId startupScriptId) throws DockerException {
57-
return createSession(UUID.randomUUID().toString(), config.regularSessionTimeoutSeconds(), false, config.evalTimeoutSeconds(), startupScriptId);
57+
return createSession(UUID.randomUUID().toString(), config.regularSessionTimeoutSeconds(), false, config.evalTimeoutSeconds(), config.sysOutCharLimit(), startupScriptId);
5858
}
5959
public JShellService oneTimeSession(@Nullable StartupScriptId startupScriptId) throws DockerException {
60-
return createSession(UUID.randomUUID().toString(), config.oneTimeSessionTimeoutSeconds(), false, config.evalTimeoutSeconds(), startupScriptId);
60+
return createSession(UUID.randomUUID().toString(), config.oneTimeSessionTimeoutSeconds(), false, config.evalTimeoutSeconds(), config.sysOutCharLimit(), startupScriptId);
6161
}
6262

6363
public void deleteSession(String id) throws DockerException {
@@ -66,7 +66,7 @@ public void deleteSession(String id) throws DockerException {
6666
scheduler.schedule(service::close, 500, TimeUnit.MILLISECONDS);
6767
}
6868

69-
private synchronized JShellService createSession(String id, long sessionTimeout, boolean renewable, long evalTimeout, @Nullable StartupScriptId startupScriptId) throws DockerException {
69+
private synchronized JShellService createSession(String id, long sessionTimeout, boolean renewable, long evalTimeout, int sysOutCharLimit, @Nullable StartupScriptId startupScriptId) throws DockerException {
7070
if(hasSession(id)) { //Just in case race condition happens just before createSession
7171
return jshellSessions.get(id);
7272
}
@@ -79,6 +79,7 @@ private synchronized JShellService createSession(String id, long sessionTimeout,
7979
sessionTimeout,
8080
renewable,
8181
evalTimeout,
82+
sysOutCharLimit,
8283
config.dockerMaxRamMegaBytes(),
8384
config.dockerCPUsUsage(),
8485
startupScriptsService.get(startupScriptId));

JShellAPI/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
jshellapi.regularSessionTimeoutSeconds=1800
44
jshellapi.oneTimeSessionTimeoutSeconds=30
55
jshellapi.evalTimeoutSeconds=15
6+
jshellapi.sysOutCharLimit=1024
67
jshellapi.maxAliveSessions=10
78

89
# Docker limits config

0 commit comments

Comments
 (0)