Skip to content

Commit ddc4a6c

Browse files
committed
[Feature/DockerJavaClient] Added properties for docker response and connection timeout
1 parent 6eced0a commit ddc4a6c

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ public record Config(
1111
long maxAliveSessions,
1212
int dockerMaxRamMegaBytes,
1313
double dockerCPUsUsage,
14-
long schedulerSessionKillScanRateSeconds) {
14+
long schedulerSessionKillScanRateSeconds,
15+
long dockerResponseTimeout,
16+
long dockerConnectionTimeout) {
1517
public Config {
1618
if(regularSessionTimeoutSeconds <= 0) throw new RuntimeException("Invalid value " + regularSessionTimeoutSeconds);
1719
if(oneTimeSessionTimeoutSeconds <= 0) throw new RuntimeException("Invalid value " + oneTimeSessionTimeoutSeconds);
@@ -21,5 +23,7 @@ public record Config(
2123
if(dockerMaxRamMegaBytes <= 0) throw new RuntimeException("Invalid value " + dockerMaxRamMegaBytes);
2224
if(dockerCPUsUsage <= 0) throw new RuntimeException("Invalid value " + dockerCPUsUsage);
2325
if(schedulerSessionKillScanRateSeconds <= 0) throw new RuntimeException("Invalid value " + schedulerSessionKillScanRateSeconds);
26+
if(dockerResponseTimeout <= 0) throw new RuntimeException("Invalid value " + dockerResponseTimeout);
27+
if(dockerConnectionTimeout <= 0) throw new RuntimeException("Invalid value " + dockerConnectionTimeout);
2428
}
2529
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import org.slf4j.Logger;
1111
import org.slf4j.LoggerFactory;
1212
import org.springframework.beans.factory.DisposableBean;
13+
import org.springframework.beans.factory.annotation.Autowired;
1314
import org.springframework.stereotype.Service;
15+
import org.togetherjava.jshellapi.Config;
1416

1517
import java.io.*;
1618
import java.nio.charset.StandardCharsets;
@@ -24,19 +26,18 @@
2426
@Service
2527
public class DockerService implements DisposableBean {
2628
private static final Logger LOGGER = LoggerFactory.getLogger(DockerService.class);
27-
2829
private static final String WORKER_LABEL = "jshell-api-worker";
2930
private static final UUID WORKER_UNIQUE_ID = UUID.randomUUID();
3031

3132
private final DockerClient client;
3233

33-
public DockerService() {
34+
public DockerService(Config config) {
3435
DefaultDockerClientConfig clientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder().build();
3536
ApacheDockerHttpClient httpClient = new ApacheDockerHttpClient.Builder()
3637
.dockerHost(clientConfig.getDockerHost())
3738
.sslConfig(clientConfig.getSSLConfig())
38-
.responseTimeout(Duration.ofSeconds(60))
39-
.connectionTimeout(Duration.ofSeconds(60))
39+
.responseTimeout(Duration.ofSeconds(config.dockerResponseTimeout()))
40+
.connectionTimeout(Duration.ofSeconds(config.dockerConnectionTimeout()))
4041
.build();
4142
this.client = DockerClientImpl.getInstance(clientConfig, httpClient);
4243

JShellAPI/src/main/resources/application.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ jshellapi.dockerMaxRamMegaBytes=100
1111
jshellapi.dockerCPUsUsage=0.5
1212

1313
# Internal config
14-
jshellapi.schedulerSessionKillScanRateSeconds=60
14+
jshellapi.schedulerSessionKillScanRateSeconds=60
15+
16+
# Docker service config
17+
jshellapi.dockerResponseTimeout=60
18+
jshellapi.dockerConnectionTimeout=60

0 commit comments

Comments
 (0)