Repository: incubator-nifi
Updated Branches:
  refs/heads/NIFI-250 953cb1227 -> de21b6090


NIFI-278: Added documentation and ensured that all annotations invoke with 
consistent arguments


Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/4dcb9fd7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/4dcb9fd7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/4dcb9fd7

Branch: refs/heads/NIFI-250
Commit: 4dcb9fd761dfaec98790c41ca16344a1d0b89340
Parents: 80b8c60
Author: Mark Payne <[email protected]>
Authored: Tue Mar 24 10:16:47 2015 -0400
Committer: Mark Payne <[email protected]>
Committed: Tue Mar 24 10:16:47 2015 -0400

----------------------------------------------------------------------
 .../nifi/annotation/lifecycle/OnAdded.java      | 13 +++++++++++--
 .../nifi/annotation/lifecycle/OnRemoved.java    | 14 +++++++++++++-
 .../nifi/annotation/lifecycle/OnShutdown.java   | 13 ++++++++++++-
 .../nifi/annotation/lifecycle/OnStopped.java    |  9 +++++++++
 .../apache/nifi/controller/FlowController.java  | 20 +++++++++++++++++++-
 .../controller/tasks/ReportingTaskWrapper.java  |  2 +-
 .../nifi/groups/StandardProcessGroup.java       |  3 ++-
 7 files changed, 67 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/4dcb9fd7/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnAdded.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnAdded.java 
b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnAdded.java
index acb7a4d..a1286ea 100644
--- 
a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnAdded.java
+++ 
b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnAdded.java
@@ -24,16 +24,25 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
 /**
+ * <p>
  * Marker annotation a {@link org.apache.nifi.processor.Processor Processor}, 
  * {@link org.apache.nifi.controller.ControllerService ControllerService}, or
  * {@link org.apache.nifi.reporting.ReportingTask ReportingTask} 
  * implementation can use to indicate a method
  * should be called whenever the component is added to the flow. This method
  * will be called once for the entire life of a component instance.
- *
+ * </p>
+ * 
+ * <p>
+ * Methods with this annotation are called without any arguments, as all 
settings
+ * and properties can be assumed to be the defaults.
+ * </p>
+ * 
+ * <p>
  * If any method annotated with this annotation throws a Throwable, the 
component
  * will not be added to the flow.
- *
+ * </p>
+ * 
  * @author none
  */
 @Documented

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/4dcb9fd7/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnRemoved.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnRemoved.java
 
b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnRemoved.java
index 696159f..71202b4 100644
--- 
a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnRemoved.java
+++ 
b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnRemoved.java
@@ -23,7 +23,11 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.processor.ProcessContext;
+
 /**
+ * <p>
  * Marker annotation a {@link org.apache.nifi.processor.Processor Processor}, 
  * {@link org.apache.nifi.controller.ControllerService ControllerService}, or
  * {@link org.apache.nifi.reporting.ReportingTask ReportingTask} 
implementation 
@@ -32,7 +36,15 @@ import java.lang.annotation.Target;
  * component instance. If the method throw any Throwable, that Throwable will 
be
  * caught and logged but will not prevent subsequent methods with this 
annotation
  * or removal of the component from the flow.
- *
+ * </p>
+ * 
+ * <p>
+ * Methods with this annotation are permitted to take no arguments or to take 
a single
+ * argument. If using a single argument, that argument must be of type {@link 
ConfigurationContext}
+ * if the component is a ReportingTask or a ControllerService. If the 
component is a Processor,
+ * then the argument must be of type {@link ProcessContext}.
+ * </p>
+ * 
  * @author none
  */
 @Documented

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/4dcb9fd7/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnShutdown.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnShutdown.java
 
b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnShutdown.java
index a4129e1..3d1ce6c 100644
--- 
a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnShutdown.java
+++ 
b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnShutdown.java
@@ -23,7 +23,11 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.processor.ProcessContext;
+
 /**
+ * <p>
  * Marker annotation a {@link org.apache.nifi.processor.Processor Processor}, 
  * {@link org.apache.nifi.controller.ControllerService ControllerService}, or
  * {@link org.apache.nifi.reporting.ReportingTask ReportingTask} 
implementation 
@@ -31,7 +35,14 @@ import java.lang.annotation.Target;
  * This will be called at most once for each component in a JVM lifetime.
  * It is not, however, guaranteed that this method will be called on shutdown, 
as 
  * the service may be killed suddenly.
- *
+ * </p>
+ * 
+ * <p>
+ * Methods with this annotation are permitted to take either 0 or 1 argument. 
If an argument
+ * is used, it must be of type {@link ConfigurationContext} if the component 
is a ReportingTask
+ * or Controller Service, or of type {@link ProcessContext} if the component 
is a Processor.
+ * </p>
+ *  
  * @author none
  */
 @Documented

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/4dcb9fd7/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnStopped.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnStopped.java
 
