Appendix H Elevator Model (on CD) 1429 Line (Web server)
Appendix H Elevator Model (on CD) 1429 Line 191 of method run allows the Elevator to travel to the Floor by calling method pauseThread (lines 219 229) this simulates travel by invoking method sleepof class Thread. The Elevatorstops moving when its thread awakens after five seconds. Line 197 calls private method changeFloors (lines 149 154), which swaps currentFloorLocation and destinationFloorLocation. Line 200 calls private method sendArrivalEvent (lines 287 313), which invokes method elevatorArrived of all listeners in Set elevatorMoveListeners. Lines 306 309 of method sendArrivalEvent service any queued request (e.g., a Person pressed a Button on the Floor from which the Elevator has departed). If a queued request exists, line 308 invokes method setMovingto move the Elevatorto the opposite Floor. Method requestElevator(lines 336 364) requests the Elevatorand generates a queued request. In our model, the ButtonListener defined in the inner class of the ElevatorShaftcalls this method when a Buttonon either Floorhas been pressed. The activity diagram of Fig. 5.30 specifies the logic for method requestElevator. If the Elevatoris idle and on the same Flooras the Floorof the request, line 345 calls method sendArrivalEvent, because the Elevatorhas already arrived. If the Elevatoris idle but on the opposite Floorfrom the Floorof the request, line 352 moves the Elevator to the opposite Floor. If the Elevator is traveling to the Floor that generated the request, the Elevator should continue traveling to that Floor. If the Elevatoris traveling away from the Floorthat generated the request, the Elevator must remember to return to that Floor(lines 358 359). Lastly, as mentioned in Section 15.12, class Elevator contains synchronized method ride (lines 207 216). The Person calls this method to guarantee exclusivity with the Elevator. Method rideensures that two Person objects cannot occupy the Elevatorat the same time. When a Personobject invokes method ride, that Person object obtains a monitor on the Elevatorobject. Other objects may not access the Elevatoruntil that Personreleases the monitor by exiting method ride. H.9 Class Person Class Person(Fig. H.13) represents a Person that walks across the Floors and rides the Elevatorin our simulation. According to the class diagram of Fig. 15.21, class Person contains one object of class Location (line 20) that represents the Person s current location in the model (either on a Flooror in the Elevator). In addition, Fig. 15.21 specifies that Person requires int attribute ID (line 14) as a unique identifier and booleanattribute moving(line 17), which indicates whether Personis walking across the Flooror waiting for a Doorto open. 1 // Person.java 2 // Person riding the elevator 3 package com.deitel.jhtp4.elevator.model; 5 // Java core packages 6 import java.util.*; Fig. H.13 Class Personrepresents the Personthat rides the Elevator. The Personoperates asynchronously with other objects (part 1 of 7).
We recommend high quality webhost to host and run your jsp application: christian web host services.