camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r801249 - in /camel/trunk/camel-core/src/main/java/org/apache/camel: Exchange.java Message.java impl/DefaultExchange.java impl/DefaultMessage.java impl/MessageSupport.java
Date Wed, 05 Aug 2009 15:00:52 GMT
Author: davsclaus
Date: Wed Aug  5 15:00:52 2009
New Revision: 801249

URL: http://svn.apache.org/viewvc?rev=801249&view=rev
Log:
A little optimization to avoid copying if not needed.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java?rev=801249&r1=801248&r2=801249&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Exchange.java Wed Aug  5 15:00:52
2009
@@ -170,6 +170,13 @@
     Map<String, Object> getProperties();
 
     /**
+     * Returns whether any properties has been set
+     *
+     * @return <tt>true</tt> if any properties has been set
+     */
+    boolean hasProperties();
+
+    /**
      * Returns the inbound request message
      *
      * @return the message

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java?rev=801249&r1=801248&r2=801249&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java Wed Aug  5 15:00:52
2009
@@ -107,6 +107,13 @@
     void setHeaders(Map<String, Object> headers);
 
     /**
+     * Returns whether has any headers has been set.
+     *
+     * @return <tt>true</tt> if any headers has been set
+     */
+    boolean hasHeaders();
+
+    /**
      * Returns the body of the message as a POJO
      * <p/>
      * The body can be <tt>null</tt> if no body is set

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java?rev=801249&r1=801248&r2=801249&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java Wed Aug
 5 15:00:52 2009
@@ -84,7 +84,9 @@
     public Exchange copy() {
         DefaultExchange exchange = new DefaultExchange(this);
 
-        exchange.setProperties(safeCopy(getProperties()));
+        if (exchange.hasProperties()) {
+            exchange.setProperties(getProperties());
+        }
         safeCopy(exchange.getIn(), getIn());
         if (hasOut()) {
             safeCopy(exchange.getOut(), getOut());
@@ -99,13 +101,6 @@
         }
     }
 
-    private static Map<String, Object> safeCopy(Map<String, Object> properties)
{
-        if (properties == null) {
-            return null;
-        }
-        return new ConcurrentHashMap<String, Object>(properties);
-    }
-
     public CamelContext getContext() {
         return context;
     }
@@ -152,6 +147,10 @@
         return properties;
     }
 
+    public boolean hasProperties() {
+        return properties != null && !properties.isEmpty();
+    }
+
     public void setProperties(Map<String, Object> properties) {
         this.properties = properties;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java?rev=801249&r1=801248&r2=801249&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java Wed Aug
 5 15:00:52 2009
@@ -101,6 +101,10 @@
         this.headers = headers;
     }
 
+    public boolean hasHeaders() {
+        return headers != null && !headers.isEmpty();
+    }
+
     public DefaultMessage newInstance() {
         return new DefaultMessage();
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java?rev=801249&r1=801248&r2=801249&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java Wed Aug
 5 15:00:52 2009
@@ -131,8 +131,12 @@
     public void copyFrom(Message that) {
         setMessageId(that.getMessageId());
         setBody(that.getBody());
-        getHeaders().putAll(that.getHeaders());
-        getAttachments().putAll(that.getAttachments());
+        if (that.hasHeaders()) {
+            getHeaders().putAll(that.getHeaders());
+        }
+        if (that.hasAttachments()) {
+            getAttachments().putAll(that.getAttachments());
+        }
     }
 
     public Exchange getExchange() {



Mime
View raw message