You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by jo...@apache.org on 2017/03/30 19:29:47 UTC

nifi git commit: NIFI-3421: This closes #1620. - On contextDestroyed, referencing beans created during contextInitialized to prevent successive attempts to create a bean if that bean failed to be created initially.

Repository: nifi
Updated Branches:
  refs/heads/master e20353516 -> 282e1a7b1


NIFI-3421: This closes #1620.
- On contextDestroyed, referencing beans created during contextInitialized to prevent successive attempts to create a bean if that bean failed to be created initially.

Signed-off-by: joewitt <jo...@apache.org>


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

Branch: refs/heads/master
Commit: 282e1a7b1a7123abe21de8ac022b7f5636da79da
Parents: e203535
Author: Matt Gilman <ma...@gmail.com>
Authored: Fri Mar 24 16:30:48 2017 -0400
Committer: joewitt <jo...@apache.org>
Committed: Thu Mar 30 15:14:41 2017 -0400

----------------------------------------------------------------------
 .../ApplicationStartupContextListener.java      | 23 ++++++++++----------
 1 file changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/282e1a7b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java
index 6ce7cb4..70f2cec 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java
@@ -43,15 +43,18 @@ public class ApplicationStartupContextListener implements ServletContextListener
 
     private static final Logger logger = LoggerFactory.getLogger(ApplicationStartupContextListener.class);
 
+    private FlowController flowController = null;
+    private FlowService flowService = null;
+    private RequestReplicator requestReplicator = null;
+
     @Override
     public void contextInitialized(ServletContextEvent sce) {
-
-        ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
-        NiFiProperties properties = ctx.getBean("nifiProperties", NiFiProperties.class);
-        FlowService flowService = null;
+        final ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
+        final NiFiProperties properties = ctx.getBean("nifiProperties", NiFiProperties.class);
         try {
             flowService = ctx.getBean("flowService", FlowService.class);
-            final FlowController flowController = ctx.getBean("flowController", FlowController.class);
+            flowController = ctx.getBean("flowController", FlowController.class);
+            requestReplicator = ctx.getBean("requestReplicator", RequestReplicator.class);
 
             // start and load the flow if we're not clustered (clustered flow loading should
             // happen once the application (wars) is fully loaded and initialized). non clustered
@@ -81,7 +84,7 @@ public class ApplicationStartupContextListener implements ServletContextListener
                 logger.info("Flow Controller started successfully.");
             }
         } catch (BeansException | RepositoryPurgeException | IOException e) {
-            shutdown(flowService, ctx.getBean("requestReplicator", RequestReplicator.class));
+            shutdown();
             throw new NiFiCoreException("Unable to start Flow Controller.", e);
         }
 
@@ -90,21 +93,19 @@ public class ApplicationStartupContextListener implements ServletContextListener
             ctx.getBean("loginIdentityProvider", LoginIdentityProvider.class);
             ctx.getBean("authorizer", Authorizer.class);
         } catch (final BeansException e) {
-            shutdown(flowService, ctx.getBean("requestReplicator", RequestReplicator.class));
+            shutdown();
             throw new NiFiCoreException("Unable to start Flow Controller.", e);
         }
     }
 
     @Override
     public void contextDestroyed(ServletContextEvent sce) {
-        ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
-
         logger.info("Initiating shutdown of flow service...");
-        shutdown(ctx.getBean("flowService", FlowService.class), ctx.getBean("requestReplicator", RequestReplicator.class));
+        shutdown();
         logger.info("Flow service termination completed.");
     }
 
-    private void shutdown(final FlowService flowService, final RequestReplicator requestReplicator) {
+    private void shutdown() {
         try {
             // ensure the flow service is terminated
             if (flowService != null && flowService.isRunning()) {