You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2015/02/19 20:46:38 UTC
[3/3] incubator-nifi git commit: NIFI-250: Updated javadocs to
clarify how lifecycle annotations are used;
cleaned up handling of exceptions in scheduler
NIFI-250: Updated javadocs to clarify how lifecycle annotations are used; cleaned up handling of exceptions in scheduler
Project: http://git-wip-us.apache.org/repos/asf/incubator-nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-nifi/commit/767f37b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-nifi/tree/767f37b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-nifi/diff/767f37b8
Branch: refs/heads/NIFI-250
Commit: 767f37b8311f5fbbcfa5aacd6ef1230103034f09
Parents: 5f2a435
Author: Mark Payne <ma...@hotmail.com>
Authored: Thu Feb 19 14:46:32 2015 -0500
Committer: Mark Payne <ma...@hotmail.com>
Committed: Thu Feb 19 14:46:32 2015 -0500
----------------------------------------------------------------------
.../nifi/annotation/lifecycle/OnDisabled.java | 29 ++++++++++++-----
.../nifi/annotation/lifecycle/OnEnabled.java | 34 ++++++++++----------
.../annotation/lifecycle/OnUnscheduled.java | 2 --
.../scheduling/StandardProcessScheduler.java | 32 +++---------------
4 files changed, 42 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/767f37b8/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnDisabled.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnDisabled.java b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnDisabled.java
index 0f78010..b227968 100644
--- a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnDisabled.java
+++ b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnDisabled.java
@@ -23,19 +23,32 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.apache.nifi.controller.ConfigurationContext;
+
/**
- * 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}
- * can use to indicate a method should be called whenever the component is disabled.
+ * <p>
+ * Marker annotation a {@link org.apache.nifi.controller.ControllerService ControllerService}
+ * can use to indicate a method should be called whenever the service is disabled.
+ *</p>
*
* <p>
- * Methods using this annotation must take no arguments. If a method with this annotation
- * throws a Throwable, a log message and bulletin will be issued for the component, but
- * the component will still be disabled.
+ * Methods using this annotation are permitted to take zero arguments or to take a single
+ * argument of type {@link ConfigurationContext}. If a method with this annotation
+ * throws a Throwable, a log message and bulletin will be issued for the service, and the
+ * service will remain in a 'DISABLING' state. When this occurs, the method with this annotation
+ * will be called again after some period of time. This will continue until the method returns
+ * without throwing any Throwable. Until that time, the service will remain in a 'DISABLING' state
+ * and cannot be enabled again.
+ * </p>
+ *
+ * <p>
+ * Note that this annotation will be ignored if applied to a ReportingTask or Processor. For a Controller
+ * Service, enabling and disabling are considered lifecycle events, as the action makes them usable or
+ * unusable by other components. However, for a Processor and a Reporting
+ * Task, these are not lifecycle events but rather a mechanism to allow a component to be excluded when
+ * starting or stopping a group of components.
* </p>
*
- * @author none
*/
@Documented
@Target({ElementType.METHOD})
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/767f37b8/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnEnabled.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnEnabled.java b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnEnabled.java
index 1536dec..32aeec6 100644
--- a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnEnabled.java
+++ b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnEnabled.java
@@ -25,35 +25,35 @@ 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}
- * can use to indicate a method should be called whenever the component is enabled.
- * Any method that has this annotation will be called every time a user enables the component.
+ * Marker annotation a {@link org.apache.nifi.controller.ControllerService ControllerService}
+ * can use to indicate a method should be called whenever the service is enabled.
+ * Any method that has this annotation will be called every time a user enables the service.
* Additionally, each time that NiFi is restarted, if NiFi is configured to "auto-resume state"
- * and the component is enabled (whether stopped or running), the method will be invoked.
+ * and the service is enabled, the method will be invoked.
* </p>
*
* <p>
- * Methods using this annotation must take either 0 arguments or a single argument.
+ * Methods using this annotation must take either 0 arguments or a single argument of type
+ * {@link org.apache.nifi.controller.ConfigurationContext ConfigurationContext}.
* </p>
*
* <p>
- * If using 1 argument and the component using the annotation is a Processor, that argument must
- * be of type {@link org.apache.nifi.processor.ProcessContext ProcessContext}.
- * </p>
- *
- * <p>
- * If using 1 argument and the component using the annotation is a Reporting Task or Controller Service,
- * that argument must be of type {@link org.apache.nifi.controller.ConfigurationContext ConfigurationContext}.
+ * If a method with this annotation throws a Throwable, a log message and bulletin will be issued
+ * for the component. In this event, the service will remain in an 'ENABLING' state and will not be
+ * usable. All methods with this annotation will then be called again after a delay. The service will
+ * not be made available for use until all methods with this annotation have returned without throwing
+ * anything.
* </p>
*
* <p>
- * If a method with this annotation throws a Throwable, a log message and bulletin will be issued
- * for the component, but the component will still be enabled.
+ * Note that this annotation will be ignored if applied to a ReportingTask or Processor. For a Controller
+ * Service, enabling and disabling are considered lifecycle events, as the action makes them usable or
+ * unusable by other components. However, for a Processor and a Reporting
+ * Task, these are not lifecycle events but rather a mechanism to allow a component to be excluded when
+ * starting or stopping a group of components.
* </p>
*
- * @author none
+ *
*/
@Documented
@Target({ElementType.METHOD})
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/767f37b8/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnUnscheduled.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnUnscheduled.java b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnUnscheduled.java
index b1dbde1..5c7e13d 100644
--- a/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnUnscheduled.java
+++ b/nifi/nifi-api/src/main/java/org/apache/nifi/annotation/lifecycle/OnUnscheduled.java
@@ -47,8 +47,6 @@ import java.lang.annotation.Target;
* If using 1 argument and the component using the annotation is a Reporting Task, that argument must
* be of type {@link org.apache.nifi.controller.ConfigurationContext ConfigurationContext}.
* </p>
- *
- * @author none
*/
@Documented
@Target({ElementType.METHOD})
http://git-wip-us.apache.org/repos/asf/incubator-nifi/blob/767f37b8/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
----------------------------------------------------------------------
diff --git a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
index 2b4757d..0e181c5 100644
--- a/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
+++ b/nifi/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/scheduling/StandardProcessScheduler.java
@@ -230,18 +230,12 @@ public final class StandardProcessScheduler implements ProcessScheduler {
try (final NarCloseable x = NarCloseable.withNarLoader()) {
ReflectionUtils.invokeMethodsWithAnnotation(OnUnscheduled.class, org.apache.nifi.processor.annotation.OnUnscheduled.class, reportingTask, configurationContext);
}
- } catch (final InvocationTargetException ite) {
- LOG.error("Failed to invoke the @OnConfigured methods of {} due to {}; administratively yielding this ReportingTask and will attempt to schedule it again after {}",
- new Object[]{reportingTask, ite.getTargetException(), administrativeYieldDuration});
- LOG.error("", ite.getTargetException());
-
- try {
- Thread.sleep(administrativeYieldMillis);
- } catch (final InterruptedException ie) {
- }
} catch (final Exception e) {
+ final Throwable cause = (e instanceof InvocationTargetException) ? e.getCause() : e;
LOG.error("Failed to invoke the @OnConfigured methods of {} due to {}; administratively yielding this ReportingTask and will attempt to schedule it again after {}",
- new Object[]{reportingTask, e.toString(), administrativeYieldDuration}, e);
+ reportingTask, cause.toString(), administrativeYieldDuration);
+ LOG.error("", cause);
+
try {
Thread.sleep(administrativeYieldMillis);
} catch (final InterruptedException ie) {
@@ -544,11 +538,6 @@ public final class StandardProcessScheduler implements ProcessScheduler {
}
procNode.setScheduledState(ScheduledState.STOPPED);
-
- try (final NarCloseable x = NarCloseable.withNarLoader()) {
- final ProcessorLog processorLog = new SimpleProcessLogger(procNode.getIdentifier(), procNode.getProcessor());
- ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnEnabled.class, procNode.getProcessor(), processorLog);
- }
}
@Override
@@ -558,11 +547,6 @@ public final class StandardProcessScheduler implements ProcessScheduler {
}
procNode.setScheduledState(ScheduledState.DISABLED);
-
- try (final NarCloseable x = NarCloseable.withNarLoader()) {
- final ProcessorLog processorLog = new SimpleProcessLogger(procNode.getIdentifier(), procNode.getProcessor());
- ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnDisabled.class, procNode.getProcessor(), processorLog);
- }
}
public synchronized void enableReportingTask(final ReportingTaskNode taskNode) {
@@ -571,10 +555,6 @@ public final class StandardProcessScheduler implements ProcessScheduler {
}
taskNode.setScheduledState(ScheduledState.STOPPED);
-
- try (final NarCloseable x = NarCloseable.withNarLoader()) {
- ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnEnabled.class, taskNode.getReportingTask());
- }
}
public synchronized void disableReportingTask(final ReportingTaskNode taskNode) {
@@ -583,10 +563,6 @@ public final class StandardProcessScheduler implements ProcessScheduler {
}
taskNode.setScheduledState(ScheduledState.DISABLED);
-
- try (final NarCloseable x = NarCloseable.withNarLoader()) {
- ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnDisabled.class, taskNode.getReportingTask());
- }
}
@Override