   import javax.realtime.*;
   public class FireMissile
   {
   
      public FireMissile()
      {
        System.out.println("Fire missile constrcutor");
        //try
        {
          fireController1 = new FireAction();
          fireController2 = new FireAction();
          immortalController1 = new ImmortalAction();
          immortalController2 = new ImmortalAction();
          SizeEstimator s = new SizeEstimator();
          s.reserve(Decrypt.class,2);
          s.reserve(Barrier.class,1);
          shared = new LTMemory(s.getEstimate(), s.getEstimate());
          System.out.println("Fire missile created memory area, size " 
               +s.getEstimate());
        }
       // catch(Exception e) {System.out.println("Exception " +e);};
      
      }
   
      class FireAction implements Runnable
      { 
        String authorization;
        boolean result;
        public void run()
        {
          Barrier sync;
          // System.out.println("running in shared scoped memory 1");
          Decrypt check = new Decrypt();
          // System.out.println("running in shared scoped memory 2");
          boolean confirmed = check.confirm(authorization);
          // System.out.println("running in shared scoped memory 3");
          synchronized(RealtimeThread.getCurrentMemoryArea())
          {
            sync = (Barrier)shared.getPortal();
            // System.out.println("running in shared scoped memory 4");
                                 
            if(sync == null)
            {
              try {
              sync = new Barrier(2);
              shared.setPortal(sync);
              Thread.sleep(10000);
              } catch(InterruptedException ie) {};
                                   
              // System.out.println("running in shared scoped memory 5");
            }
          }
          result = sync.waitB(confirmed); 
         //System.out.println("running in shared scoped memory result " +result);
       }
    }
      
    class ImmortalAction implements Runnable
    {
        FireAction fireController;
        public void run()
        {
         System.out.println("running in immortal memory, new stack");
         shared.enter(fireController); // enter shared scoped memory
        }
    }
      
      private LTMemory shared;
      // private boolean result;
      private FireAction fireController1, fireController2;
      private ImmortalAction immortalController1, immortalController2;
   
      public boolean fire1(final String authorizationCode)
      {
        try
        {
         immortalController1.fireController = fireController1;
         fireController1.authorization = authorizationCode;
         ImmortalMemory.instance().executeInArea(immortalController1);
        }
        catch(Exception e) { System.out.println("caught exception " +e);};
        return fireController1.result;
      }  
      public boolean fire2(final String authorizationCode)
      {
        try
        {
         immortalController2.fireController = fireController2;
         fireController2.authorization = authorizationCode;
         ImmortalMemory.instance().executeInArea(immortalController2);
        }
        catch(Exception e) { System.out.println("caught exception " +e);};
        return fireController2.result;
      }  
       
   }
