Search in sources :

Example 1 with SchedulingAgentCallback

use of org.apache.nifi.controller.SchedulingAgentCallback in project nifi by apache.

the class StandardProcessScheduler method startProcessor.

/**
 * Starts the given {@link Processor} by invoking its
 * {@link ProcessorNode#start(ScheduledExecutorService, long, org.apache.nifi.processor.ProcessContext, Runnable)}
 * method.
 *
 * @see StandardProcessorNode#start(ScheduledExecutorService, long, org.apache.nifi.processor.ProcessContext, Runnable)
 */
@Override
public synchronized CompletableFuture<Void> startProcessor(final ProcessorNode procNode, final boolean failIfStopping) {
    final LifecycleState lifecycleState = getLifecycleState(requireNonNull(procNode), true);
    final StandardProcessContext processContext = new StandardProcessContext(procNode, this.controllerServiceProvider, this.encryptor, getStateManager(procNode.getIdentifier()), lifecycleState::isTerminated);
    final CompletableFuture<Void> future = new CompletableFuture<>();
    final SchedulingAgentCallback callback = new SchedulingAgentCallback() {

        @Override
        public void trigger() {
            lifecycleState.clearTerminationFlag();
            getSchedulingAgent(procNode).schedule(procNode, lifecycleState);
            future.complete(null);
        }

        @Override
        public Future<?> scheduleTask(final Callable<?> task) {
            lifecycleState.incrementActiveThreadCount(null);
            return componentMonitoringThreadPool.submit(task);
        }

        @Override
        public void onTaskComplete() {
            lifecycleState.decrementActiveThreadCount(null);
        }
    };
    LOG.info("Starting {}", procNode);
    procNode.start(this.componentMonitoringThreadPool, this.administrativeYieldMillis, processContext, callback, failIfStopping);
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) SchedulingAgentCallback(org.apache.nifi.controller.SchedulingAgentCallback) StandardProcessContext(org.apache.nifi.processor.StandardProcessContext) Callable(java.util.concurrent.Callable)

Aggregations

Callable (java.util.concurrent.Callable)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 SchedulingAgentCallback (org.apache.nifi.controller.SchedulingAgentCallback)1 StandardProcessContext (org.apache.nifi.processor.StandardProcessContext)1