This project implements a Producer-Consumer system using various design patterns to ensure efficient and flexible code. The project involves designing and simulating a factory where machines and queues interact to process products. The application utilizes WebSocket for real-time updates and maintains a simple design for ease of use and understanding. Threads are employed to handle concurrent operations efficiently.
frontend.-.Google.Chrome.2024-01-23.17-32-28.-.Copy.1.mp4
- Factory Simulation: Allows users to design a factory layout with machines and queues.
- Asynchronous Processing: Uses a queue to manage the production and consumption of products asynchronously.
- Real-Time Updates: Frontend is updated in real-time using WebSocket.
- Control Options: Users can start, stop, replay, and create new simulations.
- Thread Management: Ensures efficient handling of concurrent operations during the simulation.
- Color Scheme: The colors used are suitable and provide clear visual distinction between different elements.
- Time Left Display: Each machine shows the remaining time to complete the current product.
- Queue Information: The number of products in each queue is displayed, helping users monitor the flow of production.
- Purpose: To allow an object (subject) to notify dependent objects (observers) of state changes.
- Implementation:
- An interface declares the update method.
- The subject calls this method to notify changes.
- Promotes flexibility and decouples subjects from observers.
- Purpose: To capture and externalize an object's internal state, allowing it to be restored later.
- Implementation:
- Originator saves its state to a Memento.
- Caretaker maintains a history of Mementos.
- Facilitates undo functionality and separates state management concerns.
- Purpose: To ensure a single instance of a class.
- Implementation:
- Used for MachineManager, QueueManager, and SimulationManager.
- Private constructors and synchronized getInstance() methods.
- Ensures efficient resource usage and streamlined management.
- Purpose: To manage asynchronous processing between producers and consumers.
- Implementation:
- Producers add items to a queue.
- Consumers pull items from the queue.
- Scheduler sends updates at regular intervals.
- Modular Design: The project is broken into parts to ease programming.
- Observer Integration: Models for machines, queues, and products contain observers to track changes.
- WebSocket Usage: Keeps the frontend updated in real-time.
- Thread Management: Threads are used to handle concurrent operations during the simulation.
- Factory Layout: Users can design the factory by adding machines and queues and connecting them.
- Add Machine: Select "Add Machine" and click on the screen to place it.
- Add Queue: Select "Add Queue" and click on the screen to place it.
- Connect Items: Select "Connect Items" and click on the shapes to connect machines and queues.
- Play: Starts the simulation and input stream.
- Stop: Pauses the simulation. Click "Play" to resume.
- Replay: Replays the last simulation.
- New Simulation: Starts a new simulation and resets the factory layout.
- Node.js
- A web browser (preferably Google Chrome)
- Run the Backend:
-
Open a terminal.
-
Navigate to the backend directory.
-
Run the backend server:
sh Copy code npm start -
The backend will run on port 8080.
-
- Run the Frontend:
-
Open a new terminal.
-
Navigate to the frontend directory.
-
Run the frontend server:
sh Copy code npm run serve -
The frontend will run on port 8081.
-
- Access the Application:
- Open a web browser.
- Navigate to localhost:8081.

