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 2005/02/05 20:53:07 UTC
svn commit: r151524 - in cocoon/trunk/src: core/java/org/apache/cocoon/core/
core/java/org/apache/cocoon/core/container/handler/
java/org/apache/cocoon/components/container/
java/org/apache/cocoon/components/treeprocessor/
java/org/apache/cocoon/components/treeprocessor/sitemap/
Author: cziegeler
Date: Sat Feb 5 11:53:04 2005
New Revision: 151524
URL: http://svn.apache.org/viewcvs?view=rev&rev=151524
Log:
Continue work on proxies for pooled components
Modified:
cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/handler/AbstractComponentHandler.java
cocoon/trunk/src/core/java/org/apache/cocoon/core/container/handler/PoolableComponentHandler.java
cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java?view=diff&r1=151523&r2=151524
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/Core.java Sat Feb 5 11:53:04 2005
@@ -35,7 +35,7 @@
/** Application <code>Context</code> Key for the settings @since 2.2 */
public static final String CONTEXT_SETTINGS = "settings";
- private static final ThreadLocal cleanup = new InheritableThreadLocal();
+ private static final ThreadLocal cleanup = new ThreadLocal();
public static void addCleanupTask(CleanupTask task) {
List l = (List)cleanup.get();
Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/handler/AbstractComponentHandler.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/handler/AbstractComponentHandler.java?view=diff&r1=151523&r2=151524
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/handler/AbstractComponentHandler.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/handler/AbstractComponentHandler.java Sat Feb 5 11:53:04 2005
@@ -97,6 +97,7 @@
if( Poolable.class.isAssignableFrom( componentClass ) ) {
numInterfaces++;
+ // FIXME : Activate proxied pooling as default
info.setModel(ComponentInfo.MODEL_NON_THREAD_SAFE_POOLED);
if ( "non-thread-safe-pooled".equals(info.getConfiguration().getAttribute("model", null))) {
info.setModel(ComponentInfo.MODEL_NON_THREAD_SAFE_POOLED);
Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/handler/PoolableComponentHandler.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/core/java/org/apache/cocoon/core/container/handler/PoolableComponentHandler.java?view=diff&r1=151523&r2=151524
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/handler/PoolableComponentHandler.java (original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/handler/PoolableComponentHandler.java Sat Feb 5 11:53:04 2005
@@ -30,31 +30,8 @@
import org.apache.cocoon.core.container.ComponentFactory;
/**
- * The PoolableComponentHandler to make sure that poolable components are initialized
- * destroyed and pooled correctly.
- * <p>
- * Components which implement Poolable may be configured to be pooled using the following
- * example configuration. This example assumes that the user component class MyComp
- * implements Poolable.
- * <p>
- * Configuration Example:
- * <pre>
- * <my-comp pool-max="8"/>
- * </pre>
- * <p>
- * Roles Example:
- * <pre>
- * <role name="com.mypkg.MyComponent"
- * shorthand="my-comp"
- * default-class="com.mypkg.DefaultMyComponent"/>
- * </pre>
- * <p>
- * Configuration Attributes:
- * <ul>
- * <li>The <code>pool-max</code> attribute is used to set the maximum number of components which
- * will be pooled. (Defaults to "8") If additional instances are required, they're created,
- * but not pooled.</li>
- * </ul>
+ * This is an extension to the {@link org.apache.cocoon.core.container.handler.NonThreadSafePoolableComponentHandler}
+ * that uses proxies to make the poolable components thread safe.
*
* @version $Id$
*/
@@ -78,7 +55,13 @@
final Configuration config )
throws Exception {
super(info, logger, factory, config);
- this.interfaces = this.guessWorkInterfaces(factory.getCreatedClass());
+ final HashSet workInterfaces = new HashSet();
+
+ // Get *all* interfaces
+ this.guessWorkInterfaces( factory.getCreatedClass(), workInterfaces );
+
+ this.interfaces = (Class[]) workInterfaces.toArray( new Class[workInterfaces.size()] );
+ System.out.println("New poolable handler for " + factory.getCreatedClass());
}
/* (non-Javadoc)
@@ -95,6 +78,9 @@
// nothing to do
}
+ /* (non-Javadoc)
+ * @see org.apache.cocoon.core.container.handler.AbstractComponentHandler#doInitialize()
+ */
protected void doInitialize() {
// nothing to do here
}
@@ -107,23 +93,6 @@
/**
* Get a list of interfaces to proxy by scanning through
- * all interfaces a class implements and skipping invalid interfaces
- * (as defined in {@link #INVALID_INTERFACES}).
- *
- * @param clazz the class
- * @return the list of interfaces to proxy
- */
- protected Class[] guessWorkInterfaces( final Class clazz ) {
- final HashSet workInterfaces = new HashSet();
-
- // Get *all* interfaces
- this.guessWorkInterfaces( clazz, workInterfaces );
-
- return (Class[]) workInterfaces.toArray( new Class[workInterfaces.size()] );
- }
-
- /**
- * Get a list of interfaces to proxy by scanning through
* all interfaces a class implements.
*
* @param clazz the class
@@ -155,7 +124,7 @@
protected static final class ProxyHandler implements InvocationHandler, Core.CleanupTask {
- private ThreadLocal componentHolder = new InheritableThreadLocal();
+ private final ThreadLocal componentHolder = new ThreadLocal();
private final PoolableComponentHandler handler;
public ProxyHandler(PoolableComponentHandler handler) {
@@ -188,11 +157,9 @@
public void invoke() {
try {
final Object o = this.componentHolder.get();
- /*if ( o == null ) {
- System.out.println("Releasing null for " + this.handler.factory.getCreatedClass());
- } else {
- System.out.println("Releasing: " + o);
- }*/
+ if ( o == null ) {
+ System.out.println(this.hashCode() + "/" + Thread.currentThread() + " : Releasing null for " + this.handler.factory.getCreatedClass());
+ }
this.handler.putIntoPool(o);
} catch (Exception ignore) {
// we ignore this
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java?view=diff&r1=151523&r2=151524
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/container/CocoonServiceManager.java Sat Feb 5 11:53:04 2005
@@ -55,6 +55,8 @@
}
public void addComponent(String role, String clazz, Configuration config) throws ConfigurationException {
+ this.info.prepareConfig(role, clazz, config);
+
super.addComponent(role, clazz, config);
// Let's ProcessorComponentInfo do its stuff.
// Note: if more behaviours of this kind are needed, we may setup an
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java?view=diff&r1=151523&r2=151524
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/ProcessorComponentInfo.java Sat Feb 5 11:53:04 2005
@@ -23,6 +23,7 @@
import java.util.StringTokenizer;
import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.components.pipeline.ProcessingPipeline;
@@ -54,6 +55,7 @@
private static final String TRANSFORMER_PREFIX = Transformer.ROLE + "/";
private static final String SERIALIZER_PREFIX = Serializer.ROLE + "/";
private static final String READER_PREFIX = Reader.ROLE + "/";
+ private static final String PIPELINE_PREFIX = ProcessingPipeline.ROLE + "/";
private static final Set DEFAULT_ROLES = new HashSet(Arrays.asList(new String[] {
Generator.ROLE + "/" + DefaultServiceSelector.DEFAULT_HINT,
@@ -111,6 +113,25 @@
}
}
+ /**
+ * Prepares the configuration for pooled sitemap components:
+ * Per default pooled components are proxied - we override this
+ * for generators, transformers, serializers, readers and pipes
+ * @param role the component's role
+ * @param clazz the component's class
+ * @param config the component's configuration
+ */
+ public void prepareConfig(String role, String clazz, Configuration config) {
+ if (role.startsWith(GENERATOR_PREFIX)
+ || role.startsWith(TRANSFORMER_PREFIX)
+ || role.startsWith(SERIALIZER_PREFIX)
+ || role.startsWith(READER_PREFIX)
+ || role.startsWith(PIPELINE_PREFIX)) {
+
+ ((DefaultConfiguration)config).setAttribute("model", "non-thread-safe-pooled");
+ }
+ }
+
public void roleAliased(String existingRole, String newRole) {
if (DEFAULT_ROLES.contains(newRole)) {
// A default role for a sitemap component has been added
Modified: cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java?view=diff&r1=151523&r2=151524
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/components/treeprocessor/sitemap/SitemapLanguage.java Sat Feb 5 11:53:04 2005
@@ -89,7 +89,7 @@
Environment env = EnvironmentHelper.getCurrentEnvironment();
newContext.put(Constants.CONTEXT_ENV_URI, env.getURI());
newContext.put(Constants.CONTEXT_ENV_PREFIX, env.getURIPrefix());
- // FIXME How to get rif of EnvironmentHelper?
+ // FIXME How to get rid of EnvironmentHelper?
newContext.put(Constants.CONTEXT_ENV_HELPER, getProcessor().getWrappingProcessor().getEnvironmentHelper());
return newContext;
}
@@ -118,6 +118,9 @@
*/
public static final String LAST_POS_LABEL = "!last!";
+ /* (non-Javadoc)
+ * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
+ */
public void recycle() {
super.recycle();