Beispiel #1
0
  public static void downloadEncrypted(List<NUSTitleInformation> output_, final Progress progress) {
    ForkJoinPool pool = ForkJoinPool.commonPool();
    List<ForkJoinTask<Boolean>> list = new ArrayList<>();

    for (final NUSTitleInformation nus : output_) {
      final long tID = nus.getTitleID();
      list.add(
          pool.submit(
              new Callable<Boolean>() {
                @Override
                public Boolean call() throws Exception {
                  NUSTitle nusa =
                      new NUSTitle(
                          tID, nus.getSelectedVersion(), Util.ByteArrayToString(nus.getKey()));
                  Progress childProgress = new Progress();
                  progress.add(childProgress);
                  nusa.downloadEncryptedFiles(progress);

                  return true;
                }
              }));
    }
    for (ForkJoinTask<Boolean> task : list) {
      try {
        task.get();
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
Beispiel #2
0
 /** Completed submit(ForkJoinTask) returns result */
 public void testSubmitForkJoinTask() throws Throwable {
   ForkJoinPool p = new ForkJoinPool(1);
   try (PoolCleaner cleaner = cleaner(p)) {
     ForkJoinTask<Integer> f = p.submit(new FibTask(8));
     assertEquals(21, (int) f.get());
   }
 }
 /**
  * Start the ingest procedure.
  *
  * @param iterator the iterator to iterate on
  * @return the pid of the root object, or null of something odd failed
  */
 @Override
 public String ingest(TreeIterator iterator) {
   this.iterator = iterator;
   ForkJoinPool forkJoinPool = new ForkJoinPool(concurrency);
   ForkJoinTask<String> result;
   result = forkJoinPool.submit(this);
   forkJoinPool.shutdown();
   try {
     return result.get();
   } catch (CancellationException | ExecutionException | InterruptedException e) {
     log.warn("Shutting down pool {}", forkJoinPool);
     result.cancel(true);
     forkJoinPool.shutdownNow();
     boolean shutdown;
     try {
       shutdown = forkJoinPool.awaitTermination(3, TimeUnit.MINUTES);
     } catch (InterruptedException e1) {
       shutdown = false;
     }
     if (!shutdown) {
       log.error("Failed to shut down forkjoinpool {}", forkJoinPool);
       System.exit(1);
     }
     log.debug("Pool shot down {}", forkJoinPool);
     throw new IngesterShutdownException(e);
   }
 }
Beispiel #4
0
 /** Pool maintains parallelism when using ManagedBlocker */
 public void testBlockingForkJoinTask() throws Throwable {
   ForkJoinPool p = new ForkJoinPool(4);
   try {
     ReentrantLock lock = new ReentrantLock();
     ManagedLocker locker = new ManagedLocker(lock);
     ForkJoinTask<Integer> f = new LockingFibTask(20, locker, lock);
     p.execute(f);
     assertEquals(6765, (int) f.get());
   } finally {
     p.shutdownNow(); // don't wait out shutdown
   }
 }
Beispiel #5
0
  public static void downloadEncryptedAllVersions(
      List<NUSTitleInformation> output_, final Progress progress) {
    ForkJoinPool pool = new ForkJoinPool(25);

    List<ForkJoinTask<Boolean>> list = new ArrayList<>();
    final int outputsize = output_.size();
    for (final NUSTitleInformation nus : output_) {
      final long tID = nus.getTitleID();
      list.add(
          pool.submit(
              new Callable<Boolean>() {
                @Override
                public Boolean call() throws Exception {
                  int count = 1;
                  for (Integer i : nus.getAllVersions()) {
                    NUSTitle nusa = new NUSTitle(tID, i, Util.ByteArrayToString(nus.getKey()));
                    Progress childProgress = new Progress();
                    progress.add(childProgress);
                    nusa.downloadEncryptedFiles(progress);
                    System.out.println(
                        "Update download progress "
                            + "("
                            + nus.getLongnameEN()
                            + ") version "
                            + i
                            + " complete! This was "
                            + count
                            + " of "
                            + nus.getAllVersions().size()
                            + "!");
                    count++;
                  }
                  System.out.println(
                      "Update download complete "
                          + "("
                          + nus.getLongnameEN()
                          + ")"
                          + "! Loaded updates for "
                          + nus.getAllVersions().size()
                          + " version. Now are "
                          + finished.incrementAndGet()
                          + " of "
                          + outputsize
                          + " done! ");
                  return true;
                }
              }));
    }

    for (ForkJoinTask<Boolean> task : list) {
      try {
        task.get();
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }