Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
7c5075d
init for the web app -- not necessary for the coursework
mkutay Feb 19, 2025
d6e775a
Merge branch 'web-app' into main
mkutay Feb 20, 2025
5a43db3
Merge pull request #1 from mkutay/main
mkutay Feb 20, 2025
f73b856
it's pretty hard to get all of the data from redis to be displayed on…
mkutay Feb 21, 2025
88cc803
refactor(RenderPanel): remove unnecessary code
mkutay Feb 25, 2025
8535e57
refactor(CanvasComponent): clean up imports and improve useEffect dep…
mkutay Feb 25, 2025
9f7e405
refactor(CanvasComponent, RenderPanel): update function names in redis
mkutay Feb 25, 2025
cfdb7f4
refactor(graphics): add interface for the render panel to increase co…
mkutay Feb 25, 2025
1f4fc0a
fix(CanvasComponent): fix the rendering so that it actually renders a…
mkutay Feb 25, 2025
334a623
feat(CanvasComponent): add drawing functions for lines, rectangles, t…
mkutay Feb 25, 2025
ce89d05
fix(DisplayData, RenderPanelWeb): make the indexes of the function ca…
mkutay Feb 25, 2025
b9afa64
fix(RenderPanelWeb): fix uncontrollable increase of index
mkutay Feb 25, 2025
44d4009
feat(env): add example environment
mkutay Feb 25, 2025
f918775
refactor(api data): change how graphics data is stored to decrease si…
mkutay Feb 26, 2025
c42ecdd
docs(graphics methods): add documentation render panel and api data
mkutay Feb 26, 2025
1f8b5c0
feat(Dockerfile): add dockerfile for deployment on server
mkutay Feb 27, 2025
5e93845
fix(Dockerfile): update docker
mkutay Feb 27, 2025
015343c
chore(Dockerfile): move redis dependencies and update dockerfile
mkutay Feb 27, 2025
5f17062
fix(Dockerfile): change path for simulation_data.json
mkutay Feb 27, 2025
f18fc96
feat(lib): add slf4j provider for logging purposes in redis
mkutay Feb 27, 2025
c2b5805
chore(frontend): move frontend code to another branch
mkutay Feb 27, 2025
0883722
fix(simulator): reduce fixed delta time
mkutay Feb 27, 2025
ecffab6
feat(graphics): add delta time logging in RenderPanelWeb update
mkutay Feb 27, 2025
f8c4977
refactor(api data): change how data is stored to be a single array
mkutay Feb 27, 2025
1949317
fix(graphics): mark length variable as transient to prevent serializa…
mkutay Feb 27, 2025
fc6816e
fix(api data): remove reversing the data
mkutay Feb 27, 2025
d0f08b8
feat: add start/stop button implementation with subscribe feeature of…
mkutay Feb 28, 2025
e2c513a
refactor(SimulationData): change how simulation data is received to m…
mkutay Mar 1, 2025
21abc7e
fix(Parser): improve error handling for simulation data parsing and f…
mkutay Mar 1, 2025
21e105e
docs(api): add code comments and method/class documentation
mkutay Mar 1, 2025
bd49339
feat(Publisher): implement message publishing to Redis channel
mkutay Mar 3, 2025
ed0794f
feat: add websockets instead of redis
mkutay Aug 19, 2025
50009c1
chore: update dockerfile
mkutay Aug 19, 2025
2ea7fcc
chore: update dockerfile
mkutay Aug 19, 2025
8f14b07
fix: client disconnect and engine stopiing
mkutay Aug 19, 2025
6440272
feat: better web socket server implementation and multiple client con…
mkutay Aug 20, 2025
a558dd5
chore: move java code into java-backend directory
mkutay Aug 20, 2025
41857c4
Merge branch 'main' into pr/mkutay/4
mkutay Aug 20, 2025
b20634e
fix: update source path in CI workflow to reflect new directory struc…
mkutay Aug 20, 2025
43c4cfb
fix: update classpath in JUnit test execution to include java-backend…
mkutay Aug 20, 2025
203380a
fix: update simulation data file path in tests to reflect new directo…
mkutay Aug 20, 2025
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
Binary file added .DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Compile Java code and tests
run: |
mkdir -p bin
find src -name "*.java" > sources.txt
javac -cp "lib/*" -d bin @sources.txt
find java-backend/src -name "*.java" > sources.txt
javac -cp "java-backend/lib/*" -d bin @sources.txt
- name: Run JUnit tests
run: java -cp "bin:lib/*" org.junit.platform.console.ConsoleLauncher --scan-class-path
run: java -cp "bin:java-backend/lib/*" org.junit.platform.console.ConsoleLauncher --scan-class-path
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"java.project.sourcePaths": [
"java-backend/src"
],
"java.project.referencedLibraries": [
"java-backend/lib/**/*.jar",
]
}
3 changes: 2 additions & 1 deletion .gitignore → java-backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ we-get-these-100s.iml
latex/main.aux
latex/main.log
.DS_Store
main.out
main.out
.env
53 changes: 53 additions & 0 deletions java-backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Use Eclipse Temurin as the builder (more secure and maintained)
FROM eclipse-temurin:21-jdk-alpine AS builder
WORKDIR /app

