public synchronized void stop() {
   if (thread != null) {
     thread.interrupt();
   }
   thread = null;
   notifyAll();
 }
 @Override
 protected void onCancelPressed() {
   super.onUpdatePressed();
   if (installerThread != null) {
     installerThread.interrupt();
   }
 }
Example #3
0
 public void run() {
   if (Thread.currentThread() != this.mt)
     throw (new RuntimeException("MainFrame is being run from an invalid context"));
   Thread ui = new HackThread(p, "Haven UI thread");
   ui.start();
   try {
     try {
       Session sess = null;
       while (true) {
         UI.Runner fun;
         if (sess == null) {
           Bootstrap bill = new Bootstrap(Config.defserv, Config.mainport);
           if ((Config.authuser != null) && (Config.authck != null)) {
             bill.setinitcookie(Config.authuser, Config.authck);
             Config.authck = null;
           }
           fun = bill;
           setTitle(String.format("Amish Paradise %s", version));
         } else {
           fun = new RemoteUI(sess);
           setTitle(String.format("Amish Paradise %s \u2013 %s", version, sess.username));
         }
         sess = fun.run(p.newui(sess));
       }
     } catch (InterruptedException e) {
     }
     savewndstate();
   } finally {
     ui.interrupt();
     dispose();
   }
 }
Example #4
0
 public void stopEvaluate() {
   // user requested run be stopped so tell
   // run thread to stop
   Thread tmp = runThread;
   runThread = null;
   tmp.interrupt();
 }
 public synchronized void stop() {
   running = false;
   try {
     thread.join();
   } catch (InterruptedException e) {
     thread.interrupt();
   }
 }
Example #6
0
 /** Request that the loading of the applet be stopped. */
 protected synchronized void stopLoading() {
   // REMIND: fill in the body
   if (loaderThread != null) {
     // System.out.println("Interrupting applet loader thread: " + loaderThread);
     loaderThread.interrupt();
   } else {
     setLoadAbortRequest();
   }
 }
Example #7
0
 void setMessage(Animator a) {
   anim = a;
   who.setText(a.author());
   ref.setText(a.description());
   pan.remove(last);
   last = a.container();
   pan.add(last, "Center");
   if (T != null) T.interrupt();
 }
 /** Disconnects from running debugged process. */
 public void disconnect() throws DebuggerException {
   threadGroup.setRemoteThreadGroup(null);
   if (remoteDebugger != null) {
     remoteDebugger.close();
     remoteDebugger = null;
   }
   if (debuggerThread != null) {
     debuggerThread.interrupt();
     debuggerThread.stop();
   }
   super.finishDebugger();
   synchronizer = null;
 }
 public static synchronized void fail(String whyFailed) {
   Sysout.println("The test failed: " + whyFailed);
   Sysout.println("The test is over, hit  Ctl-C to stop Java VM");
   // check if this called from main thread
   if (mainThread == Thread.currentThread()) {
     // If main thread, fail now 'cause not sleeping
     throw new RuntimeException(whyFailed);
   }
   theTestPassed = false;
   testGeneratedInterrupt = true;
   failureMessage = whyFailed;
   mainThread.interrupt();
 } // fail()
