Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ jobs:
uses: gradle/actions/setup-gradle@v4

- name: Build with Gradle
run: ./gradlew build
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
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,22 @@ 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"

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"
Expand Down Expand Up @@ -256,4 +256,4 @@ idea {
}
tasks.withType(Jar).configureEach {
zip64 = true
}
}
13 changes: 11 additions & 2 deletions src/main/java/eu/cronmoth/createtrainwebapi/ApiServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 -> {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
}
}
Loading