Author: timfox
Date: 2010-04-15 10:46:37 -0400 (Thu, 15 Apr 2010)
New Revision: 9128
Modified:
trunk/src/main/org/hornetq/api/core/Message.java
trunk/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java
trunk/src/main/org/hornetq/core/filter/impl/FilterImpl.java
trunk/src/main/org/hornetq/core/filter/impl/FilterParser.jj
trunk/src/main/org/hornetq/core/message/impl/MessageImpl.java
trunk/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
trunk/src/main/org/hornetq/jms/client/HornetQMessage.java
trunk/src/main/org/hornetq/jms/client/HornetQMessageProducer.java
trunk/src/main/org/hornetq/jms/client/SelectorTranslator.java
trunk/src/main/org/hornetq/jms/server/impl/JMSServerConfigParserImpl.java
trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java
trunk/src/main/org/hornetq/utils/UUID.java
trunk/tests/jms-tests/src/org/hornetq/jms/tests/selector/SelectorTest.java
trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java
trunk/tests/src/org/hornetq/tests/unit/jms/client/SelectorTranslatorTest.java
Log:
https://jira.jboss.org/jira/browse/HORNETQ-357
Modified: trunk/src/main/org/hornetq/api/core/Message.java
===================================================================
--- trunk/src/main/org/hornetq/api/core/Message.java 2010-04-15 14:41:40 UTC (rev 9127)
+++ trunk/src/main/org/hornetq/api/core/Message.java 2010-04-15 14:46:37 UTC (rev 9128)
@@ -16,7 +16,9 @@
import java.util.Map;
import java.util.Set;
+import org.hornetq.utils.UUID;
+
/**
* A Message is a routable instance that has a payload.
* <br/>
@@ -90,17 +92,17 @@
long getMessageID();
/**
- * Returns the userID - this is an optional user specified String that can be set to
identify the message
+ * Returns the userID - this is an optional user specified UUID that can be set to
identify the message
* and will be passed around with the message
- * @return
+ * @return the user id
*/
- SimpleString getUserID();
+ UUID getUserID();
/**
* Sets the user ID
* @param userID
*/
- void setUserID(SimpleString userID);
+ void setUserID(UUID userID);
/**
* Returns the address this message is sent to.
Modified: trunk/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java 2010-04-15
14:41:40 UTC (rev 9127)
+++ trunk/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java 2010-04-15
14:46:37 UTC (rev 9128)
@@ -1167,7 +1167,6 @@
{
return;
}
- //log.info("calling check flush on client");
connection.getTransportConnection().checkFlushBatchBuffer();
}
Modified: trunk/src/main/org/hornetq/core/filter/impl/FilterImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/filter/impl/FilterImpl.java 2010-04-15 14:41:40 UTC
(rev 9127)
+++ trunk/src/main/org/hornetq/core/filter/impl/FilterImpl.java 2010-04-15 14:46:37 UTC
(rev 9128)
@@ -187,7 +187,8 @@
{
if (FilterConstants.HORNETQ_USERID.equals(fieldName))
{
- return msg.getUserID();
+ //It's the stringified (hex) representation of a user id that can be used in
a selector expression
+ return new SimpleString("ID:" + msg.getUserID());
}
else if (FilterConstants.HORNETQ_PRIORITY.equals(fieldName))
{
Modified: trunk/src/main/org/hornetq/core/filter/impl/FilterParser.jj
===================================================================
--- trunk/src/main/org/hornetq/core/filter/impl/FilterParser.jj 2010-04-15 14:41:40 UTC
(rev 9127)
+++ trunk/src/main/org/hornetq/core/filter/impl/FilterParser.jj 2010-04-15 14:46:37 UTC
(rev 9128)
@@ -62,7 +62,7 @@
public FilterParser()
{
- // keep the parser from feaking out, init using one of
+ // keep the parser from freaking out, init using one of
// the JavaCC generated constructor
this(new StringReader(""));
}
Modified: trunk/src/main/org/hornetq/core/message/impl/MessageImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/message/impl/MessageImpl.java 2010-04-15 14:41:40 UTC
(rev 9127)
+++ trunk/src/main/org/hornetq/core/message/impl/MessageImpl.java 2010-04-15 14:46:37 UTC
(rev 9128)
@@ -30,6 +30,7 @@
import org.hornetq.core.protocol.core.impl.PacketImpl;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.TypedProperties;
+import org.hornetq.utils.UUID;
/**
* A concrete implementation of a message
@@ -86,7 +87,7 @@
private boolean bufferUsed;
- private SimpleString userID;
+ private UUID userID;
// Constructors --------------------------------------------------
@@ -186,7 +187,8 @@
public int getHeadersAndPropertiesEncodeSize()
{
return DataConstants.SIZE_LONG + // Message ID
- SimpleString.sizeofNullableString(userID) +
+ DataConstants.SIZE_BYTE + // user id null?
+ (userID == null ? 0 : 16) +
/* address */SimpleString.sizeofNullableString(address) +
DataConstants./* Type */SIZE_BYTE +
DataConstants./* Durable */SIZE_BOOLEAN +
@@ -201,7 +203,15 @@
{
buffer.writeLong(messageID);
buffer.writeNullableSimpleString(address);
- buffer.writeNullableSimpleString(userID);
+ if (userID == null)
+ {
+ buffer.writeByte(DataConstants.NULL);
+ }
+ else
+ {
+ buffer.writeByte(DataConstants.NOT_NULL);
+ buffer.writeBytes(userID.asBytes());
+ }
buffer.writeByte(type);
buffer.writeBoolean(durable);
buffer.writeLong(expiration);
@@ -214,7 +224,16 @@
{
messageID = buffer.readLong();
address = buffer.readNullableSimpleString();
- userID = buffer.readNullableSimpleString();
+ if (buffer.readByte() == DataConstants.NOT_NULL)
+ {
+ byte[] bytes = new byte[16];
+ buffer.readBytes(bytes);
+ userID = new UUID(UUID.TYPE_TIME_BASED, bytes);
+ }
+ else
+ {
+ userID = null;
+ }
type = buffer.readByte();
durable = buffer.readBoolean();
expiration = buffer.readLong();
@@ -245,12 +264,12 @@
return messageID;
}
- public SimpleString getUserID()
+ public UUID getUserID()
{
return userID;
}
- public void setUserID(final SimpleString userID)
+ public void setUserID(final UUID userID)
{
this.userID = userID;
}
@@ -355,7 +374,10 @@
Map<String, Object> map = new HashMap<String, Object>();
map.put("messageID", messageID);
- map.put("userID", userID);
+ if (userID != null)
+ {
+ map.put("userID", "ID:" + userID.toString());
+ }
map.put("address", address.toString());
map.put("type", type);
map.put("durable", durable);
Modified: trunk/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2010-04-15
14:41:40 UTC (rev 9127)
+++ trunk/src/main/org/hornetq/core/server/cluster/impl/ClusterManagerImpl.java 2010-04-15
14:46:37 UTC (rev 9128)
@@ -343,8 +343,6 @@
localBindAddress = null;
}
- log.info("local bind address " + localBindAddress);
-
DiscoveryGroup group = new DiscoveryGroupImpl(nodeUUID.toString(),
config.getName(),
localBindAddress,
Modified: trunk/src/main/org/hornetq/jms/client/HornetQMessage.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQMessage.java 2010-04-15 14:41:40 UTC (rev
9127)
+++ trunk/src/main/org/hornetq/jms/client/HornetQMessage.java 2010-04-15 14:46:37 UTC (rev
9128)
@@ -42,6 +42,7 @@
import org.hornetq.api.jms.HornetQJMSConstants;
import org.hornetq.core.client.impl.ClientMessageImpl;
import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.UUID;
/**
* HornetQ implementation of a JMS Message.
@@ -330,9 +331,9 @@
{
if (msgID == null)
{
- SimpleString uid = message.getUserID();
+ UUID uid = message.getUserID();
- msgID = uid == null ? null : uid.toString();
+ msgID = uid == null ? null : "ID:" + uid.toString();
}
return msgID;
}
Modified: trunk/src/main/org/hornetq/jms/client/HornetQMessageProducer.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/HornetQMessageProducer.java 2010-04-15 14:41:40
UTC (rev 9127)
+++ trunk/src/main/org/hornetq/jms/client/HornetQMessageProducer.java 2010-04-15 14:46:37
UTC (rev 9128)
@@ -405,23 +405,11 @@
if (!disableMessageID)
{
- // Generate an id
+ // Generate a JMS id
UUID uid = UUIDGenerator.getInstance().generateUUID();
- byte[] bytes = uid.asBytes();
-
- byte[] id = new byte[6 + 16];
-
- id[0] = (byte)'I';
- id[2] = (byte)'D';
- id[4] = (byte)':';
-
- System.arraycopy(bytes, 0, id, 6, 16);
-
- SimpleString ssid = new SimpleString(id);
-
- msg.getCoreMessage().setUserID(ssid);
+ msg.getCoreMessage().setUserID(uid);
msg.resetMessageID(null);
}
Modified: trunk/src/main/org/hornetq/jms/client/SelectorTranslator.java
===================================================================
--- trunk/src/main/org/hornetq/jms/client/SelectorTranslator.java 2010-04-15 14:41:40 UTC
(rev 9127)
+++ trunk/src/main/org/hornetq/jms/client/SelectorTranslator.java 2010-04-15 14:46:37 UTC
(rev 9128)
@@ -49,6 +49,7 @@
filterString = SelectorTranslator.parse(filterString,
"'NON_PERSISTENT'", "'NON_DURABLE'");
filterString = SelectorTranslator.parse(filterString, "JMSPriority",
"HQPriority");
filterString = SelectorTranslator.parse(filterString, "JMSTimestamp",
"HQTimestamp");
+ filterString = SelectorTranslator.parse(filterString, "JMSMessageID",
"HQUserID");
return filterString;
Modified: trunk/src/main/org/hornetq/jms/server/impl/JMSServerConfigParserImpl.java
===================================================================
--- trunk/src/main/org/hornetq/jms/server/impl/JMSServerConfigParserImpl.java 2010-04-15
14:41:40 UTC (rev 9127)
+++ trunk/src/main/org/hornetq/jms/server/impl/JMSServerConfigParserImpl.java 2010-04-15
14:46:37 UTC (rev 9128)
@@ -366,7 +366,6 @@
if (discoveryGroupName != null)
{
- log.info("discovery group name is " + discoveryGroupName);
cfConfig = new ConnectionFactoryConfigurationImpl(name, strbindings);
cfConfig.setInitialWaitTimeout(discoveryInitialWaitTimeout);
cfConfig.setDiscoveryGroupName(discoveryGroupName);
Modified: trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java 2010-04-15
14:41:40 UTC (rev 9127)
+++ trunk/src/main/org/hornetq/jms/server/impl/JMSServerManagerImpl.java 2010-04-15
14:46:37 UTC (rev 9128)
@@ -801,8 +801,6 @@
final String groupId,
final String... jndiBindings) throws
Exception
{
- log.info("calling create cf " + discoveryRefreshTimeout + " lba
" + localBindAddress);
-
checkInitialised();
HornetQConnectionFactory cf = connectionFactories.get(name);
if (cf == null)
Modified: trunk/src/main/org/hornetq/utils/UUID.java
===================================================================
--- trunk/src/main/org/hornetq/utils/UUID.java 2010-04-15 14:41:40 UTC (rev 9127)
+++ trunk/src/main/org/hornetq/utils/UUID.java 2010-04-15 14:46:37 UTC (rev 9128)
@@ -85,7 +85,7 @@
*/
private static boolean sDescCaching = true;
- private final byte[] mId = new byte[16];
+ private final byte[] mId;
// Both string presentation and hash value may be cached...
private transient String mDesc = null;
@@ -93,8 +93,8 @@
private transient int mHashCode = 0;
/**
- * Protected constructor used by UUIDGenerator
*
+ *
* @param type
* UUID type
* @param data
@@ -102,10 +102,7 @@
*/
public UUID(final int type, final byte[] data)
{
- for (int i = 0; i < 16; ++i)
- {
- mId[i] = data[i];
- }
+ mId = data;
// Type is multiplexed with time_hi:
mId[UUID.INDEX_TYPE] &= (byte)0x0F;
mId[UUID.INDEX_TYPE] |= (byte)(type << 4);
Modified: trunk/tests/jms-tests/src/org/hornetq/jms/tests/selector/SelectorTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/hornetq/jms/tests/selector/SelectorTest.java 2010-04-15
14:41:40 UTC (rev 9127)
+++ trunk/tests/jms-tests/src/org/hornetq/jms/tests/selector/SelectorTest.java 2010-04-15
14:46:37 UTC (rev 9128)
@@ -712,7 +712,226 @@
}
}
}
+
+ public void testJMSMessageIDOnSelector() throws Exception
+ {
+ Connection conn = null;
+ try
+ {
+ conn = getConnectionFactory().createConnection();
+ conn.start();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(HornetQServerTestCase.queue1);
+
+ TextMessage msg1 = session.createTextMessage("msg1");
+ prod.send(msg1);
+
+ TextMessage msg2 = session.createTextMessage("msg2");
+ prod.send(msg2);
+
+ String selector = "JMSMessageID = '" + msg2.getJMSMessageID() +
"'";
+
+ MessageConsumer cons = session.createConsumer(HornetQServerTestCase.queue1,
selector);
+
+ conn.start();
+
+ TextMessage rec = (TextMessage)cons.receive(10000);
+
+ assertNotNull(rec);
+
+ assertEquals("msg2", rec.getText());
+
+ assertNull(cons.receiveNoWait());
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+ public void testJMSPriorityOnSelector() throws Exception
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = getConnectionFactory().createConnection();
+ conn.start();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(HornetQServerTestCase.queue1);
+
+ TextMessage msg1 = session.createTextMessage("msg1");
+ prod.send(msg1, DeliveryMode.NON_PERSISTENT, 8, 0);
+
+ TextMessage msg2 = session.createTextMessage("msg2");
+ prod.send(msg2, DeliveryMode.NON_PERSISTENT, 2, 0);
+
+ String selector = "JMSPriority = 2";
+
+ MessageConsumer cons = session.createConsumer(HornetQServerTestCase.queue1,
selector);
+
+ conn.start();
+
+ TextMessage rec = (TextMessage)cons.receive(10000);
+
+ assertNotNull(rec);
+
+ assertEquals("msg2", rec.getText());
+
+ assertNull(cons.receiveNoWait());
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+ public void testJMSTimestampOnSelector() throws Exception
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = getConnectionFactory().createConnection();
+ conn.start();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(HornetQServerTestCase.queue1);
+
+ TextMessage msg1 = session.createTextMessage("msg1");
+ prod.send(msg1);
+
+ TextMessage msg2 = session.createTextMessage("msg2");
+ prod.send(msg2);
+
+ String selector = "JMSTimestamp = " + msg2.getJMSTimestamp();
+
+ MessageConsumer cons = session.createConsumer(HornetQServerTestCase.queue1,
selector);
+
+ conn.start();
+
+ TextMessage rec = (TextMessage)cons.receive(10000);
+
+ assertNotNull(rec);
+
+ assertEquals("msg2", rec.getText());
+
+ assertNull(cons.receiveNoWait());
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+ public void testJMSTypeOnSelector() throws Exception
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = getConnectionFactory().createConnection();
+ conn.start();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(HornetQServerTestCase.queue1);
+
+ TextMessage msg1 = session.createTextMessage("msg1");
+ msg1.setJMSType("type1");
+ prod.send(msg1);
+
+ TextMessage msg2 = session.createTextMessage("msg2");
+ msg2.setJMSType("type2");
+ prod.send(msg2);
+
+ String selector = "JMSType = 'type2'";
+
+ MessageConsumer cons = session.createConsumer(HornetQServerTestCase.queue1,
selector);
+
+ conn.start();
+
+ TextMessage rec = (TextMessage)cons.receive(10000);
+
+ assertNotNull(rec);
+
+ assertEquals("msg2", rec.getText());
+
+ assertNull(cons.receiveNoWait());
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
+ public void testJMSCorrelationIDOnSelector() throws Exception
+ {
+ Connection conn = null;
+
+ try
+ {
+ conn = getConnectionFactory().createConnection();
+ conn.start();
+
+ Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ MessageProducer prod = session.createProducer(HornetQServerTestCase.queue1);
+
+ TextMessage msg1 = session.createTextMessage("msg1");
+ msg1.setJMSCorrelationID("cid1");
+ prod.send(msg1);
+
+ TextMessage msg2 = session.createTextMessage("msg2");
+ msg2.setJMSCorrelationID("cid2");
+ prod.send(msg2);
+
+ String selector = "JMSCorrelationID = 'cid2'";
+
+ MessageConsumer cons = session.createConsumer(HornetQServerTestCase.queue1,
selector);
+
+ conn.start();
+
+ TextMessage rec = (TextMessage)cons.receive(10000);
+
+ assertNotNull(rec);
+
+ assertEquals("msg2", rec.getText());
+
+ assertNull(cons.receiveNoWait());
+
+ }
+ finally
+ {
+ if (conn != null)
+ {
+ conn.close();
+ }
+ }
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified:
trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java
===================================================================
---
trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java 2010-04-15
14:41:40 UTC (rev 9127)
+++
trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java 2010-04-15
14:46:37 UTC (rev 9128)
@@ -41,6 +41,7 @@
import org.hornetq.core.transaction.TransactionOperation;
import org.hornetq.tests.util.UnitTestCase;
import org.hornetq.utils.TypedProperties;
+import org.hornetq.utils.UUID;
/**
* A BindingImplTest
@@ -886,13 +887,13 @@
}
- public SimpleString getUserID()
+ public UUID getUserID()
{
// TODO Auto-generated method stub
return null;
}
- public void setUserID(SimpleString userID)
+ public void setUserID(UUID userID)
{
// TODO Auto-generated method stub
Modified: trunk/tests/src/org/hornetq/tests/unit/jms/client/SelectorTranslatorTest.java
===================================================================
---
trunk/tests/src/org/hornetq/tests/unit/jms/client/SelectorTranslatorTest.java 2010-04-15
14:41:40 UTC (rev 9127)
+++
trunk/tests/src/org/hornetq/tests/unit/jms/client/SelectorTranslatorTest.java 2010-04-15
14:46:37 UTC (rev 9128)
@@ -97,23 +97,23 @@
{
String selector = "JMSMessageID='ID:HQ-12435678";
- Assert.assertEquals(selector,
SelectorTranslator.convertToHornetQFilterString(selector));
+ Assert.assertEquals("HQUserID='ID:HQ-12435678",
SelectorTranslator.convertToHornetQFilterString(selector));
selector = " JMSMessageID='ID:HQ-12435678";
- Assert.assertEquals(selector,
SelectorTranslator.convertToHornetQFilterString(selector));
+ Assert.assertEquals(" HQUserID='ID:HQ-12435678",
SelectorTranslator.convertToHornetQFilterString(selector));
selector = " JMSMessageID = 'ID:HQ-12435678";
- Assert.assertEquals(selector,
SelectorTranslator.convertToHornetQFilterString(selector));
+ Assert.assertEquals(" HQUserID = 'ID:HQ-12435678",
SelectorTranslator.convertToHornetQFilterString(selector));
selector = " myHeader = JMSMessageID";
- Assert.assertEquals(selector,
SelectorTranslator.convertToHornetQFilterString(selector));
+ Assert.assertEquals(" myHeader = HQUserID",
SelectorTranslator.convertToHornetQFilterString(selector));
selector = " myHeader = JMSMessageID OR (JMSMessageID = 'ID-HQ' +
'12345')";
- Assert.assertEquals(selector,
SelectorTranslator.convertToHornetQFilterString(selector));
+ Assert.assertEquals(" myHeader = HQUserID OR (HQUserID = 'ID-HQ' +
'12345')", SelectorTranslator.convertToHornetQFilterString(selector));
checkNoSubstitute("JMSMessageID");
}