camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r896898 - in /camel/trunk/components/camel-cache/src/main/java/org/apache/camel: component/cache/ component/cache/factory/ processor/cache/
Date Thu, 07 Jan 2010 14:57:41 GMT
Author: davsclaus
Date: Thu Jan  7 14:55:44 2010
New Revision: 896898

URL: http://svn.apache.org/viewvc?rev=896898&view=rev
Log:
Polished code and reduced logging noise.

Modified:
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheComponent.java
Thu Jan  7 14:55:44 2010
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.cache;
 
 import java.net.URI;
@@ -37,8 +36,8 @@
     }
 
     @Override
-    protected Endpoint createEndpoint(String uri, String remaining,
-            Map parameters) throws Exception {
+    @SuppressWarnings("unchecked")
+    protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws
Exception {
         config.parseURI(new URI(uri));
         
         CacheEndpoint cacheEndpoint = new CacheEndpoint(uri, this, config);
@@ -46,5 +45,4 @@
         return cacheEndpoint;
     }
 
-    
 }

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConfiguration.java
Thu Jan  7 14:55:44 2010
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.cache;
 
 import java.net.URI;
@@ -39,8 +38,7 @@
     private long timeToIdleSeconds = 300;
     private boolean diskPersistent;
     private long diskExpiryThreadIntervalSeconds;
-    private Map cacheSettings;
-    
+
     public CacheConfiguration() {
     }
 
@@ -58,7 +56,7 @@
         
         setCacheName(uri.getHost());
         
-        cacheSettings = URISupport.parseParameters(uri);
+        Map cacheSettings = URISupport.parseParameters(uri);
         if (cacheSettings.containsKey("maxElementsInMemory")) {
             setMaxElementsInMemory(Integer.valueOf((String) cacheSettings.get("maxElementsInMemory")).intValue());
         }
@@ -163,8 +161,7 @@
         return diskExpiryThreadIntervalSeconds;
     }
 
-    public void setDiskExpiryThreadIntervalSeconds(
-            long diskExpiryThreadIntervalSeconds) {
+    public void setDiskExpiryThreadIntervalSeconds(long diskExpiryThreadIntervalSeconds)
{
         this.diskExpiryThreadIntervalSeconds = diskExpiryThreadIntervalSeconds;
     }
    

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConsumer.java
Thu Jan  7 14:55:44 2010
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.cache;
 
 import net.sf.ehcache.Cache;
@@ -44,16 +43,14 @@
 
     @Override
     protected void doStart() throws Exception {
-        // TODO Auto-generated method stub
         super.doStart();
         createConsumerCacheConnection();
     }
 
     @Override
     protected void doStop() throws Exception {
-        // TODO Auto-generated method stub
-        super.doStop();
         removeConsumerCacheConnection();
+        super.doStop();
     }
 
     @Override
@@ -61,7 +58,7 @@
         return endpoint;
     }
     
-    private void createConsumerCacheConnection() {
+    protected void createConsumerCacheConnection() {
         cacheManager = new CacheManagerFactory().instantiateCacheManager();
         CacheEventListener cacheEventListener = new CacheEventListenerFactory().createCacheEventListener(null);
         cacheEventListener.setCacheConsumer(this);
@@ -83,11 +80,12 @@
                     null);
             cache.getCacheEventNotificationService().registerListener(cacheEventListener);
             cacheManager.addCache(cache);
-            LOG.debug("Added a new cache: " + cache.getName());  
+
+            LOG.info("Added a new cache: " + cache.getName());
         }
     }
     
