camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r646003 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ components/camel-jms/src/main/java/org/apache/camel/component/jms/
Date Tue, 08 Apr 2008 17:12:40 GMT
Author: jstrachan
Date: Tue Apr  8 10:12:38 2008
New Revision: 646003

URL: http://svn.apache.org/viewvc?rev=646003&view=rev
Log:
use getter rather than field to allow customization by derived classes

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelTemplate.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
    activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelTemplate.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelTemplate.java?rev=646003&r1=646002&r2=646003&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelTemplate.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelTemplate.java Tue
Apr  8 10:12:38 2008
@@ -103,7 +103,8 @@
      * @param exchange the exchange to send
      */
     public E send(Endpoint<E> endpoint, E exchange) {
-        E convertedExchange = endpoint.createExchange(exchange);
+        //E convertedExchange = endpoint.createExchange(exchange);
+        E convertedExchange = exchange;
         producerCache.send(endpoint, convertedExchange);
         return convertedExchange;
     }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java?rev=646003&r1=646002&r2=646003&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
Tue Apr  8 10:12:38 2008
@@ -40,7 +40,7 @@
     private Message out;
     private Message fault;
     private Throwable exception;
-    private String exchangeId = DefaultExchange.DEFAULT_ID_GENERATOR.generateId();
+    private String exchangeId;
     private UnitOfWork unitOfWork;
     private ExchangePattern pattern;
 
@@ -233,6 +233,9 @@
     }
 
     public String getExchangeId() {
+        if (exchangeId == null) {
+            exchangeId = DefaultExchange.DEFAULT_ID_GENERATOR.generateId();
+        }
         return exchangeId;
     }
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java?rev=646003&r1=646002&r2=646003&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
Tue Apr  8 10:12:38 2008
@@ -35,7 +35,7 @@
     private static final UuidGenerator DEFALT_ID_GENERATOR = new UuidGenerator();
     private Exchange exchange;
     private Object body;
-    private String messageId = DEFALT_ID_GENERATOR.generateId();
+    private String messageId;
 
     public Object getBody() {
         if (body == null) {
@@ -117,6 +117,9 @@
      * @return the messageId
      */
     public String getMessageId() {
+        if (messageId == null) {
+            messageId = createMessageId();
+        }
         return this.messageId;
     }
 
@@ -125,5 +128,12 @@
      */
     public void setMessageId(String messageId) {
         this.messageId = messageId;
+    }
+
+    /**
+     * Lets allow implementations to auto-create a messageId
+     */
+    protected String createMessageId() {
+        return DEFALT_ID_GENERATOR.generateId();
     }
 }

Modified: activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java?rev=646003&r1=646002&r2=646003&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
(original)
+++ activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsMessage.java
Tue Apr  8 10:12:38 2008
@@ -57,11 +57,30 @@
     public String toString() {
         if (jmsMessage != null) {
             return "JmsMessage: " + jmsMessage;
-        } else {
+        }
+        else {
             return "JmsMessage: " + getBody();
         }
     }
 
+    @Override
+    public void copyFrom(org.apache.camel.Message that) {
+        // for performance lets not copy the messageID if we are a JMS message
+        boolean copyMessageId = true;
+        if (that instanceof JmsMessage) {
+            JmsMessage thatMessage = (JmsMessage) that;
+            this.jmsMessage = thatMessage.jmsMessage;
+            if (this.jmsMessage != null) {
+                copyMessageId = false;
+            }
+        }
+        if (!copyMessageId) {
+            setMessageId(that.getMessageId());
+        }
+        setBody(that.getBody());
+        getHeaders().putAll(that.getHeaders());
+    }
+
     /**
      * Returns the underlying JMS message
      *
@@ -75,9 +94,10 @@
         if (binding == null) {
             Exchange exchange = getExchange();
             if (exchange instanceof JmsExchange) {
-                JmsExchange jmsExchange = (JmsExchange)exchange;
+                JmsExchange jmsExchange = (JmsExchange) exchange;
                 return jmsExchange.getBinding();
-            } else {
+            }
+            else {
                 return new JmsBinding();
             }
         }
@@ -90,13 +110,6 @@
 
     public void setJmsMessage(Message jmsMessage) {
         this.jmsMessage = jmsMessage;
-        try {
-            String id = getDestinationAsString(jmsMessage.getJMSDestination());
-            id += getSanitizedString(jmsMessage.getJMSMessageID());
-            setMessageId(id);
-        } catch (JMSException e) {
-            LOG.error("Failed to get message id from message " + jmsMessage, e);
-        }
     }
 
     public Object getHeader(String name) {
@@ -107,7 +120,8 @@
         if (jmsMessage != null && !name.startsWith("JMS")) {
             try {
                 answer = jmsMessage.getObjectProperty(name);
-            } catch (JMSException e) {
+            }
+            catch (JMSException e) {
                 throw new MessagePropertyAccessException(name, e);
             }
         }
@@ -148,15 +162,16 @@
 
                 // TODO this works around a bug in the ActiveMQ property handling
                 map.put("JMSXGroupID", jmsMessage.getStringProperty("JMSXGroupID"));
-
-            } catch (JMSException e) {
+            }
+            catch (JMSException e) {
                 throw new MessageJMSPropertyAccessException(e);
             }
 
             Enumeration names;
             try {
                 names = jmsMessage.getPropertyNames();
-            } catch (JMSException e) {
+            }
+            catch (JMSException e) {
                 throw new MessagePropertyNamesAccessException(e);
             }
             while (names.hasMoreElements()) {
@@ -164,23 +179,36 @@
                 try {
                     Object value = jmsMessage.getObjectProperty(name);
                     map.put(name, value);
-                } catch (JMSException e) {
+                }
+                catch (JMSException e) {
                     throw new MessagePropertyAccessException(name, e);
                 }
             }
         }
     }
 
+    @Override
+    protected String createMessageId() {
+        try {
+            String id = getDestinationAsString(jmsMessage.getJMSDestination()) + jmsMessage.getJMSMessageID();
+            return getSanitizedString(id);
+        } catch (JMSException e) {
+            LOG.error("Failed to get message id from message " + jmsMessage, e);
+            return super.createMessageId();
+        }
+    }
+
     private String getDestinationAsString(Destination destination) throws JMSException {
-        String result = "";
+        String result;
         if (destination == null) {
-            result = "null destination!";
-        } else if (destination instanceof Topic) {
-            result += "topic" + File.separator + getSanitizedString(((Topic)destination).getTopicName());
-        } else {
-            result += "queue" + File.separator + getSanitizedString(((Queue)destination).getQueueName());
+            result = "null destination!" + File.separator;
+        }
+        else if (destination instanceof Topic) {
+            result = "topic" + File.separator + ((Topic) destination).getTopicName() + File.separator;
+        }
+        else {
+            result = "queue" + File.separator + ((Queue) destination).getQueueName() + File.separator;
         }
-        result += File.separator;
         return result;
     }
 



Mime
View raw message