How agrawald/elevator works
Main Components
• Frontend UI: Represented by the Angular.js components integrated in the JSP pages (e.g., “index.jsp”) and the JavaScript file (elevator.js). This is the client side interfacing with the REST API.
• REST Controllers: Include the BuildingController and ElevatorController. These handle REST endpoints for triggering elevator calls (up/down from floors) and actions from inside the elevator (go to floor, stop, get status).
• Service Layer: Consists of BuildingSvc and ElevatorSvc along with their respective implementations (BuildingSvcImpl and ElevatorSvcImpl). These abstract and manage the core business rules and coordinate interactions between the controllers and the underlying business/logical operations.
• Business/Simulation Layer: Contains the elevator logic via components like ElevatorPub, ElevatorSub, and ElevatorPubSingleton which initialize and run the elevator simulation using a publisher-subscriber pattern.
• Common Definitions: The “common” package provides shared constants, direction enumerations, and the representation for a floor call.
• Integration/3rd Party API: The services, particularly BuildingSvc and ElevatorSvc, also expose APIs to be used by external hardware companies.
• Testing Components: Represented by test classes (SimulatorTest, ElevatorFloorPubSubFactoryTest, etc.) which confirm simulation behavior and REST API functionality.
Relationships and Interactions
• The frontend invokes REST calls (via HTTP methods) which route to the appropriate controllers.
• The controllers translate incoming REST requests into service calls.
• The services then delegate to the business logic:
– For example, a REST call to call an elevator triggers a publisher method (ElevatorPub) to issue a floor call.
– The subscriber (ElevatorSub) for each elevator receives these events such that each elevator thread processes its assigned events.
• The business layer leverages the singleton (ElevatorPubSingleton) to ensure a single source of events for simulation.
• Additionally, external API calls made by hardware companies interact with the services.
• Testing modules simulate calls to both the simulation logic and the REST endpoints to verify correct operation.
Architectural Patterns & Technologies
• MVC Pattern: The Spring MVC design in the backend divides the application into Controllers, Services, and View (JSP).
• Publisher-Subscriber Pattern: Used for handling event distribution between floor call publishers (ElevatorPub) and elevator-specific subscribers (ElevatorSub).
• Singleton Pattern: Used with ElevatorPubSingleton to ensure consistent control over the simulation thread.
• Technologies: Spring MVC for server-side logic, Maven for project build, embedded Jetty as the server, Angular.js for client-side interactions, and traditional REST methods to couple the layers.
Final Checklist for the Principal Software Engineer
• Component (e.g., Frontend, Controllers, Services, Business Logic, Common, Test) is clearly labeled.
• HTTP call → Controller → Service → Business/Simulation layer.
• Business events flowing from ElevatorPub to ElevatorSub.
• Build or configuration artifacts (Maven’s pom.xml, Jetty configuration in web.xml and mvc-dispatcher-servlet.xml) if they affect deployment architecture.