Archive for November, 2007

Ipower web hosting - Appendix H Elevator Model (on CD) 1435 267

Friday, November 30th, 2007

Appendix H Elevator Model (on CD) 1435 267 break; 269 default: 270 break; 271 } 272 } // end method sendPersonMoveEvent 273 } Fig. H.13 Class Personrepresents the Personthat rides the Elevator. The Personoperates asynchronously with other objects (part 7 of 7). Class Personis subclass of class Thread. The Personperforms all actions, such as walking across Floors and riding the Elevator, in method run (lines 101 172). Method run represents the lifetime of a Person described in the sequence diagram of Fig. 15.20. Class Personcontains a PersonMoveListenerobject (line 23) to which the Personsends PersonMoveEvents. In our simulation, the ElevatorModeluses method setPersonMoveListener (lines 50 54) to register itself as the Person- MoveListener. The ElevatorModel, upon receiving a PersonMoveEvent, sends the event to the ElevatorView therefore, the ElevatorView knows when a Personhas performed certain actions discussed momentarily. There are several types of actions a Person performs in its lifetime, so there exists several types of PersonMoveEvents that a Person may send to the person- MoveListener. Lines 32 37 define a series of constants in which each constant represents a unique type of PersonMoveEvent. The Person sends events to personMoveListenerwhen the Personhas been created the Personarrives at the Elevator the Personenters the Elevator the Personpresses a Button(either in the Elevatoror on a Floor) the Personexits the Elevator the Personexits the simulation When the Person decides to send an event to its PersonMoveListener, the Personcalls privatemethod sendPersonMoveEventand passes the desired constant as a parameter. This method sends the event associated with the constant. For example, line 124 calls sendPersonMoveEvent( PERSON_PRESSED_BUTTON ); when the Person presses a Button on a Floor. In method run, the Person walks to the Elevator, then sends a personArrivedevent upon arrival at the Elevator. We use the activity diagram of Fig. 5.29 to determine the Person s next action. If the Door on the Floor is closed (line 121), the Person must wait for that Door to open. Specifically, line 128 registers the Person as a DoorListener for that Door, and lines 131 132 allow the Personto press the Buttonon that Floor. The Person waits for the Door to open by calling method sleep (line 135) of the Person s superclass Thread. When the Door opens, that Door informs Person in doorOpened
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

1434 Elevator Model (on CD) (Best web hosting) Appendix H 215

Friday, November 30th, 2007

1434 Elevator Model (on CD) Appendix H 215 216 // pause thread for desired number of milliseconds 217 private void pauseThread( int milliseconds ) 218 { 219 try { 220 sleep( milliseconds ); 221 } 222 223 // handle exception if interrupted when paused 224 catch ( InterruptedException interruptedException ) { 225 interruptedException.printStackTrace(); 226 } 227 } // end method pauseThread 228 229 // send PersonMoveEvent to listener, depending on event type 230 private void sendPersonMoveEvent( int eventType ) 231 { 232 // create new event 233 PersonMoveEvent event = 234 new PersonMoveEvent( this, getLocation(), getID() ); 235 236 // send Event to this listener, depending on eventType 237 switch ( eventType ) { 238 239 // Person has been created 240 case PERSON_CREATED: 241 personMoveListener.personCreated( event ); 242 break; 243 244 // Person arrived at Elevator 245 case PERSON_ARRIVED: 246 personMoveListener.personArrived( event ); 247 break; 248 249 // Person entered Elevator 250 case PERSON_ENTERING_ELEVATOR: 251 personMoveListener.personEntered( event ); 252 break; 253 254 // Person pressed Button object 255 case PERSON_PRESSING_BUTTON: 256 personMoveListener.personPressedButton( event ); 257 break; 258 259 // Person exited Elevator 260 case PERSON_EXITING_ELEVATOR: 261 personMoveListener.personDeparted( event ); 262 break; 263 264 // Person exited simulation 265 case PERSON_EXITED: 266 personMoveListener.personExited( event ); Fig. H.13 Class Personrepresents the Personthat rides the Elevator. The Personoperates asynchronously with other objects (part 6 of 7).
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Free web hosting music - Appendix H Elevator Model (on CD) 1433 163

Friday, November 30th, 2007