# Create lib directory first to avoid errors if it doesn't exist
RUN mkdir -p lib

# Copy project source and dependencies
COPY src/ ./src/
COPY lib/*.jar ./lib/
COPY src/simulation_data.json ./simulation_data.json

# Compile the Java sources.
# Adjust the classpath, output directory, and source files as needed.
RUN mkdir out && javac -d out -cp "./lib/*" $(find src -name "*.java")

# Final stage: use a minimal JRE image for runtime
FROM eclipse-temurin:21-jre-alpine
WORKDIR /app

# Create a non-root user for security
RUN addgroup -g 1001 -S appgroup && \
adduser -S appuser -u 1001 -G appgroup

# Copy compiled classes and the lib folder from builder stage
COPY --from=builder /app/out/ ./out/
COPY --from=builder /app/lib/ ./lib/
COPY --from=builder /app/simulation_data.json ./simulation_data.json

# Change ownership to the non-root user
RUN chown -R appuser:appgroup /app

# Switch to non-root user
USER appuser

# Expose the WebSocket port
EXPOSE 8080

# Add a simple healthcheck
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD exit 0

# Run in headless mode with server optimizations
CMD ["java", \
"-Djava.awt.headless=true", \
"-server", \
"-XX:+UseContainerSupport", \
"-XX:MinRAMPercentage=50", \
"-XX:MaxRAMPercentage=80", \
"-Dfile.encoding=UTF-8", \
"-Duser.timezone=UTC", \
"-cp", "./out:./lib/*", \
"Main"]
Binary file added java-backend/lib/commons-pool2-2.12.1.jar
Binary file not shown.
Binary file added java-backend/lib/dotenv-java-3.1.0.jar
Binary file not shown.
File renamed without changes.
Binary file added java-backend/lib/json-20250107.jar
Binary file not shown.
File renamed without changes.
Binary file added java-backend/lib/resilience4j-all-2.3.0.jar
Binary file not shown.
Binary file not shown.
Binary file added java-backend/lib/resilience4j-retry-2.3.0.jar
Binary file not shown.
Binary file added java-backend/lib/slf4j-api-2.0.16.jar
Binary file not shown.
Binary file added java-backend/lib/slf4j-simple-2.0.17.jar
Binary file not shown.
22 changes: 22 additions & 0 deletions java-backend/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import api.Connector;
import simulation.simulationData.Data;
import util.Parser;
import view.Engine;

/**
* Main class to start the simulation through the Engine class.
*
* @author Mehmet Kutay Bozkurt and Anas Ahmed
* @version 1.0
*/
public class Main {
private static final String PATH = System.getProperty("user.dir"); // The main directory of the project.

public static void main(String[] args) {
Connector.getInstance().start(); // For use with the web API.

// If you want to run the simulation without the web API, uncomment the following lines:
// Data.setSimulationData(Parser.parseSimulationData(Parser.getContentsOfFile(PATH + "/java-backend/src/simulation_data.json")));
// new Engine(800, 600, 60).start();
}
}
71 changes: 71 additions & 0 deletions java-backend/src/api/Connector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A class to manage WebSocket connections and handle simulation control.
*
* @author Mehmet Kutay Bozkurt
* @version 1.0
*/
public class Connector {
// The port for the WebSocket server
public static final int WEBSOCKET_PORT = 8080;

// The logger to log messages.
private static Logger logger = LoggerFactory.getLogger(Connector.class);

private static Connector instance; // Singleton instance
private final WebSocketHandler webSocketServer; // The unified WebSocket server.

/**
* Private constructor for singleton pattern.
*/
private Connector() {
webSocketServer = new WebSocketHandler(WEBSOCKET_PORT);
}

/**
* Get the singleton instance.
*/
public static synchronized Connector getInstance() {
if (instance == null) {
instance = new Connector();
}
return instance;
}

/**
* Start listening for WebSocket connections and messages.
*/
public void listen() {
try {
webSocketServer.start();
} catch (Exception e) {
logger.error("WebSocket server failed.", e);
}
}

/**
* Start the listener in a new thread.
*/
public void start() {
Thread t = new Thread(this::listen);
t.start();
}

/**
* Close the WebSocket server.
*/
public void close() {
webSocketServer.stop();
}

/**
* Get the WebSocket server instance.
*/
public WebSocketServer getWebSocketServer() {
return webSocketServer;
}
}
Loading