示例#1
0
  private void processClose() {
    if (Registry.getInstance().isRestartNeeded()) {
      final ApplicationEx app = (ApplicationEx) ApplicationManager.getApplication();
      final ApplicationInfo info = ApplicationInfo.getInstance();

      final int r =
          Messages.showOkCancelDialog(
              myContent,
              "You need to restart " + info.getVersionName() + " for the changes to take effect",
              "Restart Required",
              (app.isRestartCapable() ? "Restart Now" : "Shutdown Now"),
              (app.isRestartCapable() ? "Restart Later" : "Shutdown Later"),
              Messages.getQuestionIcon());

      if (r == 0) {
        LaterInvocator.invokeLater(
            new Runnable() {
              public void run() {
                if (app.isRestartCapable()) {
                  app.restart();
                } else {
                  app.exit(true);
                }
              }
            },
            ModalityState.NON_MODAL);
      }
    }
  }
  static void invokeAndWait(
      @NotNull final Runnable runnable, @NotNull ModalityState modalityState) {
    LOG.assertTrue(!isDispatchThread());

    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    final Ref<Throwable> exception = Ref.create();
    Runnable runnable1 =
        new Runnable() {
          @Override
          public void run() {
            try {
              runnable.run();
            } catch (Throwable e) {
              exception.set(e);
            } finally {
              semaphore.up();
            }
          }

          @Override
          @NonNls
          public String toString() {
            return "InvokeAndWait[" + runnable + "]";
          }
        };
    invokeLater(runnable1, modalityState);
    semaphore.waitFor();
    if (!exception.isNull()) {
      throw new RuntimeException(exception.get());
    }
  }
示例#3
0
  public static void invokeAndWaitInterruptedWhenClosing(
      final Project project, final Runnable runnable, final ModalityState modalityState) {
    final Ref<Boolean> start = new Ref<Boolean>(Boolean.TRUE);
    final Application application = ApplicationManager.getApplication();
    LOG.assertTrue(!application.isDispatchThread());

    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    Runnable runnable1 =
        new Runnable() {
          public void run() {
            try {
              runnable.run();
            } finally {
              semaphore.up();
            }
          }

          @NonNls
          public String toString() {
            return "PeriodicalTaskCloser's invoke and wait [" + runnable.toString() + "]";
          }
        };
    LaterInvocator.invokeLater(
        runnable1,
        modalityState,
        new Condition<Object>() {
          public boolean value(Object o) {
            synchronized (start) {
              return !start.get();
            }
          }
        });

    while (true) {
      if (semaphore.waitFor(1000)) {
        return;
      }
      final Ref<Boolean> fire = new Ref<Boolean>();
      synchronized (ourLock) {
        final Boolean state = myStates.get(project);
        if (!Boolean.TRUE.equals(state)) {
          fire.set(Boolean.TRUE);
        }
        if (Boolean.TRUE.equals(fire.get())) {
          synchronized (start) {
            start.set(Boolean.FALSE);
            return;
          }
        }
      }
    }
  }