[prev in list] [next in list] [prev in thread] [next in thread] 

List:       activemq-commits
Subject:    svn commit: r523758 - in /activemq/camel/trunk/camel-core/src:
From:       jstrachan () apache ! org
Date:       2007-03-29 16:25:43
Message-ID: 20070329162548.12E011A9838 () eris ! apache ! org
[Download RAW message or body]

Author: jstrachan
Date: Thu Mar 29 09:25:35 2007
New Revision: 523758

URL: http://svn.apache.org/viewvc?view=rev&rev=523758
Log:
reuse a converter instance across the different conversion methods. Also tidied up \
the logging

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CachingInjector.java \
(with props)  activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Provider.java  \
(with props) Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
  activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java
  activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
  activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CachingInjector.java
                
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CachingInjector.java?view=auto&rev=523758
 ==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CachingInjector.java \
                (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CachingInjector.java \
Thu Mar 29 09:25:35 2007 @@ -0,0 +1,47 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import org.apache.camel.impl.converter.Injector;
+import org.apache.camel.impl.converter.TypeConverterRegistry;
+
+/**
+ * A caching proxy so that a single 
+ * @version $Revision$
+ */
+public class CachingInjector<T> {
+    private final TypeConverterRegistry repository;
+    private final Class<T> type;
+    private T instance;
+
+    public CachingInjector(TypeConverterRegistry repository, Class<T> type) {
+        this.repository = repository;
+        this.type = type;
+    }
+
+    public synchronized T newInstance() {
+        if (instance == null) {
+            instance = createInstance(type);
+        }
+        return instance;
+    }
+
+    protected T createInstance(Class<T> type) {
+        return (T) repository.getInjector().newInstance(type);
+    }
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CachingInjector.java
                
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CachingInjector.java
                
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CachingInjector.java
                
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java
                
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/ap \
ache/camel/impl/converter/AnnotationTypeConverterLoader.java?view=diff&rev=523758&r1=523757&r2=523758
 ==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java \
                (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java \
Thu Mar 29 09:25:35 2007 @@ -18,6 +18,7 @@
 package org.apache.camel.impl.converter;
 
 import org.apache.camel.Converter;
+import org.apache.camel.impl.CachingInjector;
 import org.apache.camel.util.ResolverUtil;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
@@ -121,6 +122,8 @@
         }
         visitedClasses.add(type);
         Method[] methods = type.getDeclaredMethods();
+        CachingInjector injector = null;
+
         for (Method method : methods) {
             Converter annotation = method.getAnnotation(Converter.class);
             if (annotation != null) {
@@ -147,7 +150,10 @@
                                 registry.addTypeConverter(fromType, toType, new \
StaticMethodTypeConverter(method));  }
                             else {
-                                registry.addTypeConverter(fromType, toType, new \
InstanceMethodTypeConverter(registry, type, method)); +                               \
if (injector == null) { +                                    injector = new \
CachingInjector(registry, type); +                                }
+                                registry.addTypeConverter(fromType, toType, new \
InstanceMethodTypeConverter(injector, method));  }
                         }
                     }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java
                
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/ap \
ache/camel/impl/converter/InstanceMethodTypeConverter.java?view=diff&rev=523758&r1=523757&r2=523758
 ==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java \
                (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/InstanceMethodTypeConverter.java \
Thu Mar 29 09:25:35 2007 @@ -17,11 +17,12 @@
  */
 package org.apache.camel.impl.converter;
 
-import org.apache.camel.TypeConverter;
 import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.TypeConverter;
+import org.apache.camel.impl.CachingInjector;
 
-import java.lang.reflect.Method;
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 
 /**
  * A {@link TypeConverter} implementation which instantiates an object
@@ -30,30 +31,23 @@
  * @version $Revision$
  */
 public class InstanceMethodTypeConverter implements TypeConverter {
-    private Object instance;
-    private final TypeConverterRegistry repository;
-    private final Class type;
+    private final CachingInjector injector;
     private final Method method;
 
-    public InstanceMethodTypeConverter(TypeConverterRegistry repository, Class type, \
                Method method) {
-        this.repository = repository;
-        this.type = type;
+    public InstanceMethodTypeConverter(CachingInjector injector, Method method) {
+        this.injector = injector;
         this.method = method;
     }
 
-
     @Override
     public String toString() {
         return "InstanceMethodTypeConverter: " + method;
     }
 
-
     public synchronized <T> T convertTo(Class<T> type, Object value) {
+        Object instance = injector.newInstance();
         if (instance == null) {
-            instance = createInstance();
-            if (instance == null) {
-                throw new RuntimeCamelException("Could not instantiate aninstance \
                of: " + type.getName());
-            }
+            throw new RuntimeCamelException("Could not instantiate aninstance of: " \
+ type.getName());  }
         try {
             return (T) method.invoke(instance, value);
@@ -64,9 +58,5 @@
         catch (InvocationTargetException e) {
             throw new RuntimeCamelException(e.getCause());
         }
-    }
-
-    protected Object createInstance() {
-        return repository.getInjector().newInstance(type);
     }
 }

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Provider.java
                
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Provider.java?view=auto&rev=523758
 ==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Provider.java \
                (added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Provider.java \
Thu Mar 29 09:25:35 2007 @@ -0,0 +1,25 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+/**
+ * Represents a factory or po
+ * @version $Revision$
+ */
+public interface Provider<T> {
+}

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Provider.java
                
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Provider.java
                
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/Provider.java
                
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java
                
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java?view=diff&rev=523758&r1=523757&r2=523758
 ==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java \
                (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ResolverUtil.java \
Thu Mar 29 09:25:35 2007 @@ -209,7 +209,7 @@
             urls = loader.getResources(packageName);
         }
         catch (IOException ioe) {
-            ResolverUtil.log.warn("Could not read package: " + packageName, ioe);
+            log.warn("Could not read package: " + packageName, ioe);
             return;
         }
 
@@ -228,7 +228,7 @@
                     urlPath = urlPath.substring(0, urlPath.indexOf('!'));
                 }
 
-                ResolverUtil.log.info("Scanning for classes in [" + urlPath + "] \
matching criteria: " + test); +                log.debug("Scanning for classes in [" \
+ urlPath + "] matching criteria: " + test);  File file = new File(urlPath);
                 if ( file.isDirectory() ) {
                     loadImplementationsInDirectory(test, packageName, file);
@@ -238,7 +238,7 @@
                 }
             }
             catch (IOException ioe) {
-                ResolverUtil.log.warn("could not read entries", ioe);
+                log.warn("could not read entries", ioe);
             }
         }
     }
@@ -297,7 +297,7 @@
             }
         }
         catch (IOException ioe) {
-            ResolverUtil.log.error("Could not search jar file '" + jarfile + "' for \
classes matching criteria: " + +            log.error("Could not search jar file '" + \
                jarfile + "' for classes matching criteria: " +
                       test + "due to an IOException: " + ioe.getMessage());
         }
     }
