camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1362130 - in /camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel: builder/xml/XsltBuilder.java component/xslt/XsltComponent.java
Date Mon, 16 Jul 2012 16:56:41 GMT
Author: dkulp
Date: Mon Jul 16 16:56:40 2012
New Revision: 1362130

URL: http://svn.apache.org/viewvc?rev=1362130&view=rev
Log:
Merged revisions 1362126 via  git cherry-pick from
https://svn.apache.org/repos/asf/camel/trunk

........
  r1362126 | dkulp | 2012-07-16 12:53:57 -0400 (Mon, 16 Jul 2012) | 4 lines

  [CAMEL-5450] Add support to xslt component to cache the transformers
  (off by default, but likely could/should be on and set to something like
  5 or 10)

........

Modified:
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java?rev=1362130&r1=1362129&r2=1362130&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/builder/xml/XsltBuilder.java
Mon Jul 16 16:56:40 2012
@@ -23,6 +23,9 @@ import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.ErrorListener;
 import javax.xml.transform.Result;
@@ -69,6 +72,7 @@ public class XsltBuilder implements Proc
     private Map<String, Object> parameters = new HashMap<String, Object>();
     private XmlConverter converter = new XmlConverter();
     private Templates template;
+    private volatile BlockingQueue<Transformer> transformers;
     private ResultHandlerFactory resultHandlerFactory = new StringResultHandlerFactory();
     private boolean failOnNullBody = true;
     private URIResolver uriResolver;
@@ -97,7 +101,7 @@ public class XsltBuilder implements Proc
             exchange.addOnCompletion(new XsltBuilderOnCompletion(fileName));
         }
 
-        Transformer transformer = getTemplate().newTransformer();
+        Transformer transformer = getTransformer();
         configureTransformer(transformer, exchange);
         transformer.setErrorListener(new DefaultTransformErrorHandler());
         ResultHandler resultHandler = resultHandlerFactory.createResult(exchange);
@@ -124,6 +128,7 @@ public class XsltBuilder implements Proc
             LOG.trace("Transform complete with result {}", result);
             resultHandler.setBody(out);
         } finally {
+            releaseTransformer(transformer);
             // IOHelper can handle if is is null
             IOHelper.close(is);
         }
@@ -238,6 +243,16 @@ public class XsltBuilder implements Proc
         setAllowStAX(true);
         return this;
     }
+    
+    
+    public XsltBuilder transformerCacheSize(int numberToCache) {
+        if (numberToCache > 0) {
+            transformers = new ArrayBlockingQueue<Transformer>(numberToCache);
+        } else {
+            transformers = null;
+        }
+        return this;
+    }
 
     // Properties
     // -------------------------------------------------------------------------
@@ -252,6 +267,9 @@ public class XsltBuilder implements Proc
 
     public void setTemplate(Templates template) {
         this.template = template;
+        if (transformers != null) {
+            transformers.clear();
+        }
     }
     
     public Templates getTemplate() {
@@ -365,6 +383,23 @@ public class XsltBuilder implements Proc
 
     // Implementation methods
     // -------------------------------------------------------------------------
+    private void releaseTransformer(Transformer transformer) {
+        if (transformers != null) {
+            transformer.reset();
+            transformers.offer(transformer);
+        }
+    }
+
+    private Transformer getTransformer() throws TransformerConfigurationException {
+        Transformer t = null; 
+        if (transformers != null) {
+            t = transformers.poll();
+        }
+        if (t == null) {
+            t = getTemplate().newTransformer();
+        }
+        return t;
+    }
 
     /**
      * Checks whether we need an {@link InputStream} to access the message body.

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java?rev=1362130&r1=1362129&r2=1362130&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/xslt/XsltComponent.java
Mon Jul 16 16:56:40 2012
@@ -110,6 +110,9 @@ public class XsltComponent extends Defau
         }
         String output = getAndRemoveParameter(parameters, "output", String.class);
         configureOutput(xslt, output);
+        
+        Integer cs = getAndRemoveParameter(parameters, "transformerCacheSize", Integer.class,
Integer.valueOf(0));
+        xslt.transformerCacheSize(cs);
 
         // default to use the cache option from the component if the endpoint did not have
the contentCache parameter
         boolean cache = getAndRemoveParameter(parameters, "contentCache", Boolean.class,
contentCache);



Mime
View raw message