Skip to content

rowaina2025/Producer-Consumer-Simulation-Program-1

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Producer-Consumer-Simulation-Program

A project generated by Angular CLI version 14.2.10 for frontend and Springboot version 3.0.2 for backend.

Contents:

Section number Title
1 Description
2 Features
3 Design patterns applied
4 Design Decisions
5 UML class diagram
6 User manual to run the code
7 Program_UI
8 User Guide

Description:

An assembly line that produces different products consists of different processing machines Ms that are responsible for processing the product at different stages and queue Qs to handle product movement between different processing stages. In this assignment, we will develop a simulation program to simulate this production line as a queuing network.

Features:

The simulation system supports the following features:

  • Users can graphically add Qs and Ms, connect them via UI arbitrarily.
  • The input (products arriving at Q0 to get processed) has a random input rate.
  • Each M has a random service time and can serve one product at a time. Once completed, it needs to check the queue if waiting products need to be consumed, if not then it needs to register itself to the queue as ready (Hint: check observer design pattern).
  • Each machine is running and processing its products on a separate thread different from other machines’ processing threads. The UI shows the simulation by displaying the number of elements in the Qs in real time.
  • Ms flash when they finish servicing an item and every product has its own color (a random color) that will keep it from start till the end and each machine will change its color the product’s color being processed by it then change back to a default color once done to make following the simulation easy for the user.
  • After the simulation ends, the user can start a new simulation or replay the previous simulation.

Design_patterns_applied

1. Concurrency: “ Producer/Consumer DP”

  • Each machine runs on a separate thread consuming products from a queue such that if the queue is empty, it waits, otherwise it takes a product from the queue and processes it for its service time.

2. Observer:

  • Each machine is an observer which observes the queues -observable- it consumes its products from.
  • When the queue is empty, it registers itself to the queue as an observer and waits for notification.
  • When the queue contains elements, it notifies its observers so they can consume them.

3. Snapshot:

  • System keeps states of its machines and queues once updated so we can replay the whole simulation again.
  • A Memento class saves the state of the machine and the queue.
  • An Originator class to save the states.
  • A CareTaker class to retrieve the state.

4. Singleton:

  • CareTaker class implements singleton to have only one instance of it.

Design_Decisions

  • User should specify the total number of products at the beginning.
  • User can’t connect 2 queues or 2 machines together.
  • Each machine has only one destination queue.
  • A machine can’t be either the source or the final destination of the unit.
  • Products have random input rate (5 seconds maximum).
  • Each machine has random service time (5 seconds maximum).

UML_class_diagram

Backend:

image

Frontend:

image

User_manual_to_run_the_code

  • In cmd cd to backend folder and run ./mvnw spring-boot: run or by opening the folder with java IDE then run the main file ProducerConsumerApplication.java
  • Open frontend folder and open new terminal then type ng serve and navigate to this link http://localhost:4200/

Program_UI

User_Guide

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 46.7%
  • TypeScript 43.9%
  • CSS 3.7%
  • JavaScript 2.9%
  • HTML 2.8%