Home Projects About Contact Linkedin GitHub

UDP Elevator


This elevator application used Java Threads and uses UDP Communication to allow a Scheduler to handle multiple elevators and user requests.




Project Goal


The UDP Elevator project was proposed to my team and I as part of my course work towards my Software Engineering degree at Carleton University. The goal was to develop a system that began by using Java Threads for asynchronous communication between the different subsystems. It then used UDP Communication so each subsystem was able to run on different computers. There were three distinct subsystems that we needed to implement:



Project Breakdown


The Floor subsystem is how instructions are passed from the user, a data.txt file, to the other two subsystems, similar to how a regular elevator would work. To begin, the Floor organizes the instructions in order of occurrnce based on time before sending the commands one by one to the Scheduler subsystem. Through asynchronous Java Thread or UDP communication, the Floor puts the commands in a waiting area until the Scheduler picks them up.


The Scheduler subsystem is how instructions are handled and passed to the correct elevator. It determines the best elevator to send an instruction to based on a few metrics such as where each elevator is relative to the incoming request and which direction they're going. Similarly to the Floor subsystem, the Scheduler sends the instruction to chosen elevator's waiting area until that elevator picks it up to execute.


The Elevator subsystem is the subsystem that handles executing all the instructions that are passed properly. It handles the elevators moving up and down floors, picking up passengers, and dropping them off on their correct floors. It also handles if there are any errors with the elevator such as doors not opening or the elevator getting stuck. It sends these errors back to the Scheduler so that the Scheduler can remove that elevator from the list of working elevators.


Thought Process & Design


We began by building upon a lock and key example of Java Threads using mutual exclusion with a Chef, an Agent, and a Table portion. The Chef is tasked with making peanut butter and jelly sandwiches. It consists of three ingredients - peanut butter, jelly, and bread. The Agent provides two out of the three ingredients and stores them on the Table. The Chef then takes the ingredients from the table and provides the missing ingredients in order to complete the sandwich. In this case, the Table represents the lock or critical section and can only be unlocked by either the Chef or Agent, depending on the state of the running Thread.


In the UDP Elevator case, the Scheduler was the critical section with the Floor putting instructions into the critical section and the Elevator getting instructions.


We then improved on the critical section by implementing a state machine that decides which elevator to send an instruction to. At this point, we had four elevators that needed to be properly scheduled with incoming requests. For this, we had to write sudo code for how our state machine would make decisions. It took a few iterations to get the decision logic just right so that it worked as an elevator should and properly sent correct elevators instructions.


After the state machine was implemented, we transitioned our backend from using Java Threads to handle communication, to UDP/IP communication over ports. We used Datagram Packets and Sockets to implement the UDP functionality and spent a lot of time transitioning how information was passed from Floor to Scheduler to Elevator and back again as the information being passed needed to remain the same.


Finally, we implemented error handling throughout the software. We began by handling input faults that made sure that proper commands were being sent from the data.txt file to the Floor. We also implemented handles for if an elevator's doors didn't open or close. Our elevator handles the error gracefully and continues on its way to pick up and drop off passengers. We also implemented error handling for if the elevator got stuck. This would send an error message back to the Scheduler letting it know to take that elevator off the list of elevators.


Final Thoughts


Overall this project was very interesting and I definitely learned a lot about Java Threads and UDP/IP communcation. I also learned how to plan an algorithm at the sudo level before its actually implemented and realized its importance. Furthermore, I learned how to implement a state machine within a piece of software as the dicision maker.