-    private void removeConsumerCacheConnection() {
+    protected void removeConsumerCacheConnection() {
         cacheManager.removeCache(config.getCacheName());
         if (cacheManager.getCacheNames().length == 0) {
             cacheManager.shutdown();

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
Thu Jan  7 14:55:44 2010
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.cache;
 
 import org.apache.camel.Component;
@@ -65,8 +64,6 @@
         message.setBody(value);
         exchange.setIn(message);
         return exchange;
-        
-        
     }
     
 }

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListener.java
Thu Jan  7 14:55:44 2010
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.cache;
 
 import net.sf.ehcache.CacheException;
@@ -31,7 +30,6 @@
     private static final transient Log LOG = LogFactory.getLog(CacheEventListener.class);
     CacheConsumer cacheConsumer;
 
-    
     public CacheEventListener() {
         super();
     }
@@ -100,7 +98,7 @@
         try {
             cacheConsumer.getProcessor().process(exchange);
         } catch (Exception e) {
-            throw new CacheException("Error in consumer while dispatching exchange containing
Key " + (String) element.getObjectKey() + " for further processing  ", e);
+            throw new CacheException("Error in consumer while dispatching exchange containing
Key " + element.getObjectKey() + " for further processing", e);
         }
     }
     
@@ -113,7 +111,7 @@
     }
 
     public void dispose() {
-        
+        // noop
     }
 
     public Object clone() throws CloneNotSupportedException {

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEventListenerFactory.java
Thu Jan  7 14:55:44 2010
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.cache;
 
 import java.util.Properties;

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/factory/CacheManagerFactory.java
Thu Jan  7 14:55:44 2010
@@ -14,19 +14,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.camel.component.cache.factory;
 
 import net.sf.ehcache.CacheManager;
 
 public class CacheManagerFactory {
-    public CacheManager cacheManager;
 
-    public CacheManager instantiateCacheManager() {        
+    private CacheManager cacheManager;
+
+    public synchronized CacheManager instantiateCacheManager() {
         if (cacheManager == null) {
             cacheManager = CacheManager.getInstance();
         }
         
         return cacheManager;
     }
+
 }

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
Thu Jan  7 14:55:44 2010
@@ -31,7 +31,6 @@
     Ehcache cache;
     private String cacheName;
     private String key;
-    
 
     public CacheBasedMessageBodyReplacer(String cacheName, String key) {
         super();

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
Thu Jan  7 14:55:44 2010
@@ -53,6 +53,7 @@
 
         if (isValid(cacheManager, cacheName, key)) {
             cache = cacheManager.getCache(cacheName);
+
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Replacing Token " + replacementToken + "in Message with value
stored against key "
                          + key + " in CacheName " + cacheName);
@@ -65,12 +66,13 @@
             is.close();
 
             // Note: The value in the cache must be a String
-            String cacheValue = exchange.getContext().getTypeConverter().convertTo(
-                                                                                   String.class,
-                                                                                   cache.get(key)
-                                                                                       .getObjectValue());
+            String cacheValue = exchange.getContext().getTypeConverter()
+                    .convertTo(String.class, cache.get(key).getObjectValue());
             String replacedTokenString = new String(buffer).replaceAll(replacementToken,
cacheValue);
-            LOG.debug("replacedTokenString = " + replacedTokenString);
+
+            if (LOG.isTraceEnabled()) {
+                LOG.trace("replacedTokenString = " + replacedTokenString);
+            }
             exchange.getIn().setBody(replacedTokenString.getBytes());
         }
     }

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
Thu Jan  7 14:55:44 2010
@@ -38,7 +38,6 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-
 public class CacheBasedXPathReplacer extends CacheValidate implements Processor {
     private static final transient Log LOG = LogFactory.getLog(CacheBasedXPathReplacer.class);
     private String cacheName;
@@ -67,6 +66,7 @@
 
         if (isValid(cacheManager, cacheName, key)) {
             cache = cacheManager.getCache(cacheName);
+
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Replacing XPath value " + xpath + "in Message with value stored
against key " + key
                         + " in CacheName " + cacheName);
@@ -89,7 +89,7 @@
 
                 // Create/setup the Transformer
                 XmlConverter xmlConverter = new XmlConverter();
-                String xslString = IOConverter.toString(new File("./src/main/resources/xpathreplacer.xsl"));
+                String xslString = IOConverter.toString(new File("./src/main/resources/xpathreplacer.xsl"),
exchange);
                 xslString = xslString.replace("##match_token##", xpath);
                 Source xslSource = xmlConverter.toStreamSource(new StringReader(xslString));
                 TransformerFactory transformerFactory = xmlConverter.createTransformerFactory();
@@ -104,7 +104,7 @@
             }
         }
 
-        // DOMSource can be coverted to byte[] by camel type converter mechanism
+        // DOMSource can be converted to byte[] by camel type converter mechanism
         DOMSource dom = new DOMSource(result.getNode());
         exchange.getIn().setBody(dom, byte[].class);
     }

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java?rev=896898&r1=896897&r2=896898&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheValidate.java
Thu Jan  7 14:55:44 2010
@@ -26,31 +26,33 @@
     private static final transient Log LOG = LogFactory.getLog(CacheValidate.class);
 
     public boolean isValid(CacheManager cacheManager, String cacheName, String key) {
-        LOG.debug("Cache Name: " + cacheName);
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Cache Name: " + cacheName);
+        }
+
         if (!cacheManager.cacheExists(cacheName)) {
             if (LOG.isDebugEnabled()) {
-                LOG.debug("No existing Cache found with name: "
-                      + cacheName
-                      + ". Please ensure a cache is first instantiated using a Cache Consumer
or Cache Producer");
-                LOG.debug("Replacement will not be performed since the cache " + cacheName
-                     + "does not presently exist");
+                LOG.debug("No existing Cache found with name: " + cacheName
+                        + ". Please ensure a cache is first instantiated using a Cache Consumer
or Cache Producer."
+                        + " Replacement will not be performed since the cache " + cacheName
+ "does not presently exist");
             }
             return false;
         }
 
         LOG.debug("Found an existing cache: " + cacheName);
-        LOG.debug("Cache " + cacheName + " currently contains " + cacheManager.getCache(cacheName).getSize()
-                 + " elements");
+
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Cache " + cacheName + " currently contains " + cacheManager.getCache(cacheName).getSize()
+ " elements");
+        }
         Ehcache cache = cacheManager.getCache(cacheName);
+
         if (!cache.isKeyInCache(key)) {
             if (LOG.isDebugEnabled()) {
-                LOG.debug("No Key with name: "
-                      + key
-                      + "presently exists in the cache. It is also possible that the key
may have expired in the cache");
-                LOG.debug("Replacement will not be performed until an appropriate key/value
pair is added to (or) found in the cache.");
+                LOG.debug("No Key with name: " + key
+                        + "presently exists in the cache. It is also possible that the key
may have expired in the cache."
+                        + " Replacement will not be performed until an appropriate key/value
pair is added to (or) found in the cache.");
             }
             return false;
-
         }
 
         return true;



Mime
View raw message