Appendix H Elevator Model (on CD) 1433 163 // Person exits Elevator 164 sendPersonMoveEvent( PERSON_EXITING_ELEVATOR ); 165 166 // walking from elevator takes five seconds 167 pauseThread( 2 * TIME_TO_WALK ); 168 169 // Person exits simulation 170 sendPersonMoveEvent( PERSON_EXITED ); 171 172 } // end method run 173 174 // Person enters Elevator 175 private void enterAndRideElevator() 176 { 177 // Person enters Elevator 178 sendPersonMoveEvent( PERSON_ENTERING_ELEVATOR ); 179 180 // set Person Location to Elevator 181 Floor floorLocation = ( Floor ) getLocation(); 182 setLocation( 183 floorLocation.getElevatorShaft().getElevator() ); 184 185 // Person takes one second to enter Elevator 186 pauseThread( 1000 ); 187 188 // register for Elevator’s Door’s doorOpen event 189 Door elevatorDoor = getLocation().getDoor(); 190 elevatorDoor.addDoorListener( this ); 191 192 // pressing Elevator Button takes one second 193 sendPersonMoveEvent( PERSON_PRESSING_BUTTON ); 194 pauseThread( 1000 ); 195 196 // get Elevator’s Button 197 Button elevatorButton = getLocation().getButton(); 198 199 // press Elevator’s Button 200 elevatorButton.pressButton( location ); 201 202 // Door closing takes one second 203 pauseThread( 1000 ); 204 205 // ride in Elevator 206 Elevator elevator = ( Elevator ) getLocation(); 207 elevator.ride(); 208 209 // Person finished riding Elevator 210 211 // unregister for Elevator’s Door’s doorOpen event 212 elevatorDoor.removeDoorListener( this ); 213 214 } // end method enterAndRideElevator Fig. H.13 Class Personrepresents the Personthat rides the Elevator. The Personoperates asynchronously with other objects (part 5 of 7).
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

1432 Elevator (Yahoo web space) Model (on CD) Appendix H 111

Thursday, November 29th, 2007

1432 Elevator Model (on CD) Appendix H 111 112 // get current Door on Floor 113 Door currentFloorDoor = location.getDoor(); 114 115 // determine if Door on Floor is open 116 try { 117 118 boolean doorOpen = currentFloorDoor.isDoorOpen(); 119 120 // if Door on Floor is closed 121 if ( !doorOpen ) { 122 123 // press Floor Button 124 sendPersonMoveEvent( PERSON_PRESSING_BUTTON ); 125 pauseThread( 1000 ); 126 127 // register for Floor Door’s doorOpen event 128 currentFloorDoor.addDoorListener( this ); 129 130 // press Floor’s Button to request Elevator 131 Button floorButton = getLocation().getButton(); 132 floorButton.pressButton( getLocation() ); 133 134 // wait for Floor’s Door to open 135 sleep( TIME_WAITING ); 136 137 // unregister with Floor’s Door if too long 138 currentFloorDoor.removeDoorListener( this ); 139 } 140 141 // if Door on Floor is open, ride Eelevator 142 else 143 enterAndRideElevator(); 144 } 145 146 // handle exception when interrupted from waiting 147 catch ( InterruptedException interruptedException ) { 148 149 // Person unregisters for Floor’s Door doorOpen event 150 currentFloorDoor.removeDoorListener( this ); 15 15 // enter and ride Elevator when Door on Floor opens, 15 pauseThread( 1000 ); 15 enterAndRideElevator(); 15 } 15 15 // waiting for Elevator’s Door to open takes a second 15 pauseThread( 1000 ); 15 160 // begin walking away from Elevator 161 setMoving( true ); 162 Fig. H.13 Class Personrepresents the Personthat rides the Elevator. The Personoperates asynchronously with other objects (part 4 of 7).
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Bulletproof web design - Appendix H Elevator Model (on CD) 1431 59

Thursday, November 29th, 2007

Appendix H Elevator Model (on CD) 1431 59 // set Person on Floor where Door opened 60 setLocation( doorEvent.getLocation() ); 61 62 // interrupt Person’s sleep method in run method and 63 // Elevator’s ride method 64 interrupt(); 65 } 66 67 // invoked when Door has closed 68 public void doorClosed( DoorEvent doorEvent ) {} 69 70 // set Person Location 71 private void setLocation( Location newLocation ) 72 { 73 location = newLocation; 74 } 75 76 // get current Location 77 private Location getLocation() 78 { 79 return location; 80 } 81 82 // get identifier 83 public int getID() 84 { 85 return ID; 86 } 87 88 // set if Person should move 89 public void setMoving( boolean personMoving ) 90 { 91 moving = personMoving; 92 } 93 94 // get if Person should move 95 public boolean isMoving() 96 { 97 return moving; 98 } 99 100 // Person either rides or waits for Elevator 101 public void run() 102 { 103 sendPersonMoveEvent( PERSON_CREATED ); 104 105 // walk to Elevator 106 pauseThread( TIME_TO_WALK ); 107 setMoving( false ); 108 109 // Person arrived at Floor Button 110 sendPersonMoveEvent( PERSON_ARRIVED ); Fig. H.13 Class Personrepresents the Personthat rides the Elevator. The Personoperates asynchronously with other objects (part 3 of 7).
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Shared web hosting - 1430 Elevator Model (on CD) Appendix H 7

