The Player Communicator Service is a Java-based messaging service designed for handling and processing messages between players. It leverages a BlockingQueue to manage incoming messages and provides functionality to process and respond to these messages based on sender and recipient interactions.
- Asynchronous Message Processing: Utilizes a BlockingQueue to handle incoming messages asynchronously.
- Sender-Recipient Interaction Tracking: Keeps track of the number of messages exchanged between each sender and recipient pair.
- Graceful Shutdown: Supports graceful shutdown after processing a maximum number of messages for a given sender-recipient pair.
- Java Development Kit (JDK) 8 or higher.
- An IDE that supports Java (e.g., IntelliJ IDEA, Eclipse).
- Clone the repository to your local machine.
- Import the project into your IDE as a Maven or Gradle project, depending on your project setup.
- Ensure that your IDE recognizes the src folder as the source root.
The code can be run through the following command sh run.sh
- This will create a
player-communication-1.0-SNAPSHOT.jar
file in the target folder. - It will also run the unit test case.
- It will finally run the code.
Three players are created and they are communicating with each other with the same shared queue. It will send the message back accordingly back to the sender with concatenating the previous message respectively.
- Initialize a BlockingQueue instance with your desired capacity.
- Create an instance of MessageProcessor by passing the BlockingQueue to its constructor.
- Use the addMessage(Message message) method to add messages to the processing queue.
- Start the message processing thread by calling startProcessing(int maxProcessing), where maxProcessing is the maximum number of messages to be processed for a sender-recipient pair before shutting down the service gracefully.