Skip to content

Commit 7f1364f

Browse files
committed
Added session max count
1 parent e6283a6 commit 7f1364f

3 files changed

Lines changed: 6 additions & 0 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,12 +7,14 @@ public record Config(
77
long regularSessionTimeoutSeconds,
88
long oneTimeSessionTimeoutSeconds,
99
long evalTimeoutSeconds,
10+
long maxAliveSessions,
1011
int schedulerThreadCount,
1112
long schedulerSessionKillScanRate) {
1213
public Config {
1314
if(regularSessionTimeoutSeconds <= 0) throw new RuntimeException("Invalid value " + regularSessionTimeoutSeconds);
1415
if(oneTimeSessionTimeoutSeconds <= 0) throw new RuntimeException("Invalid value " + oneTimeSessionTimeoutSeconds);
1516
if(evalTimeoutSeconds <= 0) throw new RuntimeException("Invalid value " + evalTimeoutSeconds);
17+
if(maxAliveSessions <= 0) throw new RuntimeException("Invalid value " + maxAliveSessions);
1618
if(schedulerThreadCount <= 0) throw new RuntimeException("Invalid value " + schedulerThreadCount);
1719
if(schedulerSessionKillScanRate <= 0) throw new RuntimeException("Invalid value " + schedulerSessionKillScanRate);
1820
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ private synchronized JShellService createSession(String id, long sessionTimeout,
6363
if(hasSession(id)) { //Just in case race condition happens just before createSession
6464
return jshellSessions.get(id);
6565
}
66+
if(jshellSessions.size() >= config.maxAliveSessions()) {
67+
throw new DockerException("Too many sessions.");
68+
}
6669
JShellService service = new JShellService(this, id, sessionTimeout, renewable, evalTimeout);
6770
jshellSessions.put(id, service);
6871
return service;

JShellAPI/src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ jshellapi.regularSessionTimeoutSeconds=1800
44
# 10 * 60 = 600
55
jshellapi.oneTimeSessionTimeoutSeconds=600
66
jshellapi.evalTimeoutSeconds=15
7+
jshellapi.maxAliveSessions=10
78

89
# Internal config
910
jshellapi.schedulerThreadCount=1

0 commit comments

Comments
 (0)