Example #10
0
  // Handle the keystrokes
  public void keyTyped(KeyEvent e) {

    switch (e.getKeyChar()) {
      case 'h':
        gl.matrixMode(GL.MODELVIEW); /* manipulate modelview matrix  */
        gl.rotate(15.0, 0.0, 1.0, 0.0);
        break;
      case 'j':
        gl.matrixMode(GL.MODELVIEW); /* manipulate modelview matrix  */
        gl.rotate(15.0, 1.0, 0.0, 0.0);
        break;
      case 'k':
        gl.matrixMode(GL.MODELVIEW); /* manipulate modelview matrix  */
        gl.rotate(-15.0, 1.0, 0.0, 0.0);
        break;
      case 'l':
        gl.matrixMode(GL.MODELVIEW); /* manipulate modelview matrix  */
        gl.rotate(-15.0, 0.0, 1.0, 0.0);
        break;
      case '+':
        gl.matrixMode(GL.PROJECTION); /* manipulate Projection matrix  */
        gl.translate(0.0, 0.0, 0.5);
        e.consume();
        break;
      case '-':
        gl.matrixMode(GL.PROJECTION); /* manipulate Projection matrix  */
        gl.translate(0.0, 0.0, -0.5);
        e.consume();
        break;
      case 's':
        if (r_thread == null) {
          r_thread = new Thread(this);
          r_thread.start();
        }
        break;
      case 'p':
        if (r_thread != null) {
          r_thread.interrupt();
          r_thread = null;
        }
        break;
      case 27: /* Esc will quit */
        System.exit(1);
        break;
      default:
        break;
    }
    e.consume();
    display();
  }
 public static synchronized void pass() {
   Sysout.println("The test passed.");
   Sysout.println("The test is over, hit  Ctl-C to stop Java VM");
   // first check if this is executing in main thread
   if (mainThread == Thread.currentThread()) {
     // Still in the main thread, so set the flag just for kicks,
     // and throw a test passed exception which will be caught
     // and end the test.
     theTestPassed = true;
     throw new TestPassedException();
   }
   theTestPassed = true;
   testGeneratedInterrupt = true;
   mainThread.interrupt();
 } // pass()
  @SuppressWarnings({"BusyWait"})
  private static void forceInterrupt(Thread thread) {
    /*
      ddmlib has incorrect handling of InterruptedException, so we need to invoke it several times,
      because there are three blocking invokation in succession
    */

    for (int i = 0; i < 6 && thread.isAlive(); i++) {
      thread.interrupt();
      try {
        Thread.sleep(200);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
  }
 /**
  * The disconnect method will stop the eventreplayer, and send null to the other peers, to stop
  * their reading from their streams. The GUI-menu is updated appropriately.
  */
 public void disconnect() {
   setTitle("Disconnected");
   active = false;
   if (connected == true) {
     er.stopStreamToQueue();
     ert.interrupt();
     setDocumentFilter(null);
     connected = false;
     setLocked(false);
   }
   deregisterOnPort();
   Disconnect.setEnabled(false);
   Connect.setEnabled(true);
   Listen.setEnabled(true);
   Save.setEnabled(true);
   SaveAs.setEnabled(true);
 }
  public void run() {
    long start, end, sleepTime;

    while (running) {
      start = System.currentTimeMillis();
      if (gridSet) {
        grid.scanStep();
      }
      repaint();
      end = System.currentTimeMillis();
      // Sleep to match FPS limit
      sleepTime = (1000 / framerate) - (end - start);
      if (sleepTime > 0) {
        try {
          Thread.sleep(sleepTime);
        } catch (InterruptedException e) {
          thread.interrupt();
        }
      }
    }
  }
Example #15
0
  void killPlayThread() {
    tellThreadToStop();

    try {
      if (playThread != null) {
        while (playThread.isAlive()) {
          try {
            playThread.interrupt();
          }
          // Ignore security exceptions resulting from
          // attempting to interrupt a thread.
          // TODO Explain this better.
          catch (SecurityException ex) {
          }
          playThread.join(50);
        }

        playThread = null;
      }
    } catch (InterruptedException ex) {
      System.out.println("Interrupted while killing the play thread.  Shouldn't happen.");
    }
  }
Example #16
0
 public void stop() {
   if (thd != null) thd.interrupt();
   thd = null;
 }
  public void buttonPressed(Button button) {
    if (button.getId() == TitleMenu.RESTART_GAME_ID) {
      clearMenus();
      TitleMenu menu = new TitleMenu(GAME_WIDTH, GAME_HEIGHT);
      addMenu(menu);

    } else if (button.getId() == TitleMenu.START_GAME_ID) {
      clearMenus();
      isMultiplayer = false;

      localId = 0;
      synchronizer = new TurnSynchronizer(this, null, 0, 1);
      synchronizer.setStarted(true);

      createLevel(TitleMenu.level);
    } else if (button.getId() == TitleMenu.SELECT_LEVEL_ID) {
      addMenu(new LevelSelect(false));
    } else if (button.getId() == TitleMenu.SELECT_HOST_LEVEL_ID) {
      addMenu(new LevelSelect(true));
    } else if (button.getId() == TitleMenu.HOST_GAME_ID) {
      addMenu(new HostingWaitMenu());
      isMultiplayer = true;
      isServer = true;
      try {
        if (isServer) {
          localId = 0;
          serverSocket = new ServerSocket(3000);
          serverSocket.setSoTimeout(1000);

          hostThread =
              new Thread() {

                public void run() {
                  boolean fail = true;
                  try {
                    while (!isInterrupted()) {
                      Socket socket = null;
                      try {
                        socket = serverSocket.accept();
                      } catch (SocketTimeoutException e) {

                      }
                      if (socket == null) {
                        System.out.println("asdf");
                        continue;
                      }
                      fail = false;

                      packetLink = new NetworkPacketLink(socket);

                      createServerState = 1;
                      break;
                    }
                  } catch (Exception e) {
                    e.printStackTrace();
                  }
                  if (fail) {
                    try {
                      serverSocket.close();
                    } catch (IOException e) {
                    }
                  }
                };
              };
          hostThread.start();
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (button.getId() == TitleMenu.JOIN_GAME_ID) {
      addMenu(new JoinGameMenu());
    } else if (button.getId() == TitleMenu.CANCEL_JOIN_ID) {
      popMenu();
      if (hostThread != null) {
        hostThread.interrupt();
        hostThread = null;
      }
    } else if (button.getId() == TitleMenu.PERFORM_JOIN_ID) {
      menuStack.clear();
      isMultiplayer = true;
      isServer = false;

      try {
        localId = 1;
        packetLink = new ClientSidePacketLink(TitleMenu.ip, 3000);
        synchronizer = new TurnSynchronizer(this, packetLink, localId, 2);
        packetLink.setPacketListener(this);
      } catch (Exception e) {
        e.printStackTrace();
        // System.exit(1);
        addMenu(new TitleMenu(GAME_WIDTH, GAME_HEIGHT));
      }
    } else if (button.getId() == TitleMenu.SELECT_DIFFICULTY_ID) {
      addMenu(new DifficultySelect());
    } else if (button.getId() == TitleMenu.EXIT_GAME_ID) {
      System.exit(0);
    }
  }
 public void interrupt() {
   super.interrupt();
   System.out.println("(interrupt)");
 }