activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r924661 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/scheduler/ main/java/org/apache/activemq/command/ test/java/org/apache/activemq/broker/scheduler/ test/java/org/apache/activemq/transport/stomp/
Date Thu, 18 Mar 2010 07:21:12 GMT
Author: rajdavies
Date: Thu Mar 18 07:21:12 2010
New Revision: 924661

URL: http://svn.apache.org/viewvc?rev=924661&view=rev
Log:
Fix for https://issues.apache.org/activemq/browse/AMQ-2646

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/SchedulerBroker.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JmsSchedulerTest.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/SchedulerBroker.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/SchedulerBroker.java?rev=924661&r1=924660&r2=924661&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/SchedulerBroker.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/scheduler/SchedulerBroker.java
Thu Mar 18 07:21:12 2010
@@ -108,8 +108,9 @@ public class SchedulerBroker extends Bro
         String cronEntry = "";
         Object cronValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_CRON);
         Object periodValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD);
+        Object delayValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY);
 
-        if (cronValue != null || periodValue != null) {
+        if (cronValue != null || periodValue != null || delayValue != null) {
             org.apache.activemq.util.ByteSequence packet = wireFormat.marshal(messageSend);
                 if (cronValue != null) {
                     cronEntry = cronValue.toString();
@@ -117,7 +118,6 @@ public class SchedulerBroker extends Bro
                 if (periodValue != null) {      
                   period = (Long) TypeConversionSupport.convert(periodValue, Long.class);
                 }
-                Object delayValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY);
                 if (delayValue != null) {
                     delay = (Long) TypeConversionSupport.convert(delayValue, Long.class);
                 }
@@ -131,7 +131,6 @@ public class SchedulerBroker extends Bro
             
 
         } else {
-
             super.send(producerExchange, messageSend);
         }
     }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQMessage.java?rev=924661&r1=924660&r2=924661&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQMessage.java
Thu Mar 18 07:21:12 2010
@@ -414,7 +414,7 @@ public class ActiveMQMessage extends Mes
         }
 
         checkValidObject(value);
-        checkValidScheduled(name, value);
+        value = convertScheduled(name, value);
         PropertySetter setter = JMS_PROPERTY_SETERS.get(name);
 
         if (setter != null && value != null) {
@@ -467,6 +467,20 @@ public class ActiveMQMessage extends Mes
             CronParser.validate(value.toString());
         }
     }
+    
+    protected Object  convertScheduled(String name, Object value) throws MessageFormatException
{
+        Object result = value;
+        if (AMQ_SCHEDULED_DELAY.equals(name)){
+            result = TypeConversionSupport.convert(value, Long.class);
+        }
+        else if (AMQ_SCHEDULED_PERIOD.equals(name)){
+            result = TypeConversionSupport.convert(value, Long.class);
+        }
+        else if (AMQ_SCHEDULED_REPEAT.equals(name)){
+            result = TypeConversionSupport.convert(value, Integer.class);
+        }
+        return result;
+    }
 
     public Object getObjectProperty(String name) throws JMSException {
         if (name == null) {

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JmsSchedulerTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JmsSchedulerTest.java?rev=924661&r1=924660&r2=924661&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JmsSchedulerTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/scheduler/JmsSchedulerTest.java
Thu Mar 18 07:21:12 2010
@@ -93,7 +93,7 @@ public class JmsSchedulerTest extends Em
         MessageProducer producer = session.createProducer(destination);
         TextMessage message = session.createTextMessage("test msg");
 
-        message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, time);
+        message.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, time);
 
         producer.send(message);
         producer.close();

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java?rev=924661&r1=924660&r2=924661&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompTest.java
Thu Mar 18 07:21:12 2010
@@ -16,15 +16,6 @@
  */
 package org.apache.activemq.transport.stomp;
 
-import org.apache.activemq.ActiveMQConnectionFactory;
-import org.apache.activemq.CombinationTestSupport;
-import org.apache.activemq.broker.BrokerFactory;
-import org.apache.activemq.broker.BrokerService;
-import org.apache.activemq.broker.jmx.BrokerViewMBean;
-import org.apache.activemq.command.ActiveMQQueue;
-import org.apache.activemq.command.ActiveMQTextMessage;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import java.io.IOException;
 import java.net.Socket;
 import java.net.SocketTimeoutException;
@@ -44,6 +35,15 @@ import javax.jms.ObjectMessage;
 import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.management.ObjectName;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.CombinationTestSupport;
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.jmx.BrokerViewMBean;
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTextMessage;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class StompTest extends CombinationTestSupport {
     private static final Log LOG = LogFactory.getLog(StompTest.class);
@@ -58,7 +58,7 @@ public class StompTest extends Combinati
     private Connection connection;
     private Session session;
     private ActiveMQQueue queue;
-    private String xmlObject = "<pojo>\n"
+    private final String xmlObject = "<pojo>\n"
             + "  <name>Dejan</name>\n"
             + "  <city>Belgrade</city>\n"
             + "</pojo>";
@@ -74,7 +74,7 @@ public class StompTest extends Combinati
         + "  </entry>\n"
         + "</map>\n";
 
-    private String jsonObject = "{\"pojo\":{"
+    private final String jsonObject = "{\"pojo\":{"
         + "\"name\":\"Dejan\","
         + "\"city\":\"Belgrade\""
         + "}}";
@@ -86,6 +86,7 @@ public class StompTest extends Combinati
         + "]"
         + "}}";
 
+    @Override
     protected void setUp() throws Exception {
         // The order of the entries is different when using ibm jdk 5.
         if (System.getProperty("java.vendor").equals("IBM Corporation")
@@ -132,6 +133,7 @@ public class StompTest extends Combinati
         return getClass().getName() + "." + getName();
     }
 
+    @Override
     protected void tearDown() throws Exception {
         try {
             connection.close();
@@ -243,6 +245,26 @@ public class StompTest extends Combinati
         assertEquals("foo", "abc", message.getStringProperty("foo"));
         assertEquals("bar", "123", message.getStringProperty("bar"));
     }
+    
+    public void testSendMessageWithDelay() throws Exception {
+
+        MessageConsumer consumer = session.createConsumer(queue);
+
+        String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+
+        frame = stompConnection.receiveFrame();
+        assertTrue(frame.startsWith("CONNECTED"));
+
+        frame = "SEND\n" + "AMQ_SCHEDULED_DELAY:5000\n"  + "destination:/queue/" + getQueueName()
+ "\n\n" + "Hello World" + Stomp.NULL;
+
+        stompConnection.sendFrame(frame);
+
+        TextMessage message = (TextMessage)consumer.receive(2000);
+        assertNull(message);
+        message = (TextMessage)consumer.receive(5000);
+        assertNotNull(message);
+    }
 
     public void testSendMessageWithStandardHeaders() throws Exception {
 



Mime
View raw message