cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r641105 - /cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
Date Wed, 26 Mar 2008 01:36:03 GMT
Author: vgritsenko
Date: Tue Mar 25 18:36:02 2008
New Revision: 641105

URL: http://svn.apache.org/viewvc?rev=641105&view=rev
Log:
COCOON-1985: Close 'BIG SCARY UN-SYNCHRONIZED GAP'.
COCOON-2173: Make pipeline locking behavior optional.
Limit maximum wait time by configurable non infinite value.

Modified:
    cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java

Modified: cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java?rev=641105&r1=641104&r2=641105&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
(original)
+++ cocoon/trunk/core/cocoon-pipeline/cocoon-pipeline-impl/src/main/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
Tue Mar 25 18:36:02 2008
@@ -97,13 +97,18 @@
     /** Store for pipeline locks (optional) */
     protected Store transientStore;
 
+    /** Maximum wait time on a pipeline lock */
+    protected long lockTimeout;
 
-    /** Abstract method defined in subclasses
-     * @return <u>complete</u> cached response or <code>null</code><br>
-     *         See issue COCOON-2009 for discussion*/
+
+    /**
+     * Abstract method defined in subclasses.
+     * See issue COCOON-2009 for discussion.
+     * @return <u>complete</u> cached response or <code>null</code>.
+     */
     protected abstract CachedResponse cacheResults(Environment environment,
                                                    OutputStream os)
-        throws Exception;
+    throws Exception;
 
     /** Abstract method defined in subclasses */
     protected abstract ComponentCacheKey newComponentCacheKey(int type,
@@ -112,7 +117,7 @@
 
     /** Abstract method defined in subclasses */
     protected abstract void connectCachingPipeline(Environment environment)
-        throws ProcessingException;
+    throws ProcessingException;
 
     /**
      * Parameterizable Interface - Configuration
@@ -120,21 +125,26 @@
     public void parameterize(Parameters params) throws ParameterException {
         super.parameterize(params);
 
-        String storeRole = params.getParameter("store-role", Store.TRANSIENT_STORE);
-        try {
-            transientStore = (Store) manager.lookup(storeRole);
-        } catch (ServiceException e) {
-            if (getLogger().isDebugEnabled()) {
-                getLogger().debug("Could not look up transient store, synchronizing requests
will not work!", e);
-            }
-        }
+        // Is pipeline locking enabled?
+        if (params.getParameterAsBoolean("locking", true)) {
+            lockTimeout = params.getParameterAsLong("locking-timeout", 7000);
+            final String storeRole = params.getParameter("store-role", Store.TRANSIENT_STORE);
+            try {
+                transientStore = (Store) manager.lookup(storeRole);
+            } catch (ServiceException e) {
+                if (getLogger().isDebugEnabled()) {
+                    getLogger().debug("Transient store '" + storeRole + "' not available.
Pipeline locking will not work.", e);
+                }
+             }
+         }
     }
 
     /**
      * Set the generator.
      */
     public void setGenerator(String role, String source, Parameters param,
-                             Parameters hintParam) throws ProcessingException {
+                             Parameters hintParam)
+    throws ProcessingException {
         super.setGenerator(role, source, param, hintParam);
         this.generatorRole = role;
     }
@@ -143,7 +153,8 @@
      * Add a transformer.
      */
     public void addTransformer(String role, String source, Parameters param,
-                               Parameters hintParam) throws ProcessingException {
+                               Parameters hintParam)
+    throws ProcessingException {
         super.addTransformer(role, source, param, hintParam);
         this.transformerRoles.add(role);
     }
@@ -152,7 +163,8 @@
      * Set the serializer.
      */
     public void setSerializer(String role, String source, Parameters param,
-                              Parameters hintParam, String mimeType) throws ProcessingException
{
+                              Parameters hintParam, String mimeType)
+    throws ProcessingException {
         super.setSerializer(role, source, param, hintParam, mimeType);
         this.serializerRole = role;
     }
@@ -161,7 +173,8 @@
      * Set the Reader.
      */
     public void setReader(String role, String source, Parameters param,
-                          String mimeType) throws ProcessingException {
+                          String mimeType)
+    throws ProcessingException {
         super.setReader(role, source, param, mimeType);
         this.readerRole = role;
     }
@@ -190,7 +203,16 @@
 
                 try {
                     synchronized (lock) {
-                        lock.wait();
+                        // Close synchronization gap between retrieving the lock and
+                        // waiting on it. If lock is not in store anymore, don't wait
+                        // on it.
+                        synchronized (transientStore) {
+                            if (!transientStore.containsKey(lockKey)) {
+                                return false;
+                            }
+                        }
+
+                        lock.wait(lockTimeout);
                     }
 
                     if (getLogger().isDebugEnabled()) {



Mime
View raw message