コード例 #1
0
ファイル: Bdb.java プロジェクト: jefron-ap/TTK
  private static void startupNoFx() throws InterruptedException, ExecutionException {
    FutureTask<Void> setupPropDbTask =
        new FutureTask<>(
            new Callable<Void>() {
              @Override
              public Void call() throws Exception {
                propDb = new PropertiesBdb(readOnly, mutable);
                finishSetup();
                return null;
              }
            });

    FutureTask<Void> setupUuidsToNidMapDb =
        new FutureTask<>(
            new Callable<Void>() {
              @Override
              public Void call() throws Exception {
                uuidsToNidMapDb = new UuidToNidMapBdb(readOnly, mutable);
                finishSetup();
                return null;
              }
            });

    FutureTask<Void> setupComponentNidToConceptNidDb =
        new FutureTask<>(
            new Callable<Void>() {
              @Override
              public Void call() throws Exception {
                nidCidMapDb = new NidCNidMapBdb(readOnly, mutable);
                finishSetup();
                return null;
              }
            });

    FutureTask<Void> setupStampDb =
        new FutureTask<>(
            new Callable<Void>() {
              @Override
              public Void call() throws Exception {
                stampDb = new StampBdb(readOnly, mutable);
                finishSetup();
                return null;
              }
            });

    FutureTask<Void> setupConceptDb =
        new FutureTask<>(
            new Callable<Void>() {
              @Override
              public Void call() throws Exception {
                conceptDb = new ConceptBdb(readOnly, mutable);
                finishSetup();
                return null;
              }
            });

    ExecutorService startupService =
        Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
    Future<?> task = startupService.submit(setupPropDbTask);
    task.get();
    startupService.submit(setupUuidsToNidMapDb);
    startupService.submit(setupStampDb);
    setupUuidsToNidMapDb.get(); // prerequisite for setupComponentNidToConceptNidDb
    startupService.submit(setupComponentNidToConceptNidDb);

    setupComponentNidToConceptNidDb.get(); // prerequisite for setupConceptDb
    startupService.submit(setupConceptDb);
    startupService.shutdown();
    setupPropDbTask.get();
    setupUuidsToNidMapDb.get();
    setupStampDb.get();
    setupConceptDb.get();
  }
コード例 #2
0
ファイル: Bdb.java プロジェクト: jefron-ap/TTK
  public static void selectJeProperties(File configDir, File dbDir) throws IOException {
    long maxMem = Runtime.getRuntime().maxMemory();
    configDir.mkdirs();
    File jePropOptionsDir = new File(configDir, "je-prop-options");
    jePropOptionsDir.mkdirs();
    for (HeapSize size : HeapSize.values()) {
      File destFile = new File(configDir, size.configFileName);
      if (!destFile.exists()) {
        FileIO.copyFile(size.getPropFile(configDir), new File(configDir, size.configFileName));
      }
    }

    File mutableDir = new File(dbDir, "mutable");
    File readOnlyDir = new File(dbDir, "read-only");
    mutableDir.mkdirs();
    if (maxMem > 8000000000L) {
      heapSize = HeapSize.HEAP_8000;
      FileIO.copyFile(
          new File(configDir, HeapSize.HEAP_8000.configFileName),
          new File(mutableDir, "je.properties"));
      if (readOnlyDir.exists()) {
        FileIO.copyFile(
            new File(configDir, HeapSize.HEAP_8000.configFileName),
            new File(readOnlyDir, "je.properties"));
      }
    } else if (maxMem > 6000000000L) {
      heapSize = HeapSize.HEAP_6000;
      FileIO.copyFile(
          new File(configDir, HeapSize.HEAP_6000.configFileName),
          new File(mutableDir, "je.properties"));
      if (readOnlyDir.exists()) {
        FileIO.copyFile(
            new File(configDir, HeapSize.HEAP_6000.configFileName),
            new File(readOnlyDir, "je.properties"));
      }
    } else if (maxMem > 4000000000L) {
      heapSize = HeapSize.HEAP_4000;
      FileIO.copyFile(
          new File(configDir, HeapSize.HEAP_4000.configFileName),
          new File(mutableDir, "je.properties"));
      if (readOnlyDir.exists()) {
        FileIO.copyFile(
            new File(configDir, HeapSize.HEAP_4000.configFileName),
            new File(readOnlyDir, "je.properties"));
      }
    } else if (maxMem > 2000000000) {
      heapSize = HeapSize.HEAP_2000;
      FileIO.copyFile(
          new File(configDir, HeapSize.HEAP_2000.configFileName),
          new File(mutableDir, "je.properties"));
      if (readOnlyDir.exists()) {
        FileIO.copyFile(
            new File(configDir, HeapSize.HEAP_2000.configFileName),
            new File(readOnlyDir, "je.properties"));
      }
    } else if (maxMem > 1400000000) {
      heapSize = HeapSize.HEAP_1400;
      FileIO.copyFile(
          new File(configDir, HeapSize.HEAP_1400.configFileName),
          new File(mutableDir, "je.properties"));
      if (readOnlyDir.exists()) {
        FileIO.copyFile(
            new File(configDir, HeapSize.HEAP_1400.configFileName),
            new File(readOnlyDir, "je.properties"));
      }
    } else {
      heapSize = HeapSize.HEAP_1200;
      FileIO.copyFile(
          new File(configDir, HeapSize.HEAP_1200.configFileName),
          new File(mutableDir, "je.properties"));
      if (readOnlyDir.exists()) {
        FileIO.copyFile(
            new File(configDir, HeapSize.HEAP_1200.configFileName),
            new File(readOnlyDir, "je.properties"));
      }
    }

    System.out.println("!## maxMem: " + maxMem + " heapSize: " + heapSize);
  }
