List of usage examples for com.google.common.util.concurrent MoreExecutors platformThreadFactory
@Beta @GwtIncompatible("concurrency") public static ThreadFactory platformThreadFactory()
From source file:org.apache.bookkeeper.common.util.ExecutorUtils.java
/** * Get a {@link ThreadFactory} suitable for use in the current environment. * * @param nameFormat to apply to threads created by the factory. * @param daemon {@code true} if the threads the factory creates are daemon threads, * {@code false} otherwise. * @return a {@link ThreadFactory}./* w ww . j av a 2 s . c o m*/ */ public static ThreadFactory getThreadFactory(String nameFormat, boolean daemon) { ThreadFactory threadFactory = MoreExecutors.platformThreadFactory(); return new ThreadFactoryBuilder().setThreadFactory(threadFactory).setDaemon(daemon) .setNameFormat(nameFormat).build(); }
From source file:org.ftccommunity.ftcxtensible.robot.RobotContext.java
private RobotContext() { serverSettings = ServerSettings.createServerSettings(); status = new RobotStatus(this, RobotStatus.LogTypes.HTML); postedData = new LinkedList<>(); extensibleGamepad1 = new ExtensibleGamepad(); extensibleGamepad2 = new ExtensibleGamepad(); asyncService = MoreExecutors/*from ww w . ja v a 2 s .c om*/ .listeningDecorator(Executors.newCachedThreadPool(MoreExecutors.platformThreadFactory())); cameraManager = new CameraManager(this); logger = new RobotLogger(this); }
From source file:org.apache.beam.runners.direct.portable.ExecutorServiceParallelExecutor.java
private ExecutorServiceParallelExecutor(int targetParallelism, RootProviderRegistry rootRegistry, TransformEvaluatorRegistry registry, ExecutableGraph<PTransformNode, PCollectionNode> graph, EvaluationContext context) {//from w ww . j ava2 s .c o m this.targetParallelism = targetParallelism; // Don't use Daemon threads for workers. The Pipeline should continue to execute even if there // are no other active threads (for example, because waitUntilFinish was not called) this.executorService = Executors.newFixedThreadPool(targetParallelism, new ThreadFactoryBuilder().setThreadFactory(MoreExecutors.platformThreadFactory()) .setNameFormat("direct-runner-worker").build()); this.rootRegistry = rootRegistry; this.registry = registry; this.graph = graph; this.evaluationContext = context; // Weak Values allows TransformExecutorServices that are no longer in use to be reclaimed. // Executing TransformExecutorServices have a strong reference to their TransformExecutorService // which stops the TransformExecutorServices from being prematurely garbage collected serialExecutorServices = CacheBuilder.newBuilder().weakValues() .removalListener(shutdownExecutorServiceListener()) .build(serialTransformExecutorServiceCacheLoader()); this.visibleUpdates = new QueueMessageReceiver(); parallelExecutorService = TransformExecutorServices.parallel(executorService); executorFactory = new DirectTransformExecutor.Factory(context, registry); }
From source file:org.apache.beam.runners.direct.ExecutorServiceParallelExecutor.java
private ExecutorServiceParallelExecutor(int targetParallelism, DirectGraph graph, RootProviderRegistry rootProviderRegistry, TransformEvaluatorRegistry registry, @SuppressWarnings("rawtypes") Map<Class<? extends PTransform>, Collection<ModelEnforcementFactory>> transformEnforcements, EvaluationContext context) {/* w ww. ja v a2 s .c o m*/ this.targetParallelism = targetParallelism; // Don't use Daemon threads for workers. The Pipeline should continue to execute even if there // are no other active threads (for example, because waitUntilFinish was not called) this.executorService = Executors.newFixedThreadPool(targetParallelism, new ThreadFactoryBuilder().setThreadFactory(MoreExecutors.platformThreadFactory()) .setNameFormat("direct-runner-worker").build()); this.graph = graph; this.rootProviderRegistry = rootProviderRegistry; this.registry = registry; this.transformEnforcements = transformEnforcements; this.evaluationContext = context; // Weak Values allows TransformExecutorServices that are no longer in use to be reclaimed. // Executing TransformExecutorServices have a strong reference to their TransformExecutorService // which stops the TransformExecutorServices from being prematurely garbage collected executorServices = CacheBuilder.newBuilder().weakValues().removalListener(shutdownExecutorServiceListener()) .build(serialTransformExecutorServiceCacheLoader()); this.allUpdates = new ConcurrentLinkedQueue<>(); this.visibleUpdates = new LinkedBlockingQueue<>(); parallelExecutorService = TransformExecutorServices.parallel(executorService); defaultCompletionCallback = new TimerIterableCompletionCallback(Collections.<TimerData>emptyList()); this.pendingRootBundles = new ConcurrentHashMap<>(); }
From source file:org.apache.beam.runners.direct.SplittableProcessElementsEvaluatorFactory.java
@SuppressWarnings({ "unchecked", "rawtypes" })
private TransformEvaluator<KeyedWorkItem<String, ElementAndRestriction<InputT, RestrictionT>>> createEvaluator(
AppliedPTransform<PCollection<KeyedWorkItem<String, ElementAndRestriction<InputT, RestrictionT>>>, PCollectionTuple, ProcessElements<InputT, OutputT, RestrictionT, TrackerT>> application,
CommittedBundle<InputT> inputBundle) throws Exception {
final ProcessElements<InputT, OutputT, RestrictionT, TrackerT> transform = application.getTransform();
ProcessFn<InputT, OutputT, RestrictionT, TrackerT> processFn = transform.newProcessFn(transform.getFn());
DoFnLifecycleManager fnManager = DoFnLifecycleManager.of(processFn);
processFn = ((ProcessFn<InputT, OutputT, RestrictionT, TrackerT>) fnManager
.<KeyedWorkItem<String, ElementAndRestriction<InputT, RestrictionT>>, OutputT>get());
String stepName = evaluationContext.getStepName(application);
final DirectExecutionContext.DirectStepContext stepContext = evaluationContext
.getExecutionContext(application, inputBundle.getKey()).getStepContext(stepName);
final ParDoEvaluator<KeyedWorkItem<String, ElementAndRestriction<InputT, RestrictionT>>> parDoEvaluator = delegateFactory
.createParDoEvaluator(application, inputBundle.getKey(), transform.getSideInputs(),
transform.getMainOutputTag(), transform.getAdditionalOutputTags().getAll(), stepContext,
processFn, fnManager);
processFn.setStateInternalsFactory(new StateInternalsFactory<String>() {
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from www. jav a 2 s .c om*/
public StateInternals stateInternalsForKey(String key) {
return (StateInternals) stepContext.stateInternals();
}
});
processFn.setTimerInternalsFactory(new TimerInternalsFactory<String>() {
@Override
public TimerInternals timerInternalsForKey(String key) {
return stepContext.timerInternals();
}
});
OutputWindowedValue<OutputT> outputWindowedValue = new OutputWindowedValue<OutputT>() {
private final OutputManager outputManager = parDoEvaluator.getOutputManager();
@Override
public void outputWindowedValue(OutputT output, Instant timestamp,
Collection<? extends BoundedWindow> windows, PaneInfo pane) {
outputManager.output(transform.getMainOutputTag(),
WindowedValue.of(output, timestamp, windows, pane));
}
@Override
public <AdditionalOutputT> void outputWindowedValue(TupleTag<AdditionalOutputT> tag,
AdditionalOutputT output, Instant timestamp, Collection<? extends BoundedWindow> windows,
PaneInfo pane) {
outputManager.output(tag, WindowedValue.of(output, timestamp, windows, pane));
}
};
processFn.setProcessElementInvoker(
new OutputAndTimeBoundedSplittableProcessElementInvoker<InputT, OutputT, RestrictionT, TrackerT>(
transform.getFn(), evaluationContext.getPipelineOptions(), outputWindowedValue,
evaluationContext.createSideInputReader(transform.getSideInputs()),
// TODO: For better performance, use a higher-level executor?
// TODO: (BEAM-723) Create a shared ExecutorService for maintenance tasks in the
// DirectRunner.
Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder()
.setThreadFactory(MoreExecutors.platformThreadFactory()).setDaemon(true)
.setNameFormat("direct-splittable-process-element-checkpoint-executor").build()),
10000, Duration.standardSeconds(10)));
return DoFnLifecycleManagerRemovingTransformEvaluator.wrapping(parDoEvaluator, fnManager);
}