This project implements a two-player communication system in Java, tailored for 360T. It supports two modes of operation:
- Reactive In-Process Implementation: Both players communicate within the same Java process using reactive programming principles.
- Separate Processes Implementation: Each player runs in a separate Java process, simulating real-world inter-process communication (IPC).
The system is built with modularity, clean design principles, and extensibility in mind.
The project follows a structured layout to ensure maintainability and clarity:
src
├── main
│ ├── java
│ │ └── de
│ │ └── three
│ │ └── sixty
│ │ ├── reactive # In-process implementation
│ │ │ ├── InProcessApp.java # Main class for reactive implementation
│ │ │ └── Player.java # Player class for message handling
│ │ ├── separate # Separate processes implementation
│ │ │ ├── SeparateProcessApp.java # Main class to launch separate processes
│ │ │ └── PlayerProcess.java # Logic for each player's separate process
│ │ ├── model # Domain models
│ │ │ └── Message.java # Encapsulation of messages
│ │ └── shared # Utilities
│ │ └── LoggerUtil.java # Logging utility for players
├── test
│ ├── java
│ │ └── de
│ │ └── three
│ │ └── sixty
│ │ ├── reactive
│ │ │ ├── PlayerTest.java
│ │ │ ├── InProcessAppTest.java
│ │ ├── separate
│ │ │ ├── SeparateProcessAppTest.java
│ │ ├── shared
│ │ │ ├── LoggerUtilTest.java
├── run.sh # Shell script for building and running the application
├── Dockerfile # Docker configuration for containerized runs
├── pom.xml # Maven project configuration file
This project leverages several design patterns to achieve a robust and maintainable architecture:
-
Observer Pattern:
- Where Used: In the Reactive In-Process Implementation.
- Purpose: Players (
InitiatorandResponder) act as observers of reactive message flows. - Benefits:
- Enables reactive, event-driven communication.
- Decouples message handling logic from the main process.
-
Mediator Pattern:
- Where Used: In the Reactive In-Process Implementation.
- Purpose: The
Fluxstream acts as a mediator between the two players, coordinating message exchanges. - Benefits:
- Simplifies communication logic.
- Reduces dependencies between interacting classes.
-
Singleton Pattern:
- Where Used: In the
LoggerUtilclass. - Purpose: Ensures a single instance of the logger exists for each player.
- Benefits:
- Centralizes logging configuration.
- Ensures consistent log file handling.
- Where Used: In the
-
Builder Pattern:
- Where Used: Conceptually in the
Messageclass. - Purpose: Encapsulates message data, providing flexibility for adding metadata (e.g., timestamps) in the future.
- Where Used: Conceptually in the
- Java 21 or higher
- Maven 3.6 or higher
- Docker (for containerized execution)
Run the following commands from the project’s root directory:
mvn clean package-
For In-Process Reactive Implementation:
./run.sh inProcess 10
This will run the communication system with 10 messages exchanged between
InitiatorandResponder. -
For Separate Processes Implementation:
./run.sh separateProcess 10
This will run two separate processes for
InitiatorandResponder, simulating real-world IPC.
Run the following command to build the Docker image:
docker build -t player-communication .-
For In-Process Reactive Implementation:
docker run -it player-communication ./run.sh inProcess 10
-
For Separate Processes Implementation:
docker run -it player-communication ./run.sh separateProcess 10
The project includes a comprehensive test suite to ensure the correctness of the implementation. To run the tests locally:
mvn clean test-
Player Class:
- Validates the
sendMessageandreceiveMessagemethods. - Verifies log file creation and content.
- Validates the
-
Reactive In-Process Communication:
- Ensures seamless reactive message exchanges between
InitiatorandResponder.
- Ensures seamless reactive message exchanges between
-
Separate Processes Communication:
- Tests the setup and interaction between separate processes for
InitiatorandResponder.
- Tests the setup and interaction between separate processes for
-
Logging Utility:
- Confirms proper logging for each player's actions.
Each player’s actions are logged to separate files in the target directory:
target/initiator.log: Logs actions for theInitiator.target/responder.log: Logs actions for theResponder.
The logs contain details of all messages sent and received.