Revision: 18217
Author:   wko
Date:     2009-05-22 15:56:27 +0200 (Fri, 22 May 2009)
Log Message:
-----------
HSTTWO-581: Adding re-initialization stuffs from portal side to reduce possible 
multiple-initialization problems.

Modified Paths:
--------------
    ecm/site-toolkit/trunk/applications/site/pom.xml
    
ecm/site-toolkit/trunk/commons/src/main/java/org/hippoecm/hst/site/HstServices.java
    
ecm/site-toolkit/trunk/components/core/src/main/java/org/hippoecm/hst/site/container/HstSiteConfigServlet.java

Modified: ecm/site-toolkit/trunk/applications/site/pom.xml
===================================================================
--- ecm/site-toolkit/trunk/applications/site/pom.xml    2009-05-22 13:18:44 UTC 
(rev 18216)
+++ ecm/site-toolkit/trunk/applications/site/pom.xml    2009-05-22 13:56:27 UTC 
(rev 18217)
@@ -442,6 +442,10 @@
   <servlet>
     <servlet-name>HstSiteConfigServlet</servlet-name>
     
<servlet-class>org.hippoecm.hst.site.container.HstSiteConfigServlet</servlet-class>
+    <init-param>
+      <param-name>forceful.reinit</param-name>
+      <param-value>true</param-value>
+    </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
   

Modified: 
ecm/site-toolkit/trunk/commons/src/main/java/org/hippoecm/hst/site/HstServices.java
===================================================================
--- 
ecm/site-toolkit/trunk/commons/src/main/java/org/hippoecm/hst/site/HstServices.java
 2009-05-22 13:18:44 UTC (rev 18216)
+++ 
ecm/site-toolkit/trunk/commons/src/main/java/org/hippoecm/hst/site/HstServices.java
 2009-05-22 13:56:27 UTC (rev 18217)
@@ -34,7 +34,7 @@
     
     public static void setComponentManager(ComponentManager compManager) {
         HstServices.componentManager = compManager;
-        HstServices.available = true;
+        HstServices.available = (HstServices.componentManager != null);
     }
     
     public static ComponentManager getComponentManager() {

Modified: 
ecm/site-toolkit/trunk/components/core/src/main/java/org/hippoecm/hst/site/container/HstSiteConfigServlet.java
===================================================================
--- 
ecm/site-toolkit/trunk/components/core/src/main/java/org/hippoecm/hst/site/container/HstSiteConfigServlet.java
      2009-05-22 13:18:44 UTC (rev 18216)
+++ 
ecm/site-toolkit/trunk/components/core/src/main/java/org/hippoecm/hst/site/container/HstSiteConfigServlet.java
      2009-05-22 13:56:27 UTC (rev 18217)
@@ -64,6 +64,8 @@
 
     private static final String CHECK_REPOSITORIES_RUNNING_INIT_PARAM = 
"check.repositories.running"; 
     
+    private static final String FORCEFUL_REINIT_PARAM = "forceful.reinit";
+    
     private static final String REPOSITORY_ADDRESS_PARAM_SUFFIX = 
".repository.address";
 
     private final static Logger log = 
LoggerFactory.getLogger(HstSiteConfigServlet.class);
@@ -74,6 +76,7 @@
     
     protected boolean initialized;
     
+    protected boolean forecefulReinitialization;
     protected boolean checkRepositoriesRunning;
     protected boolean allRepositoriesAvailable;
     
@@ -93,13 +96,26 @@
     @Override
     public void init(final ServletConfig config) throws ServletException {
         super.init(config);
+
+        // If the forceful re-initialization option is not turned on
+        // and the component manager were intialized in other web application,
+        // then just skip the following.
+        // If this servlet is initialized inside a site web application 
+        // and other web application already initialized the component manager,
+        // then the followings are to be skipped.
+        forecefulReinitialization = 
Boolean.parseBoolean(config.getInitParameter(FORCEFUL_REINIT_PARAM));
+        if (!forecefulReinitialization && HstServices.isAvailable()) {
+            return;
+        }
+        // If it is not available or it is forceful re-initialization mode 
from the web app (like portal webapp)
+        // then the initialization will go on from here.
         
         this.configuration = getConfiguration(config);
 
         checkRepositoriesRunning = 
this.configuration.getBoolean(CHECK_REPOSITORIES_RUNNING_INIT_PARAM);
         
         if (!checkRepositoriesRunning) {
-            doInit(config);
+            initializeComponentManager(config);
         } else {
             this.allRepositoriesAvailable = false;
             this.repositoryCheckingStatus.clear();
@@ -135,7 +151,7 @@
                         }
                         
                         if (allRepositoriesAvailable) {
-                            doInit(config);
+                            initializeComponentManager(config);
                         }
                     }
                 };
@@ -145,7 +161,7 @@
         }
     }
     
-    protected synchronized void doInit(ServletConfig config) {
+    protected synchronized void initializeComponentManager(ServletConfig 
config) {
 
         try {
             log.info(INIT_START_MSG);
@@ -188,7 +204,7 @@
     public void doGet(HttpServletRequest req, HttpServletResponse res) throws 
IOException, ServletException {
 
         if (!this.initialized) {
-            doInit(getServletConfig());
+            initializeComponentManager(getServletConfig());
         }
         
     }

_______________________________________________
Hippocms-svn mailing list
[email protected]
http://lists.hippo.nl/mailman/listinfo/hippocms-svn

Reply via email to