Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 58211 invoked from network); 21 Jun 2007 13:25:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Jun 2007 13:25:58 -0000 Received: (qmail 59589 invoked by uid 500); 21 Jun 2007 13:25:54 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 59527 invoked by uid 500); 21 Jun 2007 13:25:54 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 59503 invoked by uid 99); 21 Jun 2007 13:25:54 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jun 2007 06:25:54 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jun 2007 06:25:49 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 72C4D1A981A; Thu, 21 Jun 2007 06:25:29 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r549470 - in /cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader: LockableApplicationContext.java SpringReloader.java Date: Thu, 21 Jun 2007 13:25:29 -0000 To: cvs@cocoon.apache.org From: reinhard@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070621132529.72C4D1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: reinhard Date: Thu Jun 21 06:25:28 2007 New Revision: 549470 URL: http://svn.apache.org/viewvc?view=rev&rev=549470 Log: - implementation of a synchronized application context (LockableApplicationContext) which wraps a ConfigurableWebApplicationContext and which can be reloaded - the SpringReloader calls the reload() method of the LockableApplicationContext now instead of implementing the reloading sequence itself Added: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/LockableApplicationContext.java (with props) Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/SpringReloader.java Added: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/LockableApplicationContext.java URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/LockableApplicationContext.java?view=auto&rev=549470 ============================================================================== --- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/LockableApplicationContext.java (added) +++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/LockableApplicationContext.java Thu Jun 21 06:25:28 2007 @@ -0,0 +1,269 @@ +/* + * 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.cocoon.tools.rcl.springreloader; + +import java.io.IOException; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; + +import org.springframework.beans.BeanInstantiationException; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.config.AutowireCapableBeanFactory; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.context.MessageSourceResolvable; +import org.springframework.context.NoSuchMessageException; +import org.springframework.core.io.Resource; +import org.springframework.web.context.ConfigurableWebApplicationContext; +import org.springframework.web.context.support.XmlWebApplicationContext; + +/** + * This implementation of a {@link ConfigurableWebApplicationContext} is completly synchronized. It wraps + * all calls and delegates them to an internally managed ConfigurableWebApplicationContext instance. + * + * Additionally it provides a {@link #reload()} method which exchanges the interal application context with a + * newly created one. + * + * @version $Id$ + */ +public class LockableApplicationContext implements ConfigurableWebApplicationContext { + + private ConfigurableWebApplicationContext appContext; + + public LockableApplicationContext() throws BeansException { + try { + appContext = (ConfigurableWebApplicationContext) + BeanUtils.instantiateClass(XmlWebApplicationContext.class); + } catch (BeanInstantiationException e) { + throw new RuntimeException("Can't create Spring application context.", e); + } + } + + public synchronized void reload() { + ConfigurableWebApplicationContext newAppContext = null; + try { + newAppContext = (ConfigurableWebApplicationContext) + BeanUtils.instantiateClass(XmlWebApplicationContext.class); + } catch (BeanInstantiationException e) { + throw new RuntimeException("Can't create Spring application context.", e); + } + newAppContext.setParent(appContext.getParent()); + newAppContext.setServletContext(appContext.getServletContext()); + appContext.close(); + appContext = newAppContext; + appContext.refresh(); + } + + public synchronized boolean containsBean(String arg0) { + return appContext.containsBean(arg0); + } + + public synchronized boolean containsBeanDefinition(String arg0) { + return appContext.containsBeanDefinition(arg0); + } + + public synchronized boolean containsLocalBean(String arg0) { + return appContext.containsLocalBean(arg0); + } + + public synchronized String[] getAliases(String arg0) { + return appContext.getAliases(arg0); + } + + public synchronized AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException { + return appContext.getAutowireCapableBeanFactory(); + } + + public synchronized Object getBean(String arg0, Class arg1) throws BeansException { + return appContext.getBean(arg0, arg1); + } + + public synchronized Object getBean(String arg0) throws BeansException { + return appContext.getBean(arg0); + } + + public synchronized int getBeanDefinitionCount() { + return appContext.getBeanDefinitionCount(); + } + + public synchronized String[] getBeanDefinitionNames() { + return appContext.getBeanDefinitionNames(); + } + + public synchronized String[] getBeanNamesForType(Class arg0, boolean arg1, boolean arg2) { + return appContext.getBeanNamesForType(arg0, arg1, arg2); + } + + public synchronized String[] getBeanNamesForType(Class arg0) { + return appContext.getBeanNamesForType(arg0); + } + + public synchronized Map getBeansOfType(Class arg0, boolean arg1, boolean arg2) throws BeansException { + return appContext.getBeansOfType(arg0, arg1, arg2); + } + + public synchronized Map getBeansOfType(Class arg0) throws BeansException { + return appContext.getBeansOfType(arg0); + } + + public synchronized ClassLoader getClassLoader() { + return appContext.getClassLoader(); + } + + public synchronized String getDisplayName() { + return appContext.getDisplayName(); + } + + public synchronized String getMessage(MessageSourceResolvable arg0, Locale arg1) throws NoSuchMessageException { + return appContext.getMessage(arg0, arg1); + } + + public synchronized String getMessage(String arg0, Object[] arg1, Locale arg2) throws NoSuchMessageException { + return appContext.getMessage(arg0, arg1, arg2); + } + + public synchronized String getMessage(String arg0, Object[] arg1, String arg2, Locale arg3) { + return appContext.getMessage(arg0, arg1, arg2, arg3); + } + + public synchronized ApplicationContext getParent() { + return appContext.getParent(); + } + + public synchronized BeanFactory getParentBeanFactory() { + return appContext.getParentBeanFactory(); + } + + public synchronized Resource getResource(String arg0) { + return appContext.getResource(arg0); + } + + public synchronized Resource[] getResources(String arg0) throws IOException { + return appContext.getResources(arg0); + } + + public synchronized long getStartupDate() { + return appContext.getStartupDate(); + } + + public synchronized Class getType(String arg0) throws NoSuchBeanDefinitionException { + return appContext.getType(arg0); + } + + public synchronized boolean isPrototype(String arg0) throws NoSuchBeanDefinitionException { + return appContext.isPrototype(arg0); + } + + public synchronized boolean isSingleton(String arg0) throws NoSuchBeanDefinitionException { + return appContext.isSingleton(arg0); + } + + public synchronized boolean isTypeMatch(String arg0, Class arg1) throws NoSuchBeanDefinitionException { + return appContext.isTypeMatch(arg0, arg1); + } + + public synchronized void publishEvent(ApplicationEvent arg0) { + appContext.publishEvent(arg0); + } + + public synchronized ServletContext getServletContext() { + return appContext.getServletContext(); + } + + public synchronized String[] getConfigLocations() { + return appContext.getConfigLocations(); + } + + public synchronized String getNamespace() { + return appContext.getNamespace(); + } + + public synchronized ServletConfig getServletConfig() { + return appContext.getServletConfig(); + } + + public synchronized void setConfigLocations(String[] arg0) { + appContext.setConfigLocations(arg0); + + } + + public synchronized void setNamespace(String arg0) { + appContext.setNamespace(arg0); + } + + public synchronized void setServletConfig(ServletConfig arg0) { + appContext.setServletConfig(arg0); + } + + public synchronized void setServletContext(ServletContext arg0) { + appContext.setServletContext(arg0); + + } + + public synchronized void addApplicationListener(ApplicationListener arg0) { + appContext.addApplicationListener(arg0); + } + + public synchronized void addBeanFactoryPostProcessor(BeanFactoryPostProcessor arg0) { + appContext.addBeanFactoryPostProcessor(arg0); + } + + public synchronized void close() { + appContext.close(); + } + + public synchronized ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException { + return appContext.getBeanFactory(); + } + + public synchronized boolean isActive() { + return appContext.isActive(); + } + + public synchronized void refresh() throws BeansException, IllegalStateException { + appContext.refresh(); + } + + public synchronized void registerShutdownHook() { + appContext.registerShutdownHook(); + } + + public synchronized void setParent(ApplicationContext arg0) { + appContext.setParent(arg0); + } + + public synchronized boolean isRunning() { + return appContext.isRunning(); + } + + public synchronized void start() { + appContext.start(); + } + + public synchronized void stop() { + appContext.stop(); + } +} \ No newline at end of file Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/LockableApplicationContext.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/LockableApplicationContext.java ------------------------------------------------------------------------------ svn:keywords = Id Propchange: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/LockableApplicationContext.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/SpringReloader.java URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/SpringReloader.java?view=diff&rev=549470&r1=549469&r2=549470 ============================================================================== --- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/SpringReloader.java (original) +++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-spring-reloader/src/main/java/org/apache/cocoon/tools/rcl/springreloader/SpringReloader.java Thu Jun 21 06:25:28 2007 @@ -5,9 +5,9 @@ * 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. @@ -18,47 +18,23 @@ import javax.servlet.ServletContext; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.context.ContextLoader; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.context.support.ServletContextFactoryBean; import org.springframework.web.context.support.WebApplicationContextUtils; -import org.springframework.web.context.support.XmlWebApplicationContext; /** *

* This class is used by the ReloadingSpringFilter to reload a Spring * web application context. In order not to run into {@link NoClassDefFoundError}s, - * is is important that this class is loaded through the reloading classloader. + * is is important that this class is loaded by the reloading classloader. *

- * + * * @version $Id$ */ public class SpringReloader { - - private final Log log = LogFactory.getLog(SpringReloader.class); public synchronized void reload(ServletContext servletContext) { - ContextLoader springContextLoader = new ContextLoader(); - - // close old Spring application context - XmlWebApplicationContext oldAc = (XmlWebApplicationContext) + LockableApplicationContext ac = (LockableApplicationContext) WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext); - if(log.isDebugEnabled()) { - this.log.debug("Removing old application context: " + oldAc); - } - oldAc.close(); - servletContext.removeAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); - - // create the new Spring application context - ServletContextFactoryBean b = new ServletContextFactoryBean(); - b.setServletContext(servletContext); - XmlWebApplicationContext xac = (XmlWebApplicationContext) springContextLoader. - initWebApplicationContext(servletContext); - if(log.isDebugEnabled()) { - log.debug("Reloading Spring application context: " + xac); - } + ac.reload(); } - + }