portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r964283 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/ jetspeed-portal-resources/src/main/resources/assembly/
Date Thu, 15 Jul 2010 02:33:01 GMT
Author: woonsan
Date: Thu Jul 15 02:33:01 2010
New Revision: 964283

URL: http://svn.apache.org/viewvc?rev=964283&view=rev
Log:
JS2-1202: Adding a utility bean which invoke start method after the application context start.
The deployment manager bean will be started by using this utility bean to guarantee it's started
after all other beans are initialized.

Added:
    portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/ApplicationEventMethodsInvoker.java
  (with props)
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/deployment.xml

Added: portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/ApplicationEventMethodsInvoker.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/ApplicationEventMethodsInvoker.java?rev=964283&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/ApplicationEventMethodsInvoker.java
(added)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/ApplicationEventMethodsInvoker.java
Thu Jul 15 02:33:01 2010
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.components;
+
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.ApplicationEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.util.MethodInvoker;
+
+/**
+ * Utility callback method invoker bean 
+ * which can be used to invoke custom callback methods 
+ * on ApplicationEvent from the ApplicationContext.
+ * 
+ * @version $Id$
+ * @see org.springframework.context.ApplicationContext
+ * @see org.springframework.context.ApplicationListener
+ * @see org.springframework.context.ApplicationEvent
+ */
+public class ApplicationEventMethodsInvoker implements ApplicationListener, ApplicationContextAware
+{
+    private static Logger log = LoggerFactory.getLogger(ApplicationEventMethodsInvoker.class);
+    
+    private AbstractApplicationContext ctx;
+    private Map<Class<? extends ApplicationEvent>, List<MethodInvoker>>
eventTypeMethodInvokersMap;
+    private boolean autoPrepareInvoker = true;
+    
+    public ApplicationEventMethodsInvoker(Map<Class<? extends ApplicationEvent>,
List<MethodInvoker>> eventTypeMethodInvokersMap) 
+    {
+        this.eventTypeMethodInvokersMap = eventTypeMethodInvokersMap;
+    }
+    
+    public void setAutoPrepareInvoker(boolean autoPrepareInvoker)
+    {
+        this.autoPrepareInvoker = autoPrepareInvoker;
+    }
+    
+    public boolean getAutoPrepareInvoker()
+    {
+        return autoPrepareInvoker;
+    }
+    
+    /** {@inheritDoc} */
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
+    {
+        if (applicationContext instanceof AbstractApplicationContext)
+        {
+            ctx = (AbstractApplicationContext) applicationContext;
+            ctx.addApplicationListener(this);
+        }  
+    }
+    
+    /** {@inheritDoc} */
+    public void onApplicationEvent(ApplicationEvent event)
+    {
+        boolean doIt = false;
+        
+        ApplicationContext ac = ctx;
+        while (ac != null && !doIt)
+        {
+            if (event.getSource() == ac)
+            {
+                doIt = true;
+            }
+            ac = ac.getParent();
+        }
+        
+        if (!doIt)
+        {
+            return;
+        }
+        
+        List<MethodInvoker> invokers = findMethodInvokersByEvent(event);
+        
+        if (invokers != null && !invokers.isEmpty())
+        {
+            for (MethodInvoker invoker : invokers)
+            {
+                try
+                {
+                    if (autoPrepareInvoker && !invoker.isPrepared())
+                    {
+                        invoker.prepare();
+                    }
+                    
+                    invoker.invoke();
+                }
+                catch (Exception e)
+                {
+                    if (log.isDebugEnabled())
+                    {
+                        log.error("Failed to invoke application event callback invoker. "
+ e, e);
+                    }
+                    else
+                    {
+                        log.error("Failed to invoke application event callback invoker. "
+ e);
+                    }
+                }
+            }
+        }
+    }
+    
+    private List<MethodInvoker> findMethodInvokersByEvent(final ApplicationEvent event)
+    {
+        if (eventTypeMethodInvokersMap != null && event != null)
+        {
+            for (Map.Entry<Class<? extends ApplicationEvent>, List<MethodInvoker>>
entry : eventTypeMethodInvokersMap.entrySet())
+            {
+                Class<? extends ApplicationEvent> eventType = entry.getKey();
+                
+                if (eventType.isAssignableFrom(event.getClass()))
+                {
+                    return entry.getValue();
+                }
+            }
+        }
+        
+        return null;
+    }
+}

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/ApplicationEventMethodsInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/ApplicationEventMethodsInvoker.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java?rev=964283&r1=964282&r2=964283&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-cm/src/main/java/org/apache/jetspeed/components/SpringComponentManager.java
Thu Jul 15 02:33:01 2010
@@ -267,8 +267,12 @@ public class SpringComponentManager impl
     {
         if (started)
         {
+            appContext.stop();
             appContext.close();
+
+            bootCtx.stop();
             bootCtx.close();
+            
             started = false;
         }
     }
@@ -304,8 +308,11 @@ public class SpringComponentManager impl
                 bootCtx.getBeanFactory().registerSingleton(entry.getKey().toString(), entry.getValue());
             }
         }
-
+        bootCtx.start();
+        
         appContext.refresh();
+        appContext.start();
+        
         started = true;
     }
 }

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/deployment.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/deployment.xml?rev=964283&r1=964282&r2=964283&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/deployment.xml
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/deployment.xml
Thu Jul 15 02:33:01 2010
@@ -173,7 +173,7 @@
     deploying components.  What components get deployed depend of
     DeploymentEventListeners registered to it.
   -->
-  <bean id="deploymentManager" class="org.apache.jetspeed.deployment.impl.StandardDeploymentManager"
init-method="start"
+  <bean id="deploymentManager" class="org.apache.jetspeed.deployment.impl.StandardDeploymentManager"
     destroy-method="stop">
     <meta key="j2:cat" value="default" />
     <constructor-arg>
@@ -189,5 +189,24 @@
       </list>
     </constructor-arg>
   </bean>
+  
+  <!-- Start the deploymentManager after the application context started. -->
+  <bean class="org.apache.jetspeed.components.ApplicationEventMethodsInvoker">
+    <meta key="j2:cat" value="default" />
+    <constructor-arg>
+      <map>
+        <entry>
+          <key><value>org.springframework.context.event.ContextStartedEvent</value></key>
+          <list>
+            <bean class="org.springframework.util.MethodInvoker">
+              <meta key="j2:cat" value="default" />
+              <property name="targetObject" ref="deploymentManager" />
+              <property name="targetMethod" value="start" />
+            </bean>
+          </list>
+        </entry>
+      </map>
+    </constructor-arg>
+  </bean>
 
 </beans>



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message