qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arnaudsi...@apache.org
Subject svn commit: r597478 - in /incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client: BasicMessageProducer.java BasicMessageProducer_0_10.java message/AbstractJMSMessage.java
Date Thu, 22 Nov 2007 19:05:34 GMT
Author: arnaudsimon
Date: Thu Nov 22 11:05:33 2007
New Revision: 597478

URL: http://svn.apache.org/viewvc?rev=597478&view=rev
Log:
optimized message creation

Modified:
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
    incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java?rev=597478&r1=597477&r2=597478&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer.java
Thu Nov 22 11:05:33 2007
@@ -456,7 +456,7 @@
             type = AMQDestination.UNKNOWN_TYPE;
         }
 
-        message.getJmsHeaders().setInteger(CustomJMSXProperty.JMS_QPID_DESTTYPE.getShortStringName(),
type);
+      //  message.getJmsHeaders().setInteger(CustomJMSXProperty.JMS_QPID_DESTTYPE.getShortStringName(),
type);
 
         sendMessage(destination, origMessage, message, deliveryMode, priority, timeToLive,
                  mandatory, immediate, wait);

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java?rev=597478&r1=597477&r2=597478&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/BasicMessageProducer_0_10.java
Thu Nov 22 11:05:33 2007
@@ -51,9 +51,7 @@
     {
         ((AMQSession_0_10) getSession()).getQpidSession().exchangeDeclare(destination.getExchangeName().toString(),
                                                                           destination.getExchangeClass().toString(),
-                                                                          null,
-                                                                          null
-                                                                          );
+                                                                          null, null);
     }
 
     //--- Overwritten methods
