예제 #1
0
파일: Bdb.java 프로젝트: jefron-ap/TTK
  public static void setup(String dbRoot, boolean staticPublish) {

    System.out.println("setup dbRoot: " + dbRoot);
    stampCache = new ConcurrentHashMap<>();
    try {
      closed = false;
      syncService =
          Executors.newFixedThreadPool(1, new NamedThreadFactory(dbdThreadGroup, "Sync service"));

      BdbCommitManager.reset();
      NidDataFromBdb.resetExecutorPool();
      BdbPathManager.reset();

      for (@SuppressWarnings("unused") OFFSETS o : OFFSETS.values()) {
        // ensure all OFFSETS are initialized prior to multi-threading.
      }
      bdbDirectory = new File(dbRoot);
      System.out.println("absolute dbRoot: " + bdbDirectory.getAbsolutePath());
      viewCoordinateMapFile = new File(bdbDirectory, "viewCoordinates.oos");
      bdbDirectory.mkdirs();
      LuceneManager.setLuceneRootDir(bdbDirectory);

      mutable = new Bdb(false, new File(bdbDirectory, "mutable"));
      File readOnlyDir = new File(bdbDirectory, "read-only");
      boolean readOnlyExists = readOnlyDir.exists();
      readOnly = new Bdb(readOnlyExists, readOnlyDir);
      if (Looker.lookup(TtkEnvironment.class).useFxWorkers()) {

        Platform.runLater(
            new Runnable() {
              @Override
              public void run() {
                try {

                  startupWithFx();

                } catch (InterruptedException | ExecutionException ex) {
                  Logger.getLogger(Bdb.class.getName()).log(Level.SEVERE, null, ex);
                }
              }
            });
      } else {
        startupNoFx();
      }

    } catch (IOException | DatabaseException | IllegalArgumentException e) {
      throw new RuntimeException(e);
    } catch (InterruptedException ex) {
      Logger.getLogger(Bdb.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ExecutionException ex) {
      Logger.getLogger(Bdb.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
예제 #2
0
파일: Bdb.java 프로젝트: jefron-ap/TTK
  // Close the environment
  public static void close() throws InterruptedException, ExecutionException {
    if (closed == false && mutable != null && mutable.bdbEnv != null) {
      closed = true;
      try {
        I_ShowActivity activity = new ConsoleActivityViewer();

        activity.setStopButtonVisible(false);

        activity.setProgressInfoLower("1-a/11: Stopping Isa Cache generation.");

        FileOutputStream fos = new FileOutputStream(viewCoordinateMapFile);
        try (ObjectOutputStream oos = new ObjectOutputStream(fos)) {
          oos.writeObject(viewCoordinates);
        }

        activity.setProgressInfoLower("2/11: Starting sync using service.");
        assert conceptDb != null : "conceptDb is null...";
        new Sync().run();
        activity.setProgressInfoLower("3/11: Shutting down sync service.");
        syncService.shutdown();

        activity.setProgressInfoLower("4/11: Awaiting termination of sync service.");
        syncService.awaitTermination(90, TimeUnit.MINUTES);

        activity.setProgressInfoLower("5/11: Starting PositionMapper close.");
        activity.setProgressInfoLower("6/11: Canceling uncommitted changes.");
        BdbCommitManager.cancel();
        activity.setProgressInfoLower("7/11: Starting BdbCommitManager shutdown.");
        BdbCommitManager.shutdown();
        activity.setProgressInfoLower("8/11: Starting LuceneManager close.");
        LuceneManager.close();

        NidDataFromBdb.close();
        activity.setProgressInfoLower("9/11: Starting mutable.bdbEnv.sync().");
        mutable.bdbEnv.sync();
        activity.setProgressInfoLower("10/11: mutable.bdbEnv.sync() finished.");
        uuidsToNidMapDb.close();
        nidCidMapDb.close();
        stampDb.close();
        conceptDb.close();
        propDb.close();
        mutable.bdbEnv.sync();
        mutable.bdbEnv.close();
        stampCache.clear();
        activity.setProgressInfoLower("11/11: Shutdown complete");
      } catch (DatabaseException e) {
        AceLog.getAppLog().alertAndLogException(e);
      } catch (Exception e) {
        AceLog.getAppLog().alertAndLogException(e);
      }
    }
    if (readOnly != null && readOnly.bdbEnv != null) {
      readOnly.bdbEnv.close();
    }
    annotationConcepts = null;
    conceptDb = null;
    mutable = null;
    nidCidMapDb = null;
    pathManager = null;
    propDb = null;
    readOnly = null;
    stampCache = null;
    stampDb = null;
    uuidsToNidMapDb = null;

    ConceptChronicle.reset();
    AceLog.getAppLog().info("bdb close finished.");
  }