コード例 #3
0
ファイル: Bdb.java プロジェクト: jefron-ap/TTK
  private static void startupWithFx() throws InterruptedException, ExecutionException {

    final Task<Void> setupPropDbTask =
        new Task<Void>() {
          {
            updateTitle("Setup property database");
            updateMessage("initializing");
            updateProgress(0, 1);
          }

          @Override
          protected Void call() throws Exception {
            updateMessage("starting");

            if (isCancelled()) {
              updateMessage("Cancelled");
              updateProgress(1, 1);
              return null;
            }
            propDb = new PropertiesBdb(readOnly, mutable);
            updateMessage("finished");
            updateProgress(1, 1);
            finishSetup();
            return null;
          }
        };

    final Task<Void> setupUuidsToNidMapDb =
        new Task<Void>() {
          {
            updateTitle("Setup uuid to nid database");
            updateMessage("initializing");
            updateProgress(0, 1);
          }

          @Override
          protected Void call() throws Exception {
            updateMessage("starting");
            if (isCancelled()) {
              updateMessage("Cancelled");
              updateProgress(1, 1);
              return null;
            }
            uuidsToNidMapDb = new UuidToNidMapBdb(readOnly, mutable);
            updateMessage("finished");
            updateProgress(1, 1);
            finishSetup();
            return null;
          }
        };

    final Task<Void> setupComponentNidToConceptNidDb =
        new Task<Void>() {
          {
            updateTitle("Setup component nid to concept nid database");
            updateMessage("initializing");
            updateProgress(0, 1);
          }

          @Override
          protected Void call() throws Exception {
            updateMessage("starting");
            if (isCancelled()) {
              updateMessage("Cancelled");
              updateProgress(1, 1);
              return null;
            }
            nidCidMapDb = new NidCNidMapBdb(readOnly, mutable);
            updateMessage("finished");
            updateProgress(1, 1);
            finishSetup();
            return null;
          }
        };

    final Task<Void> setupStampDb =
        new Task<Void>() {
          {
            updateTitle("Setup STAMP database");
            updateMessage("initializing");
            updateProgress(0, 1);
          }

          @Override
          protected Void call() throws Exception {
            updateMessage("starting");
            if (isCancelled()) {
              updateMessage("Cancelled");
              updateProgress(1, 1);
              return null;
            }
            stampDb = new StampBdb(readOnly, mutable);
            updateMessage("finished");
            updateProgress(1, 1);
            finishSetup();
            return null;
          }
        };

    final Task<Void> setupConceptDb =
        new Task<Void>() {
          {
            updateTitle("Setup Concept database");
            updateMessage("initializing");
            updateProgress(0, 1);
          }

          @Override
          protected Void call() throws Exception {
            updateMessage("starting");
            if (isCancelled()) {
              updateMessage("Cancelled");
              updateProgress(1, 1);
              return null;
            }
            conceptDb = new ConceptBdb(readOnly, mutable);
            updateMessage("finished");
            updateProgress(1, 1);
            finishSetup();
            return null;
          }
        };

    AggregateProgressItem aggregateProgressItem =
        new AggregateProgressItem(
            "Setting up Embedded Termstore...",
            "Berkeley DB Version: " + JEVersion.CURRENT_VERSION.getVersionString(),
            setupPropDbTask,
            setupUuidsToNidMapDb,
            setupComponentNidToConceptNidDb,
            setupStampDb,
            setupConceptDb);

    WorkerPublisher.publish(
        aggregateProgressItem,
        "Termstore startup worker",
        Arrays.asList(new ShowGlobalTaskProgress(), new AllowItemCancel()));

    final ExecutorService startupService =
        Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
    startupService.submit(
        new Runnable() {
          @Override
          public void run() {
            try {
              Future<?> task = startupService.submit(setupPropDbTask);
              task.get();
              startupService.submit(setupUuidsToNidMapDb);
              startupService.submit(setupStampDb);
              setupUuidsToNidMapDb.get(); // prerequisite for setupComponentNidToConceptNidDb
              startupService.submit(setupComponentNidToConceptNidDb);

              setupComponentNidToConceptNidDb.get(); // prerequisite for setupConceptDb

              startupService.submit(setupConceptDb);
              startupService.shutdown();
              setupPropDbTask.get();
              setupUuidsToNidMapDb.get();
              setupStampDb.get();
              setupConceptDb.get();
            } catch (InterruptedException | ExecutionException ex) {
              Logger.getLogger(Bdb.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        });
  }