b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnStopped.java
index 4715253..fdc4fd8 100644
--- 
a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnStopped.java
+++ 
b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnStopped.java
@@ -23,6 +23,9 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+import org.apache.nifi.controller.ConfigurationContext;
+import org.apache.nifi.processor.ProcessContext;
+
 /**
  * <p>
  * Marker annotation a {@link org.apache.nifi.processor.Processor Processor} or
@@ -47,6 +50,12 @@ import java.lang.annotation.Target;
  * longer scheduled to run (as opposed to after all threads have returned from 
the
  * <code>onTrigger</code> method), see the {@link OnUnscheduled} annotation.
  * </p>
+ * 
+ * <p>
+ * Methods with this annotation are permitted to take either 0 or 1 argument. 
If an argument
+ * is used, it must be of type {@link ConfigurationContext} if the component 
is a ReportingTask
+ * or of type {@link ProcessContext} if the component is a Processor.
+ * </p>
  *
  * @author none
  */

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/4dcb9fd7/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java
 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java
index b396039..f3fb67c 100644
--- 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java
+++ 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java
@@ -52,6 +52,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.nifi.admin.service.UserService;
 import org.apache.nifi.annotation.lifecycle.OnAdded;
 import org.apache.nifi.annotation.lifecycle.OnRemoved;
+import org.apache.nifi.annotation.lifecycle.OnShutdown;
 import org.apache.nifi.cluster.BulletinsPayload;
 import org.apache.nifi.cluster.HeartbeatPayload;
 import org.apache.nifi.cluster.protocol.DataFlow;
@@ -106,6 +107,7 @@ import 
org.apache.nifi.controller.scheduling.StandardProcessScheduler;
 import org.apache.nifi.controller.scheduling.TimerDrivenSchedulingAgent;
 import org.apache.nifi.controller.service.ControllerServiceNode;
 import org.apache.nifi.controller.service.ControllerServiceProvider;
+import org.apache.nifi.controller.service.StandardConfigurationContext;
 import org.apache.nifi.controller.service.StandardControllerServiceProvider;
 import org.apache.nifi.controller.status.ConnectionStatus;
 import org.apache.nifi.controller.status.PortStatus;
@@ -1073,7 +1075,23 @@ public class FlowController implements EventAccess, 
ControllerServiceProvider, R
 
             // Trigger any processors' methods marked with @OnShutdown to be 
called
             rootGroup.shutdown();
-
+            
+            // invoke any methods annotated with @OnShutdown on Controller 
Services
+            for ( final ControllerServiceNode serviceNode : 
getAllControllerServices() ) {
+                try (final NarCloseable narCloseable = 
NarCloseable.withNarLoader()) {
+                    final ConfigurationContext configContext = new 
StandardConfigurationContext(serviceNode, controllerServiceProvider);
+                    
ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, 
serviceNode.getControllerServiceImplementation(), configContext);
+                }
+            }
+            
+            // invoke any methods annotated with @OnShutdown on Reporting Tasks
+            for ( final ReportingTaskNode taskNode : getAllReportingTasks() ) {
+                final ConfigurationContext configContext = 
taskNode.getConfigurationContext();
+                try (final NarCloseable narCloseable = 
NarCloseable.withNarLoader()) {
+                    
ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, 
taskNode.getReportingTask(), configContext);
+                }
+            }
+            
             try {
                 
this.timerDrivenEngineRef.get().awaitTermination(gracefulShutdownSeconds / 2, 
TimeUnit.SECONDS);
                 
this.eventDrivenEngineRef.get().awaitTermination(gracefulShutdownSeconds / 2, 
TimeUnit.SECONDS);

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/4dcb9fd7/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ReportingTaskWrapper.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ReportingTaskWrapper.java
 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ReportingTaskWrapper.java
index 9b70581..e115fe7 100644
--- 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ReportingTaskWrapper.java
+++ 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/tasks/ReportingTaskWrapper.java
@@ -52,7 +52,7 @@ public class ReportingTaskWrapper implements Runnable {
             // invoke the OnStopped methods
             if (!scheduleState.isScheduled() && 
scheduleState.getActiveThreadCount() == 1 && 
scheduleState.mustCallOnStoppedMethods()) {
                 try (final NarCloseable x = NarCloseable.withNarLoader()) {
-                    
ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnStopped.class, 
org.apache.nifi.processor.annotation.OnStopped.class, 
taskNode.getReportingTask(), taskNode.getReportingContext());
+                    
ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnStopped.class, 
org.apache.nifi.processor.annotation.OnStopped.class, 
taskNode.getReportingTask(), taskNode.getConfigurationContext());
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/4dcb9fd7/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
----------------------------------------------------------------------
diff --git 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
index 75ebbeb..216d015 100644
--- 
a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
+++ 
b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/groups/StandardProcessGroup.java
@@ -331,7 +331,8 @@ public final class StandardProcessGroup implements 
ProcessGroup {
     private void shutdown(final ProcessGroup procGroup) {
         for (final ProcessorNode node : procGroup.getProcessors()) {
             try (final NarCloseable x = NarCloseable.withNarLoader()) {
-                
ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, 
org.apache.nifi.processor.annotation.OnShutdown.class, node.getProcessor());
+                final StandardProcessContext processContext = new 
StandardProcessContext(node, controllerServiceProvider, encryptor);
+                
ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnShutdown.class, 
org.apache.nifi.processor.annotation.OnShutdown.class, node.getProcessor(), 
processContext);
             }
         }
 

Reply via email to