You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2006/05/16 19:15:55 UTC
svn commit: r406997 - in /cocoon/trunk/core/cocoon-core/src/main:
java/org/apache/cocoon/components/store/impl/EHDefaultStore.java
java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java
resources/org/apache/cocoon/components/store/default.ccf
Author: cziegeler
Date: Tue May 16 10:15:53 2006
New Revision: 406997
URL: http://svn.apache.org/viewcvs?rev=406997&view=rev
Log:
Cleanup and fix dispose bug in Spring container
Removed:
cocoon/trunk/core/cocoon-core/src/main/resources/org/apache/cocoon/components/store/default.ccf
Modified:
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java
cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java?rev=406997&r1=406996&r2=406997&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/components/store/impl/EHDefaultStore.java Tue May 16 10:15:53 2006
@@ -1,12 +1,12 @@
/*
* Copyright 2004, 2005 The Apache Software Foundation.
- *
+ *
* Licensed 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.
@@ -50,9 +50,17 @@
/**
* Store implementation based on EHCache.
* (http://ehcache.sourceforge.net/)
+ * @version $Id$
*/
-public class EHDefaultStore extends AbstractLogEnabled
-implements Store, Contextualizable, Serviceable, Parameterizable, Initializable, Disposable, ThreadSafe {
+public class EHDefaultStore
+ extends AbstractLogEnabled
+ implements Store,
+ Contextualizable,
+ Serviceable,
+ Parameterizable,
+ Initializable,
+ Disposable,
+ ThreadSafe {
// ---------------------------------------------------- Constants
@@ -76,7 +84,7 @@
/** The service manager */
private ServiceManager manager;
-
+
/** The store janitor */
private StoreJanitor storeJanitor;
@@ -90,7 +98,7 @@
this.cacheName = "cocoon-ehcache-" + instanceCount;
}
- /* (non-Javadoc)
+ /**
* @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
*/
public void contextualize(Context context) throws ContextException {
@@ -98,7 +106,7 @@
this.cacheDir = (File)context.get(Constants.CONTEXT_CACHE_DIR);
}
- /* (non-Javadoc)
+ /**
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
public void service(ServiceManager aManager) throws ServiceException {
@@ -163,13 +171,11 @@
* </p>
*/
public void parameterize(Parameters parameters) throws ParameterException {
-
this.maxObjects = parameters.getParameterAsInteger("maxobjects", 10000);
this.overflowToDisk = parameters.getParameterAsBoolean("overflow-to-disk", true);
-
+
this.eternal = parameters.getParameterAsBoolean("eternal", true);
- if (!this.eternal)
- {
+ if (!this.eternal) {
this.timeToLiveSeconds = parameters.getParameterAsLong("timeToLiveSeconds", 0L);
this.timeToIdleSeconds = parameters.getParameterAsLong("timeToIdleSeconds", 0L);
}
@@ -180,22 +186,19 @@
getLogger().debug("Using cache directory: " + cacheDir);
}
setDirectory(cacheDir);
- }
- else if (parameters.getParameterAsBoolean("use-work-directory", false)) {
+ } else if (parameters.getParameterAsBoolean("use-work-directory", false)) {
if (this.getLogger().isDebugEnabled()) {
getLogger().debug("Using work directory: " + workDir);
}
setDirectory(workDir);
- }
- else if (parameters.getParameter("directory", null) != null) {
+ } else if (parameters.getParameter("directory", null) != null) {
String dir = parameters.getParameter("directory");
dir = IOUtils.getContextFilePath(workDir.getPath(), dir);
if (this.getLogger().isDebugEnabled()) {
getLogger().debug("Using directory: " + dir);
}
setDirectory(new File(dir));
- }
- else {
+ } else {
try {
// Legacy: use working directory by default
setDirectory(workDir);
@@ -205,35 +208,32 @@
} catch (IOException e) {
throw new ParameterException("Unable to set directory", e);
}
-
}
/**
* Sets the cache directory
*/
private void setDirectory(final File directory) throws IOException {
-
- /* Save directory path prefix */
+ // Save directory path prefix
String directoryPath = getFullFilename(directory);
directoryPath += File.separator;
- /* If directory doesn't exist, create it anew */
+ // If directory doesn't exist, create it anew
if (!directory.exists()) {
if (!directory.mkdir()) {
throw new IOException("Error creating store directory '" + directoryPath + "': ");
}
}
- /* Is given file actually a directory? */
+ // Is given file actually a directory?
if (!directory.isDirectory()) {
throw new IOException("'" + directoryPath + "' is not a directory");
}
- /* Is directory readable and writable? */
+ // Is directory readable and writable?
if (!(directory.canRead() && directory.canWrite())) {
throw new IOException("Directory '" + directoryPath + "' is not readable/writable");
}
-
System.setProperty("java.io.tmpdir", directoryPath);
}
@@ -267,7 +267,7 @@
this.cacheManager.addCache(this.cache);
this.storeJanitor.register(this);
}
-
+
/**
* Shutdown the CacheManager.
*/
@@ -278,14 +278,16 @@
this.storeJanitor = null;
}
this.manager = null;
- this.cacheManager.shutdown();
- this.cacheManager = null;
+ if ( this.cacheManager != null ) {
+ this.cacheManager.shutdown();
+ this.cacheManager = null;
+ }
this.cache = null;
}
-
+
// ---------------------------------------------------- Store implementation
-
- /* (non-Javadoc)
+
+ /**
* @see org.apache.excalibur.store.Store#free()
*/
public Object get(Object key) {
@@ -295,22 +297,20 @@
if (element != null) {
value = element.getValue();
}
- }
- catch (CacheException e) {
+ } catch (CacheException e) {
getLogger().error("Failure retrieving object from store", e);
}
if (getLogger().isDebugEnabled()) {
if (value != null) {
getLogger().debug("Found key: " + key);
- }
- else {
+ } else {
getLogger().debug("NOT Found key: " + key);
}
}
return value;
}
- /* (non-Javadoc)
+ /**
* @see org.apache.excalibur.store.Store#free()
*/
public void store(Object key, Object value) throws IOException {
@@ -330,7 +330,7 @@
this.cache.put(element);
}
- /* (non-Javadoc)
+ /**
* @see org.apache.excalibur.store.Store#free()
*/
public void free() {
@@ -350,15 +350,14 @@
}
}
}
- }
- catch (CacheException e) {
+ } catch (CacheException e) {
if (getLogger().isWarnEnabled()) {
getLogger().warn("Error in free()", e);
}
}
}
- /* (non-Javadoc)
+ /**
* @see org.apache.excalibur.store.Store#remove(java.lang.Object)
*/
public void remove(Object key) {
@@ -368,7 +367,7 @@
this.cache.remove((Serializable) key);
}
- /* (non-Javadoc)
+ /**
* @see org.apache.excalibur.store.Store#clear()
*/
public void clear() {
@@ -377,34 +376,31 @@
}
try {
this.cache.removeAll();
- }
- catch (IOException e) {
+ } catch (IOException e) {
getLogger().error("Failure to clearing store", e);
}
}
- /* (non-Javadoc)
+ /**
* @see org.apache.excalibur.store.Store#containsKey(java.lang.Object)
*/
public boolean containsKey(Object key) {
try {
return this.cache.get((Serializable) key) != null;
- }
- catch (CacheException e) {
+ } catch (CacheException e) {
getLogger().error("Failure retrieving object from store",e);
}
return false;
}
- /* (non-Javadoc)
+ /**
* @see org.apache.excalibur.store.Store#keys()
*/
public Enumeration keys() {
List keys = null;
try {
keys = this.cache.getKeys();
- }
- catch (CacheException e) {
+ } catch (CacheException e) {
if (getLogger().isWarnEnabled()) {
getLogger().warn("Error while getting cache keys", e);
}
@@ -413,19 +409,17 @@
return Collections.enumeration(keys);
}
- /* (non-Javadoc)
+ /**
* @see org.apache.excalibur.store.Store#size()
*/
public int size() {
try {
return this.cache.getSize();
- }
- catch (CacheException e) {
+ } catch (CacheException e) {
if (getLogger().isWarnEnabled()) {
getLogger().warn("Error while getting cache size", e);
}
return 0;
}
}
-
}
Modified: cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java?rev=406997&r1=406996&r2=406997&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java (original)
+++ cocoon/trunk/core/cocoon-core/src/main/java/org/apache/cocoon/core/container/spring/CocoonBeanFactory.java Tue May 16 10:15:53 2006
@@ -21,6 +21,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
@@ -33,6 +34,7 @@
import org.apache.cocoon.components.SitemapConfigurable;
import org.apache.cocoon.core.Settings;
import org.apache.cocoon.core.container.util.DefaultSitemapConfigurationHolder;
+import org.apache.commons.collections.IteratorUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.BeanFactory;
@@ -65,6 +67,8 @@
protected final Context avalonContext;
protected final ConfigurationInfo avalonConfiguration;
+ protected final List disposeBeans = new ArrayList();
+
public CocoonBeanFactory(BeanFactory parent) {
this(null, parent, null, null, null, null);
}
@@ -134,6 +138,17 @@
}
/**
+ * @see org.springframework.beans.factory.support.AbstractBeanFactory#destroySingletons()
+ */
+ public void destroySingletons() {
+ super.destroySingletons();
+ for(int i=this.disposeBeans.size()-1;i>=0;i--) {
+ ContainerUtil.dispose(this.disposeBeans.get(i));
+ }
+ this.disposeBeans.clear();
+ }
+
+ /**
* This is a Spring BeanPostProcessor adding support for the Avalon lifecycle interfaces.
*/
protected static final class AvalonPostProcessor implements DestructionAwareBeanPostProcessor {
@@ -142,13 +157,13 @@
protected final Logger logger;
protected final Context context;
- protected final BeanFactory beanFactory;
+ protected final CocoonBeanFactory beanFactory;
protected final Map components;
public AvalonPostProcessor(Map components,
Context context,
Logger logger,
- BeanFactory factory) {
+ CocoonBeanFactory factory) {
this.components = components;
this.context = context;
this.logger = logger;
@@ -222,7 +237,9 @@
} catch (Exception e) {
throw new BeanInitializationException("Unable to stop bean " + beanName, e);
}
- ContainerUtil.dispose(bean);
+ if ( bean instanceof Disposable ) {
+ this.beanFactory.disposeBeans.add(bean);
+ }
}
}
}