diff --git a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java index 99d8d6e28a..346e801660 100644 --- a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java +++ b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/FlowController.java @@ -756,7 +756,9 @@ public class FlowController implements EventAccess, ControllerServiceProvider, H /** *
- * Creates a new ProcessorNode with the given type and identifier.
+ * Creates a new ProcessorNode with the given type and identifier and initializes it invoking the + * methods annotated with {@link OnAdded}. + * * * @param type * @param id @@ -766,6 +768,24 @@ public class FlowController implements EventAccess, ControllerServiceProvider, H * instantiated for any reason */ public ProcessorNode createProcessor(final String type, String id) throws ProcessorInstantiationException { + return createProcessor(type, id, true); + } + + /** + *+ * Creates a new ProcessorNode with the given type and identifier and optionally initializes it. + *
+ * + * @param type the fully qualified Processor class name + * @param id the unique ID of the Processor + * @param firstTimeAdded whether or not this is the first time this Processor is added to the graph. If {@code true}, + * will invoke methods annotated with the {@link OnAdded} annotation. + * @return + * @throws NullPointerException if either arg is null + * @throws ProcessorInstantiationException if the processor cannot be + * instantiated for any reason + */ + public ProcessorNode createProcessor(final String type, String id, final boolean firstTimeAdded) throws ProcessorInstantiationException { id = id.intern(); final Processor processor = instantiateProcessor(type, id); final ValidationContextFactory validationContextFactory = new StandardValidationContextFactory(controllerServiceProvider); @@ -774,12 +794,13 @@ public class FlowController implements EventAccess, ControllerServiceProvider, H final LogRepository logRepository = LogRepositoryFactory.getRepository(id); logRepository.addObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID, LogLevel.WARN, new ProcessorLogObserver(getBulletinRepository(), procNode)); - // TODO: We should only call this the first time that it is added to the graph.... - try (final NarCloseable x = NarCloseable.withNarLoader()) { - ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, processor); - } catch (final Exception e) { - logRepository.removeObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID); - throw new ProcessorLifeCycleException("Failed to invoke @OnAdded methods of " + procNode.getProcessor(), e); + if ( firstTimeAdded ) { + try (final NarCloseable x = NarCloseable.withNarLoader()) { + ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, processor); + } catch (final Exception e) { + logRepository.removeObserver(StandardProcessorNode.BULLETIN_OBSERVER_ID); + throw new ProcessorLifeCycleException("Failed to invoke @OnAdded methods of " + procNode.getProcessor(), e); + } } return procNode; diff --git a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java index ffea644ca2..b60d18711f 100644 --- a/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java +++ b/nar-bundles/framework-bundle/framework/core/src/main/java/org/apache/nifi/controller/StandardFlowSynchronizer.java @@ -594,7 +594,7 @@ public class StandardFlowSynchronizer implements FlowSynchronizer { final List