@@ -66,97 +64,91 @@
                             boolean wait) throws JMSException
     {
         message.prepareForSending();
-        org.apache.qpidity.api.Message qpidityMessage = new ByteBufferMessage();
-        if(_logger.isDebugEnabled())
+        if (message.get010Message() == null)
         {
-            _logger.debug("Message Props: " + message.toString());
-        }
-        try
-        {
-            if (message.getData() != null)
-            {
-                qpidityMessage.appendData(message.getData().buf());
-            }
-            else
+            message.set010Message(new ByteBufferMessage());
+            if (message.getData() == null)
             {
-                   qpidityMessage.appendData(ByteBuffer.allocate(0));
+                try
+                {
+                    message.get010Message().appendData(ByteBuffer.allocate(0));
+                }
+                catch (IOException e)
+                {
+                    throw new JMSException(e.getMessage());
+                }
             }
         }
-        catch (IOException e)
-        {
-            throw ExceptionHelper.convertQpidExceptionToJMSException(e);
-        }
+
         // set the delivery properties
         if (!_disableTimestamps)
         {
             final long currentTime = System.currentTimeMillis();
-            qpidityMessage.getDeliveryProperties().setTimestamp(currentTime);
+            message.get010Message().getDeliveryProperties().setTimestamp(currentTime);
             if (timeToLive > 0)
             {
-                qpidityMessage.getDeliveryProperties().setExpiration(currentTime + timeToLive);
+                message.get010Message().getDeliveryProperties().setExpiration(currentTime
+ timeToLive);
             }
             else
             {
-                qpidityMessage.getDeliveryProperties().setExpiration(0);
+                message.get010Message().getDeliveryProperties().setExpiration(0);
             }
+            origMessage.setJMSTimestamp(message.get010Message().getDeliveryProperties().getTimestamp());
         }
-            qpidityMessage.getDeliveryProperties().setDeliveryMode((byte) deliveryMode);
-        qpidityMessage.getDeliveryProperties().setPriority((byte) priority);
-        qpidityMessage.getDeliveryProperties().setExchange(destination.getExchangeName().toString());
-        qpidityMessage.getDeliveryProperties().setRoutingKey(destination.getRoutingKey().toString());
+        message.get010Message().getDeliveryProperties().setDeliveryMode((byte) deliveryMode);
+        message.get010Message().getDeliveryProperties().setPriority((byte) priority);
+        message.get010Message().getDeliveryProperties().setExchange(destination.getExchangeName().toString());
+        message.get010Message().getDeliveryProperties().setRoutingKey(destination.getRoutingKey().toString());
+        origMessage.setJMSPriority(message.get010Message().getDeliveryProperties().getPriority());
+        origMessage.setJMSExpiration(message.get010Message().getDeliveryProperties().getExpiration());
+        origMessage.setJMSMessageID(message.getJMSMessageID());
+        origMessage.setJMSDeliveryMode(deliveryMode);
+        
         BasicContentHeaderProperties contentHeaderProperties = message.getContentHeaderProperties();
-        // set the application properties
-        qpidityMessage.getMessageProperties().setContentType(contentHeaderProperties.getContentType().toString());
-        AMQShortString type = contentHeaderProperties.getType();
-        if( type != null )
-        {
-            qpidityMessage.getMessageProperties().setType( type.toString());
-        }
-        qpidityMessage.getMessageProperties().setMessageId(message.getJMSMessageID()) ;
-        AMQShortString correlationID = contentHeaderProperties.getCorrelationId();
-        if( correlationID != null )
+        if (contentHeaderProperties.reset())
         {
-            qpidityMessage.getMessageProperties().setCorrelationId(correlationID.toString());
-        }
-        String replyToURL = contentHeaderProperties.getReplyToAsString();
-        if (replyToURL != null)
-        {
-            AMQBindingURL dest;
-            try
-            {
-                dest = new AMQBindingURL(replyToURL);
-            }
-            catch (URLSyntaxException e)
-            {
-                throw ExceptionHelper.convertQpidExceptionToJMSException(e);
-            }
-            qpidityMessage.getMessageProperties()
-                    .setReplyTo(new ReplyTo(dest.getExchangeName().toString(), dest.getRoutingKey().toString()));
-        }
-        if (contentHeaderProperties.getHeaders() != null)
-        {
-             //JMS_QPID_DESTTYPE   is always set but useles so this is a temporary fix
-            contentHeaderProperties.getHeaders().remove(CustomJMSXProperty.JMS_QPID_DESTTYPE.getShortStringName());
 
-            qpidityMessage.getMessageProperties().setApplicationHeaders(FiledTableSupport.convertToMap(contentHeaderProperties.getHeaders()));
-            for(String key:qpidityMessage.getMessageProperties().getApplicationHeaders().keySet())
-            {
-                _logger.debug(key + "=" + qpidityMessage.getMessageProperties().getApplicationHeaders().get(key));
+            // set the application properties
+            message.get010Message().getMessageProperties()
+                    .setContentType(contentHeaderProperties.getContentType().toString());
+            AMQShortString type = contentHeaderProperties.getType();
+            if (type != null)
+            {
+                message.get010Message().getMessageProperties().setType(type.toString());
+            }
+            message.get010Message().getMessageProperties().setMessageId(message.getJMSMessageID());
+            AMQShortString correlationID = contentHeaderProperties.getCorrelationId();
+            if (correlationID != null)
+            {
+                message.get010Message().getMessageProperties().setCorrelationId(correlationID.toString());
+            }
+            String replyToURL = contentHeaderProperties.getReplyToAsString();
+            if (replyToURL != null)
+            {
+                AMQBindingURL dest;
+                try
+                {
+                    dest = new AMQBindingURL(replyToURL);
+                }
+                catch (URLSyntaxException e)
+                {
+                    throw ExceptionHelper.convertQpidExceptionToJMSException(e);
+                }
+                message.get010Message().getMessageProperties()
+                        .setReplyTo(new ReplyTo(dest.getExchangeName().toString(), dest.getRoutingKey().toString()));
+            }
+            if (contentHeaderProperties.getHeaders() != null)
+            {
+                //JMS_QPID_DESTTYPE   is always set but useles so this is a temporary fix
+                contentHeaderProperties.getHeaders().remove(CustomJMSXProperty.JMS_QPID_DESTTYPE.getShortStringName());
+                message.get010Message().getMessageProperties()
+                        .setApplicationHeaders(FiledTableSupport.convertToMap(contentHeaderProperties.getHeaders()));
             }
         }
-        if(_logger.isDebugEnabled() )
-        {
-            _logger.debug("Updating original message");
-        }
-        origMessage.setJMSPriority(qpidityMessage.getDeliveryProperties().getPriority());
-        origMessage.setJMSTimestamp(qpidityMessage.getDeliveryProperties().getTimestamp());
-        origMessage.setJMSExpiration(qpidityMessage.getDeliveryProperties().getExpiration());
-        origMessage.setJMSMessageID(message.getJMSMessageID());
-        origMessage.setJMSDeliveryMode(deliveryMode);
         // send the message
         try
         {
             ((AMQSession_0_10) getSession()).getQpidSession().messageTransfer(destination.getExchangeName().toString(),
-                                                                              qpidityMessage,
+                                                                              message.get010Message(),
                                                                               org.apache.qpidity.nclient.Session.TRANSFER_CONFIRM_MODE_NOT_REQUIRED,
                                                                               org.apache.qpidity.nclient.Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE);
         }
@@ -164,19 +156,19 @@
         {
             throw ExceptionHelper.convertQpidExceptionToJMSException(e);
         }
-        catch(RuntimeException rte)
+        catch (RuntimeException rte)
         {
-            JMSException ex =  new JMSException("Exception when sending message");
+            JMSException ex = new JMSException("Exception when sending message");
             ex.setLinkedException(rte);
             throw ex;
         }
-
     }
 
 
     public boolean isBound(AMQDestination destination) throws JMSException
     {
-        return _session.isQueueBound(destination.getExchangeName(), destination.getAMQQueueName(),
destination.getRoutingKey());
+        return _session.isQueueBound(destination.getExchangeName(), destination.getAMQQueueName(),
+                                     destination.getRoutingKey());
     }
 }
 

