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.
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.
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.
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.
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.
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.
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.