mmayoub

Airport system, AirportCaller class

Aug 25th, 2017
107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package AirportPkg;
  2.  
  3. class AirportCaller extends Thread {
  4.     // create airplanes and call the airport
  5.     private boolean canBeCalled;
  6.     private Airport calledAirport;
  7.  
  8.     public AirportCaller(Airport calledAirport) {
  9.         this.calledAirport = calledAirport;
  10.         this.canBeCalled = calledAirport.isOpen();
  11.  
  12.         this.start();
  13.     }
  14.  
  15.     public void stopCalling() throws InterruptedException {
  16.         this.canBeCalled = false;
  17.         this.join();
  18.     }
  19.  
  20.     @Override
  21.     public void run() {
  22.         while (this.canBeCalled) {
  23.             calledAirport.newCall(new Airplane(calledAirport));
  24.  
  25.             try {
  26.                 Thread.sleep(Utils.getNextCallTime());
  27.             } catch (InterruptedException e) {
  28.                 // TODO Auto-generated catch block
  29.                 e.printStackTrace();
  30.             }
  31.         }
  32.     }
  33. }
RAW Paste Data