Web hosting comparison - 1406 Elevator Model (on CD) Appendix H 74
Friday, November 16th, 20071406 Elevator Model (on CD) Appendix H 74 75 doorLocation = location; 76 77 // declare Thread that ensures automatic Door closing 78 Thread closeThread = new Thread( 79 new Runnable() { 80 81 public void run() 82 { 83 // close Door if open for more than 3 seconds 84 try { 85 Thread.sleep( AUTOMATIC_CLOSE_DELAY ); 86 closeDoor( doorLocation ); 87 } 88 89 // handle exception if interrupted 90 catch ( InterruptedException exception ) { 91 exception.printStackTrace(); 92 } 93 } 94 } // end anonymous inner class 95 ); 96 97 closeThread.start(); 98 } 99 } // end method openDoor 100 101 // close Door and send all listeners DoorEvent objects 102 public void closeDoor( Location location ) 103 { 104 if ( open ) { 105 106 open = false; 107 108 // obtain iterator from Set 109 Iterator iterator; 110 synchronized( doorListeners ) 111 { 112 iterator = new HashSet( doorListeners ).iterator(); 113 } 114 115 // get next DoorListener 116 while ( iterator.hasNext() ) { 117 DoorListener doorListener = 118 ( DoorListener ) iterator.next(); 119 120 // send doorClosed event to this DoorListener 121 doorListener.doorClosed( 122 new DoorEvent( this, location ) ); 123 } 124 } 125 } // end method closeDoor Fig. H.7 Class Door, which represents a Doorin the model, informs listeners when a Doorhas opened or closed (part 3 of 4).
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.