Exemplo n.º 1
0
  public static File browseForDirectory(final Component comp, final String initialDirectory) {

    setWaitCursor(comp);

    final JFileChooser chooser;

    if (initialDirectory == null) {
      chooser = new JFileChooser();
    } else {
      chooser = new JFileChooser(initialDirectory);
    }

    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

    SyncThread<File, Object> exec =
        new SyncThread<File, Object>() {
          public void setup() {
            setDefCursor(comp);
            int rsp = chooser.showOpenDialog(comp);
            if (rsp == JFileChooser.APPROVE_OPTION) {
              setValue(chooser.getSelectedFile());
            }
          }
        };

    exec.block();
    return exec.getValue();
  }
Exemplo n.º 2
0
  public static File browseForFile(
      final Component comp, final String initialDirectory, final boolean save) {

    setWaitCursor(comp);

    final JFileChooser chooser;

    if (initialDirectory == null) {
      chooser = new JFileChooser();
    } else {
      chooser = new JFileChooser(initialDirectory);
    }

    SyncThread<File, Object> exec =
        new SyncThread<File, Object>() {
          public void setup() {
            setDefCursor(comp);
            int rsp = 0;
            if (save) {
              rsp = chooser.showSaveDialog(comp);
            } else {
              rsp = chooser.showOpenDialog(comp);
            }
            if (rsp == JFileChooser.APPROVE_OPTION) {
              setValue(chooser.getSelectedFile());
            }
          }
        };

    exec.block();
    return exec.getValue();
  }
Exemplo n.º 3
0
  public static boolean confirmAction(
      final Component parent, final String prompt, final String title) {

    SyncThread<Boolean, Object> exec =
        new SyncThread<Boolean, Object>() {
          public void setup() {
            int rtn =
                JOptionPane.showConfirmDialog(parent, prompt, title, JOptionPane.YES_NO_OPTION);
            setValue(rtn == JOptionPane.YES_OPTION);
          }
        };

    exec.block();
    return exec.getValue();
  }
Exemplo n.º 4
0
  public static int promptYesNoCancel(
      final Component parent, final String prompt, final String title) {

    SyncThread<Integer, Object> exec =
        new SyncThread<Integer, Object>() {
          public void setup() {
            int rtn =
                JOptionPane.showConfirmDialog(
                    parent, prompt, title, JOptionPane.YES_NO_CANCEL_OPTION);
            setValue(rtn);
          }
        };

    exec.block();
    return exec.getValue();
  }
Exemplo n.º 5
0
  // internal shutdown method to let shutdown bookie gracefully
  // when encountering exception
  synchronized int shutdown(int exitCode) {
    try {
      if (running) { // avoid shutdown twice
        // the exitCode only set when first shutdown usually due to exception found
        this.exitCode = exitCode;
        // mark bookie as in shutting down progress
        shuttingdown = true;

        // Shutdown Sync thread
        syncThread.shutdown();

        // Shutdown disk checker
        ledgerDirsManager.shutdown();
        if (indexDirsManager != ledgerDirsManager) {
          indexDirsManager.shutdown();
        }

        // Shutdown journal
        journal.shutdown();
        this.join();

        // Shutdown the EntryLogger which has the GarbageCollector Thread running
        ledgerStorage.shutdown();

        // close Ledger Manager
        try {
          activeLedgerManager.close();
          activeLedgerManagerFactory.uninitialize();
        } catch (IOException ie) {
          LOG.error("Failed to close active ledger manager : ", ie);
        }

        // Shutdown the ZK client
        if (zk != null) zk.close();

        // Shutdown State Service
        stateService.shutdown();

        // setting running to false here, so watch thread in bookie server know it only after bookie
        // shut down
        running = false;
      }
    } catch (InterruptedException ie) {
      LOG.error("Interrupted during shutting down bookie : ", ie);
    }
    return this.exitCode;
  }
Exemplo n.º 6
0
  @Override
  public synchronized void start() {
    setDaemon(true);
    LOG.info("I'm starting a bookie with journal directory {}", journalDirectory.getName());
    // Start DiskChecker thread
    ledgerDirsManager.start();
    if (indexDirsManager != ledgerDirsManager) {
      indexDirsManager.start();
    }

    // start sync thread first, so during replaying journals, we could do checkpoint
    // which reduce the chance that we need to replay journals again if bookie restarted
    // again before finished journal replays.
    syncThread.start();

    // replay journals
    try {
      readJournal();
    } catch (IOException ioe) {
      LOG.error("Exception while replaying journals, shutting down", ioe);
      shutdown(ExitCode.BOOKIE_EXCEPTION);
      return;
    } catch (BookieException be) {
      LOG.error("Exception while replaying journals, shutting down", be);
      shutdown(ExitCode.BOOKIE_EXCEPTION);
      return;
    }

    // Do a fully flush after journal replay
    try {
      syncThread.requestFlush().get();
    } catch (InterruptedException e) {
      LOG.warn("Interrupting the fully flush after replaying journals : ", e);
      Thread.currentThread().interrupt();
    } catch (ExecutionException e) {
      LOG.error("Error on executing a fully flush after replaying journals.");
      shutdown(ExitCode.BOOKIE_EXCEPTION);
    }

    // start bookie thread
    super.start();

    // After successful bookie startup, register listener for disk
    // error/full notifications.
    ledgerDirsManager.addLedgerDirsListener(getLedgerDirsListener());
    if (indexDirsManager != ledgerDirsManager) {
      indexDirsManager.addLedgerDirsListener(getLedgerDirsListener());
    }

    ledgerStorage.start();

    // set running here.
    // since bookie server use running as a flag to tell bookie server whether it is alive
    // if setting it in bookie thread, the watcher might run before bookie thread.
    running = true;
    try {
      registerBookie(true).get();
    } catch (Exception ie) {
      LOG.error("Couldn't register bookie with zookeeper, shutting down : ", ie);
      shutdown(ExitCode.ZK_REG_FAIL);
    }
  }