Wednesday, November 28th, 2007

1430 Elevator Model (on CD) Appendix H 7 8 // Deitel packages 9 import com.deitel.jhtp4.elevator.event.*; 10 11 public class Person extends Thread implements DoorListener { 12 13 // identification number 14 private int ID = -1; 15 16 // represents whether Person is moving or waiting 17 private boolean moving; 18 19 // reference to Location (either on Floor or in Elevator) 20 private Location location; 21 22 // listener object for PersonMoveEvents 23 private PersonMoveListener personMoveListener; 24 25 // time in milliseconds to walk to Button on Floor 26 private static final int TIME_TO_WALK = 3000; 27 28 // maximum time Person will wait for Elevator (10 minutes) 29 private static final int TIME_WAITING = 10 * 60 * 1000; 30 31 // types of messages Person may send 32 public static final int PERSON_CREATED = 1; 33 public static final int PERSON_ARRIVED = 2; 34 public static final int PERSON_ENTERING_ELEVATOR = 3; 35 public static final int PERSON_PRESSING_BUTTON = 4; 36 public static final int PERSON_EXITING_ELEVATOR = 5; 37 public static final int PERSON_EXITED = 6; 38 39 // Person constructor set initial location 40 public Person( int identifier, Location initialLocation ) 41 { 42 super(); 43 44 ID = identifier; // assign unique identifier 45 location = initialLocation; // set Floor Location 46 moving = true; // start moving toward Button on Floor 47 } 48 49 // set listener for PersonMoveEvents 50 public void setPersonMoveListener( 51 PersonMoveListener listener ) 52 { 53 personMoveListener = listener; 54 } 55 56 // invoked when Door has opened 57 public void doorOpened( DoorEvent doorEvent ) 58 { Fig. H.13 Class Personrepresents the Personthat rides the Elevator. The Personoperates asynchronously with other objects (part 2 of 7).
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Appendix H Elevator Model (on CD) 1429 Line (Web server)

Wednesday, November 28th, 2007

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.

1428 Elevator Model (on CD) Appendix H 372

Tuesday, November 27th, 2007

1428 Elevator Model (on CD) Appendix H 372 } 373 } Fig. H.12 Class Elevatorrepresents the Elevatortraveling between two Floors, operating asynchronously with other objects (part 9 of 9). According to Fig. H.2, class Elevatorimplements interfaces ButtonListener, DoorListener and BellListener and therefore can listen for ButtonEvents, DoorEvents and BellEvents. Class Elevator must send these events to a listener (in this case, the ElevatorShaft), so that these events can bubble up to the ElevatorView. Class Elevator contains a ButtonListener called elevatorButtonListener (line 32), a DoorListener called elevatorDoorListener (line 33) and a BellListenercalled bellListener(line 34). Lines 269 284 list methods setButtonListener, setDoorListenerand setBellListenerthat allow an object such as ElevatorShaft to register as a listener for these events. Class Elevatorcontains an anonymous ButtonListener(lines 84 106) that registers for ButtonEvents from the elevatorButton. When a Personhas pressed the elevatorButton, the ButtonListenercalls method buttonPressed (lines 88 96) of the ButtonListener. Lines 91 92 of this method call method buttonPressed of the elevatorButtonListener, and line 95 informs the Elevatorto move using method setMoving. When the Button has been reset, the ButtonListener calls method buttonReset (lines 99 104) of the ButtonListener. Lines 102 103 of this method calls method buttonResetof the elevatorButtonListener. Class Elevatorcontains an anonymous DoorListener(lines 110 145) that registers for DoorEvents from the elevatorDoor. When the elevatorDoor has opened, the DoorListenercalls method doorOpened(lines 114 127) of this Door- Listener. Lines 121 122 open the Door on the Floor that generated the event, and lines 125 126 call method doorOpened of the elevatorDoorListener. Method doorOpened guarantees that the Door on the Floor opens before the passenger exits the Elevator. When the elevatorDoor has closed, the DoorListener calls method doorClosed(lines 130 143) of the DoorListener. Lines 137 138 close the Door on the Floor that generated the event, and lines 141 142 call method door- Closedof the elevatorDoorListener. Class Elevatoracts as a thread because it implements interface Runnable. Method run(lines 173 204) handles the travel between Floors. The method begins with the Elevatorremaining idle in a whileloop (lines 178 179). The loop exits when method buttonPressedin the anonymous ButtonListenercalls method setMoving. When the Elevator exits the loop, the Elevator closes the elevatorDoor (line 182) then calls private method sendDepartureEvent (lines 316 333), to inform all listeners the elevatorButton, the elevatorDoor, the bell and the ElevatorShaft of the Elevator s departure. Class Elevator contains Set elevatorMoveListeners (line 31), which stores all registered Elevator- MoveListeners. Objects wishing to receive ElevatorMoveEvents from the Elevator must call method addElevatorMoveListener (lines 262 266), which appends that object to elevatorMoveListeners. Method sendDepartureEvent invokes method elevatorDeparted of each listener object in Set elevator- MoveListeners.
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

