Repository: nifi
Updated Branches:
  refs/heads/master 44fdc0e4e -> 36911957d


NIFI-3972: Ensure that we wait until service state becomes enabled before 
triggering completable future that says that it's enabled


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

Branch: refs/heads/master
Commit: eb25c8547a8fec278296ab7b846deac2295f4af4
Parents: 44fdc0e
Author: Mark Payne <[email protected]>
Authored: Wed May 24 16:15:18 2017 -0400
Committer: joewitt <[email protected]>
Committed: Thu May 25 13:31:53 2017 -0400

----------------------------------------------------------------------
 .../controller/service/StandardControllerServiceNode.java   | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/eb25c854/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
----------------------------------------------------------------------
diff --git 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
index a18fd1f..e399e7f 100644
--- 
a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
+++ 
b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/service/StandardControllerServiceNode.java
@@ -407,12 +407,13 @@ public class StandardControllerServiceNode extends 
AbstractConfiguredComponent i
                             
ReflectionUtils.invokeMethodsWithAnnotation(OnEnabled.class, 
getControllerServiceImplementation(), configContext);
                         }
 
-                        future.complete(null);
-
                         boolean shouldEnable = false;
                         synchronized (active) {
                             shouldEnable = active.get() && 
stateRef.compareAndSet(ControllerServiceState.ENABLING, 
ControllerServiceState.ENABLED);
                         }
+
+                        future.complete(null);
+
                         if (!shouldEnable) {
                             LOG.debug("Disabling service " + this + " after it 
has been enabled due to disable action being initiated.");
                             // Can only happen if user initiated DISABLE 
operation before service finished enabling. It's state will be
@@ -421,6 +422,8 @@ public class StandardControllerServiceNode extends 
AbstractConfiguredComponent i
                             stateRef.set(ControllerServiceState.DISABLED);
                         }
                     } catch (Exception e) {
+                        future.completeExceptionally(e);
+
                         final Throwable cause = e instanceof 
InvocationTargetException ? e.getCause() : e;
                         final ComponentLog componentLog = new 
SimpleProcessLogger(getIdentifier(), StandardControllerServiceNode.this);
                         componentLog.error("Failed to invoke @OnEnabled method 
due to {}", cause);
@@ -438,6 +441,8 @@ public class StandardControllerServiceNode extends 
AbstractConfiguredComponent i
                     }
                 }
             });
+        } else {
+            future.complete(null);
         }
 
         return future;

Reply via email to