Java Code Examples for org.apache.nifi.controller.ReportingTaskNode#getConfigurationContext()

The following examples show how to use org.apache.nifi.controller.ReportingTaskNode#getConfigurationContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StandardProcessScheduler.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public void unschedule(final ReportingTaskNode taskNode) {
    final ScheduleState scheduleState = getScheduleState(requireNonNull(taskNode));
    if (!scheduleState.isScheduled()) {
        return;
    }

    taskNode.verifyCanStop();
    final SchedulingAgent agent = getSchedulingAgent(taskNode.getSchedulingStrategy());
    final ReportingTask reportingTask = taskNode.getReportingTask();
    taskNode.setScheduledState(ScheduledState.STOPPED);

    final Runnable unscheduleReportingTaskRunnable = new Runnable() {
        @Override
        public void run() {
            final ConfigurationContext configurationContext = taskNode.getConfigurationContext();

            synchronized (scheduleState) {
                scheduleState.setScheduled(false);

                try {
                    try (final NarCloseable x = NarCloseable.withComponentNarLoader(reportingTask.getClass(), reportingTask.getIdentifier())) {
                        ReflectionUtils.invokeMethodsWithAnnotation(OnUnscheduled.class, reportingTask, configurationContext);
                    }
                } catch (final Exception e) {
                    final Throwable cause = e instanceof InvocationTargetException ? e.getCause() : e;
                    final ComponentLog componentLog = new SimpleProcessLogger(reportingTask.getIdentifier(), reportingTask);
                    componentLog.error("Failed to invoke @OnUnscheduled method due to {}", cause);

                    LOG.error("Failed to invoke the @OnUnscheduled methods of {} due to {}; administratively yielding this ReportingTask and will attempt to schedule it again after {}",
                            reportingTask, cause.toString(), administrativeYieldDuration);
                    LOG.error("", cause);

                    try {
                        Thread.sleep(administrativeYieldMillis);
                    } catch (final InterruptedException ie) {
                    }
                }

                agent.unschedule(taskNode, scheduleState);

                if (scheduleState.getActiveThreadCount() == 0 && scheduleState.mustCallOnStoppedMethods()) {
                    ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnStopped.class, reportingTask, configurationContext);
                }
            }
        }
    };

    componentLifeCycleThreadPool.execute(unscheduleReportingTaskRunnable);
}
 
Example 2
Source File: StandardProcessScheduler.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public void unschedule(final ReportingTaskNode taskNode) {
    final LifecycleState lifecycleState = getLifecycleState(requireNonNull(taskNode), false);
    if (!lifecycleState.isScheduled()) {
        return;
    }

    taskNode.verifyCanStop();
    final SchedulingAgent agent = getSchedulingAgent(taskNode.getSchedulingStrategy());
    final ReportingTask reportingTask = taskNode.getReportingTask();
    taskNode.setScheduledState(ScheduledState.STOPPED);

    final Runnable unscheduleReportingTaskRunnable = new Runnable() {
        @Override
        public void run() {
            final ConfigurationContext configurationContext = taskNode.getConfigurationContext();

            synchronized (lifecycleState) {
                lifecycleState.setScheduled(false);

                try (final NarCloseable x = NarCloseable.withComponentNarLoader(flowController.getExtensionManager(), reportingTask.getClass(), reportingTask.getIdentifier())) {
                    ReflectionUtils.invokeMethodsWithAnnotation(OnUnscheduled.class, reportingTask, configurationContext);
                } catch (final Exception e) {
                    final Throwable cause = e instanceof InvocationTargetException ? e.getCause() : e;
                    final ComponentLog componentLog = new SimpleProcessLogger(reportingTask.getIdentifier(), reportingTask);
                    componentLog.error("Failed to invoke @OnUnscheduled method due to {}", cause);

                    LOG.error("Failed to invoke the @OnUnscheduled methods of {} due to {}; administratively yielding this ReportingTask and will attempt to schedule it again after {}",
                            reportingTask, cause.toString(), administrativeYieldDuration);
                    LOG.error("", cause);
                }

                agent.unschedule(taskNode, lifecycleState);

                if (lifecycleState.getActiveThreadCount() == 0 && lifecycleState.mustCallOnStoppedMethods()) {
                    ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnStopped.class, reportingTask, configurationContext);
                }
            }
        }
    };

    componentLifeCycleThreadPool.execute(unscheduleReportingTaskRunnable);
}