diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 63c3cde..53f7e77 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,4 +22,10 @@ jobs: uses: gradle/actions/setup-gradle@v4 - name: Build with Gradle - run: ./gradlew build \ No newline at end of file + run: ./gradlew build + - name: Upload a Build Artifact + uses: actions/upload-artifact@v7.0.0 + with: + name: CreateTrainWebAPI + path: build/libs/*.jar + retention-days: 90 diff --git a/build.gradle b/build.gradle index d7d5c72..01e050a 100644 --- a/build.gradle +++ b/build.gradle @@ -181,14 +181,14 @@ dependencies { jarJar(implementation("com.fasterxml.jackson.core:jackson-databind")) { version { strictly '[2.0, 3.0)' - prefer '2.20.0' // The version actually used in your dev workspace + prefer '2.21.1' // The version actually used in your dev workspace } } - additionalRuntimeClasspath "com.fasterxml.jackson.core:jackson-databind:2.20.0" + additionalRuntimeClasspath "com.fasterxml.jackson.core:jackson-databind:2.21.1" jarJar(implementation("com.fasterxml.jackson.core:jackson-core")) { version { strictly '[2.0, 3.0)' - prefer '2.20.2' // Replace with the actual version in your workspace + prefer '2.21.1' // Replace with the actual version in your workspace } } additionalRuntimeClasspath "com.fasterxml.jackson.core:jackson-core" @@ -196,7 +196,7 @@ dependencies { jarJar(implementation("com.fasterxml.jackson.core:jackson-annotations")) { version { strictly '[2.0, 3.0)' - prefer '2.20.2' // Replace with the actual version in your workspace + prefer '2.21' // Replace with the actual version in your workspace } } additionalRuntimeClasspath "com.fasterxml.jackson.core:jackson-annotations" @@ -256,4 +256,4 @@ idea { } tasks.withType(Jar).configureEach { zip64 = true -} \ No newline at end of file +} diff --git a/src/main/java/eu/cronmoth/createtrainwebapi/ApiServer.java b/src/main/java/eu/cronmoth/createtrainwebapi/ApiServer.java index 63d5d3f..b24e0a2 100644 --- a/src/main/java/eu/cronmoth/createtrainwebapi/ApiServer.java +++ b/src/main/java/eu/cronmoth/createtrainwebapi/ApiServer.java @@ -17,9 +17,11 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.RejectedExecutionException; public class ApiServer { private Undertow server; + private ScheduledExecutorService scheduler; private ObjectMapper mapper = new ObjectMapper(); public void start(String host, int port, String trainModelPath) { @@ -37,7 +39,7 @@ public void start(String host, int port, String trainModelPath) { exchange.getResponseSender().send(mapper.writeValueAsString(TrackInformation.GetNetworkData())); }); - ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(4); + scheduler = Executors.newScheduledThreadPool(4); pathHandler.addExactPath("/trainsLive", exchange -> { @@ -50,6 +52,8 @@ public void start(String host, int port, String trainModelPath) { try { String update = mapper.writeValueAsString(TrackInformation.GetTrainData()); connection.send(update); + } catch (RejectedExecutionException e) { + // XNIO worker is shutting down, nothing to do } catch (Exception e) { e.printStackTrace(); } @@ -80,6 +84,11 @@ public void start(String host, int port, String trainModelPath) { server.start(); } public void stop() { - server.stop(); + if (scheduler != null) { + scheduler.shutdownNow(); + } + if (server != null) { + server.stop(); + } } }