You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2011/09/19 23:14:48 UTC

svn commit: r1172830 - in /camel/branches/camel-2.8.x: ./ components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java

Author: dkulp
Date: Mon Sep 19 21:14:48 2011
New Revision: 1172830

URL: http://svn.apache.org/viewvc?rev=1172830&view=rev
Log:
Merged revisions 1160113 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1160113 | ningjiang | 2011-08-22 01:45:04 -0400 (Mon, 22 Aug 2011) | 1 line
  
  CAMEL-4355 Should use LRUSoftCache and start/stop the cache according to the producers lifecycle
........

Modified:
    camel/branches/camel-2.8.x/   (props changed)
    camel/branches/camel-2.8.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.8.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java?rev=1172830&r1=1172829&r2=1172830&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java (original)
+++ camel/branches/camel-2.8.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java Mon Sep 19 21:14:48 2011
@@ -39,6 +39,7 @@ import org.apache.camel.component.cxf.co
 import org.apache.camel.converter.IOConverter;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.LRUCache;
+import org.apache.camel.util.LRUSoftCache;
 import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
 import org.apache.cxf.jaxrs.client.Client;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
@@ -66,6 +67,16 @@ public class CxfRsProducer extends Defau
         this.throwException = endpoint.isThrowExceptionOnFailure();
         clientFactoryBeanCache = new ClientFactoryBeanCache(endpoint.getMaxClientCacheSize());
     }
+    
+    protected void doStart() throws Exception {
+        clientFactoryBeanCache.start();
+        super.doStart();
+    }
+    
+    protected void doStop() throws Exception {
+        super.doStop();
+        clientFactoryBeanCache.stop();
+    }
 
     public void process(Exchange exchange) throws Exception {
         Message inMessage = exchange.getIn();
@@ -325,25 +336,29 @@ public class CxfRsProducer extends Defau
      * Cache contains {@link org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean}
      */
     private class ClientFactoryBeanCache {
-        private LRUCache<String, SoftReference<JAXRSClientFactoryBean>> cache;    
+        private LRUSoftCache<String, JAXRSClientFactoryBean> cache;    
         
         public ClientFactoryBeanCache(final int maxCacheSize) {
-            this.cache = new LRUCache<String, SoftReference<JAXRSClientFactoryBean>>(maxCacheSize);
+            this.cache = new LRUSoftCache<String, JAXRSClientFactoryBean>(maxCacheSize);
+        }
+        
+        public void start() throws Exception {
+            this.cache.start();
+        }
+        
+        public void stop() throws Exception {
+            this.cache.stop();
         }
 
         public JAXRSClientFactoryBean get(String address) throws Exception {
-            JAXRSClientFactoryBean retval = null;
+            JAXRSClientFactoryBean retVal = null;
             synchronized (cache) {
-                SoftReference<JAXRSClientFactoryBean> ref = cache.get(address);
+                retVal = cache.get(address);
                 
-                if (ref != null) {
-                    retval = ref.get();
-                }
-
-                if (retval == null) {
-                    retval = ((CxfRsEndpoint)getEndpoint()).createJAXRSClientFactoryBean(address);
+                if (retVal == null) {
+                    retVal = ((CxfRsEndpoint)getEndpoint()).createJAXRSClientFactoryBean(address);
                     
-                    cache.put(address, new SoftReference<JAXRSClientFactoryBean>(retval));
+                    cache.put(address, retVal);
                     
                     LOG.trace("Created client factory bean and add to cache for address '{}'", address);
                     
@@ -351,7 +366,7 @@ public class CxfRsProducer extends Defau
                     LOG.trace("Retrieved client factory bean from cache for address '{}'", address);
                 }
             }
-            return retval;
+            return retVal;
         }
     }
 }