camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] camel git commit: CAMEL-11379: Optimise - core type converters to be invoked faster
Date Thu, 29 Jun 2017 12:08:12 GMT
Repository: camel
Updated Branches:
  refs/heads/master e9091d3fc -> bde5691a8


CAMEL-11379: Optimise - core type converters to be invoked faster


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/cfd4e02d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/cfd4e02d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/cfd4e02d

Branch: refs/heads/master
Commit: cfd4e02db7981c9e65e69e6874731ce33e30ee61
Parents: e9091d3
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Jun 29 14:06:02 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jun 29 14:06:02 2017 +0200

----------------------------------------------------------------------
 .../converter/ObjectConverterOptimised.java     |  8 ----
 .../TimePatternConverterOptimised.java          | 42 ++++++++++++++++++++
 .../impl/converter/OptimisedTypeConverter.java  |  8 +++-
 3 files changed, 49 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cfd4e02d/camel-core/src/main/java/org/apache/camel/converter/ObjectConverterOptimised.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/ObjectConverterOptimised.java
b/camel-core/src/main/java/org/apache/camel/converter/ObjectConverterOptimised.java
index 149ca7a..dfbb7d5 100644
--- a/camel-core/src/main/java/org/apache/camel/converter/ObjectConverterOptimised.java
+++ b/camel-core/src/main/java/org/apache/camel/converter/ObjectConverterOptimised.java
@@ -47,14 +47,6 @@ public final class ObjectConverterOptimised {
             return null;
         }
 
-        // special for String -> long where we support time patterns
-        if (type == long.class || type == Long.class) {
-            Class fromType = value.getClass();
-            if (fromType == String.class) {
-                return TimePatternConverter.toMilliSeconds(value.toString());
-            }
-        }
-
         if (type == boolean.class || type == Boolean.class) {
             return ObjectConverter.toBoolean(value);
         } else if (type == int.class || type == Integer.class) {

http://git-wip-us.apache.org/repos/asf/camel/blob/cfd4e02d/camel-core/src/main/java/org/apache/camel/converter/TimePatternConverterOptimised.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/converter/TimePatternConverterOptimised.java
b/camel-core/src/main/java/org/apache/camel/converter/TimePatternConverterOptimised.java
new file mode 100644
index 0000000..bb45a40
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/converter/TimePatternConverterOptimised.java
@@ -0,0 +1,42 @@
+/**
+ * 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.converter;
+
+import org.apache.camel.Exchange;
+
+/**
+ * Optimised {@link TimePatternConverter}
+ */
+public final class TimePatternConverterOptimised {
+
+    private TimePatternConverterOptimised() {
+    }
+
+    public static Object convertTo(final Class<?> type, final Exchange exchange, final
Object value) throws Exception {
+        // special for String -> long where we support time patterns
+        if (type == long.class || type == Long.class) {
+            Class fromType = value.getClass();
+            if (fromType == String.class) {
+                return TimePatternConverter.toMilliSeconds(value.toString());
+            }
+        }
+
+        // no optimised type converter found
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/cfd4e02d/camel-core/src/main/java/org/apache/camel/impl/converter/OptimisedTypeConverter.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/converter/OptimisedTypeConverter.java
b/camel-core/src/main/java/org/apache/camel/impl/converter/OptimisedTypeConverter.java
index 9280793..df774f8 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/converter/OptimisedTypeConverter.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/converter/OptimisedTypeConverter.java
@@ -22,6 +22,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.converter.IOConverterOptimised;
 import org.apache.camel.converter.NIOConverterOptimised;
 import org.apache.camel.converter.ObjectConverterOptimised;
+import org.apache.camel.converter.TimePatternConverterOptimised;
 
 /**
  * Optimised type converter for performing the most common conversions using the type converters
@@ -52,7 +53,12 @@ public class OptimisedTypeConverter {
         Object answer;
 
         // use the optimised type converters and use them in the most commonly used order
-        answer = ObjectConverterOptimised.convertTo(type, exchange, value);
+
+        // we need time pattern first as it can do a special String -> long conversion
which should happen first
+        answer = TimePatternConverterOptimised.convertTo(type, exchange, value);
+        if (answer == null) {
+            answer = ObjectConverterOptimised.convertTo(type, exchange, value);
+        }
         if (answer == null) {
             answer = IOConverterOptimised.convertTo(type, exchange, value);
         }


Mime
View raw message