/** * Implements execution conventions for RecursiveActions. */ protected final boolean exec() { compute(); return true; }
@Override protected void compute() { List<RecursiveAction> actions = new ArrayList<>(); for (int i = 0; i < 6; i++) { actions.add(new RecursiveAction() { @Override protected void compute() { try { Blockers.enterMonitor(monitor); try { assertThat(monitor.isOccupiedByCurrentThread(), equalTo(true)); int n = running.incrementAndGet(); assertThat(n, equalTo(1)); Thread.sleep(100); running.decrementAndGet(); } finally { monitor.leave(); } } catch (InterruptedException e) { throw new RuntimeException(e); } } }); } invokeAll(actions); for (RecursiveAction action: actions) { action.join(); } } });
/** * Wait till all the recursive task for add replica to volume completed. * * @param subTaskQueue * {@link AddReplicaProcessor} tasks list. * @param exceptions * exceptions occurred in sub tasks. * @throws IOException * throw if any sub task or multiple sub tasks failed. */ private void waitForSubTaskToFinish(Queue<RecursiveAction> subTaskQueue, List<IOException> exceptions) throws IOException { while (!subTaskQueue.isEmpty()) { RecursiveAction task = subTaskQueue.poll(); if (task != null) { task.join(); } } if (!exceptions.isEmpty()) { throw MultipleIOException.createIOException(exceptions); } }
@Override protected void compute() { invokeAll(transforms.stream().<RecursiveAction>map(c -> new RecursiveAction() { @Override protected void compute() { // just ignore result, because removed class can't be transformed c.createVisitor(info); } }).toArray(ForkJoinTask[]::new)); } });
public boolean cancelActionIfExists() { if (actionStack != null && !actionStack.isEmpty()) { RecursiveAction action = (RecursiveAction) actionStack.poll(); action.cancel(true); return true; } return false; } }
@Override public List<IEvent> getEventsRange(Collection<String> firstEvId, Collection<String> lastEvId, long limit, long minDepth) { int realLimit = Math.min(50, (int) limit); BlockingQueue<IEvent> events = new ArrayBlockingQueue<>(realLimit); RecursiveAction getEvTask = new GetChildEventsRecursiveAction(lastEvId, firstEvId, minDepth, events); ForkJoinPool.commonPool().execute(getEvTask); try { getEvTask.get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } return new ArrayList<>(events); }
@Override protected void compute() { List<RecursiveAction> actions = new ArrayList<>(); for (int i = 0; i < 6; i++) { actions.add(new RecursiveAction() { @Override protected void compute() { try { Blockers.acquireSemaphore(sem); try { int n = running.incrementAndGet(); assertThat(n, greaterThan(0)); assertThat(n, lessThanOrEqualTo(2)); Thread.sleep(100); running.decrementAndGet(); } finally { sem.release(); } } catch (InterruptedException e) { throw new RuntimeException(e); } } }); } invokeAll(actions); for (RecursiveAction action: actions) { action.join(); } } });
/** * Update the count of each directory with quota in the namespace. * A directory's count is defined as the total number inodes in the tree * rooted at the directory. * * This is an update of existing state of the filesystem and does not * throw QuotaExceededException. */ void updateCountForQuota(int initThreads) { writeLock(); try { int threads = (initThreads < 1) ? 1 : initThreads; LOG.info("Initializing quota with " + threads + " thread(s)"); long start = Time.monotonicNow(); QuotaCounts counts = new QuotaCounts.Builder().build(); ForkJoinPool p = new ForkJoinPool(threads); RecursiveAction task = new InitQuotaTask(getBlockStoragePolicySuite(), rootDir.getStoragePolicyID(), rootDir, counts); p.execute(task); task.join(); p.shutdown(); LOG.info("Quota initialization completed in " + (Time.monotonicNow() - start) + " milliseconds\n" + counts); } finally { writeUnlock(); } }
@Override protected void compute() { RecursiveAction[] list = new RecursiveAction[buckets.size()]; for (int i = 0; i < buckets.size(); i++) { final Bucket b = buckets.get(i); list[i] = new RecursiveAction() { private static final long serialVersionUID = 1L; @Override protected void compute() { b.generateBucket(hash, maxBucketSize, maxBits); } }; } pool.invokeAll(list); } });
/** * Implements execution conventions for RecursiveActions. */ protected final boolean exec() { compute(); return true; }
public boolean joinActionIfExists() { if (actionStack != null && !actionStack.isEmpty()) { RecursiveAction action = (RecursiveAction) actionStack.poll(); action.join(); return true; } return false; }
/** * Implements execution conventions for RecursiveActions. */ protected final boolean exec() { compute(); return true; }
/** * Update the count of each directory with quota in the namespace. * A directory's count is defined as the total number inodes in the tree * rooted at the directory. * * This is an update of existing state of the filesystem and does not * throw QuotaExceededException. */ static void updateCountForQuota(BlockStoragePolicySuite bsps, INodeDirectory root, int threads) { threads = (threads < 1) ? 1 : threads; LOG.info("Initializing quota with " + threads + " thread(s)"); long start = Time.now(); QuotaCounts counts = new QuotaCounts.Builder().build(); ForkJoinPool p = new ForkJoinPool(threads); RecursiveAction task = new InitQuotaTask(bsps, root.getStoragePolicyID(), root, counts); p.execute(task); task.join(); p.shutdown(); LOG.info("Quota initialization completed in " + (Time.now() - start) + " milliseconds\n" + counts); }
/** * Implements execution conventions for RecursiveActions. */ protected final boolean exec() { compute(); return true; }
/** * Implements execution conventions for RecursiveActions. */ protected final boolean exec() { compute(); return true; }
/** * Implements execution conventions for RecursiveActions. */ protected final boolean exec() { compute(); return true; }
/** * Implements execution conventions for RecursiveActions. */ protected final boolean exec() { compute(); return true; }
/** * Implements execution conventions for RecursiveActions. */ protected final boolean exec() { compute(); return true; }
/** * Implements execution conventions for RecursiveActions. */ protected final boolean exec() { compute(); return true; }
/** * Implements execution conventions for RecursiveActions. */ protected final boolean exec() { compute(); return true; }