Modified: incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java?rev=597478&r1=597477&r2=597478&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
(original)
+++ incubator/qpid/trunk/qpid/java/client/src/main/java/org/apache/qpid/client/message/AbstractJMSMessage.java
Thu Nov 22 11:05:33 2007
@@ -42,6 +42,7 @@
 import java.util.Enumeration;
 import java.util.Map;
 import java.util.UUID;
+import java.io.IOException;
 
 public abstract class AbstractJMSMessage extends AMQMessage implements org.apache.qpid.jms.Message
 {
@@ -58,6 +59,48 @@
     private BasicMessageConsumer _consumer;
     private boolean _strictAMQP;
 
+    /**
+     * This is 0_10 specific
+     */
+    private org.apache.qpidity.api.Message _010message = null;
+
+    public void set010Message(org.apache.qpidity.api.Message m )
+    {
+        _010message = m;
+    }
+
+    public void dataChanged()
+    {
+        if (_010message != null)
+        {
+            _010message.clearData();
+            try
+            {
+                if (_data != null)
+                {
+                    _010message.appendData(_data.buf());
+                }
+                else
+                {
+                    _010message.appendData(java.nio.ByteBuffer.allocate(0));
+                }
+            }
+            catch (IOException e)
+            {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+    /**
+     * End 010 specific
+     */
+
+    public org.apache.qpidity.api.Message get010Message()
+    {
+        return _010message;
+    }
+
     protected AbstractJMSMessage(ByteBuffer data)
     {
         super(new BasicContentHeaderProperties());
@@ -652,6 +695,7 @@
         {
             throw new MessageNotWriteableException("You need to call clearProperties() to
make the message writable");
         }
+        _contentHeaderProperties.updated();
     }
 
     public boolean isReadable()
@@ -673,6 +717,7 @@
         else
         {
             _data.flip();
+            dataChanged();
             _changedData = false;
         }
     }



Mime
View raw message