Appendix H Elevator Model (on (Web server hosting) CD) 1427 320

Tuesday, November 27th, 2007

Appendix H Elevator Model (on CD) 1427 320 321 // get next DoorListener 322 while ( iterator.hasNext() ) { 323 324 // get next ElevatorMoveListener from Set 325 ElevatorMoveListener listener = 326 ( ElevatorMoveListener ) iterator.next(); 327 328 // send ElevatorMoveEvent to this listener 329 listener.elevatorDeparted( new ElevatorMoveEvent( 330 this, currentFloorLocation ) ); 331 332 } // end while loop 333 } // end method sendDepartureEvent 334 335 // request Elevator 336 public void requestElevator( Location location ) 337 { 338 // if Elevator is idle 339 if ( !isMoving() ) { 340 341 // if Elevator is on same Floor of request 342 if ( location == currentFloorLocation ) 343 344 // Elevator has already arrived; send arrival event 345 sendArrivalEvent( currentFloorLocation ); 346 347 // if Elevator is on opposite Floor of request 348 else { 349 350 if ( getDoor().isDoorOpen() ) 351 pauseThread( Door.AUTOMATIC_CLOSE_DELAY ); 352 setMoving( true ); // move to other Floor 353 } 354 } 355 else // if Elevator is moving 356 357 // if Elevator departed from same Floor as request 358 if ( location == currentFloorLocation ) 359 summoned = true; 360 36 // if Elevator is traveling to Floor of request, 36 // continue traveling 36 36 } // end method requestElevator 36 36 // invoked when bell has rung 36 public void bellRang( BellEvent bellEvent ) 36 { 36 // send event to bellListener 370 if ( bellListener != null ) 371 bellListener.bellRang( bellEvent ); Fig. H.12 Class Elevatorrepresents the Elevatortraveling between two Floors, operating asynchronously with other objects (part 8 of 9).
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Free web design - 1426 Elevator Model (on CD) Appendix H 268

Monday, November 26th, 2007

1426 Elevator Model (on CD) Appendix H 268 // register ButtonListener for ButtonEvents 269 public void setButtonListener( ButtonListener listener ) 270 { 271 elevatorButtonListener = listener; 272 } 273 274 // register DoorListener for DoorEvents 275 public void setDoorListener( DoorListener listener ) 276 { 277 elevatorDoorListener = listener; 278 } 279 280 // register BellListener fpr BellEvents 281 public void setBellListener( BellListener listener ) 282 { 283 bellListener = listener; 284 } 285 286 // notify all ElevatorMoveListeners of arrival 287 private void sendArrivalEvent( Location location ) 288 { 289 // obtain iterator from Set 290 Iterator iterator = elevatorMoveListeners.iterator(); 291 292 // get next DoorListener 293 while ( iterator.hasNext() ) { 294 295 // get next ElevatorMoveListener from Set 296 ElevatorMoveListener listener = 297 ( ElevatorMoveListener ) iterator.next(); 298 299 // send event to listener 300 listener.elevatorArrived( new 301 ElevatorMoveEvent( this, location ) ); 302 303 } // end while loop 304 305 // service queued request, if one exists 306 if ( summoned ) { 307 pauseThread( Door.AUTOMATIC_CLOSE_DELAY ); 308 setMoving( true ); // start moving Elevator 309 } 310 31 summoned = false; // request has been serviced 31 31 } // end method sendArrivalEvent 31 31 // notify all ElevatorMoveListeners of departure 31 private void sendDepartureEvent( Location location ) 31 { 31 // obtain iterator from Set 31 Iterator iterator = elevatorMoveListeners.iterator(); Fig. H.12 Class Elevatorrepresents the Elevatortraveling between two Floors, operating asynchronously with other objects (part 7 of 9).
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.