HARINIRODRIGO / Ticket-Machine

The implementation ensures the capability to print tickets and facilitates the refilling process. The monitor pattern is employed to guarantee mutual exclusion, enhancing the concurrent execution of threads.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ticket-Machine: Java Implementation of the FSP Model

1. TicketMachine Class

The TicketMachine class serves as an implementation of the ServiceTicketMachine interface. It leverages the Ticket class to represent tickets and manages ticket paper and toner levels. The implementation ensures the capability to print tickets and facilitates the refilling process. The monitor pattern is employed to guarantee mutual exclusion, enhancing the concurrent execution of threads.

2. Passenger Class

The Passenger class is designed to represent individuals engaged in purchasing and printing tickets. This class utilizes the Ticket class to store and convey ticket information. The implementation includes random sleep intervals between printing requests, simulating real-world scenarios.

3. TicketPaperTechnician Class

The TicketPaperTechnician class emulates a technician responsible for refilling the Ticket Machine's paper supply. The class attempts to refill paper three times, incorporating random sleep intervals to simulate varying real-world conditions.

4. TicketTonerTechnician Class

The TicketTonerTechnician class represents a technician tasked with replacing the Ticket Machine's toner cartridge. Similar to the paper technician, toner replacement attempts are made three times with random sleep intervals to mimic realistic operational challenges.

5. TicketPrintingSystem

The TicketPrintingSystem class serves as the orchestrator, coordinating the interactions among the TicketMachine, Passengers, and Technicians. This involves creating necessary threads and thread groups to simulate concurrent execution. Additionally, it ensures all threads complete execution before printing the final Ticket Machine status, providing a comprehensive overview of the system's state.

Usage

To utilize the Ticket Printing System, instantiate the TicketPrintingSystem class, which will automatically initiate the threads for TicketMachine, Passengers, and Technicians. Observe the final Ticket Machine status after the completion of all threads.

Implementation Details

The Java implementation adheres to the Formal Methods Specification (FSP) model, emphasizing correctness and synchronization through the monitor pattern. The use of random sleep intervals adds a touch of realism to the simulation, enhancing the robustness of the system under diverse conditions.


About

The implementation ensures the capability to print tickets and facilitates the refilling process. The monitor pattern is employed to guarantee mutual exclusion, enhancing the concurrent execution of threads.


Languages

Language:Java 100.0%