camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1326526 - /camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
Date Mon, 16 Apr 2012 07:53:23 GMT
Author: davsclaus
Date: Mon Apr 16 07:53:22 2012
New Revision: 1326526

URL: http://svn.apache.org/viewvc?rev=1326526&view=rev
Log:
CAMEL-5175: Added utilization stats to type converter registry which is also accessible from
JMX.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java?rev=1326526&r1=1326525&r2=1326526&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/BaseTypeConverterRegistry.java
Mon Apr 16 07:53:22 2012
@@ -41,6 +41,7 @@ import org.apache.camel.spi.TypeConverte
 import org.apache.camel.spi.TypeConverterLoader;
 import org.apache.camel.spi.TypeConverterRegistry;
 import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.LRUSoftCache;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -54,7 +55,8 @@ import org.slf4j.LoggerFactory;
 public abstract class BaseTypeConverterRegistry extends ServiceSupport implements TypeConverter,
TypeConverterRegistry {
     protected final transient Logger log = LoggerFactory.getLogger(getClass());
     protected final ConcurrentMap<TypeMapping, TypeConverter> typeMappings = new ConcurrentHashMap<TypeMapping,
TypeConverter>();
-    protected final ConcurrentMap<TypeMapping, TypeMapping> misses = new ConcurrentHashMap<TypeMapping,
TypeMapping>();
+    // for misses use a soft reference cache map, as the classes may be un-deployed at runtime
+    protected final LRUSoftCache<TypeMapping, TypeMapping> misses = new LRUSoftCache<TypeMapping,
TypeMapping>(1000);
     protected final List<TypeConverterLoader> typeConverterLoaders = new ArrayList<TypeConverterLoader>();
     protected final List<FallbackTypeConverter> fallbackConverters = new ArrayList<FallbackTypeConverter>();
     protected final PackageScanClassResolver resolver;
@@ -178,14 +180,18 @@ public abstract class BaseTypeConverterR
 
         Object answer;
         try {
+            attemptCounter.incrementAndGet();
             answer = doConvertTo(type, exchange, value, true);
         } catch (Exception e) {
+            failedCounter.incrementAndGet();
             return null;
         }
         if (answer == Void.TYPE) {
+            missCounter.incrementAndGet();
             // Could not find suitable conversion
             return null;
         } else {
+            hitCounter.incrementAndGet();
             return (T) answer;
         }
     }
@@ -533,10 +539,10 @@ public abstract class BaseTypeConverterR
      * Represents a mapping from one type (which can be null) to another
      */
     protected static class TypeMapping {
-        Class<?> toType;
-        Class<?> fromType;
+        private final Class<?> toType;
+        private final Class<?> fromType;
 
-        public TypeMapping(Class<?> toType, Class<?> fromType) {
+        TypeMapping(Class<?> toType, Class<?> fromType) {
             this.toType = toType;
             this.fromType = fromType;
         }
@@ -582,8 +588,8 @@ public abstract class BaseTypeConverterR
      * Represents a fallback type converter
      */
     protected static class FallbackTypeConverter {
-        private boolean canPromote;
-        private TypeConverter fallbackTypeConverter;
+        private final boolean canPromote;
+        private final TypeConverter fallbackTypeConverter;
 
         FallbackTypeConverter(TypeConverter fallbackTypeConverter, boolean canPromote) {
             this.canPromote = canPromote;



Mime
View raw message