@@ -313,7 +313,7 @@
         try {
             String externalName = fqn.substring(0, fqn.indexOf('.')).replace('/', \
'.');  ClassLoader loader = getClassLoader();
-            ResolverUtil.log.trace("Checking to see if class " + externalName + " \
matches criteria [" + test+ "]"); +            log.trace("Checking to see if class " \
+ externalName + " matches criteria [" + test+ "]");  
             Class type = loader.loadClass(externalName);
             if (test.matches(type) ) {
@@ -321,7 +321,7 @@
             }
         }
         catch (Throwable t) {
-            ResolverUtil.log.warn("Could not examine class '"+ fqn + "' due to a " +
+            log.warn("Could not examine class '"+ fqn + "' due to a " +
                      t.getClass().getName()+ " with message: " + t.getMessage());
         }
     }

Modified: activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties?view=diff&rev=523758&r1=523757&r2=523758
 ==============================================================================
--- activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties \
                (original)
+++ activemq/camel/trunk/camel-core/src/test/ide-resources/log4j.properties Thu Mar \
29 09:25:35 2007 @@ -20,8 +20,11 @@
 #
 log4j.rootLogger=DEBUG, out
 
-#log4j.logger.org.apache.activemq=DEBUG
 log4j.logger.org.apache.camel=DEBUG
+log4j.logger.org.apache.camel.impl.converter=INFO
+
+#log4j.logger.org.apache.activemq=DEBUG
+
 
 # CONSOLE appender not used by default
 log4j.appender.out=org.apache.log4j.ConsoleAppender


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic