[jboss-cvs] JBoss Messaging SVN: r4159 - in trunk: src/main/org/jboss/messaging/core/filter/impl and 34 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 8 04:48:11 EDT 2008
Author: timfox
Date: 2008-05-08 04:48:10 -0400 (Thu, 08 May 2008)
New Revision: 4159
Added:
trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java
trunk/src/main/org/jboss/messaging/util/MessagingBuffer.java
trunk/src/main/org/jboss/messaging/util/TypedProperties.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/BufferWrapperTest.java
Removed:
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/RemotingBuffer.java
trunk/src/main/org/jboss/messaging/util/StreamUtils.java
trunk/src/main/org/jboss/messaging/util/Streamable.java
trunk/tests/src/org/jboss/messaging/tests/integration/ProducerFlowControlTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MinaRemotingBufferTest.java
Modified:
trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java
trunk/src/main/org/jboss/messaging/core/journal/Journal.java
trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
trunk/src/main/org/jboss/messaging/core/message/Message.java
trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java
trunk/src/main/org/jboss/messaging/core/message/impl/MessageReferenceImpl.java
trunk/src/main/org/jboss/messaging/core/persistence/StorageManager.java
trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullStorageManager.java
trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java
trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/BytesPacketCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConnectionCreateSessionMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConnectionCreateSessionResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConsumerFlowTokenMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/EmptyPacketCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/MessagingExceptionMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/PingCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/PongCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerReceiveTokensMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerSendMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ReceiveMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionAcknowledgeMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionAddDestinationMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBindingQueryMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBindingQueryResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserHasNextMessageResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCancelMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateBrowserMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateBrowserResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateConsumerMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateConsumerResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateQueueMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionDeleteQueueMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionQueueQueryMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionQueueQueryResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionRemoveDestinationMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXACommitMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAEndMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAForgetMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAGetInDoubtXidsResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAGetTimeoutResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAJoinMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAPrepareMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAResumeMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXARollbackMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXASetTimeoutMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXASetTimeoutResponseMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAStartMessageCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/TextPacketCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java
trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ProducerSendMessage.java
trunk/src/main/org/jboss/messaging/core/server/ServerProducer.java
trunk/src/main/org/jboss/messaging/core/server/ServerSession.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerImpl.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerPacketHandler.java
trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
trunk/src/main/org/jboss/messaging/core/transaction/Transaction.java
trunk/src/main/org/jboss/messaging/core/transaction/impl/TransactionImpl.java
trunk/src/main/org/jboss/messaging/core/version/impl/VersionImpl.java
trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java
trunk/src/main/org/jboss/messaging/jms/client/JBossMapMessage.java
trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java
trunk/src/main/org/jboss/messaging/jms/client/JBossObjectMessage.java
trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java
trunk/src/main/org/jboss/messaging/jms/client/JBossTextMessage.java
trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java
trunk/src/main/org/jboss/messaging/util/SimpleString.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/MessageProducerTest.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/PersistenceTest.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/JMSTypeHeaderTest.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessagePropertyConversionTest.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageTestBase.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java
trunk/tests/src/org/jboss/messaging/tests/integration/CoreClientTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientCrashTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientExitTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/CrashClient.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/DummyInterceptor.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/GracefulClient.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/PacketFilterTest.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSL.java
trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSLTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/filter/impl/FilterTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/message/impl/MessageTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueTest.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeFilter.java
trunk/tests/src/org/jboss/messaging/tests/unit/core/transaction/impl/TransactionTest.java
trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
Log:
Refactoring of message/transport
Modified: trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/client/impl/ClientProducerImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -124,7 +124,16 @@
private void doSend(final SimpleString address, final Message msg) throws MessagingException
{
- ProducerSendMessage message = new ProducerSendMessage(address, msg.copy());
+ if (address != null)
+ {
+ msg.setDestination(address);
+ }
+ else
+ {
+ msg.setDestination(this.address);
+ }
+
+ ProducerSendMessage message = new ProducerSendMessage(msg.copy());
//TODO flow control disabled for now
Modified: trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/filter/impl/FilterImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -116,7 +116,14 @@
{
//First look it up in the headers
- val = message.getHeader(id.getName());
+ //TODO - speed this up to avoid conversion
+ //Filter should be refactored to deal with SimpleString natively
+ val = message.getProperty(new SimpleString(id.getName()));
+
+ if (val instanceof SimpleString)
+ {
+ val = ((SimpleString)val).toString();
+ }
}
if (val != null)
Modified: trunk/src/main/org/jboss/messaging/core/journal/Journal.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/Journal.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/journal/Journal.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -63,7 +63,7 @@
// Load
- void load(List<RecordInfo> committedRecords,
+ long load(List<RecordInfo> committedRecords,
List<PreparedTransactionInfo> preparedTransactions) throws Exception;
// Start and stop reclaimer
Modified: trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/journal/impl/JournalImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -493,9 +493,9 @@
tx.rollback(currentFile);
}
- public synchronized void load(final List<RecordInfo> committedRecords,
+ public synchronized long load(final List<RecordInfo> committedRecords,
final List<PreparedTransactionInfo> preparedTransactions) throws Exception
- {
+ {
if (state != STATE_STARTED)
{
throw new IllegalStateException("Journal must be in started state");
@@ -521,9 +521,6 @@
file.read(bb);
- //bb.flip();
- //bb.rewind();
-
long orderingID = bb.getLong();
orderedFiles.add(new JournalFileImpl(file, orderingID));
@@ -550,15 +547,12 @@
long maxTransactionID = -1;
+ long maxMessageID = -1;
+
for (JournalFile file: orderedFiles)
{
file.getFile().open();
-
- if (trace)
- {
- log.trace("Loading file " + file.getFile().getFileName());
- }
-
+
ByteBuffer bb = file.getFile().newBuffer(fileSize);
int bytesRead = file.getFile().read(bb);
@@ -571,9 +565,6 @@
" expected " + fileSize + " : " + file.getFile().getFileName());
}
-// bb.flip();
-// bb.rewind();
-
//First long is the ordering timestamp, we just jump its position
bb.position(file.getFile().calculateBlockStart(SIZE_LONG));
@@ -584,15 +575,14 @@
int pos = bb.position();
byte recordType = bb.get();
-
-
+
switch(recordType)
{
case ADD_RECORD:
{
- long id = bb.getLong();
+ long id = bb.getLong();
- if (trace) log.trace("ADD Record ID = " + id);
+ maxMessageID = Math.max(maxMessageID, id);
int size = bb.getInt();
byte[] record = new byte[size];
@@ -616,7 +606,8 @@
case UPDATE_RECORD:
{
long id = bb.getLong();
- if (trace) log.trace("Update Record ID = " + id);
+
+ maxMessageID = Math.max(maxMessageID, id);
int size = bb.getInt();
byte[] record = new byte[size];
@@ -649,10 +640,11 @@
case DELETE_RECORD:
{
long id = bb.getLong();
- byte end = bb.get();
- if (trace) log.trace("DeleteRecord id=" + id);
+ maxMessageID = Math.max(maxMessageID, id);
+ byte end = bb.get();
+
if (end != DONE)
{
repairFrom(pos, file);
@@ -677,10 +669,8 @@
long txID = bb.getLong();
maxTransactionID = Math.max(maxTransactionID, txID);
long id = bb.getLong();
+ maxMessageID = Math.max(maxMessageID, id);
- if (trace) log.trace("AddRecordTX txID = " + txID + " , id=" + id);
-
-
int size = bb.getInt();
byte[] record = new byte[size];
bb.get(record);
@@ -723,9 +713,8 @@
long txID = bb.getLong();
maxTransactionID = Math.max(maxTransactionID, txID);
long id = bb.getLong();
+ maxMessageID = Math.max(maxMessageID, id);
- if (trace) log.trace("UpdateRecordTX txID = " + txID + " , id=" + id);
-
int size = bb.getInt();
byte[] record = new byte[size];
bb.get(record);
@@ -767,10 +756,9 @@
{
long txID = bb.getLong();
maxTransactionID = Math.max(maxTransactionID, txID);
- long id = bb.getLong();
-
- if (trace) log.trace("DeleteRecordTX txID = " + txID + " , id=" + id);
-
+ long id = bb.getLong();
+ maxMessageID = Math.max(maxMessageID, id);
+
byte end = bb.get();
if (end != DONE)
@@ -808,9 +796,7 @@
case PREPARE_RECORD:
{
long txID = bb.getLong();
-
- if (trace) log.trace("Prepare txID=" + txID);
-
+
maxTransactionID = Math.max(maxTransactionID, txID);
byte end = bb.get();
@@ -847,8 +833,6 @@
{
long txID = bb.getLong();
- if (trace) log.trace("Commit txID=" + txID);
-
maxTransactionID = Math.max(maxTransactionID, txID);
byte end = bb.get();
@@ -883,9 +867,7 @@
case ROLLBACK_RECORD:
{
long txID = bb.getLong();
-
- if (trace) log.trace("RollbacktxID=" + txID);
-
+
maxTransactionID = Math.max(maxTransactionID, txID);
byte end = bb.get();
@@ -956,7 +938,7 @@
//Empty dataFiles with no data
freeFiles.add(file);
-// //Position it ready for writing
+ //Position it ready for writing
file.getFile().position(file.getFile().calculateBlockStart(SIZE_LONG));
}
}
@@ -1038,7 +1020,9 @@
}
state = STATE_LOADED;
- }
+
+ return maxMessageID;
+ }
public int getAlignment() throws Exception
{
Modified: trunk/src/main/org/jboss/messaging/core/message/Message.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/Message.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/message/Message.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -21,10 +21,11 @@
*/
package org.jboss.messaging.core.message;
-import java.util.Map;
+import java.util.Set;
import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.util.Streamable;
+import org.jboss.messaging.util.MessagingBuffer;
+import org.jboss.messaging.util.SimpleString;
/**
* A message is a routable instance that has a payload.
@@ -37,74 +38,36 @@
*
* $Id: Message.java 3341 2007-11-19 14:34:57Z timfox $
*/
-public interface Message extends Streamable
+public interface Message
{
- public static final String HDR_ACTUAL_EXPIRY_TIME = "JBMActualExpiryTime";
+ public static final SimpleString HDR_ACTUAL_EXPIRY_TIME = new SimpleString("JBMActualExpiryTime");
- /**
- * @return The unique id of the message
- */
+ SimpleString getDestination();
+
+ void setDestination(SimpleString destination);
+
+ int getType();
+
long getMessageID();
- /**
- * Set the message id
- *
- * @param id
- */
void setMessageID(long id);
- /**
- * @return Whether the message is durable
- */
boolean isDurable();
- /**
- * Set whether message is durable
- * @param durable
- */
void setDurable(boolean durable);
- /**
- * @return the time when this routable expires and must be removed
- * from the system. A zero value means this routable never expires.
- */
long getExpiration();
- /**
- *
- * @return true if the message has expired
- */
boolean isExpired();
- /**
- * Set the expiration for this message
- *
- * @param expiration
- */
void setExpiration(long expiration);
- /**
- * @return the time (in GMT milliseconds) when this routable was delivered to the provider.
- */
long getTimestamp();
- /**
- * Set the timestamp for this message
- * @param timestamp The timestamp
- */
void setTimestamp(long timestamp);
- /**
- *
- * @return The priority (0-9) of the message
- */
byte getPriority();
- /**
- * Get the priority of the message. Priorities range from 0 to 9.
- * Where 0 is the lowest priority and 9 is the highest priority
- * @param priority
- */
void setPriority(byte priority);
int getDeliveryCount();
@@ -114,71 +77,55 @@
long getDeliveryID();
void setDeliveryID(long deliveryID);
+
+ MessagingBuffer encode();
+
+ void decode(MessagingBuffer buffer);
+
+ Message copy();
- /**
- * Binds a header. If the header map previously contained a mapping for this name, the old value
- * is replaced by the specified value.
- *
- * @return the value associated with the name or null if there is no mapping for the name. A null
- * can also indicate that the header map previously associated null with the specified
- * name.
- */
- Object putHeader(String name, Object value);
-
- /**
- * Returns the value corresponding to the header name. Returns null if the map contains no
- * mapping for the name. A return value of null does not necessarily indicate that the map
- * contains no mapping for the name; it's also possible that the map explicitly maps the name to
- * null. The containsHeader() operation may be used to distinguish these two cases.
- *
- * @return the value associated with the header, or null if there is no mapping for the header.
- */
- Object getHeader(String name);
-
- /**
- * Removes the header.
- *
- * @return previous value associated with the header, or null if there was no mapping.
- */
- Object removeHeader(String name);
-
- /**
- * Returns true if the Routable contains the specified header.
- */
- boolean containsHeader(String name);
-
- /**
- *
- * @return The message's headers
- */
- Map<String, Object> getHeaders();
+ // Properties
+ // ------------------------------------------------------------------
- /**
- *
- * @return The message's payload
- */
- byte[] getPayload();
+ void putBooleanProperty(SimpleString key, boolean value);
+ void putByteProperty(SimpleString key, byte value);
- /**
- * Set the payload
- *
- * @param payload
- */
- void setPayload(byte[] payload);
+ void putBytesProperty(SimpleString key, byte[] value);
- /**
- *
- * @return The message's headers as byte array
- */
- byte[] getHeaderBytes() throws Exception;
-
- /**
- *
- * @return the type of the message
- */
- int getType();
+ void putShortProperty(SimpleString key, short value);
+ void putIntProperty(SimpleString key, int value);
+
+ void putLongProperty(SimpleString key, long value);
+
+ void putFloatProperty(SimpleString key, float value);
+
+ void putDoubleProperty(SimpleString key, double value);
+
+ void putStringProperty(SimpleString key, SimpleString value);
+
+
+ // TODO - should have typed property getters and do conversions herein
+
+ Object getProperty(SimpleString key);
+
+ Object removeProperty(SimpleString key);
+
+ boolean containsProperty(SimpleString key);
+
+ Set<SimpleString> getPropertyNames();
+
+ // Body
+ // ---------------------------------------------------------------------------------
+
+ MessagingBuffer getBody();
+
+ void setBody(MessagingBuffer body);
+
+ // Other stuff that should be moved to ServerMessage
+ // -------------------------------------------------------------------------------------
+
/**
* Get the connection id
* @return the connection id
@@ -213,11 +160,6 @@
*/
int getDurableRefCount();
- /**
- * Make a copy of the message
- *
- * @return The copy
- */
- Message copy();
+
}
Modified: trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/message/impl/MessageImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -21,19 +21,17 @@
*/
package org.jboss.messaging.core.message.impl;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.core.message.MessageReference;
+import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
import org.jboss.messaging.core.server.Queue;
-import org.jboss.messaging.util.StreamUtils;
+import org.jboss.messaging.util.MessagingBuffer;
+import org.jboss.messaging.util.SimpleString;
+import org.jboss.messaging.util.TypedProperties;
/**
* A concrete implementation of a message
@@ -56,6 +54,8 @@
// Attributes ----------------------------------------------------
+ private SimpleString destination;
+
private long messageID;
private int type;
@@ -67,13 +67,10 @@
private long timestamp;
- private Map<String, Object> headers;
+ private TypedProperties properties;
private byte priority;
- //The payload of MessageImpl instances is opaque
- private byte[] payload;
-
private long connectionID;
private final AtomicInteger durableRefCount = new AtomicInteger(0);
@@ -82,14 +79,16 @@
private long deliveryID;
+ private MessagingBuffer body;
+
// Constructors --------------------------------------------------
/*
- * Construct a message for deserialization or streaming
+ * Construct when reading from network
*/
public MessageImpl()
{
- this.headers = new HashMap<String, Object>();
+ this.properties = new TypedProperties();
}
/*
@@ -104,59 +103,95 @@
this.expiration = expiration;
this.timestamp = timestamp;
this.priority = priority;
+ this.body = new BufferWrapper(1024);
}
/*
* Construct a MessageImpl from storage
*/
- public MessageImpl(final long messageID, final int type, final boolean durable, final long expiration,
- final long timestamp, final byte priority, final byte[] headers, final byte[] payload)
- throws Exception
+ public MessageImpl(final long messageID)
{
- this.messageID = messageID;
- this.type = type;
- this.durable = durable;
- this.expiration = expiration;
- this.timestamp = timestamp;
- this.priority = priority;
-
- if (headers == null)
- {
- this.headers = new HashMap<String, Object>();
- }
- else
- {
- //TODO keep headers opaque on server
- ByteArrayInputStream bis = new ByteArrayInputStream(headers);
-
- DataInputStream dais = new DataInputStream(bis);
-
- this.headers = StreamUtils.readMap(dais, true);
-
- dais.close();
- }
- this.payload = payload;
+ this();
+ this.messageID = messageID;
}
- /**
+ /*
* Copy constructor
- *
- * @param other
*/
public MessageImpl(final MessageImpl other)
{
+ this.destination = other.destination;
this.messageID = other.messageID;
this.type = other.type;
this.durable = other.durable;
this.expiration = other.expiration;
this.timestamp = other.timestamp;
this.priority = other.priority;
- this.headers = new HashMap<String, Object>(other.headers);
- this.payload = other.payload;
+ this.properties = new TypedProperties(other.properties);
+ this.body = other.body;
+
+ this.deliveryCount = other.deliveryCount;
+ this.deliveryID = other.deliveryID;
}
// Message implementation ----------------------------------------
+ public MessagingBuffer encode()
+ {
+ MessagingBuffer buff = new BufferWrapper(1024);
+
+ buff.putSimpleString(destination);
+ buff.putInt(type);
+ buff.putBoolean(durable);
+ buff.putLong(expiration);
+ buff.putLong(timestamp);
+ buff.putByte(priority);
+
+ buff.putInt(deliveryCount);
+ buff.putLong(deliveryID);
+
+ properties.encode(buff);
+
+ buff.putInt(body.limit());
+
+ //TODO this can be optimisied
+ buff.putBytes(body.array(), 0, body.limit());
+
+ return buff;
+ }
+
+ public void decode(final MessagingBuffer buffer)
+ {
+ destination = buffer.getSimpleString();
+ type = buffer.getInt();
+ durable = buffer.getBoolean();
+ expiration = buffer.getLong();
+ timestamp = buffer.getLong();
+ priority = buffer.getByte();
+
+ deliveryCount = buffer.getInt();
+ deliveryID = buffer.getLong();
+
+ properties.decode(buffer);
+ int len = buffer.getInt();
+
+ //TODO - this can be optimised
+ byte[] bytes = new byte[len];
+ buffer.getBytes(bytes);
+ body = new BufferWrapper(1024);
+ body.putBytes(bytes);
+ }
+
+ public SimpleString getDestination()
+ {
+ return destination;
+ }
+
+ public void setDestination(SimpleString destination)
+ {
+ this.destination = destination;
+ }
+
public long getMessageID()
{
return messageID;
@@ -202,31 +237,7 @@
this.timestamp = timestamp;
}
- public Object putHeader(final String name, final Object value)
- {
- return headers.put(name, value);
- }
-
- public Object getHeader(final String name)
- {
- return headers.get(name);
- }
-
- public Object removeHeader(final String name)
- {
- return headers.remove(name);
- }
-
- public boolean containsHeader(final String name)
- {
- return headers.containsKey(name);
- }
-
- public Map<String, Object> getHeaders()
- {
- return headers;
- }
-
+
public byte getPriority()
{
return priority;
@@ -236,31 +247,7 @@
{
this.priority = priority;
}
-
- // TODO - combine with getPayloadAsByteArray to get one big blob
- public byte[] getHeaderBytes() throws Exception
- {
- ByteArrayOutputStream bos = new ByteArrayOutputStream(1024);
-
- DataOutputStream oos = new DataOutputStream(bos);
-
- StreamUtils.writeMap(oos, headers, true);
-
- oos.close();
-
- return bos.toByteArray();
- }
-
- public byte[] getPayload()
- {
- return payload;
- }
-
- public void setPayload(final byte[] payload)
- {
- this.payload = payload;
- }
-
+
public long getConnectionID()
{
return connectionID;
@@ -301,6 +288,96 @@
return System.currentTimeMillis() - expiration >= 0;
}
+ public Message copy()
+ {
+ return new MessageImpl(this);
+ }
+
+ // Properties
+ // ---------------------------------------------------------------------------------------
+
+ public void putBooleanProperty(final SimpleString key, final boolean value)
+ {
+ properties.putBooleanProperty(key, value);
+ }
+
+ public void putByteProperty(final SimpleString key, final byte value)
+ {
+ properties.putByteProperty(key, value);
+ }
+
+ public void putBytesProperty(final SimpleString key, final byte[] value)
+ {
+ properties.putBytesProperty(key, value);
+ }
+
+ public void putShortProperty(final SimpleString key, final short value)
+ {
+ properties.putShortProperty(key, value);
+ }
+
+ public void putIntProperty(final SimpleString key, final int value)
+ {
+ properties.putIntProperty(key, value);
+ }
+
+ public void putLongProperty(final SimpleString key, final long value)
+ {
+ properties.putLongProperty(key, value);
+ }
+
+ public void putFloatProperty(final SimpleString key, final float value)
+ {
+ properties.putFloatProperty(key, value);
+ }
+
+ public void putDoubleProperty(final SimpleString key, final double value)
+ {
+ properties.putDoubleProperty(key, value);
+ }
+
+ public void putStringProperty(final SimpleString key, final SimpleString value)
+ {
+ properties.putStringProperty(key, value);
+ }
+
+ public Object getProperty(final SimpleString key)
+ {
+ return properties.getProperty(key);
+ }
+
+ public Object removeProperty(final SimpleString key)
+ {
+ return properties.removeProperty(key);
+ }
+
+ public boolean containsProperty(final SimpleString key)
+ {
+ return properties.containsProperty(key);
+ }
+
+ public Set<SimpleString> getPropertyNames()
+ {
+ return properties.getPropertyNames();
+ }
+
+ // Body
+ // -------------------------------------------------------------------------------------
+
+ public MessagingBuffer getBody()
+ {
+ return body;
+ }
+
+ public void setBody(final MessagingBuffer body)
+ {
+ this.body = body;
+ }
+
+
+ // TODO Other stuff that should be moved to ServerMessage:
+ // -------------------------------------------------------
+
public MessageReference createReference(final Queue queue)
{
MessageReference ref = new MessageReferenceImpl(this, queue);
@@ -329,12 +406,7 @@
{
durableRefCount.incrementAndGet();
}
-
- public Message copy()
- {
- return new MessageImpl(this);
- }
-
+
// Public --------------------------------------------------------
public boolean equals(Object o)
@@ -364,75 +436,6 @@
return "M[" + messageID + "]@" + System.identityHashCode(this);
}
- // Streamable implementation ---------------------------------
-
- public void write(final DataOutputStream out) throws Exception
- {
- out.writeLong(messageID);
-
- out.writeInt(type);
-
- out.writeBoolean(durable);
-
- out.writeLong(expiration);
-
- out.writeLong(timestamp);
-
- StreamUtils.writeMap(out, headers, true);
-
- out.writeByte(priority);
-
- out.writeInt(deliveryCount);
-
- out.writeLong(deliveryID);
-
- if (payload != null)
- {
- out.writeInt(payload.length);
-
- out.write(payload);
- }
- else
- {
- out.writeInt(0);
- }
- }
-
- public void read(final DataInputStream in) throws Exception
- {
- messageID = in.readLong();
-
- type = in.readInt();
-
- durable = in.readBoolean();
-
- expiration = in.readLong();
-
- timestamp = in.readLong();
-
- headers = StreamUtils.readMap(in, true);
-
- priority = in.readByte();
-
- deliveryCount = in.readInt();
-
- deliveryID = in.readLong();
-
- int length = in.readInt();
-
- if (length == 0)
- {
- // no payload
- payload = null;
- }
- else
- {
- payload = new byte[length];
-
- in.readFully(payload);
- }
- }
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/message/impl/MessageReferenceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/message/impl/MessageReferenceImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/message/impl/MessageReferenceImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -153,7 +153,7 @@
Message copyMessage = makeCopyForDLQOrExpiry(false, persistenceManager);
- tx.addMessage(binding.getAddress(), copyMessage);
+ tx.addMessage(copyMessage);
tx.addAcknowledgement(this);
}
@@ -181,10 +181,12 @@
Transaction tx = new TransactionImpl(persistenceManager, postOffice);
+ log.info("expiring message");
+
if (expiryQueue != null)
{
Binding binding = postOffice.getBinding(expiryQueue);
-
+
if (binding == null)
{
binding = postOffice.addBinding(expiryQueue, expiryQueue, null, true, false);
@@ -192,8 +194,10 @@
Message copyMessage = makeCopyForDLQOrExpiry(false, persistenceManager);
- tx.addMessage(binding.getAddress(), copyMessage);
+ copyMessage.setDestination(binding.getAddress());
+ tx.addMessage(copyMessage);
+
tx.addAcknowledgement(this);
}
else
@@ -243,7 +247,7 @@
{
long actualExpiryTime = System.currentTimeMillis();
- copy.putHeader(Message.HDR_ACTUAL_EXPIRY_TIME, actualExpiryTime);
+ copy.putLongProperty(Message.HDR_ACTUAL_EXPIRY_TIME, actualExpiryTime);
}
return copy;
Modified: trunk/src/main/org/jboss/messaging/core/persistence/StorageManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/StorageManager.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/persistence/StorageManager.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -50,14 +50,14 @@
long generateTransactionID();
- void storeMessage(SimpleString address, Message message) throws Exception;
+ void storeMessage(Message message) throws Exception;
void storeAcknowledge(long queueID, long messageID) throws Exception;
void storeDelete(long messageID) throws Exception;
- void storeMessageTransactional(long txID, SimpleString address, Message message) throws Exception;
+ void storeMessageTransactional(long txID, Message message) throws Exception;
void storeAcknowledgeTransactional(long txID, long queueID, long messageiD) throws Exception;
Modified: trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/persistence/impl/journal/JournalStorageManager.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -20,8 +20,8 @@
import org.jboss.messaging.core.journal.PreparedTransactionInfo;
import org.jboss.messaging.core.journal.RecordInfo;
import org.jboss.messaging.core.journal.SequentialFileFactory;
-import org.jboss.messaging.core.journal.impl.JournalImpl;
import org.jboss.messaging.core.journal.impl.AIOSequentialFileFactory;
+import org.jboss.messaging.core.journal.impl.JournalImpl;
import org.jboss.messaging.core.journal.impl.NIOSequentialFileFactory;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.Message;
@@ -31,9 +31,12 @@
import org.jboss.messaging.core.postoffice.Binding;
import org.jboss.messaging.core.postoffice.PostOffice;
import org.jboss.messaging.core.postoffice.impl.BindingImpl;
+import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
import org.jboss.messaging.core.server.JournalType;
import org.jboss.messaging.core.server.Queue;
import org.jboss.messaging.core.server.QueueFactory;
+import org.jboss.messaging.util.ByteBufferWrapper;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -156,11 +159,17 @@
// Non transactional operations
- public void storeMessage(final SimpleString address, final Message message) throws Exception
- {
- byte[] bytes = messageBytes(address, message);
-
- messageJournal.appendAddRecord(message.getMessageID(), bytes);
+ public void storeMessage(final Message message) throws Exception
+ {
+ //TODO too much copying is occurring here
+
+ MessagingBuffer buffer = new BufferWrapper(1024);
+
+ buffer.putByte(ADD_MESSAGE);
+
+ buffer.putBytes(message.encode().array());
+
+ messageJournal.appendAddRecord(message.getMessageID(), buffer.array());
}
public void storeAcknowledge(final long queueID, final long messageID) throws Exception
@@ -177,11 +186,17 @@
// Transactional operations
- public void storeMessageTransactional(long txID, SimpleString address, Message message) throws Exception
+ public void storeMessageTransactional(long txID, Message message) throws Exception
{
- byte[] bytes = messageBytes(address, message);
+ //TODO too much copying is occurring here
- messageJournal.appendAddRecordTransactional(txID, message.getMessageID(), bytes);
+ MessagingBuffer buffer = new BufferWrapper(1024);
+
+ buffer.putByte(ADD_MESSAGE);
+
+ buffer.putBytes(message.encode().array());
+
+ messageJournal.appendAddRecordTransactional(txID, message.getMessageID(), buffer.array());
}
public void storeAcknowledgeTransactional(long txID, long queueID, long messageID) throws Exception
@@ -232,16 +247,14 @@
public void loadMessages(final PostOffice postOffice, final Map<Long, Queue> queues) throws Exception
{
- log.info("*** loading message data");
-
List<RecordInfo> records = new ArrayList<RecordInfo>();
List<PreparedTransactionInfo> preparedTransactions = new ArrayList<PreparedTransactionInfo>();
- messageJournal.load(records, preparedTransactions);
+ long maxMessageID = messageJournal.load(records, preparedTransactions);
- long maxMessageID = -1;
-
+ messageIDSequence.set(maxMessageID + 1);
+
for (RecordInfo record: records)
{
byte[] data = record.data;
@@ -254,41 +267,14 @@
{
case ADD_MESSAGE:
{
- int addressLength = bb.getInt();
-
- byte[] addressBytes = new byte[addressLength];
-
- bb.get(addressBytes);
-
- SimpleString address = new SimpleString(addressBytes);
-
- maxMessageID = Math.max(maxMessageID, record.id);
+ MessagingBuffer buff = new ByteBufferWrapper(bb);
- int type = bb.getInt();
-
- long expiration = bb.getLong();
-
- long timestamp = bb.getLong();
-
- byte priority = bb.get();
-
- int headerSize = bb.getInt();
-
- byte[] headers = new byte[headerSize];
-
- bb.get(headers);
-
- int payloadSize = bb.getInt();
-
- byte[] payload = new byte[payloadSize];
-
- bb.get(payload);
-
- Message message = new MessageImpl(record.id, type, true, expiration, timestamp, priority,
- headers, payload);
+ Message message = new MessageImpl(record.id);
- List<MessageReference> refs = postOffice.route(address, message);
+ message.decode(buff);
+ List<MessageReference> refs = postOffice.route(message);
+
for (MessageReference ref: refs)
{
ref.getQueue().addLast(ref);
@@ -355,10 +341,6 @@
}
}
}
-
- messageIDSequence.set(maxMessageID + 1);
-
- log.info("****** Loaded message data");
}
//Bindings operations
@@ -484,8 +466,6 @@
public void loadBindings(final QueueFactory queueFactory,
final List<Binding> bindings, final List<SimpleString> destinations) throws Exception
{
- log.info("*** loading bindings");
-
List<RecordInfo> records = new ArrayList<RecordInfo>();
bindingsJournal.load(records, null);
@@ -558,8 +538,6 @@
}
bindingIDSequence.set(maxID + 1);
-
- log.info("Loaded bindings");
}
// MessagingComponent implementation ------------------------------------------------------
@@ -597,63 +575,22 @@
}
// Private ----------------------------------------------------------------------------------
-
- private byte[] messageBytes(final SimpleString address, final Message message) throws Exception
- {
- //TODO optimise this
-
- byte[] addressBytes = address.getData();
-
- byte[] headers = message.getHeaderBytes();
+
+ private byte[] ackBytes(final long queueID, final long messageID)
+ {
+ byte[] record = new byte[SIZE_BYTE + SIZE_LONG + SIZE_LONG];
- int headersLength = headers.length;
+ ByteBuffer bb = ByteBuffer.wrap(record);
- byte[] payload = message.getPayload();
+ bb.put(ACKNOWLEDGE_REF);
- int payloadLength = payload == null ? 0 : payload.length;
+ bb.putLong(queueID);
- byte[] bytes = new byte[SIZE_BYTE + SIZE_INT + addressBytes.length + SIZE_FIELDS + 2 * SIZE_INT + headersLength + payloadLength];
-
- ByteBuffer buffer = ByteBuffer.wrap(bytes);
+ bb.putLong(messageID);
- buffer.put(ADD_MESSAGE);
-
- buffer.putInt(addressBytes.length);
- buffer.put(addressBytes);
-
- //Put the fields
- buffer.putInt(message.getType());
- buffer.putLong(message.getExpiration());
- buffer.putLong(message.getTimestamp());
- buffer.put(message.getPriority());
-
- buffer.putInt(headersLength);
- buffer.put(headers);
-
- buffer.putInt(payloadLength);
- if (payload != null)
- {
- buffer.put(payload);
- }
-
- return bytes;
- }
+ return record;
+ }
- private byte[] ackBytes(final long queueID, final long messageID)
- {
- byte[] record = new byte[SIZE_BYTE + SIZE_LONG + SIZE_LONG];
-
- ByteBuffer bb = ByteBuffer.wrap(record);
-
- bb.put(ACKNOWLEDGE_REF);
-
- bb.putLong(queueID);
-
- bb.putLong(messageID);
-
- return record;
- }
-
private void checkAndCreateDir(String dir, boolean create)
{
File f = new File(dir);
Modified: trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullStorageManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullStorageManager.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/persistence/impl/nullpm/NullStorageManager.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -108,12 +108,11 @@
{
}
- public void storeMessage(SimpleString address, Message message) throws Exception
+ public void storeMessage(Message message) throws Exception
{
}
- public void storeMessageTransactional(long txID, SimpleString address,
- Message message) throws Exception
+ public void storeMessageTransactional(long txID, Message message) throws Exception
{
}
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/PostOffice.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -69,7 +69,7 @@
Binding getBinding(SimpleString queueName) throws Exception;
- List<MessageReference> route(SimpleString address, Message message) throws Exception;
+ List<MessageReference> route(Message message) throws Exception;
//Flow control
Modified: trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/postoffice/impl/PostOfficeImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -190,8 +190,10 @@
return nameMap.get(queueName);
}
- public List<MessageReference> route(final SimpleString address, final Message message) throws Exception
+ public List<MessageReference> route(final Message message) throws Exception
{
+ SimpleString address = message.getDestination();
+
if (checkAllowable)
{
if (!destinations.contains(address))
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/AbstractPacketCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,10 +6,6 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_BYTE;
-import static org.jboss.messaging.util.DataConstants.SIZE_CHAR;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
-
import javax.transaction.xa.Xid;
import org.apache.mina.common.IoBuffer;
@@ -21,6 +17,7 @@
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.transaction.impl.XidImpl;
import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -40,18 +37,6 @@
// Static --------------------------------------------------------
- public static int sizeof(final String nullableString)
- {
- if (nullableString == null)
- {
- return SIZE_BYTE; // NULL_STRING byte
- }
- else
- {
- return SIZE_BYTE + SIZE_INT + SIZE_CHAR * nullableString.length();
- }
- }
-
// Constructors --------------------------------------------------
protected AbstractPacketCodec(PacketType type)
@@ -72,43 +57,37 @@
IoBuffer iobuf = IoBuffer.allocate(1024, false);
iobuf.setAutoExpand(true);
- RemotingBuffer buf = new BufferWrapper(iobuf);
-
- int messageLength = getBodyLength(packet) + HEADER_LENGTH;
-
+ MessagingBuffer buf = new BufferWrapper(iobuf);
+
//The standard header fields
- buf.putInt(messageLength);
- buf.put(packet.getType().byteValue());
- buf.putLong(responseTargetID);
- buf.putLong(targetID);
- buf.putLong(executorID);
+ iobuf.putInt(0); //The length gets filled in at the end
+ iobuf.put(packet.getType().byteValue());
+ iobuf.putLong(responseTargetID);
+ iobuf.putLong(targetID);
+ iobuf.putLong(executorID);
encodeBody(packet, buf);
- //for now
+ //The length doesn't include the actual length byte
+ int len = buf.position() - DataConstants.SIZE_INT;
+
+ iobuf.putInt(0, len);
+
iobuf.flip();
out.write(iobuf);
}
- public static int getXidLength(final Xid xid)
- {
- return SIZE_INT + SIZE_INT + xid.getBranchQualifier().length + SIZE_INT + xid.getGlobalTransactionId().length;
- }
-
- public void decode(final RemotingBuffer buffer, final ProtocolDecoderOutput out) throws Exception
+ public void decode(final MessagingBuffer buffer, final ProtocolDecoderOutput out) throws Exception
{
long correlationID = buffer.getLong();
long targetID = buffer.getLong();
long executorID = buffer.getLong();
- if (executorID == -1)
- executorID = targetID;
Packet packet = decodeBody(buffer);
packet.setResponseTargetID(correlationID);
packet.setTargetID(targetID);
packet.setExecutorID(executorID);
-
out.write(packet);
}
@@ -118,30 +97,28 @@
return type;
}
- public abstract int getBodyLength(P packet) throws Exception;
-
// Protected -----------------------------------------------------
- protected abstract void encodeBody(P packet, RemotingBuffer buf) throws Exception;
+ protected abstract void encodeBody(P packet, MessagingBuffer buf) throws Exception;
- protected abstract Packet decodeBody(RemotingBuffer buffer) throws Exception;
+ protected abstract Packet decodeBody(MessagingBuffer buffer) throws Exception;
- public static void encodeXid(final Xid xid, final RemotingBuffer out)
+ public static void encodeXid(final Xid xid, final MessagingBuffer out)
{
out.putInt(xid.getFormatId());
out.putInt(xid.getBranchQualifier().length);
- out.put(xid.getBranchQualifier());
+ out.putBytes(xid.getBranchQualifier());
out.putInt(xid.getGlobalTransactionId().length);
- out.put(xid.getGlobalTransactionId());
+ out.putBytes(xid.getGlobalTransactionId());
}
- protected static Xid decodeXid(final RemotingBuffer in)
+ protected static Xid decodeXid(final MessagingBuffer in)
{
int formatID = in.getInt();
byte[] bq = new byte[in.getInt()];
- in.get(bq);
+ in.getBytes(bq);
byte[] gtxid = new byte[in.getInt()];
- in.get(gtxid);
+ in.getBytes(gtxid);
Xid xid = new XidImpl(bq, formatID, gtxid);
return xid;
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/BytesPacketCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/BytesPacketCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/BytesPacketCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.BYTES;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
import org.jboss.messaging.core.remoting.impl.wireformat.BytesPacket;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
@@ -37,29 +36,24 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final BytesPacket packet)
- {
- return SIZE_INT + packet.getBytes().length;
- }
-
@Override
- protected void encodeBody(final BytesPacket packet, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final BytesPacket packet, final MessagingBuffer out) throws Exception
{
byte[] bytes = packet.getBytes();
out.putInt(bytes.length);
- out.put(bytes);
+ out.putBytes(bytes);
}
@Override
- protected BytesPacket decodeBody(final RemotingBuffer in) throws Exception
+ protected BytesPacket decodeBody(final MessagingBuffer in) throws Exception
{
int byteLength = in.getInt();
byte[] bytes = new byte[byteLength];
- in.get(bytes);
+ in.getBytes(bytes);
return new BytesPacket(bytes);
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConnectionCreateSessionMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConnectionCreateSessionMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConnectionCreateSessionMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONN_CREATESESSION;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -36,13 +35,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final ConnectionCreateSessionMessage packet)
- {
- return 3 * SIZE_BOOLEAN;
- }
-
@Override
- protected void encodeBody(final ConnectionCreateSessionMessage request, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final ConnectionCreateSessionMessage request, final MessagingBuffer out) throws Exception
{
out.putBoolean(request.isXA());
out.putBoolean(request.isAutoCommitSends());
@@ -50,7 +44,7 @@
}
@Override
- protected ConnectionCreateSessionMessage decodeBody(final RemotingBuffer in) throws Exception
+ protected ConnectionCreateSessionMessage decodeBody(final MessagingBuffer in) throws Exception
{
return new ConnectionCreateSessionMessage(in.getBoolean(), in.getBoolean(), in.getBoolean());
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConnectionCreateSessionResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConnectionCreateSessionResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConnectionCreateSessionResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,11 +6,9 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
-
import org.jboss.messaging.core.remoting.impl.wireformat.ConnectionCreateSessionResponseMessage;
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -36,19 +34,14 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final ConnectionCreateSessionResponseMessage packet)
- {
- return SIZE_LONG;
- }
-
@Override
- protected void encodeBody(final ConnectionCreateSessionResponseMessage response, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final ConnectionCreateSessionResponseMessage response, final MessagingBuffer out) throws Exception
{
out.putLong(response.getSessionID());
}
@Override
- protected ConnectionCreateSessionResponseMessage decodeBody(final RemotingBuffer in)
+ protected ConnectionCreateSessionResponseMessage decodeBody(final MessagingBuffer in)
throws Exception
{
return new ConnectionCreateSessionResponseMessage(in.getLong());
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConsumerFlowTokenMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConsumerFlowTokenMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ConsumerFlowTokenMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CONS_FLOWTOKEN;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
import org.jboss.messaging.core.remoting.impl.wireformat.ConsumerFlowTokenMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
@@ -35,19 +34,14 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final ConsumerFlowTokenMessage packet) throws Exception
- {
- return SIZE_INT;
- }
-
@Override
- protected void encodeBody(final ConsumerFlowTokenMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final ConsumerFlowTokenMessage message, final MessagingBuffer out) throws Exception
{
out.putInt(message.getTokens());
}
@Override
- protected ConsumerFlowTokenMessage decodeBody(final RemotingBuffer in) throws Exception
+ protected ConsumerFlowTokenMessage decodeBody(final MessagingBuffer in) throws Exception
{
return new ConsumerFlowTokenMessage(in.getInt());
}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,11 +7,10 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CREATECONNECTION;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
+import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionRequest;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -21,6 +20,9 @@
{
// Constants -----------------------------------------------------
+ private static final Logger log = Logger.getLogger(CreateConnectionMessageCodec.class);
+
+
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
@@ -36,17 +38,8 @@
// AbstractPackedCodec overrides----------------------------------
- public int getBodyLength(final CreateConnectionRequest packet) throws Exception
- {
- int bodyLength = SIZE_INT // version
- + SIZE_LONG +
- + sizeof(packet.getUsername())
- + sizeof(packet.getPassword());
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final CreateConnectionRequest request, final RemotingBuffer out)
+ protected void encodeBody(final CreateConnectionRequest request, final MessagingBuffer out)
throws Exception
{
int version = request.getVersion();
@@ -61,7 +54,7 @@
}
@Override
- protected CreateConnectionRequest decodeBody(final RemotingBuffer in) throws Exception
+ protected CreateConnectionRequest decodeBody(final MessagingBuffer in) throws Exception
{
int version = in.getInt();
long remotingSessionID = in.getLong();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/CreateConnectionResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -9,9 +9,9 @@
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.CREATECONNECTION_RESP;
import org.jboss.messaging.core.remoting.impl.wireformat.CreateConnectionResponse;
-import org.jboss.messaging.core.version.impl.VersionImpl;
import org.jboss.messaging.core.version.Version;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.core.version.impl.VersionImpl;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -36,16 +36,8 @@
// AbstractPackedCodec overrides----------------------------------
- public int getBodyLength(final CreateConnectionResponse packet) throws Exception
- {
- return DataConstants.SIZE_LONG +
- sizeof(packet.getServerVersion().getVersionName()) +
- 4 * DataConstants.SIZE_INT +
- sizeof(packet.getServerVersion().getVersionSuffix());
- }
-
@Override
- protected void encodeBody(final CreateConnectionResponse response, final RemotingBuffer out)
+ protected void encodeBody(final CreateConnectionResponse response, final MessagingBuffer out)
throws Exception
{
out.putLong(response.getConnectionTargetID());
@@ -58,7 +50,7 @@
}
@Override
- protected CreateConnectionResponse decodeBody(final RemotingBuffer in) throws Exception
+ protected CreateConnectionResponse decodeBody(final MessagingBuffer in) throws Exception
{
long connectionTargetID = in.getLong();
String versionName = in.getNullableString();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/EmptyPacketCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/EmptyPacketCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/EmptyPacketCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -9,6 +9,7 @@
import org.jboss.messaging.core.remoting.Packet;
import org.jboss.messaging.core.remoting.impl.wireformat.PacketImpl;
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -33,18 +34,13 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final PacketImpl packet)
- {
- return 0;
- }
-
@Override
- protected void encodeBody(final PacketImpl packet, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final PacketImpl packet, final MessagingBuffer out) throws Exception
{
}
@Override
- protected Packet decodeBody(final RemotingBuffer in) throws Exception
+ protected Packet decodeBody(final MessagingBuffer in) throws Exception
{
return new PacketImpl(type);
}
@@ -68,14 +64,14 @@
//}
//
//@Override
-//protected void encodeBody(P packet, RemotingBuffer out) throws Exception
+//protected void encodeBody(P packet, MessagingBuffer out) throws Exception
//{
//// no body
//out.putInt(0);
//}
//
//@Override
-//protected Packet decodeBody(RemotingBuffer in) throws Exception
+//protected Packet decodeBody(MessagingBuffer in) throws Exception
//{
//in.getInt(); // skip body length
//return new PacketImpl(type);
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/MessagingExceptionMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/MessagingExceptionMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/MessagingExceptionMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,11 +7,10 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.EXCEPTION;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.remoting.impl.wireformat.MessagingExceptionMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -35,21 +34,16 @@
// Public --------------------------------------------------------
// AbstractPacketCodec overrides ---------------------------------
-
- public int getBodyLength(final MessagingExceptionMessage packet) throws Exception
- {
- return SIZE_INT + sizeof(packet.getException().getMessage());
- }
-
+
@Override
- protected void encodeBody(final MessagingExceptionMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final MessagingExceptionMessage message, final MessagingBuffer out) throws Exception
{
out.putInt(message.getException().getCode());
out.putNullableString(message.getException().getMessage());
}
@Override
- protected MessagingExceptionMessage decodeBody(final RemotingBuffer in) throws Exception
+ protected MessagingExceptionMessage decodeBody(final MessagingBuffer in) throws Exception
{
int code = in.getInt();
String msg = in.getNullableString();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/PingCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/PingCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/PingCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.PING;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
import org.jboss.messaging.core.remoting.impl.wireformat.Ping;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -36,13 +35,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final Ping packet) throws Exception
- {
- return SIZE_LONG;
- }
-
@Override
- protected void encodeBody(final Ping packet, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final Ping packet, final MessagingBuffer out) throws Exception
{
long clientSessionID = packet.getSessionID();
@@ -50,7 +44,7 @@
}
@Override
- protected Ping decodeBody(final RemotingBuffer in) throws Exception
+ protected Ping decodeBody(final MessagingBuffer in) throws Exception
{
long clientSessionID = in.getLong();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/PongCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/PongCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/PongCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,11 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.PONG;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
import org.jboss.messaging.core.remoting.impl.wireformat.Pong;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -37,13 +35,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final Pong packet) throws Exception
- {
- return SIZE_LONG + SIZE_BOOLEAN;
- }
-
@Override
- protected void encodeBody(final Pong packet, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final Pong packet, final MessagingBuffer out) throws Exception
{
long sessionID = packet.getSessionID();
boolean sessionFailed = packet.isSessionFailed();
@@ -53,7 +46,7 @@
}
@Override
- protected Pong decodeBody(final RemotingBuffer in) throws Exception
+ protected Pong decodeBody(final MessagingBuffer in) throws Exception
{
long sessionID = in.getLong();
boolean sessionFailed = in.getBoolean();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerReceiveTokensMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerReceiveTokensMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerReceiveTokensMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.PROD_RECEIVETOKENS;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
import org.jboss.messaging.core.remoting.impl.wireformat.ProducerReceiveTokensMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -38,19 +37,14 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final ProducerReceiveTokensMessage packet) throws Exception
- {
- return SIZE_INT;
- }
-
@Override
- protected void encodeBody(final ProducerReceiveTokensMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final ProducerReceiveTokensMessage message, final MessagingBuffer out) throws Exception
{
out.putInt(message.getTokens());
}
@Override
- protected ProducerReceiveTokensMessage decodeBody(final RemotingBuffer in)
+ protected ProducerReceiveTokensMessage decodeBody(final MessagingBuffer in)
throws Exception
{
return new ProducerReceiveTokensMessage(in.getInt());
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerSendMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerSendMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ProducerSendMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,13 +7,12 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.PROD_SEND;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
+import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.core.message.impl.MessageImpl;
import org.jboss.messaging.core.remoting.impl.wireformat.ProducerSendMessage;
-import org.jboss.messaging.util.SimpleString;
-import org.jboss.messaging.util.StreamUtils;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -26,6 +25,9 @@
{
// Constants -----------------------------------------------------
+ private static final Logger log = Logger.getLogger(ProducerSendMessageCodec.class);
+
+
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
@@ -41,37 +43,33 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final ProducerSendMessage packet) throws Exception
+ @Override
+ protected void encodeBody(final ProducerSendMessage message, final MessagingBuffer out) throws Exception
{
- byte[] encodedMsg = StreamUtils.toBytes(packet.getMessage());
-
- int bodyLength = SimpleString.sizeofNullableString(packet.getAddress()) + SIZE_INT + encodedMsg.length;
+ MessagingBuffer buffer = message.getMessage().encode();
- return bodyLength;
+ buffer.flip();
+
+ //TODO - can be optimised
+
+ byte[] data = buffer.array();
+
+ out.putBytes(data, 0, buffer.limit());
}
@Override
- protected void encodeBody(final ProducerSendMessage message, final RemotingBuffer out) throws Exception
- {
- byte[] encodedMsg = StreamUtils.toBytes(message.getMessage());
- out.putNullableSimpleString(message.getAddress());
- out.putInt(encodedMsg.length);
- out.put(encodedMsg);
- encodedMsg = null;
- }
-
- @Override
- protected ProducerSendMessage decodeBody(final RemotingBuffer in)
+ protected ProducerSendMessage decodeBody(final MessagingBuffer in)
throws Exception
{
- SimpleString address = in.getNullableSimpleString();
- int msgLength = in.getInt();
- byte[] encodedMsg = new byte[msgLength];
- in.get(encodedMsg);
+ //TODO can be optimised
+
Message message = new MessageImpl();
- StreamUtils.fromBytes(message, encodedMsg);
+
+ message.decode(in);
+
+ message.getBody().flip();
- return new ProducerSendMessage(address, message);
+ return new ProducerSendMessage(message);
}
// Package protected ---------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ReceiveMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ReceiveMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/ReceiveMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,12 +7,12 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.RECEIVE_MSG;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
+import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.core.message.impl.MessageImpl;
import org.jboss.messaging.core.remoting.impl.wireformat.ReceiveMessage;
-import org.jboss.messaging.util.StreamUtils;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -22,6 +22,8 @@
{
// Constants -----------------------------------------------------
+ private static final Logger log = Logger.getLogger(ReceiveMessageCodec.class);
+
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
@@ -37,31 +39,32 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final ReceiveMessage packet) throws Exception
- {
- byte[] encodedMsg = StreamUtils.toBytes(packet.getMessage());
-
- return SIZE_INT + encodedMsg.length;
- }
-
@Override
- protected void encodeBody(final ReceiveMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final ReceiveMessage message, final MessagingBuffer out) throws Exception
{
- byte[] encodedMsg = StreamUtils.toBytes(message.getMessage());
- out.putInt(encodedMsg.length);
- out.put(encodedMsg);
- encodedMsg = null;
+
+ MessagingBuffer buffer = message.getMessage().encode();
+
+ buffer.flip();
+
+ //TODO - can be optimised
+
+ byte[] data = buffer.array();
+
+ out.putBytes(data, 0, buffer.limit());
}
@Override
- protected ReceiveMessage decodeBody(final RemotingBuffer in)
+ protected ReceiveMessage decodeBody(final MessagingBuffer in)
throws Exception
{
- int msgLength = in.getInt();
- byte[] encodedMsg = new byte[msgLength];
- in.get(encodedMsg);
+ //TODO can be optimised
+
Message message = new MessageImpl();
- StreamUtils.fromBytes(message, encodedMsg);
+
+ message.decode(in);
+
+ message.getBody().flip();
return new ReceiveMessage(message);
}
Deleted: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/RemotingBuffer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/RemotingBuffer.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/RemotingBuffer.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -1,62 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.core.remoting.impl.codec;
-
-import org.jboss.messaging.util.SimpleString;
-
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public interface RemotingBuffer
-{
- void put(byte byteValue);
-
- void putInt(int intValue);
-
- void putLong(long longValue);
-
- void put(byte[] bytes);
-
- void putFloat(float floatValue);
-
- byte get();
-
- int remaining();
-
- int getInt();
-
- long getLong();
-
- void get(byte[] b);
-
- float getFloat();
-
- void putBoolean(boolean b);
-
- boolean getBoolean();
-
- void putNullableString(String nullableString);
-
- String getNullableString();
-
- void putSimpleString(SimpleString simpleString);
-
- SimpleString getSimpleString();
-
- void putNullableSimpleString(SimpleString simpleString);
-
- SimpleString getNullableSimpleString();
-
- void rewind();
-
- byte[] array();
-}
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionAcknowledgeMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionAcknowledgeMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionAcknowledgeMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,12 +6,9 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
-
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionAcknowledgeMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -40,20 +37,15 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionAcknowledgeMessage packet) throws Exception
- {
- return SIZE_LONG + SIZE_BOOLEAN;
- }
-
@Override
- protected void encodeBody(final SessionAcknowledgeMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionAcknowledgeMessage message, final MessagingBuffer out) throws Exception
{
out.putLong(message.getDeliveryID());
out.putBoolean(message.isAllUpTo());
}
@Override
- protected SessionAcknowledgeMessage decodeBody(final RemotingBuffer in)
+ protected SessionAcknowledgeMessage decodeBody(final MessagingBuffer in)
throws Exception
{
long deliveryID = in.getLong();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionAddDestinationMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionAddDestinationMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionAddDestinationMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_ADD_DESTINATION;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionAddDestinationMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -39,20 +38,15 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionAddDestinationMessage packet) throws Exception
- {
- return SimpleString.sizeofString(packet.getAddress()) + SIZE_BOOLEAN;
- }
-
@Override
- protected void encodeBody(final SessionAddDestinationMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionAddDestinationMessage message, final MessagingBuffer out) throws Exception
{
out.putSimpleString(message.getAddress());
out.putBoolean(message.isTemporary());
}
@Override
- protected SessionAddDestinationMessage decodeBody(final RemotingBuffer in)
+ protected SessionAddDestinationMessage decodeBody(final MessagingBuffer in)
throws Exception
{
SimpleString address = in.getSimpleString();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBindingQueryMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBindingQueryMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBindingQueryMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -9,6 +9,7 @@
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BINDINGQUERY;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionBindingQueryMessage;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -36,14 +37,9 @@
// Public --------------------------------------------------------
// AbstractPacketCodec overrides ---------------------------------
-
- public int getBodyLength(final SessionBindingQueryMessage packet) throws Exception
- {
- return SimpleString.sizeofString(packet.getAddress());
- }
-
+
@Override
- protected void encodeBody(final SessionBindingQueryMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionBindingQueryMessage message, final MessagingBuffer out) throws Exception
{
SimpleString address = message.getAddress();
@@ -51,7 +47,7 @@
}
@Override
- protected SessionBindingQueryMessage decodeBody(final RemotingBuffer in)
+ protected SessionBindingQueryMessage decodeBody(final MessagingBuffer in)
throws Exception
{
SimpleString address = in.getSimpleString();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBindingQueryResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBindingQueryResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBindingQueryResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,13 +7,12 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BINDINGQUERY_RESP;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
import java.util.ArrayList;
import java.util.List;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionBindingQueryResponseMessage;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -42,22 +41,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionBindingQueryResponseMessage packet) throws Exception
- {
- List<SimpleString> queueNames = packet.getQueueNames();
-
- int bodyLength = SIZE_BOOLEAN + SIZE_INT;
-
- for (SimpleString queueName: queueNames)
- {
- bodyLength += SimpleString.sizeofString(queueName);
- }
-
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionBindingQueryResponseMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionBindingQueryResponseMessage message, final MessagingBuffer out) throws Exception
{
boolean exists = message.isExists();
List<SimpleString> queueNames = message.getQueueNames();
@@ -72,7 +57,7 @@
}
@Override
- protected SessionBindingQueryResponseMessage decodeBody(final RemotingBuffer in)
+ protected SessionBindingQueryResponseMessage decodeBody(final MessagingBuffer in)
throws Exception
{
boolean exists = in.getBoolean();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserHasNextMessageResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserHasNextMessageResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionBrowserHasNextMessageResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_BROWSER_HASNEXTMESSAGE_RESP;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionBrowserHasNextMessageResponseMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -35,21 +34,16 @@
// Public --------------------------------------------------------
// AbstractPacketCodec overrides ---------------------------------
-
- public int getBodyLength(final SessionBrowserHasNextMessageResponseMessage packet) throws Exception
- {
- return SIZE_BOOLEAN;
- }
-
+
@Override
protected void encodeBody(final SessionBrowserHasNextMessageResponseMessage response,
- final RemotingBuffer out) throws Exception
+ final MessagingBuffer out) throws Exception
{
out.putBoolean(response.hasNext());
}
@Override
- protected SessionBrowserHasNextMessageResponseMessage decodeBody(final RemotingBuffer in) throws Exception
+ protected SessionBrowserHasNextMessageResponseMessage decodeBody(final MessagingBuffer in) throws Exception
{
boolean hasNext = in.getBoolean();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCancelMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCancelMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCancelMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,12 +6,9 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
-
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionCancelMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -38,21 +35,16 @@
// Public --------------------------------------------------------
// AbstractPacketCodec overrides ---------------------------------
-
- public int getBodyLength(final SessionCancelMessage packet) throws Exception
- {
- return SIZE_LONG + SIZE_BOOLEAN;
- }
-
+
@Override
- protected void encodeBody(final SessionCancelMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionCancelMessage message, final MessagingBuffer out) throws Exception
{
out.putLong(message.getDeliveryID());
out.putBoolean(message.isExpired());
}
@Override
- protected SessionCancelMessage decodeBody(final RemotingBuffer in)
+ protected SessionCancelMessage decodeBody(final MessagingBuffer in)
throws Exception
{
long deliveryID = in.getLong();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateBrowserMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateBrowserMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateBrowserMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -9,6 +9,7 @@
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEBROWSER;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateBrowserMessage;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -35,18 +36,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionCreateBrowserMessage packet) throws Exception
- {
- SimpleString queueName = packet.getQueueName();
- SimpleString filterString = packet.getFilterString();
-
- int bodyLength = SimpleString.sizeofString(queueName) + SimpleString.sizeofNullableString(filterString);
-
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionCreateBrowserMessage request, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionCreateBrowserMessage request, final MessagingBuffer out) throws Exception
{
SimpleString queueName = request.getQueueName();
SimpleString filterString = request.getFilterString();
@@ -56,7 +47,7 @@
}
@Override
- protected SessionCreateBrowserMessage decodeBody(final RemotingBuffer in)
+ protected SessionCreateBrowserMessage decodeBody(final MessagingBuffer in)
throws Exception
{
SimpleString queueName = in.getSimpleString();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateBrowserResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateBrowserResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateBrowserResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEBROWSER_RESP;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateBrowserResponseMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -36,14 +35,9 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionCreateBrowserResponseMessage packet) throws Exception
- {
- return SIZE_LONG;
- }
-
@Override
protected void encodeBody(final SessionCreateBrowserResponseMessage response,
- final RemotingBuffer out) throws Exception
+ final MessagingBuffer out) throws Exception
{
long browserID = response.getBrowserTargetID();
@@ -51,7 +45,7 @@
}
@Override
- protected SessionCreateBrowserResponseMessage decodeBody(final RemotingBuffer in)
+ protected SessionCreateBrowserResponseMessage decodeBody(final MessagingBuffer in)
throws Exception
{
long browserID = in.getLong();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateConsumerMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateConsumerMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateConsumerMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,12 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATECONSUMER;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateConsumerMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -39,16 +36,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionCreateConsumerMessage packet) throws Exception
- {
- int bodyLength = SIZE_LONG + SimpleString.sizeofString(packet.getQueueName()) +
- SimpleString.sizeofNullableString(packet.getFilterString()) + 2 * SIZE_BOOLEAN + 2 * SIZE_INT;
-
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionCreateConsumerMessage request, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionCreateConsumerMessage request, final MessagingBuffer out) throws Exception
{
SimpleString queueName = request.getQueueName();
SimpleString filterString = request.getFilterString();
@@ -67,7 +56,7 @@
}
@Override
- protected SessionCreateConsumerMessage decodeBody(final RemotingBuffer in)
+ protected SessionCreateConsumerMessage decodeBody(final MessagingBuffer in)
throws Exception
{
long clientTargetID = in.getLong();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateConsumerResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateConsumerResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateConsumerResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,11 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATECONSUMER_RESP;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateConsumerResponseMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -37,14 +35,9 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionCreateConsumerResponseMessage packet) throws Exception
- {
- return SIZE_LONG + SIZE_INT;
- }
-
@Override
protected void encodeBody(final SessionCreateConsumerResponseMessage response,
- final RemotingBuffer out) throws Exception
+ final MessagingBuffer out) throws Exception
{
long consumerID = response.getConsumerTargetID();
@@ -55,7 +48,7 @@
}
@Override
- protected SessionCreateConsumerResponseMessage decodeBody(final RemotingBuffer in)
+ protected SessionCreateConsumerResponseMessage decodeBody(final MessagingBuffer in)
throws Exception
{
long consumerID = in.getLong();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEPRODUCER;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateProducerMessage;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -40,17 +39,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionCreateProducerMessage packet) throws Exception
- {
- SimpleString address = packet.getAddress();
-
- int bodyLength = SIZE_LONG + SimpleString.sizeofNullableString(address) + 2 * SIZE_INT;
-
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionCreateProducerMessage request, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionCreateProducerMessage request, final MessagingBuffer out) throws Exception
{
SimpleString address = request.getAddress();
@@ -61,7 +51,7 @@
}
@Override
- protected SessionCreateProducerMessage decodeBody(final RemotingBuffer in)
+ protected SessionCreateProducerMessage decodeBody(final MessagingBuffer in)
throws Exception
{
long clientTargetID = in.getLong();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateProducerResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,11 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEPRODUCER_RESP;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
-import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateProducerResponseMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -40,14 +38,9 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionCreateProducerResponseMessage packet) throws Exception
- {
- return SIZE_LONG + 2 * SIZE_INT;
- }
-
@Override
protected void encodeBody(final SessionCreateProducerResponseMessage response,
- final RemotingBuffer out) throws Exception
+ final MessagingBuffer out) throws Exception
{
long producerID = response.getProducerTargetID();
@@ -57,7 +50,7 @@
}
@Override
- protected SessionCreateProducerResponseMessage decodeBody(final RemotingBuffer in)
+ protected SessionCreateProducerResponseMessage decodeBody(final MessagingBuffer in)
throws Exception
{
long producerID = in.getLong();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateQueueMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateQueueMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionCreateQueueMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,9 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_CREATEQUEUE;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionCreateQueueMessage;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -37,19 +37,9 @@
// Public --------------------------------------------------------
// AbstractPacketCodec overrides ---------------------------------
-
- public int getBodyLength(final SessionCreateQueueMessage packet) throws Exception
- {
- SimpleString address = packet.getAddress();
- SimpleString queueName = packet.getQueueName();
- SimpleString filterString = packet.getFilterString();
- int bodyLength = SimpleString.sizeofString(address) + SimpleString.sizeofString(queueName) +
- SimpleString.sizeofNullableString(filterString) + 2 * SIZE_BOOLEAN;
- return bodyLength;
- }
-
+
@Override
- protected void encodeBody(final SessionCreateQueueMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionCreateQueueMessage message, final MessagingBuffer out) throws Exception
{
SimpleString address = message.getAddress();
SimpleString queueName = message.getQueueName();
@@ -65,7 +55,7 @@
}
@Override
- protected SessionCreateQueueMessage decodeBody(final RemotingBuffer in)
+ protected SessionCreateQueueMessage decodeBody(final MessagingBuffer in)
throws Exception
{
SimpleString address = in.getSimpleString();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionDeleteQueueMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionDeleteQueueMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionDeleteQueueMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -9,6 +9,7 @@
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_DELETE_QUEUE;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionDeleteQueueMessage;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -37,22 +38,15 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionDeleteQueueMessage packet) throws Exception
- {
- SimpleString queueName = packet.getQueueName();
- int bodyLength = SimpleString.sizeofString(queueName);
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionDeleteQueueMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionDeleteQueueMessage message, final MessagingBuffer out) throws Exception
{
SimpleString queueName = message.getQueueName();
out.putSimpleString(queueName);
}
@Override
- protected SessionDeleteQueueMessage decodeBody(final RemotingBuffer in)
+ protected SessionDeleteQueueMessage decodeBody(final MessagingBuffer in)
throws Exception
{
SimpleString queueName = in.getSimpleString();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionQueueQueryMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionQueueQueryMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionQueueQueryMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -9,6 +9,7 @@
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_QUEUEQUERY;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionQueueQueryMessage;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -37,22 +38,15 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionQueueQueryMessage packet) throws Exception
- {
- SimpleString queueName = packet.getQueueName();
- int bodyLength = SimpleString.sizeofString(queueName);
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionQueueQueryMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionQueueQueryMessage message, final MessagingBuffer out) throws Exception
{
SimpleString queueName = message.getQueueName();
out.putSimpleString(queueName);
}
@Override
- protected SessionQueueQueryMessage decodeBody(final RemotingBuffer in)
+ protected SessionQueueQueryMessage decodeBody(final MessagingBuffer in)
throws Exception
{
SimpleString queueName = in.getSimpleString();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionQueueQueryResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionQueueQueryResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionQueueQueryResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_QUEUEQUERY_RESP;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionQueueQueryResponseMessage;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -39,17 +38,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionQueueQueryResponseMessage packet) throws Exception
- {
- SimpleString filterString = packet.getFilterString();
- SimpleString address = packet.getAddress();
- int bodyLength = 3 * SIZE_BOOLEAN + 3 * SIZE_INT + SimpleString.sizeofNullableString(filterString) +
- SimpleString.sizeofNullableString(address);
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionQueueQueryResponseMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionQueueQueryResponseMessage message, final MessagingBuffer out) throws Exception
{
boolean exists = message.isExists();
boolean durable = message.isDurable();
@@ -71,7 +61,7 @@
}
@Override
- protected SessionQueueQueryResponseMessage decodeBody(final RemotingBuffer in)
+ protected SessionQueueQueryResponseMessage decodeBody(final MessagingBuffer in)
throws Exception
{
boolean exists = in.getBoolean();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionRemoveDestinationMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionRemoveDestinationMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionRemoveDestinationMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,10 +7,9 @@
package org.jboss.messaging.core.remoting.impl.codec;
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.SESS_REMOVE_DESTINATION;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionRemoveDestinationMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -39,15 +38,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionRemoveDestinationMessage packet) throws Exception
- {
- SimpleString address = packet.getAddress();
- int bodyLength = SimpleString.sizeofString(address) + SIZE_BOOLEAN;
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionRemoveDestinationMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionRemoveDestinationMessage message, final MessagingBuffer out) throws Exception
{
SimpleString address = message.getAddress();
@@ -56,7 +48,7 @@
}
@Override
- protected SessionRemoveDestinationMessage decodeBody(final RemotingBuffer in)
+ protected SessionRemoveDestinationMessage decodeBody(final MessagingBuffer in)
throws Exception
{
SimpleString address = in.getSimpleString();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXACommitMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXACommitMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXACommitMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,13 +6,11 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
-
import javax.transaction.xa.Xid;
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXACommitMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -39,22 +37,16 @@
// Public --------------------------------------------------------
// AbstractPacketCodec overrides ---------------------------------
-
- public int getBodyLength(final SessionXACommitMessage packet) throws Exception
- {
- int bodyLength = getXidLength(packet.getXid()) + SIZE_BOOLEAN;
- return bodyLength;
- }
-
+
@Override
- protected void encodeBody(final SessionXACommitMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXACommitMessage message, final MessagingBuffer out) throws Exception
{
encodeXid(message.getXid(), out);
out.putBoolean(message.isOnePhase());
}
@Override
- protected SessionXACommitMessage decodeBody(final RemotingBuffer in)
+ protected SessionXACommitMessage decodeBody(final MessagingBuffer in)
throws Exception
{
Xid xid = decodeXid(in);
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAEndMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAEndMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAEndMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,13 +6,11 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
-
import javax.transaction.xa.Xid;
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAEndMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -40,14 +38,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXAEndMessage packet) throws Exception
- {
- int bodyLength = getXidLength(packet.getXid()) + SIZE_BOOLEAN;
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionXAEndMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXAEndMessage message, final MessagingBuffer out) throws Exception
{
Xid xid = message.getXid();
@@ -56,7 +48,7 @@
}
@Override
- protected SessionXAEndMessage decodeBody(final RemotingBuffer in) throws Exception
+ protected SessionXAEndMessage decodeBody(final MessagingBuffer in) throws Exception
{
Xid xid = decodeXid(in);
boolean failed = in.getBoolean();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAForgetMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAForgetMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAForgetMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -10,6 +10,7 @@
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAForgetMessage;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -36,15 +37,9 @@
// Public --------------------------------------------------------
// AbstractPacketCodec overrides ---------------------------------
-
- public int getBodyLength(final SessionXAForgetMessage packet) throws Exception
- {
- int bodyLength = getXidLength(packet.getXid());
- return bodyLength;
- }
-
+
@Override
- protected void encodeBody(final SessionXAForgetMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXAForgetMessage message, final MessagingBuffer out) throws Exception
{
Xid xid = message.getXid();
@@ -52,7 +47,7 @@
}
@Override
- protected SessionXAForgetMessage decodeBody(final RemotingBuffer in)
+ protected SessionXAForgetMessage decodeBody(final MessagingBuffer in)
throws Exception
{
Xid xid = decodeXid(in);
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAGetInDoubtXidsResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAGetInDoubtXidsResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAGetInDoubtXidsResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,8 +6,6 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
-
import java.util.ArrayList;
import java.util.List;
@@ -15,7 +13,7 @@
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAGetInDoubtXidsResponseMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
@@ -44,19 +42,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXAGetInDoubtXidsResponseMessage packet) throws Exception
- {
- int bodyLength = SIZE_INT;
-
- for (Xid xid: packet.getXids())
- {
- bodyLength += getXidLength(xid);
- }
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionXAGetInDoubtXidsResponseMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXAGetInDoubtXidsResponseMessage message, final MessagingBuffer out) throws Exception
{
out.putInt(message.getXids().size());
@@ -67,7 +54,7 @@
}
@Override
- protected SessionXAGetInDoubtXidsResponseMessage decodeBody(final RemotingBuffer in)
+ protected SessionXAGetInDoubtXidsResponseMessage decodeBody(final MessagingBuffer in)
throws Exception
{
int size = in.getInt();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAGetTimeoutResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAGetTimeoutResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAGetTimeoutResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,11 +6,9 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
-
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAGetTimeoutResponseMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
@@ -39,19 +37,14 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXAGetTimeoutResponseMessage packet) throws Exception
- {
- return SIZE_INT;
- }
-
@Override
- protected void encodeBody(final SessionXAGetTimeoutResponseMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXAGetTimeoutResponseMessage message, final MessagingBuffer out) throws Exception
{
out.putInt(message.getTimeoutSeconds());
}
@Override
- protected SessionXAGetTimeoutResponseMessage decodeBody(final RemotingBuffer in)
+ protected SessionXAGetTimeoutResponseMessage decodeBody(final MessagingBuffer in)
throws Exception
{
int timeout = in.getInt();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAJoinMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAJoinMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAJoinMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -10,6 +10,7 @@
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAJoinMessage;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -37,17 +38,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXAJoinMessage packet) throws Exception
- {
- Xid xid = packet.getXid();
-
- int bodyLength = getXidLength(xid);
-
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionXAJoinMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXAJoinMessage message, final MessagingBuffer out) throws Exception
{
Xid xid = message.getXid();
@@ -55,7 +47,7 @@
}
@Override
- protected SessionXAJoinMessage decodeBody(final RemotingBuffer in)
+ protected SessionXAJoinMessage decodeBody(final MessagingBuffer in)
throws Exception
{
Xid xid = decodeXid(in);
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAPrepareMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAPrepareMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAPrepareMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -10,6 +10,7 @@
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAPrepareMessage;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -37,17 +38,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXAPrepareMessage packet) throws Exception
- {
- Xid xid = packet.getXid();
-
- int bodyLength = getXidLength(xid);
-
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionXAPrepareMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXAPrepareMessage message, final MessagingBuffer out) throws Exception
{
Xid xid = message.getXid();
@@ -55,7 +47,7 @@
}
@Override
- protected SessionXAPrepareMessage decodeBody(final RemotingBuffer in)
+ protected SessionXAPrepareMessage decodeBody(final MessagingBuffer in)
throws Exception
{
Xid xid = decodeXid(in);
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,12 +6,9 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
-
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAResponseMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
@@ -40,15 +37,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXAResponseMessage packet) throws Exception
- {
- int bodyLength = SIZE_BOOLEAN + SIZE_INT + sizeof(packet.getMessage());
-
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionXAResponseMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXAResponseMessage message, final MessagingBuffer out) throws Exception
{
out.putBoolean(message.isError());
@@ -58,7 +48,7 @@
}
@Override
- protected SessionXAResponseMessage decodeBody(final RemotingBuffer in)
+ protected SessionXAResponseMessage decodeBody(final MessagingBuffer in)
throws Exception
{
boolean isError = in.getBoolean();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAResumeMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAResumeMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAResumeMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -10,6 +10,7 @@
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAResumeMessage;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -37,17 +38,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXAResumeMessage packet) throws Exception
- {
- Xid xid = packet.getXid();
-
- int bodyLength = getXidLength(xid);
-
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionXAResumeMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXAResumeMessage message, final MessagingBuffer out) throws Exception
{
Xid xid = message.getXid();
@@ -55,7 +47,7 @@
}
@Override
- protected SessionXAResumeMessage decodeBody(final RemotingBuffer in)
+ protected SessionXAResumeMessage decodeBody(final MessagingBuffer in)
throws Exception
{
Xid xid = decodeXid(in);
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXARollbackMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXARollbackMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXARollbackMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -10,6 +10,7 @@
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXARollbackMessage;
+import org.jboss.messaging.util.MessagingBuffer;
public class SessionXARollbackMessageCodec extends AbstractPacketCodec<SessionXARollbackMessage>
{
@@ -30,17 +31,8 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXARollbackMessage packet) throws Exception
- {
- Xid xid = packet.getXid();
-
- int bodyLength = getXidLength(xid);
-
- return bodyLength;
- }
-
@Override
- protected void encodeBody(final SessionXARollbackMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXARollbackMessage message, final MessagingBuffer out) throws Exception
{
Xid xid = message.getXid();
@@ -48,7 +40,7 @@
}
@Override
- protected SessionXARollbackMessage decodeBody(final RemotingBuffer in)
+ protected SessionXARollbackMessage decodeBody(final MessagingBuffer in)
throws Exception
{
Xid xid = decodeXid(in);
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXASetTimeoutMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXASetTimeoutMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXASetTimeoutMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,11 +6,9 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_INT;
-
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASetTimeoutMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -38,19 +36,14 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXASetTimeoutMessage packet) throws Exception
- {
- return SIZE_INT;
- }
-
@Override
- protected void encodeBody(final SessionXASetTimeoutMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXASetTimeoutMessage message, final MessagingBuffer out) throws Exception
{
out.putInt(message.getTimeoutSeconds());
}
@Override
- protected SessionXASetTimeoutMessage decodeBody(final RemotingBuffer in)
+ protected SessionXASetTimeoutMessage decodeBody(final MessagingBuffer in)
throws Exception
{
int timeout = in.getInt();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXASetTimeoutResponseMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXASetTimeoutResponseMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXASetTimeoutResponseMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,11 +6,9 @@
*/
package org.jboss.messaging.core.remoting.impl.codec;
-import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
-
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXASetTimeoutResponseMessage;
-import org.jboss.messaging.util.DataConstants;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -38,19 +36,14 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXASetTimeoutResponseMessage packet) throws Exception
- {
- return SIZE_BOOLEAN;
- }
-
@Override
- protected void encodeBody(final SessionXASetTimeoutResponseMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXASetTimeoutResponseMessage message, final MessagingBuffer out) throws Exception
{
out.putBoolean(message.isOK());
}
@Override
- protected SessionXASetTimeoutResponseMessage decodeBody(final RemotingBuffer in)
+ protected SessionXASetTimeoutResponseMessage decodeBody(final MessagingBuffer in)
throws Exception
{
boolean ok = in.getBoolean();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAStartMessageCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAStartMessageCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/SessionXAStartMessageCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -10,6 +10,7 @@
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
import org.jboss.messaging.core.remoting.impl.wireformat.SessionXAStartMessage;
+import org.jboss.messaging.util.MessagingBuffer;
/**
*
@@ -37,17 +38,9 @@
// AbstractPacketCodec overrides ---------------------------------
- public int getBodyLength(final SessionXAStartMessage packet) throws Exception
- {
- Xid xid = packet.getXid();
-
- int bodyLength = getXidLength(xid);
-
- return bodyLength;
- }
-
+
@Override
- protected void encodeBody(final SessionXAStartMessage message, final RemotingBuffer out) throws Exception
+ protected void encodeBody(final SessionXAStartMessage message, final MessagingBuffer out) throws Exception
{
Xid xid = message.getXid();
@@ -55,7 +48,7 @@
}
@Override
- protected SessionXAStartMessage decodeBody(final RemotingBuffer in)
+ protected SessionXAStartMessage decodeBody(final MessagingBuffer in)
throws Exception
{
Xid xid = decodeXid(in);
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/TextPacketCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/TextPacketCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/codec/TextPacketCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -9,6 +9,7 @@
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.TEXT;
import org.jboss.messaging.core.remoting.impl.wireformat.TextPacket;
+import org.jboss.messaging.util.MessagingBuffer;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -33,14 +34,9 @@
// Public --------------------------------------------------------
// AbstractPacketCodec overrides ---------------------------------
-
- public int getBodyLength(final TextPacket packet) throws Exception
- {
- return sizeof(packet.getText());
- }
-
+
@Override
- protected void encodeBody(TextPacket packet, RemotingBuffer out)
+ protected void encodeBody(TextPacket packet, MessagingBuffer out)
throws Exception
{
String text = packet.getText();
@@ -48,7 +44,7 @@
}
@Override
- protected TextPacket decodeBody(RemotingBuffer in)
+ protected TextPacket decodeBody(MessagingBuffer in)
throws Exception
{
String text = in.getNullableString();
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/BufferWrapper.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -11,8 +11,11 @@
import static org.jboss.messaging.util.DataConstants.NULL;
import static org.jboss.messaging.util.DataConstants.TRUE;
+import java.nio.charset.Charset;
+
import org.apache.mina.common.IoBuffer;
-import org.jboss.messaging.core.remoting.impl.codec.RemotingBuffer;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
/**
@@ -23,10 +26,14 @@
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
*
*/
-public class BufferWrapper implements RemotingBuffer
+public class BufferWrapper implements MessagingBuffer
{
// Constants -----------------------------------------------------
-
+
+ private static final Charset utf8 = Charset.forName("UTF-8");
+
+ private static final Logger log = Logger.getLogger(BufferWrapper.class);
+
// Attributes ----------------------------------------------------
private final IoBuffer buffer;
@@ -35,36 +42,86 @@
// Constructors --------------------------------------------------
+ public BufferWrapper(final int size)
+ {
+ buffer = IoBuffer.allocate(size);
+
+ buffer.setAutoExpand(true);
+ }
+
public BufferWrapper(final IoBuffer buffer)
{
- assert buffer != null;
-
this.buffer = buffer;
}
// Public --------------------------------------------------------
- // RemotingBuffer implementation ----------------------------------------------
+ // MessagingBuffer implementation ----------------------------------------------
public byte[] array()
{
return buffer.array();
}
-
+
+ public int position()
+ {
+ return buffer.position();
+ }
+
+ public void position(final int position)
+ {
+ buffer.position(position);
+ }
+
+ public int limit()
+ {
+ return buffer.limit();
+ }
+
+ public void limit(final int limit)
+ {
+ buffer.limit(limit);
+ }
+
+ public int capacity()
+ {
+ return buffer.capacity();
+ }
+
+ public void flip()
+ {
+ buffer.flip();
+ }
+
+ public MessagingBuffer slice()
+ {
+ return new BufferWrapper(buffer.slice());
+ }
+
public int remaining()
{
return buffer.remaining();
}
+
+ public void rewind()
+ {
+ buffer.rewind();
+ }
- public void put(final byte byteValue)
+ public void putByte(byte byteValue)
{
buffer.put(byteValue);
}
- public void put(final byte[] byteArray)
+ public void putBytes(final byte[] byteArray)
{
buffer.put(byteArray);
}
+
+ public void putBytes(final byte[] bytes, int offset, int length)
+ {
+ buffer.put(bytes, offset, length);
+ }
public void putInt(final int intValue)
{
@@ -80,21 +137,51 @@
{
buffer.putFloat(floatValue);
}
-
- public byte get()
+
+ public void putDouble(final double d)
{
+ buffer.putDouble(d);
+ }
+
+ public void putShort(final short s)
+ {
+ buffer.putShort(s);
+ }
+
+ public void putChar(final char chr)
+ {
+ buffer.putChar(chr);
+ }
+
+ public byte getByte()
+ {
return buffer.get();
}
+
+ public short getUnsignedByte()
+ {
+ return buffer.getUnsigned();
+ }
- public void get(final byte[] b)
+ public void getBytes(final byte[] b)
{
buffer.get(b);
}
+
+ public void getBytes(final byte[] b, final int offset, final int length)
+ {
+ buffer.get(b, offset, length);
+ }
public int getInt()
{
return buffer.getInt();
}
+
+ public long getUnsignedInt()
+ {
+ return buffer.getUnsignedInt();
+ }
public long getLong()
{
@@ -105,14 +192,33 @@
{
return buffer.getFloat();
}
+
+ public short getShort()
+ {
+ return buffer.getShort();
+ }
+
+ public int getUnsignedShort()
+ {
+ return buffer.getUnsignedShort();
+ }
+
+ public double getDouble()
+ {
+ return buffer.getDouble();
+ }
+
+ public char getChar()
+ {
+ return buffer.getChar();
+ }
public void putBoolean(final boolean b)
{
if (b)
{
buffer.put(TRUE);
- }
- else
+ } else
{
buffer.put(FALSE);
}
@@ -124,6 +230,16 @@
return (b == TRUE);
}
+ public void putString(final String nullableString)
+ {
+ buffer.putInt(nullableString.length());
+
+ for (int i = 0; i < nullableString.length(); i++)
+ {
+ buffer.putChar(nullableString.charAt(i));
+ }
+ }
+
public void putNullableString(final String nullableString)
{
if (nullableString == null)
@@ -137,6 +253,20 @@
putString(nullableString);
}
}
+
+ public String getString()
+ {
+ int len = buffer.getInt();
+
+ char[] chars = new char[len];
+
+ for (int i = 0; i < len; i++)
+ {
+ chars[i] = buffer.getChar();
+ }
+
+ return new String(chars);
+ }
public String getNullableString()
{
@@ -148,93 +278,74 @@
}
else
{
- return getString();
+ return getString();
}
}
+
+ public void putUTF(final String str) throws Exception
+ {
+ buffer.putPrefixedString(str, utf8.newEncoder());
+ }
+
+ public void putNullableSimpleString(final SimpleString string)
+ {
+ if (string == null)
+ {
+ buffer.put(NULL);
+ }
+ else
+ {
+ buffer.put(NOT_NULL);
+ putSimpleString(string);
+ }
+ }
public void putSimpleString(final SimpleString string)
{
- byte[] data = string.getData();
-
- buffer.putInt(data.length);
- buffer.put(data);
+ byte[] data = string.getData();
+
+ buffer.putInt(data.length);
+ buffer.put(data);
}
public SimpleString getSimpleString()
{
- int len = buffer.getInt();
-
- byte[] data = new byte[len];
- buffer.get(data);
-
- return new SimpleString(data);
- }
+ int len = buffer.getInt();
- public void putNullableSimpleString(final SimpleString string)
- {
- if (string == null)
- {
- buffer.put(NULL);
- }
- else
- {
- buffer.put(NOT_NULL);
- putSimpleString(string);
- }
+ byte[] data = new byte[len];
+ buffer.get(data);
+
+ return new SimpleString(data);
}
-
+
public SimpleString getNullableSimpleString()
{
- int b = buffer.get();
- if (b == NULL)
- {
- return null;
- }
- else
- {
- return getSimpleString();
- }
+ int b = buffer.get();
+ if (b == NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return getSimpleString();
+ }
}
-
- public void rewind()
+
+ public String getUTF() throws Exception
{
- buffer.rewind();
+ return buffer.getPrefixedString(utf8.newDecoder());
}
-
- public void flip()
+
+ public Object getUnderlyingBuffer()
{
- buffer.flip();
+ return buffer;
}
-
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
- private void putString(final String nullableString)
- {
- buffer.putInt(nullableString.length());
-
- for (int i = 0; i < nullableString.length(); i++)
- {
- buffer.putChar(nullableString.charAt(i));
- }
- }
-
- private String getString()
- {
- int len = buffer.getInt();
-
- char[] chars = new char[len];
-
- for (int i = 0; i < len; i++)
- {
- chars[i] = buffer.getChar();
- }
-
- return new String(chars);
- }
-
// Inner classes -------------------------------------------------
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/mina/MessagingCodec.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -21,7 +21,6 @@
import org.jboss.messaging.core.remoting.Packet;
import org.jboss.messaging.core.remoting.impl.codec.AbstractPacketCodec;
import org.jboss.messaging.core.remoting.impl.wireformat.PacketType;
-import org.jboss.messaging.util.DataConstants;
/**
*
@@ -73,7 +72,7 @@
}
int length = in.getInt();
-
+
if (in.remaining() < length)
{
in.position(start);
Modified: trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ProducerSendMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ProducerSendMessage.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/remoting/impl/wireformat/ProducerSendMessage.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -9,7 +9,6 @@
import static org.jboss.messaging.core.remoting.impl.wireformat.PacketType.PROD_SEND;
import org.jboss.messaging.core.message.Message;
-import org.jboss.messaging.util.SimpleString;
/**
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -23,30 +22,21 @@
// Attributes ----------------------------------------------------
- private final SimpleString address;
-
private final Message message;
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
- public ProducerSendMessage(final SimpleString address, final Message message)
+ public ProducerSendMessage(final Message message)
{
super(PROD_SEND);
- this.address = address;
-
this.message = message;
}
// Public --------------------------------------------------------
- public SimpleString getAddress()
- {
- return address;
- }
-
public Message getMessage()
{
return message;
@@ -55,7 +45,7 @@
@Override
public String toString()
{
- return getParentString() + ", address=" + address + ", message=" + message
+ return getParentString() + ", message=" + message
+ "]";
}
Modified: trunk/src/main/org/jboss/messaging/core/server/ServerProducer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/ServerProducer.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/server/ServerProducer.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -1,7 +1,6 @@
package org.jboss.messaging.core.server;
import org.jboss.messaging.core.message.Message;
-import org.jboss.messaging.util.SimpleString;
/**
*
@@ -16,7 +15,7 @@
void close() throws Exception;
- void send(SimpleString address, Message msg) throws Exception;
+ void send(Message msg) throws Exception;
void sendCredits() throws Exception;
Modified: trunk/src/main/org/jboss/messaging/core/server/ServerSession.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/ServerSession.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/server/ServerSession.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -63,7 +63,7 @@
void promptDelivery(Queue queue);
- void send(SimpleString address, Message msg) throws Exception;
+ void send(Message msg) throws Exception;
void acknowledge(long deliveryID, boolean allUpTo) throws Exception;
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerConsumerImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -175,7 +175,7 @@
return HandleStatus.HANDLED;
}
-
+
synchronized (startStopLock)
{
// If the consumer is stopped then we don't accept the message, it should go back into the
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -86,24 +86,21 @@
{
session.removeProducer(this);
}
-
-
- public void send(final SimpleString address, final Message message) throws Exception
+
+ public void send(final Message message) throws Exception
{
- if (address != null)
- {
- //Anonymous producer - no flow control
- session.send(address, message);
+ if (this.address != null)
+ {
+ //Only do flow control with non anonymous producers
+
+ //TODO - flow control currently disabled
+// if (flowController != null)
+// {
+// flowController.messageReceived(this, 1);
+// }
}
- else
- {
- session.send(this.address, message);
-
- if (flowController != null)
- {
- flowController.messageReceived(this, 1);
- }
- }
+
+ session.send(message);
}
public void sendCredits() throws Exception
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerPacketHandler.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerPacketHandler.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerProducerPacketHandler.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -61,7 +61,7 @@
{
case PROD_SEND:
ProducerSendMessage message = (ProducerSendMessage) packet;
- producer.send(message.getAddress(), message.getMessage());
+ producer.send(message.getMessage());
break;
case CLOSE:
producer.close();
Modified: trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/server/impl/ServerSessionImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -300,10 +300,10 @@
});
}
- public void send(final SimpleString address, final Message msg) throws Exception
+ public void send(final Message msg) throws Exception
{
//check the user has write access to this address
- securityStore.check(address.toString(), CheckType.WRITE, connection);
+ securityStore.check(msg.getDestination().toString(), CheckType.WRITE, connection);
msg.setMessageID(persistenceManager.generateMessageID());
@@ -314,11 +314,11 @@
if (autoCommitSends)
{
- List<MessageReference> refs = postOffice.route(address, msg);
+ List<MessageReference> refs = postOffice.route(msg);
if (msg.getDurableRefCount() != 0)
{
- persistenceManager.storeMessage(address, msg);
+ persistenceManager.storeMessage(msg);
}
for (MessageReference ref: refs)
@@ -328,7 +328,7 @@
}
else
{
- tx.addMessage(address, msg);
+ tx.addMessage(msg);
}
}
Modified: trunk/src/main/org/jboss/messaging/core/transaction/Transaction.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/transaction/Transaction.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/transaction/Transaction.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -29,7 +29,6 @@
import org.jboss.messaging.core.message.MessageReference;
import org.jboss.messaging.core.settings.HierarchicalRepository;
import org.jboss.messaging.core.settings.impl.QueueSettings;
-import org.jboss.messaging.util.SimpleString;
/**
*
@@ -46,7 +45,7 @@
void rollback(HierarchicalRepository<QueueSettings> queueSettingsRepository) throws Exception;
- void addMessage(SimpleString address, Message message) throws Exception;
+ void addMessage(Message message) throws Exception;
List<MessageReference> getAcknowledgements();
Modified: trunk/src/main/org/jboss/messaging/core/transaction/impl/TransactionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/transaction/impl/TransactionImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/transaction/impl/TransactionImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -38,7 +38,6 @@
import org.jboss.messaging.core.settings.HierarchicalRepository;
import org.jboss.messaging.core.settings.impl.QueueSettings;
import org.jboss.messaging.core.transaction.Transaction;
-import org.jboss.messaging.util.SimpleString;
/**
*
@@ -99,7 +98,7 @@
return id;
}
- public void addMessage(final SimpleString address, final Message message)
+ public void addMessage(final Message message)
throws Exception
{
if (state != State.ACTIVE)
@@ -107,13 +106,13 @@
throw new IllegalStateException("Transaction is in invalid state " + state);
}
- List<MessageReference> refs = postOffice.route(address, message);
+ List<MessageReference> refs = postOffice.route(message);
refsToAdd.addAll(refs);
if (message.getDurableRefCount() != 0)
{
- storageManager.storeMessageTransactional(id, address, message);
+ storageManager.storeMessageTransactional(id, message);
containsPersistent = true;
}
Modified: trunk/src/main/org/jboss/messaging/core/version/impl/VersionImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/version/impl/VersionImpl.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/core/version/impl/VersionImpl.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -6,20 +6,17 @@
*/
package org.jboss.messaging.core.version.impl;
-import java.io.*;
-import java.util.Properties;
-import java.net.URL;
+import java.io.Serializable;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.version.Version;
-import org.jboss.messaging.util.Streamable;
/**
* A VersionImpl
*
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
*/
-public class VersionImpl implements Version, Streamable, Serializable
+public class VersionImpl implements Version, Serializable
{
// Constants -----------------------------------------------------
@@ -106,35 +103,5 @@
// Private -------------------------------------------------------
- public void read(DataInputStream in) throws Exception
- {
- versionName = in.readUTF();
-
- majorVersion = in.readInt();
-
- minorVersion = in.readInt();
-
- microVersion = in.readInt();
-
- versionSuffix = in.readUTF();
-
- incrementingVersion = in.readInt();
- }
-
- public void write(DataOutputStream out) throws Exception
- {
- out.writeUTF(versionName);
-
- out.writeInt(majorVersion);
-
- out.writeInt(minorVersion);
-
- out.writeInt(microVersion);
-
- out.writeUTF(versionSuffix);
-
- out.writeInt(incrementingVersion);
- }
-
// Inner classes -------------------------------------------------
}
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossBytesMessage.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -21,12 +21,7 @@
*/
package org.jboss.messaging.jms.client;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.EOFException;
-import java.io.IOException;
+import java.nio.BufferUnderflowException;
import javax.jms.BytesMessage;
import javax.jms.JMSException;
@@ -34,6 +29,8 @@
import javax.jms.MessageFormatException;
import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
/**
* This class implements javax.jms.BytesMessage.
@@ -51,21 +48,12 @@
{
// Static -------------------------------------------------------
+ private static final Logger log = Logger.getLogger(JBossBytesMessage.class);
+
public static final byte TYPE = 4;
// Attributes ----------------------------------------------------
- // TODO - use abstraction of MINA byte buffer to write directly and avoid
- // unnecessary copying
-
- private ByteArrayOutputStream baos;
- private DataOutputStream dos;
-
- private ByteArrayInputStream bais;
- private DataInputStream dis;
-
- private byte[] data;
-
// Constructor ---------------------------------------------------
/*
@@ -76,20 +64,25 @@
super(JBossBytesMessage.TYPE);
}
- public JBossBytesMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
+ /*
+ * Constructor on receipt at client side
+ */
+ public JBossBytesMessage(
+ final org.jboss.messaging.core.message.Message message,
+ final ClientSession session)
{
super(message, session);
}
- public JBossBytesMessage(BytesMessage foreign) throws JMSException
+ /*
+ * Foreign message constructor
+ */
+ public JBossBytesMessage(final BytesMessage foreign) throws JMSException
{
super(foreign, JBossBytesMessage.TYPE);
foreign.reset();
- baos = new ByteArrayOutputStream();
- dos = new DataOutputStream(baos);
-
byte[] buffer = new byte[1024];
int n = foreign.readBytes(buffer);
while (n != -1)
@@ -106,18 +99,12 @@
checkRead();
try
{
- return dis.readBoolean();
+ return body.getBoolean();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
}
public byte readByte() throws JMSException
@@ -125,18 +112,12 @@
checkRead();
try
{
- return dis.readByte();
+ return body.getByte();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
}
public int readUnsignedByte() throws JMSException
@@ -144,18 +125,12 @@
checkRead();
try
{
- return dis.readUnsignedByte();
+ return body.getUnsignedByte();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
}
public short readShort() throws JMSException
@@ -163,18 +138,12 @@
checkRead();
try
{
- return dis.readShort();
+ return body.getShort();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
}
public int readUnsignedShort() throws JMSException
@@ -182,18 +151,12 @@
checkRead();
try
{
- return dis.readUnsignedShort();
+ return body.getUnsignedShort();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
}
public char readChar() throws JMSException
@@ -201,18 +164,12 @@
checkRead();
try
{
- return dis.readChar();
+ return body.getChar();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
}
public int readInt() throws JMSException
@@ -220,18 +177,12 @@
checkRead();
try
{
- return dis.readInt();
+ return body.getInt();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
}
public long readLong() throws JMSException
@@ -239,18 +190,12 @@
checkRead();
try
{
- return dis.readLong();
+ return body.getLong();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
}
public float readFloat() throws JMSException
@@ -258,18 +203,12 @@
checkRead();
try
{
- return dis.readFloat();
+ return body.getFloat();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
}
public double readDouble() throws JMSException
@@ -277,18 +216,12 @@
checkRead();
try
{
- return dis.readDouble();
+ return body.getDouble();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
}
public String readUTF() throws JMSException
@@ -296,416 +229,212 @@
checkRead();
try
{
- return dis.readUTF();
+ return body.getUTF();
}
- catch (EOFException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
- catch (IOException e)
+ catch (Exception e)
{
- JMSException je = new JMSException("IOException");
- je.initCause(e);
+ JMSException je = new JMSException("Failed to get UTF");
+ je.setLinkedException(e);
throw je;
}
}
- public int readBytes(byte[] value) throws JMSException
+ public int readBytes(final byte[] value) throws JMSException
{
- checkRead();
- try
- {
- return dis.read(value);
- }
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+ return readBytes(value, value.length);
}
- public int readBytes(byte[] value, int length) throws JMSException
+ public int readBytes(final byte[] value, final int length)
+ throws JMSException
{
checkRead();
- try
+
+ if (body.remaining() == 0) { return -1; }
+
+ int read = Math.min(length, body.remaining());
+
+ if (read != 0)
{
- return dis.read(value, 0, length);
+ body.getBytes(value, 0, read);
}
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+
+ return read;
}
- public void writeBoolean(boolean value) throws JMSException
+ public void writeBoolean(final boolean value) throws JMSException
{
checkWrite();
- try
- {
- dos.writeBoolean(value);
- }
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+ body.putBoolean(value);
}
- public void writeByte(byte value) throws JMSException
+ public void writeByte(final byte value) throws JMSException
{
checkWrite();
- try
- {
- dos.writeByte(value);
- }
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+ body.putByte(value);
}
- public void writeShort(short value) throws JMSException
+ public void writeShort(final short value) throws JMSException
{
checkWrite();
- try
- {
- dos.writeShort(value);
- }
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+ body.putShort(value);
}
- public void writeChar(char value) throws JMSException
+ public void writeChar(final char value) throws JMSException
{
checkWrite();
- try
- {
- dos.writeChar(value);
- }
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+ body.putChar(value);
}
- public void writeInt(int value) throws JMSException
+ public void writeInt(final int value) throws JMSException
{
checkWrite();
- try
- {
- dos.writeInt(value);
- }
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+ body.putInt(value);
}
- public void writeLong(long value) throws JMSException
+ public void writeLong(final long value) throws JMSException
{
checkWrite();
- try
- {
- dos.writeLong(value);
- }
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+ body.putLong(value);
}
- public void writeFloat(float value) throws JMSException
+ public void writeFloat(final float value) throws JMSException
{
checkWrite();
- try
- {
- dos.writeFloat(value);
- }
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+ body.putFloat(value);
}
- public void writeDouble(double value) throws JMSException
+ public void writeDouble(final double value) throws JMSException
{
checkWrite();
- try
- {
- dos.writeDouble(value);
- }
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+ body.putDouble(value);
}
- public void writeUTF(String value) throws JMSException
+ public void writeUTF(final String value) throws JMSException
{
checkWrite();
try
{
- dos.writeUTF((String) value);
+ body.putUTF(value);
}
- catch (IOException e)
+ catch (Exception e)
{
- JMSException je = new JMSException("IOException");
- je.initCause(e);
+ JMSException je = new JMSException("Failed to write UTF");
+ je.setLinkedException(e);
throw je;
}
}
- public void writeBytes(byte[] value) throws JMSException
+ public void writeBytes(final byte[] value) throws JMSException
{
checkWrite();
- try
- {
- dos.write(value, 0, value.length);
- }
- catch (IOException e)
- {
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
- }
+ body.putBytes(value);
}
- public void writeBytes(byte[] value, int offset, int length)
+ public void writeBytes(final byte[] value, final int offset, final int length)
throws JMSException
{
checkWrite();
- try
+ body.putBytes(value, offset, length);
+ }
+
+ public void writeObject(final Object value) throws JMSException
+ {
+ if (value == null) { throw new NullPointerException(
+ "Attempt to write a null value"); }
+ if (value instanceof String)
{
- dos.write(value, offset, length);
+ writeUTF((String) value);
}
- catch (IOException e)
+ else if (value instanceof Boolean)
{
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
+ writeBoolean((Boolean) value);
}
- }
-
- public void writeObject(Object value) throws JMSException
- {
- checkWrite();
- try
+ else if (value instanceof Byte)
{
- if (value == null) { throw new NullPointerException(
- "Attempt to write a new value"); }
- if (value instanceof String)
- {
- dos.writeUTF((String) value);
- }
- else if (value instanceof Boolean)
- {
- dos.writeBoolean(((Boolean) value).booleanValue());
- }
- else if (value instanceof Byte)
- {
- dos.writeByte(((Byte) value).byteValue());
- }
- else if (value instanceof Short)
- {
- dos.writeShort(((Short) value).shortValue());
- }
- else if (value instanceof Integer)
- {
- dos.writeInt(((Integer) value).intValue());
- }
- else if (value instanceof Long)
- {
- dos.writeLong(((Long) value).longValue());
- }
- else if (value instanceof Float)
- {
- dos.writeFloat(((Float) value).floatValue());
- }
- else if (value instanceof Double)
- {
- dos.writeDouble(((Double) value).doubleValue());
- }
- else if (value instanceof byte[])
- {
- dos.write((byte[]) value, 0, ((byte[]) value).length);
- }
- else
- {
- throw new MessageFormatException("Invalid object for properties");
- }
+ writeByte((Byte) value);
}
- catch (IOException e)
+ else if (value instanceof Short)
{
- JMSException je = new JMSException("IOException");
- je.initCause(e);
- throw je;
+ writeShort((Short) value);
}
+ else if (value instanceof Integer)
+ {
+ writeInt((Integer) value);
+ }
+ else if (value instanceof Long)
+ {
+ writeLong((Long) value);
+ }
+ else if (value instanceof Float)
+ {
+ writeFloat((Float) value);
+ }
+ else if (value instanceof Double)
+ {
+ writeDouble((Double) value);
+ }
+ else if (value instanceof byte[])
+ {
+ writeBytes((byte[]) value);
+ }
+ else
+ {
+ throw new MessageFormatException("Invalid object for properties");
+ }
}
public void reset() throws JMSException
{
- try
+ if (!readOnly)
{
- if (baos != null)
- {
- dos.flush();
+ readOnly = true;
- data = baos.toByteArray();
-
- baos.close();
- }
- baos = null;
- bais = null;
- dis = null;
- dos = null;
+ body.flip();
}
- catch (Exception e)
+ else
{
- JMSException e2 = new JMSException(e.getMessage());
- e2.setStackTrace(e.getStackTrace());
- throw e2;
+ body.rewind();
}
-
- readOnly = true;
}
// JBossMessage overrides ----------------------------------------
-
+
public void clearBody() throws JMSException
{
super.clearBody();
-
- try
- {
- if (baos != null)
- {
- baos.close();
- }
- else
- {
- if (bais != null)
- {
- bais.close();
- }
- }
- }
- catch (IOException e)
- {
- // don't throw an exception
- }
- baos = new ByteArrayOutputStream();
- dos = new DataOutputStream(baos);
- data = null;
- bais = null;
- dis = null;
+ body = new BufferWrapper(1024);
}
public long getBodyLength() throws JMSException
{
checkRead();
- if (data != null)
- {
- return data.length;
- }
- else
- {
- return 0;
- }
+ return body.limit();
}
-
-
- // Public --------------------------------------------------------
-
- public byte getType()
- {
- return JBossBytesMessage.TYPE;
- }
-
public void doBeforeSend() throws Exception
{
reset();
- beforeSend();
+ message.setBody(body);
}
- public void doBeforeReceive() throws Exception
+ // Public --------------------------------------------------------
+
+ public byte getType()
{
- beforeReceive();
+ return JBossBytesMessage.TYPE;
}
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
-
- protected void checkRead() throws JMSException
- {
- super.checkRead();
-
- if (bais == null)
- {
- bais = new ByteArrayInputStream(data);
- dis = new DataInputStream(bais);
- }
- }
-
- protected void checkWrite() throws JMSException
- {
- super.checkWrite();
-
- if (baos == null)
- {
- baos = new ByteArrayOutputStream();
- dos = new DataOutputStream(baos);
- }
- }
-
- protected void writePayload(DataOutputStream daos) throws Exception
- {
- if (data == null)
- {
- daos.writeInt(0);
- }
- else
- {
- daos.writeInt(data.length);
- daos.write(data);
- }
- }
-
- protected void readPayload(DataInputStream dais) throws Exception
- {
- int length = dais.readInt();
-
- data = new byte[length];
-
- dais.read(data);
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossMapMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossMapMessage.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossMapMessage.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -21,20 +21,18 @@
*/
package org.jboss.messaging.jms.client;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashMap;
import java.util.HashSet;
-import java.util.Map;
+import java.util.Set;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageFormatException;
import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.util.StreamUtils;
+import org.jboss.messaging.util.SimpleString;
+import org.jboss.messaging.util.TypedProperties;
/**
* This class implements javax.jms.MapMessage
@@ -56,7 +54,7 @@
// Attributes ----------------------------------------------------
- private Map<String, Object> map = new HashMap<String, Object>();
+ private TypedProperties map = new TypedProperties();
// Static --------------------------------------------------------
@@ -68,9 +66,11 @@
public JBossMapMessage()
{
super(JBossMapMessage.TYPE);
+
+ map = new TypedProperties();
}
- public JBossMapMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
+ public JBossMapMessage(final org.jboss.messaging.core.message.Message message, final ClientSession session)
{
super(message, session);
}
@@ -81,7 +81,7 @@
* @param foreign
* @throws JMSException
*/
- public JBossMapMessage(MapMessage foreign) throws JMSException
+ public JBossMapMessage(final MapMessage foreign) throws JMSException
{
super(foreign, JBossMapMessage.TYPE);
Enumeration names = foreign.getMapNames();
@@ -102,67 +102,67 @@
// MapMessage implementation -------------------------------------
- public void setBoolean(String name, boolean value) throws JMSException
+ public void setBoolean(final String name, final boolean value) throws JMSException
{
checkName(name);
- map.put(name, Boolean.valueOf(value));
+ map.putBooleanProperty(new SimpleString(name), value);
}
- public void setByte(String name, byte value) throws JMSException
+ public void setByte(final String name, final byte value) throws JMSException
{
checkName(name);
- map.put(name, Byte.valueOf(value));
+ map.putByteProperty(new SimpleString(name), value);
}
- public void setShort(String name, short value) throws JMSException
+ public void setShort(final String name, final short value) throws JMSException
{
checkName(name);
- map.put(name, Short.valueOf(value));
+ map.putShortProperty(new SimpleString(name), value);
}
- public void setChar(String name, char value) throws JMSException
+ public void setChar(final String name, final char value) throws JMSException
{
checkName(name);
- map.put(name, Character.valueOf(value));
+ map.putCharProperty(new SimpleString(name), value);
}
- public void setInt(String name, int value) throws JMSException
+ public void setInt(final String name, final int value) throws JMSException
{
checkName(name);
- map.put(name, Integer.valueOf(value));
+ map.putIntProperty(new SimpleString(name), value);
}
- public void setLong(String name, long value) throws JMSException
+ public void setLong(final String name, final long value) throws JMSException
{
checkName(name);
- map.put(name, Long.valueOf(value));
+ map.putLongProperty(new SimpleString(name), value);
}
- public void setFloat(String name, float value) throws JMSException
+ public void setFloat(final String name, final float value) throws JMSException
{
checkName(name);
- map.put(name, Float.valueOf(value));
+ map.putFloatProperty(new SimpleString(name), value);
}
- public void setDouble(String name, double value) throws JMSException
+ public void setDouble(final String name, final double value) throws JMSException
{
checkName(name);
- map.put(name, Double.valueOf(value));
+ map.putDoubleProperty(new SimpleString(name), value);
}
- public void setString(String name, String value) throws JMSException
+ public void setString(final String name, final String value) throws JMSException
{
checkName(name);
- map.put(name, value);
+ map.putStringProperty(new SimpleString(name), value == null ? null : new SimpleString(value));
}
- public void setBytes(String name, byte[] value) throws JMSException
+ public void setBytes(final String name, final byte[] value) throws JMSException
{
checkName(name);
- map.put(name, value.clone());
+ map.putBytesProperty(new SimpleString(name), value);
}
- public void setBytes(String name, byte[] value, int offset, int length) throws JMSException
+ public void setBytes(final String name, final byte[] value, final int offset, final int length) throws JMSException
{
checkName(name);
if (offset + length > value.length)
@@ -171,69 +171,70 @@
}
byte[] newBytes = new byte[length];
System.arraycopy(value, offset, newBytes, 0, length);
- map.put(name, newBytes);
+ map.putBytesProperty(new SimpleString(name), newBytes);
}
- public void setObject(String name, Object value) throws JMSException
+ public void setObject(final String name, final Object value) throws JMSException
{
checkName(name);
+ SimpleString key = new SimpleString(name);
if (value instanceof Boolean)
- map.put(name, value);
+ map.putBooleanProperty(key, (Boolean)value);
else if (value instanceof Byte)
- map.put(name, value);
+ map.putByteProperty(key, (Byte)value);
else if (value instanceof Short)
- map.put(name, value);
+ map.putShortProperty(key, (Short)value);
else if (value instanceof Character)
- map.put(name, value);
+ map.putCharProperty(key, (Character)value);
else if (value instanceof Integer)
- map.put(name, value);
+ map.putIntProperty(key, (Integer)value);
else if (value instanceof Long)
- map.put(name, value);
+ map.putLongProperty(key, (Long)value);
else if (value instanceof Float)
- map.put(name, value);
+ map.putFloatProperty(key, (Float)value);
else if (value instanceof Double)
- map.put(name, value);
+ map.putDoubleProperty(key, (Double)value);
else if (value instanceof String)
- map.put(name, value);
+ map.putStringProperty(key, new SimpleString((String)value));
else if (value instanceof byte[])
- map.put(name, ((byte[]) value).clone());
+ map.putBytesProperty(key, (byte[]) value);
else
throw new MessageFormatException("Invalid object type.");
}
- public boolean getBoolean(String name) throws JMSException
+ public boolean getBoolean(final String name) throws JMSException
{
- Object value = map.get(name);
+ Object value = map.getProperty(new SimpleString(name));
if (value == null)
return Boolean.valueOf(null).booleanValue();
if (value instanceof Boolean)
return ((Boolean) value).booleanValue();
- else if (value instanceof String)
- return Boolean.valueOf((String) value).booleanValue();
+ else if (value instanceof SimpleString)
+ return Boolean.valueOf(((SimpleString) value).toString()).booleanValue();
else
throw new MessageFormatException("Invalid conversion");
}
- public byte getByte(String name) throws JMSException
+ public byte getByte(final String name) throws JMSException
{
- Object value = map.get(name);
+ Object value = map.getProperty(new SimpleString(name));
if (value == null)
return Byte.parseByte(null);
if (value instanceof Byte)
return ((Byte) value).byteValue();
- else if (value instanceof String)
- return Byte.parseByte((String) value);
+ else if (value instanceof SimpleString)
+ return Byte.parseByte(((SimpleString) value).toString());
else
throw new MessageFormatException("Invalid conversion");
}
- public short getShort(String name) throws JMSException
+ public short getShort(final String name) throws JMSException
{
- Object value = map.get(name);
+ Object value = map.getProperty(new SimpleString(name));
if (value == null)
return Short.parseShort(null);
@@ -242,15 +243,15 @@
return ((Byte) value).shortValue();
else if (value instanceof Short)
return ((Short) value).shortValue();
- else if (value instanceof String)
- return Short.parseShort((String) value);
+ else if (value instanceof SimpleString)
+ return Short.parseShort(((SimpleString) value).toString());
else
throw new MessageFormatException("Invalid conversion");
}
- public char getChar(String name) throws JMSException
+ public char getChar(final String name) throws JMSException
{
- Object value = map.get(name);
+ Object value = map.getProperty(new SimpleString(name));
if (value == null)
throw new NullPointerException("Invalid conversion");
@@ -261,9 +262,9 @@
throw new MessageFormatException("Invalid conversion");
}
- public int getInt(String name) throws JMSException
+ public int getInt(final String name) throws JMSException
{
- Object value = map.get(name);
+ Object value = map.getProperty(new SimpleString(name));
if (value == null)
return Integer.parseInt(null);
@@ -274,15 +275,15 @@
return ((Short) value).intValue();
else if (value instanceof Integer)
return ((Integer) value).intValue();
- else if (value instanceof String)
- return Integer.parseInt((String) value);
+ else if (value instanceof SimpleString)
+ return Integer.parseInt(((SimpleString) value).toString());
else
throw new MessageFormatException("Invalid conversion");
}
- public long getLong(String name) throws JMSException
+ public long getLong(final String name) throws JMSException
{
- Object value = map.get(name);
+ Object value = map.getProperty(new SimpleString(name));
if (value == null)
return Long.parseLong(null);
@@ -295,30 +296,30 @@
return ((Integer) value).longValue();
else if (value instanceof Long)
return ((Long) value).longValue();
- else if (value instanceof String)
- return Long.parseLong((String) value);
+ else if (value instanceof SimpleString)
+ return Long.parseLong(((SimpleString) value).toString());
else
throw new MessageFormatException("Invalid conversion");
}
- public float getFloat(String name) throws JMSException
+ public float getFloat(final String name) throws JMSException
{
- Object value = map.get(name);
+ Object value = map.getProperty(new SimpleString(name));
if (value == null)
return Float.parseFloat(null);
if (value instanceof Float)
return ((Float) value).floatValue();
- else if (value instanceof String)
- return Float.parseFloat((String) value);
+ else if (value instanceof SimpleString)
+ return Float.parseFloat(((SimpleString) value).toString());
else
throw new MessageFormatException("Invalid conversion");
}
- public double getDouble(String name) throws JMSException
+ public double getDouble(final String name) throws JMSException
{
- Object value = map.get(name);
+ Object value = map.getProperty(new SimpleString(name));
if (value == null)
return Double.parseDouble(null);
@@ -327,21 +328,25 @@
return ((Float) value).doubleValue();
else if (value instanceof Double)
return ((Double) value).doubleValue();
- else if (value instanceof String)
- return Double.parseDouble((String) value);
+ else if (value instanceof SimpleString)
+ return Double.parseDouble(((SimpleString) value).toString());
else
throw new MessageFormatException("Invalid conversion");
}
- public String getString(String name) throws JMSException
+ public String getString(final String name) throws JMSException
{
- Object value = map.get(name);
+ Object value = map.getProperty(new SimpleString(name));
if (value == null)
return null;
- if (value instanceof Boolean)
+ if (value instanceof SimpleString)
{
+ return ((SimpleString) value).toString();
+ }
+ else if (value instanceof Boolean)
+ {
return value.toString();
}
else if (value instanceof Byte)
@@ -372,19 +377,15 @@
{
return value.toString();
}
- else if (value instanceof String)
- {
- return (String) value;
- }
else
{
throw new MessageFormatException("Invalid conversion");
}
}
- public byte[] getBytes(String name) throws JMSException
+ public byte[] getBytes(final String name) throws JMSException
{
- Object value = map.get(name);
+ Object value = map.getProperty(new SimpleString(name));
if (value == null)
return null;
@@ -394,19 +395,33 @@
throw new MessageFormatException("Invalid conversion");
}
- public Object getObject(String name) throws JMSException
+ public Object getObject(final String name) throws JMSException
{
- return map.get(name);
+ Object val = map.getProperty(new SimpleString(name));
+
+ if (val instanceof SimpleString)
+ {
+ val = ((SimpleString)val).toString();
+ }
+
+ return val;
}
public Enumeration getMapNames() throws JMSException
{
- return Collections.enumeration(new HashSet<String>(map.keySet()));
+ Set propNames = new HashSet<String>();
+
+ for (SimpleString str: map.getPropertyNames())
+ {
+ propNames.add(str.toString());
+ }
+
+ return Collections.enumeration(propNames);
}
- public boolean itemExists(String name) throws JMSException
+ public boolean itemExists(final String name) throws JMSException
{
- return map.containsKey(name);
+ return map.containsProperty(new SimpleString(name));
}
// JBossMessage overrides ----------------------------------------
@@ -420,29 +435,22 @@
public void doBeforeSend() throws Exception
{
- beforeSend();
+ map.encode(body);
+
+ super.doBeforeSend();
}
public void doBeforeReceive() throws Exception
- {
- beforeReceive();
+ {
+ super.doBeforeReceive();
+
+ map.decode(body);
}
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
- protected void writePayload(DataOutputStream daos) throws Exception
- {
- StreamUtils.writeMap(daos, map, false);
- }
-
- protected void readPayload(DataInputStream dais) throws Exception
- {
- map = StreamUtils.readMap(dais, false);
- }
-
// Private -------------------------------------------------------
/**
@@ -452,7 +460,7 @@
*/
private void checkName(String name) throws JMSException
{
- checkWrite();
+ checkWrite();
if (name == null)
{
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossMessage.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -21,17 +21,15 @@
*/
package org.jboss.messaging.jms.client;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
-import java.util.Iterator;
+import java.util.List;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
+import javax.jms.InvalidDestinationException;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageFormatException;
@@ -42,6 +40,10 @@
import org.jboss.messaging.core.exception.MessagingException;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
+import org.jboss.messaging.jms.JBossDestination;
+import org.jboss.messaging.util.MessagingBuffer;
+import org.jboss.messaging.util.SimpleString;
/**
*
@@ -65,35 +67,25 @@
{
// Constants -----------------------------------------------------
- //FIXME - this will disappear
- private static final String DESTINATION_HEADER_NAME = "JMSDestination2";
+ private static final SimpleString REPLYTO_HEADER_NAME = new SimpleString("JMSReplyTo");
- private static final String REPLYTO_HEADER_NAME = "JMSReplyTo";
-
- private static final String CORRELATIONID_HEADER_NAME = "JMSCorrelationID";
+ private static final SimpleString CORRELATIONID_HEADER_NAME = new SimpleString("JMSCorrelationID");
- private static final String JBM_MESSAGE_ID = "JMSMessageID";
+ private static final SimpleString JBM_MESSAGE_ID = new SimpleString("JMSMessageID");
- private static final String TYPE_HEADER_NAME = "JMSType";
+ private static final SimpleString TYPE_HEADER_NAME = new SimpleString("JMSType");
- public static final String JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME = "JMS_JBOSS_SCHEDULED_DELIVERY";
+ private static final SimpleString JMS = new SimpleString("JMS");
- //Used when sending a message to the DLQ
- public static final String JBOSS_MESSAGING_ORIG_DESTINATION = "JBM_ORIG_DESTINATION";
-
- //Used when sending a message to the DLQ
- public static final String JBOSS_MESSAGING_ORIG_MESSAGE_ID = "JBM_ORIG_MESSAGE_ID";
+ private static final SimpleString JMSX = new SimpleString("JMSX");
- //Used when sending a mesage to the DLQ
- public static final String JBOSS_MESSAGING_ACTUAL_EXPIRY_TIME = "JBM_ACTUAL_EXPIRY";
+ private static final SimpleString JMS_ = new SimpleString("JMS_");
+ private static final String JMSXDELIVERYCOUNT = "JMSXDeliveryCount";
+
//Used when bridging a message
public static final String JBOSS_MESSAGING_BRIDGE_MESSAGE_ID_LIST = "JBM_BRIDGE_MSG_ID_LIST";
- protected static final byte NULL = 0;
-
- protected static final byte NOT_NULL = 1;
-
private static final int TYPE = 0;
// Static --------------------------------------------------------
@@ -115,9 +107,8 @@
}
private static final Logger log = Logger.getLogger(JBossMessage.class);
-
-
- public static JBossMessage createMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
+
+ public static JBossMessage createMessage(final org.jboss.messaging.core.message.Message message, final ClientSession session)
{
int type = message.getType();
@@ -147,8 +138,6 @@
throw new IllegalArgumentException("Invalid message type " + type);
}
- message.putHeader("JMSXDeliveryCount", message.getDeliveryCount());
-
return msg;
}
@@ -157,16 +146,39 @@
//The underlying message
protected org.jboss.messaging.core.message.Message message;
+ protected MessagingBuffer body;
+
private ClientSession session;
//Read-only?
protected boolean readOnly;
-
+
+ //Cache it
+ private Destination dest;
+
+ //Cache it
+ private String msgID;
+
+ //Cache it
+ private Destination replyTo;
+
+ //Cache it
+ private String jmsCorrelationID;
+
+ //Cache it
+ private String jmsType;
+
// Constructors --------------------------------------------------
- protected JBossMessage(int type)
+ /*
+ * Create a new message prior to sending
+ */
+ protected JBossMessage(final int type)
{
message = new MessageImpl(type, true, 0, System.currentTimeMillis(), (byte)4);
+
+ //TODO - can we lazily create this?
+ body = message.getBody();
}
public JBossMessage()
@@ -177,24 +189,26 @@
/**
* Constructor for when receiving a message from the server
*/
- public JBossMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
+ public JBossMessage(final org.jboss.messaging.core.message.Message message, ClientSession session)
{
this.message = message;
this.readOnly = true;
this.session = session;
+
+ this.body = message.getBody();
}
/*
* A constructor that takes a foreign message
*/
- public JBossMessage(Message foreign) throws JMSException
+ public JBossMessage(final Message foreign) throws JMSException
{
this(foreign, JBossMessage.TYPE);
}
- protected JBossMessage(Message foreign, int type) throws JMSException
+ protected JBossMessage(final Message foreign, final int type) throws JMSException
{
this(type);
@@ -219,7 +233,7 @@
setJMSDestination(foreign.getJMSDestination());
setJMSDeliveryMode(foreign.getJMSDeliveryMode());
setJMSExpiration(foreign.getJMSExpiration());
- setJMSPriority(foreign.getJMSPriority());
+ setJMSPriority(foreign.getJMSPriority());
setJMSType(foreign.getJMSType());
//We can't avoid a cast warning here since getPropertyNames() is on the JMS API
@@ -237,10 +251,16 @@
public String getJMSMessageID()
{
- return (String)message.getHeader(JBM_MESSAGE_ID);
+ if (msgID == null)
+ {
+ SimpleString id = (SimpleString)message.getProperty(JBM_MESSAGE_ID);
+
+ msgID = id == null ? null : id.toString();
+ }
+ return msgID;
}
-
- public void setJMSMessageID(String jmsMessageID) throws JMSException
+
+ public void setJMSMessageID(final String jmsMessageID) throws JMSException
{
if (jmsMessageID != null && !jmsMessageID.startsWith("ID:"))
{
@@ -248,12 +268,13 @@
}
if (jmsMessageID == null)
{
- message.removeHeader(JBM_MESSAGE_ID);
+ message.removeProperty(JBM_MESSAGE_ID);
}
else
{
- message.putHeader(JBM_MESSAGE_ID, jmsMessageID);
+ message.putStringProperty(JBM_MESSAGE_ID, new SimpleString(jmsMessageID));
}
+ msgID = jmsMessageID;
}
public long getJMSTimestamp() throws JMSException
@@ -261,14 +282,14 @@
return message.getTimestamp();
}
- public void setJMSTimestamp(long timestamp) throws JMSException
+ public void setJMSTimestamp(final long timestamp) throws JMSException
{
message.setTimestamp(timestamp);
}
public byte[] getJMSCorrelationIDAsBytes() throws JMSException
{
- Object obj = message.getHeader(CORRELATIONID_HEADER_NAME);
+ Object obj = message.getProperty(CORRELATIONID_HEADER_NAME);
if (obj instanceof byte[])
{
@@ -280,52 +301,98 @@
}
}
- public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException
+ public void setJMSCorrelationIDAsBytes(final byte[] correlationID) throws JMSException
{
if (correlationID == null || correlationID.length == 0)
{
throw new JMSException("Please specify a non-zero length byte[]");
}
- message.putHeader(CORRELATIONID_HEADER_NAME, correlationID);
+ message.putBytesProperty(CORRELATIONID_HEADER_NAME, correlationID);
}
- public void setJMSCorrelationID(String correlationID) throws JMSException
+ public void setJMSCorrelationID(final String correlationID) throws JMSException
{
- message.putHeader(CORRELATIONID_HEADER_NAME, correlationID);
+ if (correlationID == null)
+ {
+ message.removeProperty(CORRELATIONID_HEADER_NAME);
+
+ jmsCorrelationID = null;
+ }
+ else
+ {
+ message.putStringProperty(CORRELATIONID_HEADER_NAME, new SimpleString(correlationID));
+
+ jmsCorrelationID = correlationID;
+ }
}
-
+
public String getJMSCorrelationID() throws JMSException
{
- Object obj = message.getHeader(CORRELATIONID_HEADER_NAME);
-
- if (obj instanceof String)
+ if (jmsCorrelationID == null)
{
- return (String)obj;
+ Object obj = message.getProperty(CORRELATIONID_HEADER_NAME);
+
+ if (obj != null)
+ {
+ jmsCorrelationID = ((SimpleString)obj).toString();
+ }
}
- else
- {
- return null;
- }
+
+ return jmsCorrelationID;
}
-
+
public Destination getJMSReplyTo() throws JMSException
{
- return (Destination)message.getHeader(REPLYTO_HEADER_NAME);
+ if (replyTo == null)
+ {
+ SimpleString repl = (SimpleString)message.getProperty(REPLYTO_HEADER_NAME);
+
+ if (repl != null)
+ {
+ replyTo = JBossDestination.fromAddress(repl.toString());
+ }
+ }
+ return replyTo;
}
- public void setJMSReplyTo(Destination replyTo) throws JMSException
+ public void setJMSReplyTo(final Destination dest) throws JMSException
{
- message.putHeader(REPLYTO_HEADER_NAME, replyTo);
+ if (dest == null)
+ {
+ message.removeProperty(REPLYTO_HEADER_NAME);
+
+ replyTo = null;
+ }
+ else
+ {
+ if (dest instanceof JBossDestination == false)
+ {
+ throw new InvalidDestinationException("Not a JBoss destination " + dest);
+ }
+
+ JBossDestination jbd = (JBossDestination)dest;
+
+ message.putStringProperty(REPLYTO_HEADER_NAME, jbd.getSimpleAddress());
+
+ replyTo = jbd;
+ }
}
-
+
public Destination getJMSDestination() throws JMSException
{
- return (Destination)message.getHeader(DESTINATION_HEADER_NAME);
+ if (dest == null)
+ {
+ SimpleString sdest = message.getDestination();
+
+ dest = sdest == null ? null : JBossDestination.fromAddress(sdest.toString());
+ }
+
+ return dest;
}
- public void setJMSDestination(Destination destination) throws JMSException
+ public void setJMSDestination(final Destination destination) throws JMSException
{
- message.putHeader(DESTINATION_HEADER_NAME, destination);
+ this.dest = destination;
}
public int getJMSDeliveryMode() throws JMSException
@@ -333,7 +400,7 @@
return message.isDurable() ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT;
}
- public void setJMSDeliveryMode(int deliveryMode) throws JMSException
+ public void setJMSDeliveryMode(final int deliveryMode) throws JMSException
{
if (deliveryMode == DeliveryMode.PERSISTENT)
{
@@ -355,7 +422,7 @@
return message.getDeliveryCount() > 1;
}
- public void setJMSRedelivered(boolean redelivered) throws JMSException
+ public void setJMSRedelivered(final boolean redelivered) throws JMSException
{
if (message.getDeliveryCount() > 1)
{
@@ -366,24 +433,29 @@
message.setDeliveryCount(2);
}
}
-
- /**
- * @return The JMSType header
- * @throws JMSException
- */
- public String getJMSType() throws JMSException
+
+ public void setJMSType(final String type) throws JMSException
{
- return (String)message.getHeader(TYPE_HEADER_NAME);
+ if (type != null)
+ {
+ message.putStringProperty(TYPE_HEADER_NAME, new SimpleString(type));
+
+ jmsType = type;
+ }
}
- /**
- *
- * @param type
- * @throws JMSException
- */
- public void setJMSType(String type) throws JMSException
+ public String getJMSType() throws JMSException
{
- message.putHeader(TYPE_HEADER_NAME, type);
+ if (jmsType == null)
+ {
+ SimpleString ss = (SimpleString)message.getProperty(TYPE_HEADER_NAME);
+
+ if (ss != null)
+ {
+ jmsType = ss.toString();
+ }
+ }
+ return jmsType;
}
public long getJMSExpiration() throws JMSException
@@ -391,7 +463,7 @@
return message.getExpiration();
}
- public void setJMSExpiration(long expiration) throws JMSException
+ public void setJMSExpiration(final long expiration) throws JMSException
{
message.setExpiration(expiration);
}
@@ -401,36 +473,26 @@
return message.getPriority();
}
- public void setJMSPriority(int priority) throws JMSException
+ public void setJMSPriority(final int priority) throws JMSException
{
message.setPriority((byte)priority);
}
-
+
public void clearProperties() throws JMSException
- {
- Iterator<String> iter = message.getHeaders().keySet().iterator();
+ {
+ List<SimpleString> toRemove = new ArrayList<SimpleString>();
- while (iter.hasNext())
+ for (SimpleString propName: message.getPropertyNames())
{
- String propName = iter.next();
-
- boolean remove = false;
- if (!propName.startsWith("JMS"))
+ if (!propName.startsWith(JMS) || propName.startsWith(JMSX) || propName.startsWith(JMS_))
{
- remove = true;
+ toRemove.add(propName);
}
- else
- {
- if (propName.startsWith("JMSX") || propName.startsWith("JMS_"))
- {
- remove = true;
- }
- }
-
- if (remove)
- {
- iter.remove();
- }
+ }
+
+ for (SimpleString propName: toRemove)
+ {
+ message.removeProperty(propName);
}
}
@@ -439,43 +501,43 @@
readOnly = false;
}
- public boolean propertyExists(String name) throws JMSException
+ public boolean propertyExists(final String name) throws JMSException
{
- return message.containsHeader(name)
- || name.equals("JMSXDeliveryCount");
+ return message.containsProperty(new SimpleString(name))
+ || name.equals(JMSXDELIVERYCOUNT);
}
- public boolean getBooleanProperty(String name) throws JMSException
+ public boolean getBooleanProperty(final String name) throws JMSException
{
- Object value = message.getHeader(name);
+ Object value = message.getProperty(new SimpleString(name));
if (value == null)
return Boolean.valueOf(null).booleanValue();
if (value instanceof Boolean)
return ((Boolean) value).booleanValue();
- else if (value instanceof String)
- return Boolean.valueOf((String) value).booleanValue();
+ else if (value instanceof SimpleString)
+ return Boolean.valueOf(((SimpleString) value).toString()).booleanValue();
else
throw new MessageFormatException("Invalid conversion");
}
- public byte getByteProperty(String name) throws JMSException
+ public byte getByteProperty(final String name) throws JMSException
{
- Object value = message.getHeader(name);
+ Object value = message.getProperty(new SimpleString(name));
if (value == null)
throw new NumberFormatException("Message property '" + name + "' not set.");
if (value instanceof Byte)
return ((Byte) value).byteValue();
- else if (value instanceof String)
- return Byte.parseByte((String) value);
+ else if (value instanceof SimpleString)
+ return Byte.parseByte(((SimpleString) value).toString());
else
throw new MessageFormatException("Invalid conversion");
}
- public short getShortProperty(String name) throws JMSException
+ public short getShortProperty(final String name) throws JMSException
{
- Object value = message.getHeader(name);
+ Object value = message.getProperty(new SimpleString(name));
if (value == null)
throw new NumberFormatException("Message property '" + name + "' not set.");
@@ -483,15 +545,20 @@
return ((Byte) value).shortValue();
else if (value instanceof Short)
return ((Short) value).shortValue();
- else if (value instanceof String)
- return Short.parseShort((String) value);
+ else if (value instanceof SimpleString)
+ return Short.parseShort(((SimpleString) value).toString());
else
throw new MessageFormatException("Invalid conversion");
}
- public int getIntProperty(String name) throws JMSException
+ public int getIntProperty(final String name) throws JMSException
{
- Object value = message.getHeader(name);
+ if (JMSXDELIVERYCOUNT.equals(name))
+ {
+ return message.getDeliveryCount();
+ }
+
+ Object value = message.getProperty(new SimpleString(name));
if (value == null)
{
@@ -510,9 +577,9 @@
{
return ((Integer) value).intValue();
}
- else if (value instanceof String)
+ else if (value instanceof SimpleString)
{
- return Integer.parseInt((String) value);
+ return Integer.parseInt(((SimpleString) value).toString());
}
else
{
@@ -520,9 +587,14 @@
}
}
- public long getLongProperty(String name) throws JMSException
+ public long getLongProperty(final String name) throws JMSException
{
- Object value = message.getHeader(name);
+ if (JMSXDELIVERYCOUNT.equals(name))
+ {
+ return message.getDeliveryCount();
+ }
+
+ Object value = message.getProperty(new SimpleString(name));
if (value == null)
{
@@ -545,9 +617,9 @@
{
return ((Long) value).longValue();
}
- else if (value instanceof String)
+ else if (value instanceof SimpleString)
{
- return Long.parseLong((String) value);
+ return Long.parseLong(((SimpleString) value).toString());
}
else
{
@@ -555,23 +627,23 @@
}
}
- public float getFloatProperty(String name) throws JMSException
+ public float getFloatProperty(final String name) throws JMSException
{
- Object value = message.getHeader(name);
+ Object value = message.getProperty(new SimpleString(name));
if (value == null)
return Float.valueOf(null).floatValue();
if (value instanceof Float)
return ((Float) value).floatValue();
- else if (value instanceof String)
- return Float.parseFloat((String) value);
+ else if (value instanceof SimpleString)
+ return Float.parseFloat(((SimpleString) value).toString());
else
throw new MessageFormatException("Invalid conversion");
}
- public double getDoubleProperty(String name) throws JMSException
+ public double getDoubleProperty(final String name) throws JMSException
{
- Object value = message.getHeader(name);
+ Object value = message.getProperty(new SimpleString(name));
if (value == null)
return Double.valueOf(null).doubleValue();
@@ -579,20 +651,28 @@
return ((Float) value).doubleValue();
else if (value instanceof Double)
return ((Double) value).doubleValue();
- else if (value instanceof String)
- return Double.parseDouble((String) value);
+ else if (value instanceof SimpleString)
+ return Double.parseDouble(((SimpleString) value).toString());
else
throw new MessageFormatException("Invalid conversion");
}
- public String getStringProperty(String name) throws JMSException
+ public String getStringProperty(final String name) throws JMSException
{
- Object value = message.getHeader(name);
+ if (JMSXDELIVERYCOUNT.equals(name))
+ {
+ return String.valueOf(message.getDeliveryCount());
+ }
+ Object value = message.getProperty(new SimpleString(name));
if (value == null)
return null;
- if (value instanceof Boolean)
+ if (value instanceof SimpleString)
{
+ return ((SimpleString) value).toString();
+ }
+ else if (value instanceof Boolean)
+ {
return value.toString();
}
else if (value instanceof Byte)
@@ -619,123 +699,139 @@
{
return value.toString();
}
- else if (value instanceof String)
- {
- return (String) value;
- }
else
{
throw new MessageFormatException("Invalid conversion");
}
}
- public Object getObjectProperty(String name) throws JMSException
+ public Object getObjectProperty(final String name) throws JMSException
{
- return message.getHeader(name);
+ if (JMSXDELIVERYCOUNT.equals(name))
+ {
+ return String.valueOf(message.getDeliveryCount());
+ }
+ Object val = message.getProperty(new SimpleString(name));
+ if (val instanceof SimpleString)
+ {
+ val = ((SimpleString)val).toString();
+ }
+ return val;
}
public Enumeration getPropertyNames() throws JMSException
{
HashSet<String> set = new HashSet<String>();
- for (String propName: message.getHeaders().keySet())
+ for (SimpleString propName: message.getPropertyNames())
{
- boolean add = false;
- if (!propName.startsWith("JMS"))
+ if (!propName.startsWith(JMS) || propName.startsWith(JMSX) || propName.startsWith(JMS_))
{
- add = true;
+ set.add(propName.toString());
}
- else
- {
- if (propName.startsWith("JMSX") || propName.startsWith("JMS_"))
- {
- add = true;
- }
- }
-
- if (add)
- {
- set.add(propName);
- }
}
+ set.add(JMSXDELIVERYCOUNT);
+
return Collections.enumeration(set);
}
- public void setBooleanProperty(String name, boolean value) throws JMSException
+ public void setBooleanProperty(final String name, final boolean value) throws JMSException
{
Boolean b = Boolean.valueOf(value);
checkProperty(name, b);
- message.putHeader(name, b);
+ message.putBooleanProperty(new SimpleString(name), b);
}
- public void setByteProperty(String name, byte value) throws JMSException
+ public void setByteProperty(final String name, final byte value) throws JMSException
{
Byte b = new Byte(value);
checkProperty(name, b);
- message.putHeader(name, b);
+ message.putByteProperty(new SimpleString(name), value);
}
- public void setShortProperty(String name, short value) throws JMSException
+ public void setShortProperty(final String name, final short value) throws JMSException
{
Short s = new Short(value);
checkProperty(name, s);
- message.putHeader(name, s);
+ message.putShortProperty(new SimpleString(name), value);
}
- public void setIntProperty(String name, int value) throws JMSException
+ public void setIntProperty(final String name, final int value) throws JMSException
{
Integer i = new Integer(value);
checkProperty(name, i);
- message.putHeader(name, i);
+ message.putIntProperty(new SimpleString(name), value);
}
- public void setLongProperty(String name, long value) throws JMSException
+ public void setLongProperty(final String name, final long value) throws JMSException
{
Long l = new Long(value);
checkProperty(name, l);
- message.putHeader(name, l);
+ message.putLongProperty(new SimpleString(name), value);
}
- public void setFloatProperty(String name, float value) throws JMSException
+ public void setFloatProperty(final String name, final float value) throws JMSException
{
Float f = new Float(value);
checkProperty(name, f);
- message.putHeader(name, f);
+ message.putFloatProperty(new SimpleString(name), f);
}
- public void setDoubleProperty(String name, double value) throws JMSException
+ public void setDoubleProperty(final String name, final double value) throws JMSException
{
Double d = new Double(value);
checkProperty(name, d);
- message.putHeader(name, d);
+ message.putDoubleProperty(new SimpleString(name), d);
}
- public void setStringProperty(String name, String value) throws JMSException
+ public void setStringProperty(final String name, final String value) throws JMSException
{
checkProperty(name, value);
- message.putHeader(name, value);
+ message.putStringProperty(new SimpleString(name), new SimpleString(value));
}
- public void setObjectProperty(String name, Object value) throws JMSException
+ public void setObjectProperty(final String name, final Object value) throws JMSException
{
checkProperty(name, value);
+
+ SimpleString key = new SimpleString(name);
- if ((value instanceof Boolean)
- || (value instanceof Byte)
- || (value instanceof Short)
- || (value instanceof Integer)
- || (value instanceof Long)
- || (value instanceof Float)
- || (value instanceof Double)
- || (value instanceof String)
- || (value == null))
+ if (value instanceof Boolean)
{
- message.putHeader(name, value);
+ message.putBooleanProperty(key, (Boolean)value);
}
+ else if (value instanceof Byte)
+ {
+ message.putByteProperty(key, (Byte)value);
+ }
+ else if (value instanceof Short)
+ {
+ message.putShortProperty(key, (Short)value);
+ }
+ else if (value instanceof Integer)
+ {
+ message.putIntProperty(key, (Integer)value);
+ }
+ else if (value instanceof Long)
+ {
+ message.putLongProperty(key, (Long)value);
+ }
+ else if (value instanceof Float)
+ {
+ message.putFloatProperty(key, (Float)value);
+ }
+ else if (value instanceof Double)
+ {
+ message.putDoubleProperty(key, (Double)value);
+ }
+ else if (value instanceof String)
+ {
+ message.putStringProperty(key, new SimpleString((String)value));
+ }
else
{
- throw new MessageFormatException("Invalid object type");
+ throw new MessageFormatException("Invalid property type");
}
}
@@ -764,42 +860,16 @@
public void doBeforeSend() throws Exception
{
- //NOOP
+ body.flip();
+
+ message.setBody(body);
}
public void doBeforeReceive() throws Exception
{
- //NOOP
+ body = message.getBody();
}
- protected void beforeSend() throws Exception
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
-
- DataOutputStream daos = new DataOutputStream(baos);
-
- writePayload(daos);
-
- daos.close();
-
- message.setPayload(baos.toByteArray());
- }
-
- protected void beforeReceive() throws Exception
- {
- DataInputStream dais = new DataInputStream(new ByteArrayInputStream(message.getPayload()));
-
- readPayload(dais);
- }
-
- protected void writePayload(DataOutputStream daos) throws Exception
- {
- }
-
- protected void readPayload(DataInputStream dais) throws Exception
- {
- }
-
public byte getType()
{
return JBossMessage.TYPE;
@@ -810,11 +880,6 @@
return session;
}
- public void copyMessage()
- {
- message = message.copy();
- }
-
public String toString()
{
StringBuffer sb = new StringBuffer("JBossMessage[");
@@ -847,7 +912,7 @@
// Private ------------------------------------------------------------
- private void checkProperty(String name, Object value) throws JMSException
+ private void checkProperty(final String name, final Object value) throws JMSException
{
checkWrite();
@@ -894,7 +959,7 @@
}
}
- public boolean isValidJavaIdentifier(String s)
+ private boolean isValidJavaIdentifier(final String s)
{
if (s == null || s.length() == 0)
{
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossObjectMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossObjectMessage.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossObjectMessage.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -22,19 +22,23 @@
package org.jboss.messaging.jms.client;
import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.util.StreamUtils;
/**
* This class implements javax.jms.ObjectMessage
*
+ * Don't used ObjectMessage if you want good performance!
+ *
+ * Serialization is slooooow!
+ *
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
* @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
*
@@ -64,7 +68,7 @@
super(JBossObjectMessage.TYPE);
}
- public JBossObjectMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
+ public JBossObjectMessage(final org.jboss.messaging.core.message.Message message, ClientSession session)
{
super(message, session);
}
@@ -72,7 +76,7 @@
/**
* A copy constructor for foreign JMS ObjectMessages.
*/
- public JBossObjectMessage(ObjectMessage foreign) throws JMSException
+ public JBossObjectMessage(final ObjectMessage foreign) throws JMSException
{
super(foreign, JBossObjectMessage.TYPE);
@@ -88,14 +92,26 @@
public void doBeforeSend() throws Exception
{
- beforeSend();
+ if (object != null)
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+ oos.writeObject(object);
+
+ oos.flush();
+
+ byte[] data = baos.toByteArray();
+
+ body.putInt(data.length);
+ body.putBytes(data);
+ }
+
+ super.doBeforeSend();
}
- public void doBeforeReceive() throws Exception
- {
- }
-
-
+
// ObjectMessage implementation ----------------------------------
public void setObject(Serializable object) throws JMSException
@@ -108,27 +124,25 @@
// lazy deserialize the Object the first time the client requests it
public Serializable getObject() throws JMSException
{
- if (object != null)
+ if (object == null)
{
- return object;
- }
- else if (message.getPayload() != null)
- {
- DataInputStream dais = new DataInputStream(new ByteArrayInputStream(message.getPayload()));
try
{
- readPayload(dais);
+ int len = body.getInt();
+ byte[] data = new byte[len];
+ body.getBytes(data);
+ ByteArrayInputStream bais = new ByteArrayInputStream(data);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ object = (Serializable)ois.readObject();
}
catch (Exception e)
{
- RuntimeException e2 = new RuntimeException(e.getMessage());
- e2.setStackTrace(e.getStackTrace());
- throw e2;
- }
- return object;
- } else {
- return null;
+ JMSException je = new JMSException("Failed to deserialize object");
+ je.setLinkedException(e);
+ }
}
+
+ return object;
}
public void clearBody() throws JMSException
@@ -137,21 +151,13 @@
object = null;
}
+
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
- protected void writePayload(DataOutputStream daos) throws Exception
- {
- StreamUtils.writeObject(daos, object, false, true);
- }
-
- protected void readPayload(DataInputStream dais) throws Exception
- {
- object = (Serializable)StreamUtils.readObject(dais, true);
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossStreamMessage.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -21,10 +21,7 @@
*/
package org.jboss.messaging.jms.client;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.util.ArrayList;
-import java.util.List;
+import java.nio.BufferUnderflowException;
import javax.jms.JMSException;
import javax.jms.MessageEOFException;
@@ -32,11 +29,17 @@
import javax.jms.StreamMessage;
import org.jboss.messaging.core.client.ClientSession;
-import org.jboss.messaging.util.StreamUtils;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
+import org.jboss.messaging.util.DataConstants;
/**
* This class implements javax.jms.StreamMessage.
*
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ * Some parts based on JBM 1.x class by:
+ *
* @author Norbert Lataille (Norbert.Lataille at m4x.org)
* @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -50,18 +53,13 @@
{
// Constants -----------------------------------------------------
+ private static final Logger log = Logger.getLogger(JBossStreamMessage.class);
+
+
public static final byte TYPE = 6;
// Attributes ----------------------------------------------------
-
- private int position;
-
- private int offset;
-
- //private int size;
-
- private List<Object> list = new ArrayList<Object>();
-
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -74,12 +72,12 @@
super(JBossStreamMessage.TYPE);
}
- public JBossStreamMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
+ public JBossStreamMessage(final org.jboss.messaging.core.message.Message message, final ClientSession session)
{
super(message, session);
}
- public JBossStreamMessage(StreamMessage foreign) throws JMSException
+ public JBossStreamMessage(final StreamMessage foreign) throws JMSException
{
super(foreign, JBossStreamMessage.TYPE);
@@ -113,38 +111,23 @@
checkRead();
try
{
- Object value = list.get(position);
+ byte type = body.getByte();
- offset = 0;
-
- boolean result;
-
- if (value == null)
+ switch (type)
{
- throw new NullPointerException("Value is null");
+ case DataConstants.BOOLEAN:
+ return body.getBoolean();
+ case DataConstants.STRING:
+ String s = body.getNullableString();
+ return Boolean.valueOf(s);
+ default:
+ throw new MessageFormatException("Invalid conversion");
}
- else if (value instanceof Boolean)
- {
- result = ((Boolean)value).booleanValue();
- }
- else if (value instanceof String)
- {
- result = Boolean.valueOf((String) value).booleanValue();
- }
- else
- {
- throw new MessageFormatException("Invalid conversion");
- }
-
- position++;
-
- return result;
}
- catch (IndexOutOfBoundsException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
-
}
public byte readByte() throws JMSException
@@ -152,34 +135,19 @@
checkRead();
try
{
- Object value = list.get(position);
-
- offset = 0;
-
- byte result;
-
- if (value == null)
+ byte type = body.getByte();
+ switch (type)
{
- throw new NullPointerException("Value is null");
+ case DataConstants.BYTE:
+ return body.getByte();
+ case DataConstants.STRING:
+ String s = body.getNullableString();
+ return Byte.parseByte(s);
+ default:
+ throw new MessageFormatException("Invalid conversion");
}
- else if (value instanceof Byte)
- {
- result = ((Byte) value).byteValue();
- }
- else if (value instanceof String)
- {
- result = Byte.parseByte((String) value);
- }
- else
- {
- throw new MessageFormatException("Invalid conversion");
- }
-
- position++;
-
- return result;
}
- catch (IndexOutOfBoundsException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
@@ -190,38 +158,21 @@
checkRead();
try
{
- Object value = list.get(position);
-
- short result;
-
- offset = 0;
-
- if (value == null)
+ byte type = body.getByte();
+ switch (type)
{
- throw new NullPointerException("Value is null");
+ case DataConstants.BYTE:
+ return body.getByte();
+ case DataConstants.SHORT:
+ return body.getShort();
+ case DataConstants.STRING:
+ String s = body.getNullableString();
+ return Short.parseShort(s);
+ default:
+ throw new MessageFormatException("Invalid conversion");
}
- else if (value instanceof Byte)
- {
- result = ((Byte) value).shortValue();
- }
- else if (value instanceof Short)
- {
- result = ((Short) value).shortValue();
- }
- else if (value instanceof String)
- {
- result = Short.parseShort((String) value);
- }
- else
- {
- throw new MessageFormatException("Invalid conversion");
- }
-
- position++;
-
- return result;
}
- catch (IndexOutOfBoundsException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
@@ -232,30 +183,16 @@
checkRead();
try
{
- Object value = list.get(position);
-
- char result;
-
- offset = 0;
-
- if (value == null)
+ byte type = body.getByte();
+ switch (type)
{
- throw new NullPointerException("Value is null");
+ case DataConstants.CHAR:
+ return body.getChar();
+ default:
+ throw new MessageFormatException("Invalid conversion");
}
- else if (value instanceof Character)
- {
- result = ((Character) value).charValue();
- }
- else
- {
- throw new MessageFormatException("Invalid conversion");
- }
-
- position++;
-
- return result;
}
- catch (IndexOutOfBoundsException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
@@ -266,42 +203,23 @@
checkRead();
try
{
- Object value = list.get(position);
-
- int result;
-
- offset = 0;
-
- if (value == null)
+ byte type = body.getByte();
+ switch (type)
{
- throw new NullPointerException("Value is null");
+ case DataConstants.BYTE:
+ return body.getByte();
+ case DataConstants.SHORT:
+ return body.getShort();
+ case DataConstants.INT:
+ return body.getInt();
+ case DataConstants.STRING:
+ String s = body.getNullableString();
+ return Integer.parseInt(s);
+ default:
+ throw new MessageFormatException("Invalid conversion");
}
- else if (value instanceof Byte)
- {
- result = ((Byte) value).intValue();
- }
- else if (value instanceof Short)
- {
- result = ((Short) value).intValue();
- }
- else if (value instanceof Integer)
- {
- result = ((Integer) value).intValue();
- }
- else if (value instanceof String)
- {
- result = Integer.parseInt((String) value);
- }
- else
- {
- throw new MessageFormatException("Invalid conversion");
- }
-
- position++;
-
- return result;
}
- catch (IndexOutOfBoundsException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
@@ -312,46 +230,25 @@
checkRead();
try
{
- Object value = list.get(position);
-
- long result;
-
- offset = 0;
-
- if (value == null)
+ byte type = body.getByte();
+ switch (type)
{
- throw new NullPointerException("Value is null");
+ case DataConstants.BYTE:
+ return body.getByte();
+ case DataConstants.SHORT:
+ return body.getShort();
+ case DataConstants.INT:
+ return body.getInt();
+ case DataConstants.LONG:
+ return body.getLong();
+ case DataConstants.STRING:
+ String s = body.getNullableString();
+ return Long.parseLong(s);
+ default:
+ throw new MessageFormatException("Invalid conversion");
}
- else if (value instanceof Byte)
- {
- result = ((Byte) value).longValue();
- }
- else if (value instanceof Short)
- {
- result = ((Short) value).longValue();
- }
- else if (value instanceof Integer)
- {
- result = ((Integer) value).longValue();
- }
- else if (value instanceof Long)
- {
- result = ((Long) value).longValue();
- }
- else if (value instanceof String)
- {
- result = Long.parseLong((String) value);
- }
- else
- {
- throw new MessageFormatException("Invalid conversion");
- }
-
- position++;
-
- return result;
}
- catch (IndexOutOfBoundsException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
@@ -362,34 +259,19 @@
checkRead();
try
{
- Object value = list.get(position);
-
- float result;
-
- offset = 0;
-
- if (value == null)
+ byte type = body.getByte();
+ switch (type)
{
- throw new NullPointerException("Value is null");
+ case DataConstants.FLOAT:
+ return body.getFloat();
+ case DataConstants.STRING:
+ String s = body.getNullableString();
+ return Float.parseFloat(s);
+ default:
+ throw new MessageFormatException("Invalid conversion");
}
- else if (value instanceof Float)
- {
- result = ((Float) value).floatValue();
- }
- else if (value instanceof String)
- {
- result = Float.parseFloat((String) value);
- }
- else
- {
- throw new MessageFormatException("Invalid conversion");
- }
-
- position++;
-
- return result;
}
- catch (IndexOutOfBoundsException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
@@ -400,340 +282,298 @@
checkRead();
try
{
- Object value = list.get(position);
-
- offset = 0;
-
- double result;
-
- if (value == null)
+ byte type = body.getByte();
+ switch (type)
{
- throw new NullPointerException("Value is null");
+ case DataConstants.FLOAT:
+ return body.getFloat();
+ case DataConstants.DOUBLE:
+ return body.getDouble();
+ case DataConstants.STRING:
+ String s = body.getNullableString();
+ return Double.parseDouble(s);
+ default:
+ throw new MessageFormatException("Invalid conversion: " + type);
}
- else if (value instanceof Float)
- {
- result = ((Float) value).doubleValue();
- }
- else if (value instanceof Double)
- {
- result = ((Double) value).doubleValue();
- }
- else if (value instanceof String)
- {
- result = Double.parseDouble((String) value);
- }
- else
- {
- throw new MessageFormatException("Invalid conversion");
- }
-
- position++;
-
- return result;
}
- catch (IndexOutOfBoundsException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
}
-
+
public String readString() throws JMSException
{
checkRead();
try
{
- Object value = list.get(position);
-
- String result;
-
- offset = 0;
-
- if (value == null)
+ byte type = body.getByte();
+ switch (type)
{
- result = null;
+ case DataConstants.BOOLEAN:
+ return String.valueOf(body.getBoolean());
+ case DataConstants.BYTE:
+ return String.valueOf(body.getByte());
+ case DataConstants.SHORT:
+ return String.valueOf(body.getShort());
+ case DataConstants.CHAR:
+ return String.valueOf(body.getChar());
+ case DataConstants.INT:
+ return String.valueOf(body.getInt());
+ case DataConstants.LONG:
+ return String.valueOf(body.getLong());
+ case DataConstants.FLOAT:
+ return String.valueOf(body.getFloat());
+ case DataConstants.DOUBLE:
+ return String.valueOf(body.getDouble());
+ case DataConstants.STRING:
+ return body.getNullableString();
+ default:
+ throw new MessageFormatException("Invalid conversion");
}
- else if (value instanceof Boolean)
- {
- result = ((Boolean) value).toString();
- }
- else if (value instanceof Byte)
- {
- result = ((Byte) value).toString();
- }
- else if (value instanceof Short)
- {
- result = ((Short) value).toString();
- }
- else if (value instanceof Character)
- {
- result = ((Character) value).toString();
- }
- else if (value instanceof Integer)
- {
- result = ((Integer) value).toString();
- }
- else if (value instanceof Long)
- {
- result = ((Long) value).toString();
- }
- else if (value instanceof Float)
- {
- result = ((Float) value).toString();
- }
- else if (value instanceof Double)
- {
- result = ((Double) value).toString();
- }
- else if (value instanceof String)
- {
- result = (String) value;
- }
- else
- {
- throw new MessageFormatException("Invalid conversion");
- }
-
- position++;
-
- return result;
}
- catch (IndexOutOfBoundsException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
}
- public int readBytes(byte[] value) throws JMSException
+ private int len;
+
+ public int readBytes(final byte[] value) throws JMSException
{
checkRead();
try
{
- Object myObj = list.get(position);
-
- if (myObj == null)
+ if (len == -1)
{
- throw new NullPointerException("Value is null");
- }
-
- if (!(myObj instanceof byte[]))
- {
- throw new MessageFormatException("Invalid conversion");
- }
-
- byte[] obj = (byte[]) myObj;
-
- if (obj.length == 0)
- {
- position++;
- offset = 0;
- return 0;
- }
-
- if (offset >= obj.length)
- {
- position++;
- offset = 0;
+ len = 0;
return -1;
}
-
- if (obj.length - offset < value.length)
+ else if (len == 0)
{
- for (int i = 0; i < obj.length; i++)
- value[i] = obj[i + offset];
-
- position++;
- offset = 0;
-
- return obj.length - offset;
- }
- else
+ byte type = body.getByte();
+ if (type != DataConstants.BYTES)
+ {
+ throw new MessageFormatException("Invalid conversion");
+ }
+ len = body.getInt();
+ }
+ int read = Math.min(value.length, len);
+ body.getBytes(value, 0, read);
+ len -= read;
+ if (len == 0)
{
- for (int i = 0; i < value.length; i++)
- value[i] = obj[i + offset];
- offset += value.length;
-
- return value.length;
+ len = -1;
}
-
+ return read;
}
- catch (IndexOutOfBoundsException e)
+ catch (BufferUnderflowException e)
{
throw new MessageEOFException("");
}
}
-
+
public Object readObject() throws JMSException
{
checkRead();
- try
+ byte type = body.getByte();
+ switch (type)
{
- Object value = list.get(position);
- position++;
- offset = 0;
-
- return value;
+ case DataConstants.BOOLEAN:
+ return body.getBoolean();
+ case DataConstants.BYTE:
+ return body.getByte();
+ case DataConstants.SHORT:
+ return body.getShort();
+ case DataConstants.CHAR:
+ return body.getChar();
+ case DataConstants.INT:
+ return body.getInt();
+ case DataConstants.LONG:
+ return body.getLong();
+ case DataConstants.FLOAT:
+ return body.getFloat();
+ case DataConstants.DOUBLE:
+ return body.getDouble();
+ case DataConstants.STRING:
+ return body.getNullableString();
+ case DataConstants.BYTES:
+ int len = body.getInt();
+ byte[] bytes = new byte[len];
+ body.getBytes(bytes);
+ return bytes;
+ default:
+ throw new MessageFormatException("Invalid conversion");
}
- catch (IndexOutOfBoundsException e)
- {
- throw new MessageEOFException("");
- }
}
- public void writeBoolean(boolean value) throws JMSException
+ public void writeBoolean(final boolean value) throws JMSException
{
checkWrite();
- list.add(Boolean.valueOf(value));
+ body.putByte(DataConstants.BOOLEAN);
+ body.putBoolean(value);
}
- public void writeByte(byte value) throws JMSException
+ public void writeByte(final byte value) throws JMSException
{
checkWrite();
- list.add(Byte.valueOf(value));
+ body.putByte(DataConstants.BYTE);
+ body.putByte(value);
}
- public void writeShort(short value) throws JMSException
- {
+ public void writeShort(final short value) throws JMSException
+ {
checkWrite();
- list.add(Short.valueOf(value));
+ body.putByte(DataConstants.SHORT);
+ body.putShort(value);
}
- public void writeChar(char value) throws JMSException
+ public void writeChar(final char value) throws JMSException
{
checkWrite();
- list.add(Character.valueOf(value));
+ body.putByte(DataConstants.CHAR);
+ body.putChar(value);
}
- public void writeInt(int value) throws JMSException
+ public void writeInt(final int value) throws JMSException
{
checkWrite();
- list.add(Integer.valueOf(value));
+ body.putByte(DataConstants.INT);
+ body.putInt(value);
}
- public void writeLong(long value) throws JMSException
+ public void writeLong(final long value) throws JMSException
{
checkWrite();
- list.add(Long.valueOf(value));
+ body.putByte(DataConstants.LONG);
+ body.putLong(value);
}
- public void writeFloat(float value) throws JMSException
+ public void writeFloat(final float value) throws JMSException
{
checkWrite();
- list.add(Float.valueOf(value));
+ body.putByte(DataConstants.FLOAT);
+ body.putFloat(value);
}
- public void writeDouble(double value) throws JMSException
+ public void writeDouble(final double value) throws JMSException
{
checkWrite();
- list.add(Double.valueOf(value));
+ body.putByte(DataConstants.DOUBLE);
+ body.putDouble(value);
}
-
- public void writeString(String value) throws JMSException
+
+ public void writeString(final String value) throws JMSException
{
checkWrite();
- if (value == null)
- {
- list.add(null);
- }
- else
- {
- list.add(value);
- }
+ body.putByte(DataConstants.STRING);
+ body.putNullableString(value);
}
- public void writeBytes(byte[] value) throws JMSException
+ public void writeBytes(final byte[] value) throws JMSException
{
checkWrite();
- list.add(value.clone());
+ body.putByte(DataConstants.BYTES);
+ body.putInt(value.length);
+ body.putBytes(value);
}
- public void writeBytes(byte[] value, int offset, int length) throws JMSException
+ public void writeBytes(final byte[] value, final int offset, final int length)
+ throws JMSException
{
checkWrite();
- if (offset + length > value.length)
- {
- throw new JMSException("Invalid offset/length");
- }
-
- byte[] newBytes = new byte[length];
-
- System.arraycopy(value, offset, newBytes, 0, length);
-
- list.add(newBytes);
+ body.putByte(DataConstants.BYTES);
+ body.putInt(length);
+ body.putBytes(value, offset, length);
}
- public void writeObject(Object value) throws JMSException
+ public void writeObject(final Object value) throws JMSException
{
- checkWrite();
- if (value == null)
- list.add(null);
+ if (value == null)
+ {
+ throw new NullPointerException("Attempt to write a null value");
+ }
+ if (value instanceof String)
+ {
+ writeString((String)value);
+ }
else if (value instanceof Boolean)
- list.add(value);
+ {
+ writeBoolean((Boolean)value);
+ }
else if (value instanceof Byte)
- list.add(value);
+ {
+ writeByte((Byte)value);
+ }
else if (value instanceof Short)
- list.add(value);
- else if (value instanceof Character)
- list.add(value);
+ {
+ writeShort((Short)value);
+ }
else if (value instanceof Integer)
- list.add(value);
+ {
+ writeInt((Integer)value);
+ }
else if (value instanceof Long)
- list.add(value);
+ {
+ writeLong((Long)value);
+ }
else if (value instanceof Float)
- list.add(value);
+ {
+ writeFloat((Float)value);
+ }
else if (value instanceof Double)
- list.add(value);
- else if (value instanceof String)
- list.add(value);
+ {
+ writeDouble((Double)value);
+ }
else if (value instanceof byte[])
- list.add(((byte[]) value).clone());
+ {
+ writeBytes((byte[])value);
+ }
+ else if (value instanceof Character)
+ {
+ this.writeChar((Character)value);
+ }
else
- throw new MessageFormatException("Invalid object type");
+ {
+ throw new MessageFormatException("Invalid object type: " + value.getClass());
+ }
}
public void reset() throws JMSException
- {
- position = 0;
- offset = 0;
- readOnly = true;
+ {
+ if (!readOnly)
+ {
+ readOnly = true;
+
+ body.flip();
+ }
+ else
+ {
+ body.rewind();
+ }
}
// JBossMessage overrides ----------------------------------------
-
+
public void clearBody() throws JMSException
{
super.clearBody();
- list.clear();
- position = 0;
- offset = 0;
+ body = new BufferWrapper(1024);
}
public void doBeforeSend() throws Exception
{
reset();
-
- beforeSend();
+
+ message.setBody(body);
}
-
- public void doBeforeReceive() throws Exception
- {
- beforeReceive();
- }
-
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
-
- protected void writePayload(DataOutputStream daos) throws Exception
- {
- StreamUtils.writeList(daos, list);
- }
- protected void readPayload(DataInputStream dais) throws Exception
- {
- list = StreamUtils.readList(dais);
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/jms/client/JBossTextMessage.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/client/JBossTextMessage.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/jms/client/JBossTextMessage.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -22,15 +22,11 @@
package org.jboss.messaging.jms.client;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-
import javax.jms.JMSException;
import javax.jms.TextMessage;
import org.jboss.messaging.core.client.ClientSession;
import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.util.SafeUTF;
/**
* This class implements javax.jms.TextMessage ported from SpyTextMessage in JBossMQ.
@@ -55,8 +51,9 @@
// Attributes ----------------------------------------------------
+ //We cache it locally
private String text;
-
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -69,15 +66,15 @@
super(JBossTextMessage.TYPE);
}
- public JBossTextMessage(org.jboss.messaging.core.message.Message message, ClientSession session)
- {
+ public JBossTextMessage(final org.jboss.messaging.core.message.Message message, ClientSession session)
+ {
super(message, session);
}
/**
* A copy constructor for non-JBoss Messaging JMS TextMessages.
*/
- public JBossTextMessage(TextMessage foreign) throws JMSException
+ public JBossTextMessage(final TextMessage foreign) throws JMSException
{
super(foreign, JBossTextMessage.TYPE);
@@ -90,20 +87,10 @@
{
return JBossTextMessage.TYPE;
}
-
- public void doBeforeSend() throws Exception
- {
- beforeSend();
- }
-
- public void doBeforeReceive() throws Exception
- {
- beforeReceive();
- }
-
+
// TextMessage implementation ------------------------------------
- public void setText(String text) throws JMSException
+ public void setText(final String text) throws JMSException
{
checkWrite();
@@ -112,6 +99,7 @@
public String getText() throws JMSException
{
+ //TODO lazily get the text
return text;
}
@@ -124,41 +112,24 @@
// JBossMessage override -----------------------------------------
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- protected void writePayload(DataOutputStream daos) throws Exception
+ public void doBeforeSend() throws Exception
{
- //TODO - if send strings in plain format as opposed to UTF-8 then we can calculate the size
- //in advance more easily - so we can allocate a byte buffer - as opposed to using a stream
+ body.putNullableString(text);
- if (text == null)
- {
- daos.writeByte(NULL);
- }
- else
- {
- daos.writeByte(NOT_NULL);
-
- SafeUTF.safeWriteUTF(daos, text);
- }
+ super.doBeforeSend();
}
- protected void readPayload(DataInputStream dais) throws Exception
+ public void doBeforeReceive() throws Exception
{
- byte b = dais.readByte();
+ super.doBeforeReceive();
- if (b == NULL)
- {
- text = null;
- }
- else
- {
- text = SafeUTF.safeReadUTF(dais);
- }
+ text = body.getNullableString();
}
+
+ // Package protected ---------------------------------------------
+ // Protected -----------------------------------------------------
+
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/jms/server/impl/JMSServerDeployer.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -183,7 +183,7 @@
if (ENTRY_NODE_NAME.equalsIgnoreCase(children.item(i).getNodeName()))
{
- log.info("CReating cf ** with ws:" + producerWindowSize);
+ log.info("Creating cf ** with ws:" + producerWindowSize);
String jndiName = child.getAttributes().getNamedItem("name").getNodeValue();
String name = node.getAttributes().getNamedItem(getKeyAttribute()).getNodeValue();
Added: trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/util/ByteBufferWrapper.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -0,0 +1,330 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.util;
+
+import static org.jboss.messaging.util.DataConstants.FALSE;
+import static org.jboss.messaging.util.DataConstants.NOT_NULL;
+import static org.jboss.messaging.util.DataConstants.NULL;
+import static org.jboss.messaging.util.DataConstants.TRUE;
+
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.charset.Charset;
+
+/**
+ *
+ * A ByteBufferWrapper
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class ByteBufferWrapper implements MessagingBuffer
+{
+ private static final Charset utf8 = Charset.forName("UTF-8");
+
+ private ByteBuffer buffer;
+
+ public ByteBufferWrapper(final ByteBuffer buffer)
+ {
+ this.buffer = buffer;
+ }
+
+ public byte[] array()
+ {
+ return buffer.array();
+ }
+
+ public int position()
+ {
+ return buffer.position();
+ }
+
+ public void position(final int position)
+ {
+ buffer.position(position);
+ }
+
+ public int capacity()
+ {
+ return buffer.capacity();
+ }
+
+ public void flip()
+ {
+ buffer.flip();
+ }
+
+ public MessagingBuffer slice()
+ {
+ return new ByteBufferWrapper(buffer.slice());
+ }
+
+ public void rewind()
+ {
+ buffer.rewind();
+ }
+
+ public boolean getBoolean()
+ {
+ byte b = buffer.get();
+ return (b == TRUE);
+ }
+
+ public byte getByte()
+ {
+ return buffer.get();
+ }
+
+ public short getUnsignedByte()
+ {
+ return (short)(buffer.get() & 0xFF);
+ }
+
+ public void getBytes(byte[] bytes)
+ {
+ buffer.get(bytes);
+ }
+
+ public void getBytes(byte[] bytes, int offset, int length)
+ {
+ buffer.get(bytes, offset, length);
+ }
+
+ public double getDouble()
+ {
+ return buffer.getDouble();
+ }
+
+ public float getFloat()
+ {
+ return buffer.getFloat();
+ }
+
+ public int getInt()
+ {
+ return buffer.getInt();
+ }
+
+ public long getUnsignedInt()
+ {
+ return buffer.getInt() & 0xFFFFFFFFL;
+ }
+
+ public long getLong()
+ {
+ return buffer.getLong();
+ }
+
+ public void putNullableString(final String nullableString)
+ {
+ if (nullableString == null)
+ {
+ buffer.put(NULL);
+ }
+ else
+ {
+ buffer.put(NOT_NULL);
+
+ putString(nullableString);
+ }
+ }
+
+ public String getNullableString()
+ {
+ byte check = buffer.get();
+
+ if (check == NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return getString();
+ }
+ }
+
+ public void putString(final String nullableString)
+ {
+ //We don't encode
+
+ buffer.putInt(nullableString.length());
+
+ for (int i = 0; i < nullableString.length(); i++)
+ {
+ buffer.putChar(nullableString.charAt(i));
+ }
+ }
+
+ public void putUTF(final String str) throws Exception
+ {
+ //TODO This is quite inefficient - can be improved using a method similar to what MINA IOBuffer does
+ //(putPrefixedString)
+ ByteBuffer bb = utf8.encode(str);
+ buffer.putInt(bb.capacity());
+ buffer.put(bb);
+ }
+
+ public short getShort()
+ {
+ return buffer.getShort();
+ }
+
+ public int getUnsignedShort()
+ {
+ return buffer.getShort() & 0xFFFF;
+ }
+
+ public char getChar()
+ {
+ return buffer.getChar();
+ }
+
+ public String getString()
+ {
+ int len = buffer.getInt();
+
+ char[] chars = new char[len];
+
+ for (int i = 0; i < len; i++)
+ {
+ chars[i] = buffer.getChar();
+ }
+
+ return new String(chars);
+ }
+
+ public void putSimpleString(final SimpleString string)
+ {
+ byte[] data = string.getData();
+
+ buffer.putInt(data.length);
+ buffer.put(data);
+ }
+
+ public SimpleString getNullableSimpleString()
+ {
+ int b = buffer.get();
+ if (b == NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return getSimpleString();
+ }
+ }
+
+ public void putNullableSimpleString(final SimpleString string)
+ {
+ if (string == null)
+ {
+ buffer.put(NULL);
+ }
+ else
+ {
+ putSimpleString(string);
+ }
+ }
+
+ public SimpleString getSimpleString()
+ {
+ int len = buffer.getInt();
+
+ byte[] data = new byte[len];
+ buffer.get(data);
+
+ return new SimpleString(data);
+ }
+
+ public String getUTF() throws Exception
+ {
+ int len = buffer.getInt();
+ byte[] data = new byte[len];
+ buffer.get(data);
+ ByteBuffer bb = ByteBuffer.wrap(data);
+ CharBuffer cb = utf8.newDecoder().decode(bb);
+ return cb.toString();
+ }
+
+ public int limit()
+ {
+ return buffer.limit();
+ }
+
+ public void limit(final int limit)
+ {
+ buffer.limit(limit);
+ }
+
+ public void putBoolean(boolean val)
+ {
+ if (val)
+ {
+ buffer.put(TRUE);
+ }
+ else
+ {
+ buffer.put(FALSE);
+ }
+ }
+
+ public void putByte(byte val)
+ {
+ buffer.put(val);
+ }
+
+ public void putBytes(byte[] bytes)
+ {
+ buffer.put(bytes);
+ }
+
+ public void putBytes(byte[] bytes, int offset, int len)
+ {
+ buffer.put(bytes, offset, len);
+ }
+
+ public void putDouble(double val)
+ {
+ buffer.putDouble(val);
+ }
+
+ public void putFloat(float val)
+ {
+ buffer.putFloat(val);
+ }
+
+ public void putInt(int val)
+ {
+ buffer.putInt(val);
+ }
+
+ public void putLong(long val)
+ {
+ buffer.putLong(val);
+ }
+
+ public void putShort(short val)
+ {
+ buffer.putShort(val);
+ }
+
+ public void putChar(char chr)
+ {
+ buffer.putChar(chr);
+ }
+
+ public int remaining()
+ {
+ return buffer.remaining();
+ }
+
+ public Object getUnderlyingBuffer()
+ {
+ return buffer;
+ }
+
+}
Added: trunk/src/main/org/jboss/messaging/util/MessagingBuffer.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/MessagingBuffer.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/util/MessagingBuffer.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.util;
+
+/**
+ *
+ * A MessagingBuffer
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public interface MessagingBuffer
+{
+ void putByte(byte val);
+
+ void putBytes(byte[] bytes);
+
+ void putBytes(byte[] bytes, int offset, int length);
+
+ void putInt(int val);
+
+ void putLong(long val);
+
+ void putShort(short val);
+
+ void putDouble(double val);
+
+ void putFloat(float val);
+
+ void putBoolean(boolean val);
+
+ void putChar(char val);
+
+ void putNullableString(String val);
+
+ void putString(String val);
+
+ void putSimpleString(SimpleString val);
+
+ void putNullableSimpleString(SimpleString val);
+
+ void putUTF(String utf) throws Exception;
+
+ byte getByte();
+
+ short getUnsignedByte();
+
+ void getBytes(byte[] bytes);
+
+ void getBytes(byte[] bytes, int offset, int length);
+
+ int getInt();
+
+ long getUnsignedInt();
+
+ long getLong();
+
+ short getShort();
+
+ int getUnsignedShort();
+
+ double getDouble();
+
+ float getFloat();
+
+ boolean getBoolean();
+
+ char getChar();
+
+ String getString();
+
+ String getNullableString();
+
+ SimpleString getSimpleString();
+
+ SimpleString getNullableSimpleString();
+
+ String getUTF() throws Exception;
+
+ byte[] array();
+
+ int remaining();
+
+ int capacity();
+
+ int limit();
+
+ void limit(int limit);
+
+ void flip();
+
+ void position(int position);
+
+ int position();
+
+ void rewind();
+
+ MessagingBuffer slice();
+
+ Object getUnderlyingBuffer();
+
+}
Modified: trunk/src/main/org/jboss/messaging/util/SimpleString.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/SimpleString.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/util/SimpleString.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -190,11 +190,6 @@
return hash;
}
- public static int sizeofNullableString(final SimpleString str)
- {
- return str == null ? SIZE_BYTE : SIZE_BYTE + SIZE_INT + str.data.length;
- }
-
public static int sizeofString(final SimpleString str)
{
return SIZE_INT + str.data.length;
Deleted: trunk/src/main/org/jboss/messaging/util/StreamUtils.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/StreamUtils.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/util/StreamUtils.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -1,357 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.util;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.messaging.core.logging.Logger;
-
-/**
- * A StreamUtils
- *
- * Utility methods for reading and writing stuff to and from streams
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public class StreamUtils
-{
- public static final Logger log = Logger.getLogger(StreamUtils.class);
-
-
- private static final int BUFFER_SIZE = 4096;
-
- public static final byte NULL = 0;
-
- public static final byte STRING = 1;
-
- public static final byte MAP = 2;
-
- public static final byte BYTE = 3;
-
- public static final byte SHORT = 4;
-
- public static final byte INT = 5;
-
- public static final byte LONG = 6;
-
- public static final byte FLOAT = 7;
-
- public static final byte DOUBLE = 8;
-
- public static final byte BOOLEAN = 9;
-
- public static final byte BYTES = 10;
-
- public static final byte LIST = 11;
-
- public static final byte SERIALIZABLE = 12;
-
- public static final byte SIMPLE_STRING = 13;
-
- public static Object readObject(DataInputStream in, boolean longStrings)
- throws IOException, ClassNotFoundException
- {
- byte type = in.readByte();
- Object value = null;
- switch (type)
- {
- case NULL:
- {
- value = null;
- break;
- }
- case STRING :
- if (longStrings)
- {
- //We cope with >= 64K Strings
- value = SafeUTF.safeReadUTF(in);
- }
- else
- {
- //Limited to < 64K Strings
- value = in.readUTF();
- }
- break;
- case SIMPLE_STRING:
- byte[] data = new byte[in.readInt()];
- in.read(data);
- value = new SimpleString(data);
- break;
- case MAP:
- {
- value = readMap(in, false);
- break;
- }
- case BYTE :
- value = new Byte(in.readByte());
- break;
- case SHORT :
- value = new Short(in.readShort());
- break;
- case INT :
- value = new Integer(in.readInt());
- break;
- case LONG :
- value = new Long(in.readLong());
- break;
- case FLOAT :
- value = new Float(in.readFloat());
- break;
- case DOUBLE :
- value = new Double(in.readDouble());
- break;
- case BOOLEAN :
- value = in.readBoolean() ? Boolean.TRUE : Boolean.FALSE;
- break;
- case BYTES :
- int size = in.readInt();
- byte[] bytes = new byte[size];
- in.readFully(bytes);
- value = bytes;
- break;
- case LIST:
- {
- value = readList(in);
- break;
- }
- case SERIALIZABLE:
- {
- ObjectInputStream ois = new ObjectInputStreamWithClassLoader(in);
-
- value = ois.readObject();
- break;
- }
- default :
- {
- throw new IllegalStateException("Unknown type: " + type);
- }
- }
- return value;
- }
-
- public static void writeObject(DataOutputStream out, Object object,
- boolean containerTypes, boolean longStrings) throws IOException
- {
- // more efficient than using object serialization for well known types
- if (object == null)
- {
- out.writeByte(NULL);
- }
- else if (object instanceof String)
- {
- out.writeByte(STRING);
- if (longStrings)
- {
- //We can cope with >=64K Strings
- SafeUTF.safeWriteUTF(out, (String)object);
- }
- else
- {
- //Limited to < 64K Strings
- out.writeUTF((String)object);
- }
- }
- else if (object instanceof SimpleString)
- {
- //TODO - this will disappear in next refactoring
- out.writeByte(SIMPLE_STRING);
- SimpleString ss = (SimpleString)object;
- out.writeInt(ss.getData().length);
- out.write(ss.getData());
- }
- else if (containerTypes && object instanceof Map)
- {
- out.writeByte(MAP);
- writeMap(out, (Map)object, false);
- }
- else if (object instanceof Integer)
- {
- out.writeByte(INT);
- out.writeInt(((Integer) object).intValue());
- }
- else if (object instanceof Boolean)
- {
- out.writeByte(BOOLEAN);
- out.writeBoolean(((Boolean) object).booleanValue());
- }
- else if (object instanceof Byte)
- {
- out.writeByte(BYTE);
- out.writeByte(((Byte) object).byteValue());
- }
- else if (object instanceof Short)
- {
- out.writeByte(SHORT);
- out.writeShort(((Short) object).shortValue());
- }
- else if (object instanceof Long)
- {
- out.writeByte(LONG);
- out.writeLong(((Long) object).longValue());
- }
- else if (object instanceof Float)
- {
- out.writeByte(FLOAT);
- out.writeFloat(((Float) object).floatValue());
- }
- else if (object instanceof Double)
- {
- out.writeByte(DOUBLE);
- out.writeDouble(((Double) object).doubleValue());
- }
- else if (object instanceof byte[])
- {
- out.writeByte(BYTES);
- byte[] bytes = (byte[])object;
- out.writeInt(bytes.length);
- out.write(bytes);
- }
- else if (containerTypes && object instanceof List)
- {
- out.write(LIST);
- writeList(out, (List)object);
- }
- else if (object instanceof Serializable)
- {
- out.writeByte(SERIALIZABLE);
- ObjectOutputStream oos = new ObjectOutputStream(out);
-
- oos.writeObject(object);
- oos.flush();
- }
- else
- {
- throw new IllegalArgumentException("Don't know how to deal with object " + object);
- }
- }
-
- public static void writeList(DataOutputStream out, List list) throws IOException
- {
- out.writeInt(list.size());
- Iterator iter = list.iterator();
- while (iter.hasNext())
- {
- Object value = iter.next();
- writeObject(out, value, false, false);
- }
- }
-
- public static ArrayList readList(DataInputStream in) throws ClassNotFoundException, IOException
- {
- int size = in.readInt();
- ArrayList list = new ArrayList(size);
- for (int i = 0; i < size; i++)
- {
- Object obj = readObject(in, false);
- list.add(obj);
- }
- return list;
- }
-
- public static void writeMap(DataOutputStream out, Map map, boolean stringKeys) throws IOException
- {
- Set entrySet = map.entrySet();
- out.writeInt(entrySet.size());
- for (Iterator it = entrySet.iterator(); it.hasNext(); )
- {
- Map.Entry me = (Map.Entry)it.next();
-
- //Write the key
- if (stringKeys)
- {
- out.writeUTF((String)me.getKey());
- }
- else
- {
- writeObject(out, me.getKey(), false, false);
- }
-
- // write the value
- writeObject(out, me.getValue(), false, false);
- }
- }
-
- public static HashMap readMap(DataInputStream in, boolean stringKeys) throws IOException, ClassNotFoundException
- {
- int size = in.readInt();
- HashMap m = new HashMap(size);
- for (int i = 0; i < size; i++)
- {
- Object key;
- if (stringKeys)
- {
- key = in.readUTF();
- }
- else
- {
- key = readObject(in, false);
- }
-
- Object value = readObject(in, false);
-
- m.put(key, value);
- }
- return m;
- }
-
- public static byte[] toBytes(Streamable streamable) throws Exception
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream(BUFFER_SIZE);
-
- DataOutputStream daos = new DataOutputStream(baos);
-
- streamable.write(daos);
-
- daos.close();
-
- return baos.toByteArray();
- }
-
- public static void fromBytes(Streamable streamable, byte[] bytes) throws Exception
- {
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-
- DataInputStream dais = new DataInputStream(bais);
-
- streamable.read(dais);
-
- dais.close();
- }
-
-}
Deleted: trunk/src/main/org/jboss/messaging/util/Streamable.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/Streamable.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/src/main/org/jboss/messaging/util/Streamable.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -1,41 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.util;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-
-/**
- * A Streamable
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version <tt>$Revision$</tt>
- *
- * $Id$
- *
- */
-public interface Streamable
-{
- void write(DataOutputStream out) throws Exception;
-
- void read(DataInputStream in) throws Exception;
-}
Added: trunk/src/main/org/jboss/messaging/util/TypedProperties.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/TypedProperties.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/util/TypedProperties.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -0,0 +1,693 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.messaging.util;
+
+import static org.jboss.messaging.util.DataConstants.BOOLEAN;
+import static org.jboss.messaging.util.DataConstants.BYTE;
+import static org.jboss.messaging.util.DataConstants.BYTES;
+import static org.jboss.messaging.util.DataConstants.CHAR;
+import static org.jboss.messaging.util.DataConstants.DOUBLE;
+import static org.jboss.messaging.util.DataConstants.FLOAT;
+import static org.jboss.messaging.util.DataConstants.INT;
+import static org.jboss.messaging.util.DataConstants.LONG;
+import static org.jboss.messaging.util.DataConstants.NOT_NULL;
+import static org.jboss.messaging.util.DataConstants.NULL;
+import static org.jboss.messaging.util.DataConstants.SHORT;
+import static org.jboss.messaging.util.DataConstants.SIZE_BOOLEAN;
+import static org.jboss.messaging.util.DataConstants.SIZE_BYTE;
+import static org.jboss.messaging.util.DataConstants.SIZE_CHAR;
+import static org.jboss.messaging.util.DataConstants.SIZE_DOUBLE;
+import static org.jboss.messaging.util.DataConstants.SIZE_FLOAT;
+import static org.jboss.messaging.util.DataConstants.SIZE_INT;
+import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
+import static org.jboss.messaging.util.DataConstants.SIZE_SHORT;
+import static org.jboss.messaging.util.DataConstants.STRING;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ *
+ * A TypedProperties
+ *
+ * TODO - should have typed property getters and do conversions herein
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class TypedProperties
+{
+ private static final Logger log = Logger.getLogger(TypedProperties.class);
+
+
+ private Map<SimpleString, PropertyValue> properties;
+
+ public TypedProperties()
+ {
+ }
+
+ public TypedProperties(final TypedProperties other)
+ {
+ this.properties = other.properties == null ? null : new HashMap<SimpleString, PropertyValue>(other.properties);
+ }
+
+ public void putBooleanProperty(final SimpleString key, final boolean value)
+ {
+ checkCreateProperties();
+ properties.put(key, new BooleanValue(value));
+ }
+
+ public void putByteProperty(final SimpleString key, final byte value)
+ {
+ checkCreateProperties();
+ properties.put(key, new ByteValue(value));
+ }
+
+ public void putBytesProperty(final SimpleString key, final byte[] value)
+ {
+ checkCreateProperties();
+ properties.put(key, value == null ? new NullValue() : new BytesValue(value));
+ }
+
+ public void putShortProperty(final SimpleString key, final short value)
+ {
+ checkCreateProperties();
+ properties.put(key, new ShortValue(value));
+ }
+
+ public void putIntProperty(final SimpleString key, final int value)
+ {
+ checkCreateProperties();
+ properties.put(key, new IntValue(value));
+ }
+
+ public void putLongProperty(final SimpleString key, final long value)
+ {
+ checkCreateProperties();
+ properties.put(key, new LongValue(value));
+ }
+
+ public void putFloatProperty(final SimpleString key, final float value)
+ {
+ checkCreateProperties();
+ properties.put(key, new FloatValue(value));
+ }
+
+ public void putDoubleProperty(final SimpleString key, final double value)
+ {
+ checkCreateProperties();
+ properties.put(key, new DoubleValue(value));
+ }
+
+ public void putStringProperty(final SimpleString key, final SimpleString value)
+ {
+ checkCreateProperties();
+ properties.put(key, value == null ? new NullValue() : new StringValue(value));
+ }
+
+ public void putCharProperty(final SimpleString key, final char value)
+ {
+ checkCreateProperties();
+ properties.put(key, new CharValue(value));
+ }
+
+ public Object getProperty(final SimpleString key)
+ {
+ return doGetProperty(key);
+ }
+
+ public Object removeProperty(final SimpleString key)
+ {
+ return doRemoveProperty(key);
+ }
+
+ public boolean containsProperty(final SimpleString key)
+ {
+ return properties.containsKey(key);
+ }
+
+ public Set<SimpleString> getPropertyNames()
+ {
+ return properties.keySet();
+ }
+
+ public void decode(final MessagingBuffer buffer)
+ {
+ byte b = buffer.getByte();
+
+ if (b == NULL)
+ {
+ properties = null;
+ }
+ else
+ {
+ int numHeaders = buffer.getInt();
+
+ properties = new HashMap<SimpleString, PropertyValue>(numHeaders);
+
+ for (int i = 0; i < numHeaders; i++)
+ {
+ int len = buffer.getInt();
+ byte[] data = new byte[len];
+ buffer.getBytes(data);
+ SimpleString key = new SimpleString(data);
+
+ byte type = buffer.getByte();
+
+ PropertyValue val;
+
+ switch (type)
+ {
+ case NULL:
+ {
+ val = new NullValue();
+ properties.put(key, val);
+ break;
+ }
+ case CHAR:
+ {
+ val = new CharValue(buffer);
+ properties.put(key, val);
+ break;
+ }
+ case BOOLEAN:
+ {
+ val = new BooleanValue(buffer);
+ properties.put(key, val);
+ break;
+ }
+ case BYTE:
+ {
+ val = new ByteValue(buffer);
+ properties.put(key, val);
+ break;
+ }
+ case BYTES:
+ {
+ val = new BytesValue(buffer);
+ properties.put(key, val);
+ break;
+ }
+ case SHORT:
+ {
+ val = new ShortValue(buffer);
+ properties.put(key, val);
+ break;
+ }
+ case INT:
+ {
+ val = new IntValue(buffer);
+ properties.put(key, val);
+ break;
+ }
+ case LONG:
+ {
+ val = new LongValue(buffer);
+ properties.put(key, val);
+ break;
+ }
+ case FLOAT:
+ {
+ val = new FloatValue(buffer);
+ properties.put(key, val);
+ break;
+ }
+ case DOUBLE:
+ {
+ val = new DoubleValue(buffer);
+ properties.put(key, val);
+ break;
+ }
+ case STRING:
+ {
+ val = new StringValue(buffer);
+ properties.put(key, val);
+ break;
+ }
+ default:
+ {
+ throw new IllegalArgumentException("Invalid type: " + type);
+ }
+ }
+ }
+ }
+ }
+
+ public void encode(final MessagingBuffer buffer)
+ {
+ if (properties == null)
+ {
+ buffer.putByte(NULL);
+ }
+ else
+ {
+ buffer.putByte(NOT_NULL);
+
+ buffer.putInt(properties.size());
+
+ for (Map.Entry<SimpleString, PropertyValue> entry: properties.entrySet())
+ {
+ SimpleString s = entry.getKey();;
+ byte[] data = s.getData();
+ buffer.putInt(data.length);
+ buffer.putBytes(data);
+
+ entry.getValue().write(buffer);
+ }
+ }
+ }
+
+ public void clear()
+ {
+ if (properties != null)
+ {
+ properties.clear();
+ }
+ }
+
+ // Private ------------------------------------------------------------------------------------
+
+ private void checkCreateProperties()
+ {
+ if (properties == null)
+ {
+ properties = new HashMap<SimpleString, PropertyValue>();
+ }
+ }
+
+ private Object doRemoveProperty(final Object key)
+ {
+ if (properties == null)
+ {
+ return null;
+ }
+
+ PropertyValue val = properties.remove(key);
+
+ if (val == null)
+ {
+ return null;
+ }
+ else
+ {
+ return val.getValue();
+ }
+ }
+
+ private Object doGetProperty(final Object key)
+ {
+ if (properties == null)
+ {
+ return null;
+ }
+
+ PropertyValue val = properties.get(key);
+
+ if (val == null)
+ {
+ return null;
+ }
+ else
+ {
+ return val.getValue();
+ }
+ }
+
+ // Inner classes ------------------------------------------------------------------------------
+
+ private interface PropertyValue
+ {
+ Object getValue();
+
+ void write(MessagingBuffer buffer);
+
+ byte getType();
+ }
+
+ private static final class NullValue implements PropertyValue
+ {
+ public NullValue()
+ {
+ }
+
+ public Object getValue()
+ {
+ return null;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(NULL);
+ }
+
+ public byte getType()
+ {
+ return NULL;
+ }
+ }
+
+ private static final class BooleanValue implements PropertyValue
+ {
+ final boolean val;
+
+ public BooleanValue(final boolean val)
+ {
+ this.val = val;
+ }
+
+ public BooleanValue(final MessagingBuffer buffer)
+ {
+ this.val = buffer.getBoolean();
+ }
+
+ public Object getValue()
+ {
+ return val;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(BOOLEAN);
+ buffer.putBoolean(val);
+ }
+
+ public byte getType()
+ {
+ return BOOLEAN;
+ }
+ }
+
+ private static final class ByteValue implements PropertyValue
+ {
+ final byte val;
+
+ public ByteValue(final byte val)
+ {
+ this.val = val;
+ }
+
+ public ByteValue(final MessagingBuffer buffer)
+ {
+ this.val = buffer.getByte();
+ }
+
+ public Object getValue()
+ {
+ return val;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(BYTE);
+ buffer.putByte(val);
+ }
+
+ public byte getType()
+ {
+ return BYTE;
+ }
+ }
+
+ private static final class BytesValue implements PropertyValue
+ {
+ final byte[] val;
+
+ public BytesValue(final byte[] val)
+ {
+ this.val = val;
+ }
+
+ public BytesValue(final MessagingBuffer buffer)
+ {
+ int len = buffer.getInt();
+ this.val = new byte[len];
+ buffer.getBytes(val);
+ }
+
+ public Object getValue()
+ {
+ return val;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(BYTES);
+ buffer.putInt(val.length);
+ buffer.putBytes(val);
+ }
+
+ public byte getType()
+ {
+ return BYTES;
+ }
+ }
+
+ private static final class ShortValue implements PropertyValue
+ {
+ final short val;
+
+ public ShortValue(final short val)
+ {
+ this.val = val;
+ }
+
+ public ShortValue(final MessagingBuffer buffer)
+ {
+ this.val = buffer.getShort();
+ }
+
+ public Object getValue()
+ {
+ return val;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(SHORT);
+ buffer.putShort(val);
+ }
+
+ public byte getType()
+ {
+ return SHORT;
+ }
+ }
+
+ private static final class IntValue implements PropertyValue
+ {
+ final int val;
+
+ public IntValue(final int val)
+ {
+ this.val = val;
+ }
+
+ public IntValue(final MessagingBuffer buffer)
+ {
+ this.val = buffer.getInt();
+ }
+
+ public Object getValue()
+ {
+ return val;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(INT);
+ buffer.putInt(val);
+ }
+
+ public byte getType()
+ {
+ return INT;
+ }
+ }
+
+ private static final class LongValue implements PropertyValue
+ {
+ final long val;
+
+ public LongValue(final long val)
+ {
+ this.val = val;
+ }
+
+ public LongValue(final MessagingBuffer buffer)
+ {
+ this.val = buffer.getLong();
+ }
+
+ public Object getValue()
+ {
+ return val;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(LONG);
+ buffer.putLong(val);
+ }
+
+ public byte getType()
+ {
+ return LONG;
+ }
+ }
+
+ private static final class FloatValue implements PropertyValue
+ {
+ final float val;
+
+ public FloatValue(final float val)
+ {
+ this.val = val;
+ }
+
+ public FloatValue(final MessagingBuffer buffer)
+ {
+ this.val = buffer.getFloat();
+ }
+
+ public Object getValue()
+ {
+ return val;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(FLOAT);
+ buffer.putFloat(val);
+ }
+
+ public byte getType()
+ {
+ return FLOAT;
+ }
+ }
+
+ private static final class DoubleValue implements PropertyValue
+ {
+ final double val;
+
+ public DoubleValue(final double val)
+ {
+ this.val = val;
+ }
+
+ public DoubleValue(final MessagingBuffer buffer)
+ {
+ this.val = buffer.getDouble();
+ }
+
+ public Object getValue()
+ {
+ return val;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(DOUBLE);
+ buffer.putDouble(val);
+ }
+
+ public byte getType()
+ {
+ return DOUBLE;
+ }
+ }
+
+ private static final class CharValue implements PropertyValue
+ {
+ final char val;
+
+ public CharValue(final char val)
+ {
+ this.val = val;
+ }
+
+ public CharValue(final MessagingBuffer buffer)
+ {
+ this.val = buffer.getChar();
+ }
+
+ public Object getValue()
+ {
+ return val;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(CHAR);
+ buffer.putChar(val);
+ }
+
+ public byte getType()
+ {
+ return CHAR;
+ }
+
+ public int size()
+ {
+ return SIZE_CHAR;
+ }
+ }
+
+ private static final class StringValue implements PropertyValue
+ {
+ final SimpleString val;
+
+ public StringValue(final SimpleString val)
+ {
+ this.val = val;
+ }
+
+ public StringValue(final MessagingBuffer buffer)
+ {
+ this.val = buffer.getSimpleString();
+ }
+
+ public Object getValue()
+ {
+ return val;
+ }
+
+ public void write(final MessagingBuffer buffer)
+ {
+ buffer.putByte(STRING);
+ buffer.putSimpleString(val);
+ }
+
+ public byte getType()
+ {
+ return STRING;
+ }
+
+ public int size()
+ {
+ return SimpleString.sizeofString(val);
+ }
+ }
+}
Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/MessageProducerTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/MessageProducerTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/MessageProducerTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -23,6 +23,7 @@
import java.io.Serializable;
+import javax.jms.BytesMessage;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
@@ -117,6 +118,8 @@
{
pconn = cf.createConnection();
cconn = cf.createConnection();
+
+ log.info("** created connections");
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session cs = cconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -127,6 +130,8 @@
TextMessage m = ps.createTextMessage("test");
p.send(m);
+
+ log.info("** sent message");
TextMessage r = (TextMessage)c.receive(3000);
@@ -135,8 +140,14 @@
}
finally
{
- pconn.close();
- cconn.close();
+ if (pconn != null)
+ {
+ pconn.close();
+ }
+ if (cconn != null)
+ {
+ cconn.close();
+ }
}
}
@@ -148,22 +159,37 @@
{
pconn = cf.createConnection();
- Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ Session ps = pconn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
MessageProducer p = ps.createProducer(queue1);
+ // MessageConsumer cons = ps.createConsumer(queue1);
+
+ // pconn.start();
+
p.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+ p.setDisableMessageID(true);
+ p.setDisableMessageTimestamp(true);
- final int numMessages = 10000;
+ final int numMessages = 20000;
long start = System.currentTimeMillis();
+ BytesMessage msg = ps.createBytesMessage();
+
+ msg.writeBytes(new byte[1000]);
+
+
for (int i = 0; i < numMessages; i++)
{
- Message msg = ps.createMessage();
-
p.send(msg);
}
+
+// for (int i = 0; i < numMessages; i++)
+// {
+// cons.receive(1000);
+// }
long end = System.currentTimeMillis();
Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/PersistenceTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/PersistenceTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/PersistenceTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -82,7 +82,7 @@
stop();
startNoDelete();
-
+
// Messaging server restart implies new ConnectionFactory lookup
deployAndLookupAdministeredObjects();
@@ -131,12 +131,16 @@
TextMessage tm = sess.createTextMessage("message" + i);
prod.send(tm);
}
+
+ log.info("Sent messages");
Session sess2 = conn.createSession(true, Session.SESSION_TRANSACTED);
MessageConsumer cons = sess2.createConsumer(queue1);
conn.start();
+
+ log.info("Started connection");
for (int i = 0; i < 10; i++)
{
@@ -150,6 +154,8 @@
assertEquals(1, tm.getIntProperty("JMSXDeliveryCount"));
}
+
+ log.info("** got messages");
//rollback
sess2.rollback();
@@ -203,385 +209,385 @@
}
}
}
+//
+//
+// /**
+// * First test that message order survives a restart
+// */
+// public void testMessageOrderPersistence_1() throws Exception
+// {
+// Connection conn = null;
+//
+// try
+// {
+// conn = cf.createConnection();
+// Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessSend.createProducer(queue1);
+//
+// TextMessage m0 = sessSend.createTextMessage("a");
+// TextMessage m1 = sessSend.createTextMessage("b");
+// TextMessage m2 = sessSend.createTextMessage("c");
+// TextMessage m3 = sessSend.createTextMessage("d");
+// TextMessage m4 = sessSend.createTextMessage("e");
+// TextMessage m5 = sessSend.createTextMessage("f");
+// TextMessage m6 = sessSend.createTextMessage("g");
+// TextMessage m7 = sessSend.createTextMessage("h");
+// TextMessage m8 = sessSend.createTextMessage("i");
+// TextMessage m9 = sessSend.createTextMessage("j");
+//
+// prod.send(m0, DeliveryMode.PERSISTENT, 0, 0);
+// prod.send(m1, DeliveryMode.PERSISTENT, 1, 0);
+// prod.send(m2, DeliveryMode.PERSISTENT, 2, 0);
+// prod.send(m3, DeliveryMode.PERSISTENT, 3, 0);
+// prod.send(m4, DeliveryMode.PERSISTENT, 4, 0);
+// prod.send(m5, DeliveryMode.PERSISTENT, 5, 0);
+// prod.send(m6, DeliveryMode.PERSISTENT, 6, 0);
+// prod.send(m7, DeliveryMode.PERSISTENT, 7, 0);
+// prod.send(m8, DeliveryMode.PERSISTENT, 8, 0);
+// prod.send(m9, DeliveryMode.PERSISTENT, 9, 0);
+//
+// conn.close();
+//
+// stop();
+//
+// startNoDelete();
+//
+// // Messaging server restart implies new ConnectionFactory lookup
+// deployAndLookupAdministeredObjects();
+//
+// conn = cf.createConnection();
+// Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// conn.start();
+// MessageConsumer cons = sessReceive.createConsumer(queue1);
+//
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("j", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("i", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("h", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("g", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("f", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("e", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("d", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("c", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("b", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("a", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(500);
+// assertNull(t);
+// }
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// }
+// }
+//
+//
+// /**
+// * Second test that message order survives a restart
+// */
+// public void testMessageOrderPersistence_2() throws Exception
+// {
+// Connection conn = null;
+//
+// try
+// {
+// conn = cf.createConnection();
+// Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessSend.createProducer(queue1);
+//
+// TextMessage m0 = sessSend.createTextMessage("a");
+// TextMessage m1 = sessSend.createTextMessage("b");
+// TextMessage m2 = sessSend.createTextMessage("c");
+// TextMessage m3 = sessSend.createTextMessage("d");
+// TextMessage m4 = sessSend.createTextMessage("e");
+// TextMessage m5 = sessSend.createTextMessage("f");
+// TextMessage m6 = sessSend.createTextMessage("g");
+// TextMessage m7 = sessSend.createTextMessage("h");
+// TextMessage m8 = sessSend.createTextMessage("i");
+// TextMessage m9 = sessSend.createTextMessage("j");
+//
+//
+// prod.send(m0, DeliveryMode.PERSISTENT, 0, 0);
+// prod.send(m1, DeliveryMode.PERSISTENT, 0, 0);
+// prod.send(m2, DeliveryMode.PERSISTENT, 0, 0);
+// prod.send(m3, DeliveryMode.PERSISTENT, 3, 0);
+// prod.send(m4, DeliveryMode.PERSISTENT, 3, 0);
+// prod.send(m5, DeliveryMode.PERSISTENT, 4, 0);
+// prod.send(m6, DeliveryMode.PERSISTENT, 4, 0);
+// prod.send(m7, DeliveryMode.PERSISTENT, 5, 0);
+// prod.send(m8, DeliveryMode.PERSISTENT, 5, 0);
+// prod.send(m9, DeliveryMode.PERSISTENT, 6, 0);
+//
+// conn.close();
+//
+// stop();
+//
+// startNoDelete();
+//
+// deployAndLookupAdministeredObjects();
+//
+// conn = cf.createConnection();
+// Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// conn.start();
+// MessageConsumer cons = sessReceive.createConsumer(queue1);
+//
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("j", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("h", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("i", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("f", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("g", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("d", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("e", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("a", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("b", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receive(1000);
+// assertNotNull(t);
+// assertEquals("c", t.getText());
+// }
+// {
+// TextMessage t = (TextMessage)cons.receiveNoWait();
+// assertNull(t);
+// }
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// }
+// }
+//
+// /*
+// * Test durable subscription state survives a server crash
+// */
+// public void testDurableSubscriptionPersistence_1() throws Exception
+// {
+// Connection conn = null;
+//
+// try
+// {
+// conn = cf.createConnection();
+// conn.setClientID("five");
+//
+// Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+// MessageConsumer ds = s.createDurableSubscriber(topic1, "sub", null, false);
+//
+// MessageProducer p = s.createProducer(topic1);
+// p.setDeliveryMode(DeliveryMode.PERSISTENT);
+// TextMessage tm = s.createTextMessage("thebody");
+//
+// p.send(tm);
+// log.debug("message sent");
+//
+// conn.close();
+//
+// stop();
+//
+// startNoDelete();
+//
+// deployAndLookupAdministeredObjects();
+//
+// conn = cf.createConnection();
+// conn.setClientID("five");
+//
+// s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// conn.start();
+//
+// ds = s.createDurableSubscriber(topic1, "sub", null, false);
+//
+// TextMessage rm = (TextMessage)ds.receive(3000);
+// assertNotNull(rm);
+// assertEquals("thebody", rm.getText());
+//
+// ds.close();
+//
+// log.info("************* UNSUBSCRIBE CALLED");
+// s.unsubscribe("sub");
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// }
+// }
+//
+// /*
+// * Test durable subscription state survives a restart
+// */
+// public void testDurableSubscriptionPersistence_2() throws Exception
+// {
+// Connection conn = null;
+//
+// try
+// {
+// conn = cf.createConnection();
+// conn.setClientID("Sausages");
+//
+// Session sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+//
+// MessageConsumer sub1 = sessConsume.createDurableSubscriber(topic1, "sub1", null, false);
+// MessageConsumer sub2 = sessConsume.createDurableSubscriber(topic1, "sub2", null, false);
+// MessageConsumer sub3 = sessConsume.createDurableSubscriber(topic1, "sub3", null, false);
+//
+//
+// Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// MessageProducer prod = sessSend.createProducer(topic1);
+// prod.setDeliveryMode(DeliveryMode.PERSISTENT);
+//
+// for (int i = 0; i < 10; i++)
+// {
+// TextMessage tm = sessSend.createTextMessage("message" + i);
+// prod.send(tm);
+// }
+//
+// conn.close();
+//
+// stop();
+//
+// startNoDelete();
+//
+// // Messaging server restart implies new ConnectionFactory lookup
+// deployAndLookupAdministeredObjects();
+//
+// conn = cf.createConnection();
+// conn.setClientID("Sausages");
+//
+// sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+// conn.start();
+//
+// sub1 = sessConsume.createDurableSubscriber(topic1, "sub1", null, false);
+// sub2 = sessConsume.createDurableSubscriber(topic1, "sub2", null, false);
+// sub3 = sessConsume.createDurableSubscriber(topic1, "sub3", null, false);
+//
+// for (int i = 0; i < 10; i++)
+// {
+// TextMessage tm1 = (TextMessage)sub1.receive(3000);
+// assertNotNull(tm1);
+// if (tm1 == null)
+// {
+// break;
+// }
+// assertEquals("message" + i, tm1.getText());
+//
+// TextMessage tm2 = (TextMessage)sub2.receive(3000);
+// assertNotNull(tm2);
+// if (tm2 == null)
+// {
+// break;
+// }
+// assertEquals("message" + i, tm2.getText());
+//
+// TextMessage tm3 = (TextMessage)sub3.receive(3000);
+// assertNotNull(tm3);
+// if (tm3 == null)
+// {
+// break;
+// }
+// assertEquals("message" + i, tm3.getText());
+// }
+//
+// sub1.close();
+// sub2.close();
+// sub3.close();
+//
+// sessConsume.unsubscribe("sub1");
+// sessConsume.unsubscribe("sub2");
+// sessConsume.unsubscribe("sub3");
+// }
+// finally
+// {
+// if (conn != null)
+// {
+// conn.close();
+// }
+// }
+// }
- /**
- * First test that message order survives a restart
- */
- public void testMessageOrderPersistence_1() throws Exception
- {
- Connection conn = null;
-
- try
- {
- conn = cf.createConnection();
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue1);
-
- TextMessage m0 = sessSend.createTextMessage("a");
- TextMessage m1 = sessSend.createTextMessage("b");
- TextMessage m2 = sessSend.createTextMessage("c");
- TextMessage m3 = sessSend.createTextMessage("d");
- TextMessage m4 = sessSend.createTextMessage("e");
- TextMessage m5 = sessSend.createTextMessage("f");
- TextMessage m6 = sessSend.createTextMessage("g");
- TextMessage m7 = sessSend.createTextMessage("h");
- TextMessage m8 = sessSend.createTextMessage("i");
- TextMessage m9 = sessSend.createTextMessage("j");
-
- prod.send(m0, DeliveryMode.PERSISTENT, 0, 0);
- prod.send(m1, DeliveryMode.PERSISTENT, 1, 0);
- prod.send(m2, DeliveryMode.PERSISTENT, 2, 0);
- prod.send(m3, DeliveryMode.PERSISTENT, 3, 0);
- prod.send(m4, DeliveryMode.PERSISTENT, 4, 0);
- prod.send(m5, DeliveryMode.PERSISTENT, 5, 0);
- prod.send(m6, DeliveryMode.PERSISTENT, 6, 0);
- prod.send(m7, DeliveryMode.PERSISTENT, 7, 0);
- prod.send(m8, DeliveryMode.PERSISTENT, 8, 0);
- prod.send(m9, DeliveryMode.PERSISTENT, 9, 0);
-
- conn.close();
-
- stop();
-
- startNoDelete();
-
- // Messaging server restart implies new ConnectionFactory lookup
- deployAndLookupAdministeredObjects();
-
- conn = cf.createConnection();
- Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn.start();
- MessageConsumer cons = sessReceive.createConsumer(queue1);
-
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("j", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("i", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("h", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("g", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("f", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("e", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("d", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("c", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("b", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("a", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(500);
- assertNull(t);
- }
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
-
-
- /**
- * Second test that message order survives a restart
- */
- public void testMessageOrderPersistence_2() throws Exception
- {
- Connection conn = null;
-
- try
- {
- conn = cf.createConnection();
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(queue1);
-
- TextMessage m0 = sessSend.createTextMessage("a");
- TextMessage m1 = sessSend.createTextMessage("b");
- TextMessage m2 = sessSend.createTextMessage("c");
- TextMessage m3 = sessSend.createTextMessage("d");
- TextMessage m4 = sessSend.createTextMessage("e");
- TextMessage m5 = sessSend.createTextMessage("f");
- TextMessage m6 = sessSend.createTextMessage("g");
- TextMessage m7 = sessSend.createTextMessage("h");
- TextMessage m8 = sessSend.createTextMessage("i");
- TextMessage m9 = sessSend.createTextMessage("j");
-
-
- prod.send(m0, DeliveryMode.PERSISTENT, 0, 0);
- prod.send(m1, DeliveryMode.PERSISTENT, 0, 0);
- prod.send(m2, DeliveryMode.PERSISTENT, 0, 0);
- prod.send(m3, DeliveryMode.PERSISTENT, 3, 0);
- prod.send(m4, DeliveryMode.PERSISTENT, 3, 0);
- prod.send(m5, DeliveryMode.PERSISTENT, 4, 0);
- prod.send(m6, DeliveryMode.PERSISTENT, 4, 0);
- prod.send(m7, DeliveryMode.PERSISTENT, 5, 0);
- prod.send(m8, DeliveryMode.PERSISTENT, 5, 0);
- prod.send(m9, DeliveryMode.PERSISTENT, 6, 0);
-
- conn.close();
-
- stop();
-
- startNoDelete();
-
- deployAndLookupAdministeredObjects();
-
- conn = cf.createConnection();
- Session sessReceive = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn.start();
- MessageConsumer cons = sessReceive.createConsumer(queue1);
-
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("j", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("h", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("i", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("f", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("g", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("d", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("e", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("a", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("b", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receive(1000);
- assertNotNull(t);
- assertEquals("c", t.getText());
- }
- {
- TextMessage t = (TextMessage)cons.receiveNoWait();
- assertNull(t);
- }
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
-
- /*
- * Test durable subscription state survives a server crash
- */
- public void testDurableSubscriptionPersistence_1() throws Exception
- {
- Connection conn = null;
-
- try
- {
- conn = cf.createConnection();
- conn.setClientID("five");
-
- Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer ds = s.createDurableSubscriber(topic1, "sub", null, false);
-
- MessageProducer p = s.createProducer(topic1);
- p.setDeliveryMode(DeliveryMode.PERSISTENT);
- TextMessage tm = s.createTextMessage("thebody");
-
- p.send(tm);
- log.debug("message sent");
-
- conn.close();
-
- stop();
-
- startNoDelete();
-
- deployAndLookupAdministeredObjects();
-
- conn = cf.createConnection();
- conn.setClientID("five");
-
- s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn.start();
-
- ds = s.createDurableSubscriber(topic1, "sub", null, false);
-
- TextMessage rm = (TextMessage)ds.receive(3000);
- assertNotNull(rm);
- assertEquals("thebody", rm.getText());
-
- ds.close();
-
- log.info("************* UNSUBSCRIBE CALLED");
- s.unsubscribe("sub");
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
-
- /*
- * Test durable subscription state survives a restart
- */
- public void testDurableSubscriptionPersistence_2() throws Exception
- {
- Connection conn = null;
-
- try
- {
- conn = cf.createConnection();
- conn.setClientID("Sausages");
-
- Session sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- MessageConsumer sub1 = sessConsume.createDurableSubscriber(topic1, "sub1", null, false);
- MessageConsumer sub2 = sessConsume.createDurableSubscriber(topic1, "sub2", null, false);
- MessageConsumer sub3 = sessConsume.createDurableSubscriber(topic1, "sub3", null, false);
-
-
- Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- MessageProducer prod = sessSend.createProducer(topic1);
- prod.setDeliveryMode(DeliveryMode.PERSISTENT);
-
- for (int i = 0; i < 10; i++)
- {
- TextMessage tm = sessSend.createTextMessage("message" + i);
- prod.send(tm);
- }
-
- conn.close();
-
- stop();
-
- startNoDelete();
-
- // Messaging server restart implies new ConnectionFactory lookup
- deployAndLookupAdministeredObjects();
-
- conn = cf.createConnection();
- conn.setClientID("Sausages");
-
- sessConsume = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- conn.start();
-
- sub1 = sessConsume.createDurableSubscriber(topic1, "sub1", null, false);
- sub2 = sessConsume.createDurableSubscriber(topic1, "sub2", null, false);
- sub3 = sessConsume.createDurableSubscriber(topic1, "sub3", null, false);
-
- for (int i = 0; i < 10; i++)
- {
- TextMessage tm1 = (TextMessage)sub1.receive(3000);
- assertNotNull(tm1);
- if (tm1 == null)
- {
- break;
- }
- assertEquals("message" + i, tm1.getText());
-
- TextMessage tm2 = (TextMessage)sub2.receive(3000);
- assertNotNull(tm2);
- if (tm2 == null)
- {
- break;
- }
- assertEquals("message" + i, tm2.getText());
-
- TextMessage tm3 = (TextMessage)sub3.receive(3000);
- assertNotNull(tm3);
- if (tm3 == null)
- {
- break;
- }
- assertEquals("message" + i, tm3.getText());
- }
-
- sub1.close();
- sub2.close();
- sub3.close();
-
- sessConsume.unsubscribe("sub1");
- sessConsume.unsubscribe("sub2");
- sessConsume.unsubscribe("sub3");
- }
- finally
- {
- if (conn != null)
- {
- conn.close();
- }
- }
- }
-
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/JMSTypeHeaderTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/JMSTypeHeaderTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/JMSTypeHeaderTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -50,7 +50,7 @@
String originalType = "TYPE1";
m.setJMSType(originalType);
queueProducer.send(m);
- String gotType = queueConsumer.receive().getJMSType();
+ String gotType = queueConsumer.receive(1000).getJMSType();
assertEquals(originalType, gotType);
}
@@ -58,7 +58,7 @@
{
Message m = queueProducerSession.createMessage();
queueProducer.send(m);
- assertEquals(null, queueConsumer.receive().getJMSType());
+ assertEquals(null, queueConsumer.receive(1000).getJMSType());
}
Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -565,9 +565,14 @@
fail();
} catch (MessageFormatException e) {}
+ log.info("** clearing props");
m2.clearProperties();
+ log.info("** getting prop names");
Enumeration en2 = m2.getPropertyNames();
+ log.info("** got prop names");
+ assertTrue(en2.hasMoreElements());
+ en2.nextElement();
assertFalse(en2.hasMoreElements());
@@ -765,34 +770,35 @@
ensureEquivalent(receivedMessage, (JBossMessage)message);
}
- public void testForeignJMSReplyTo() throws JMSException
- {
- Message msg = queueProducerSession.createTextMessage();
-
- JBossMessage jbossMessage = (JBossMessage)msg;
-
- Destination foreignDestination = new ForeignDestination();
-
- jbossMessage.setJMSReplyTo(foreignDestination);
-
- queueProducer.send(msg);
-
- Message receivedMessage = queueConsumer.receive(2000);
+// Invalid!!
+// public void testForeignJMSReplyTo() throws JMSException
+// {
+// Message msg = queueProducerSession.createTextMessage();
+//
+// JBossMessage jbossMessage = (JBossMessage)msg;
+//
+// Destination foreignDestination = new ForeignDestination();
+//
+// jbossMessage.setJMSReplyTo(foreignDestination);
+//
+// queueProducer.send(msg);
+//
+// Message receivedMessage = queueConsumer.receive(2000);
+//
+// ensureEquivalent(receivedMessage, jbossMessage);
+// }
+//
+// public void testCopyForeignDestinationAndReplyTo() throws JMSException
+// {
+// Message foreignMessage = new SimpleJMSMessage();
+// foreignMessage.setJMSDestination(new ForeignDestination());
+// foreignMessage.setJMSReplyTo(new ForeignDestination());
+//
+// JBossMessage copy = new JBossMessage(foreignMessage);
+//
+// ensureEquivalent(foreignMessage, copy);
+// }
- ensureEquivalent(receivedMessage, jbossMessage);
- }
-
- public void testCopyForeignDestinationAndReplyTo() throws JMSException
- {
- Message foreignMessage = new SimpleJMSMessage();
- foreignMessage.setJMSDestination(new ForeignDestination());
- foreignMessage.setJMSReplyTo(new ForeignDestination());
-
- JBossMessage copy = new JBossMessage(foreignMessage);
-
- ensureEquivalent(foreignMessage, copy);
- }
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessagePropertyConversionTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessagePropertyConversionTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessagePropertyConversionTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -1,24 +1,24 @@
/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.test.messaging.jms.message;
import javax.jms.Connection;
@@ -32,12 +32,11 @@
/**
*
- * Testing of message property conversion.
- * See javax.jms.Message for details
+ * Testing of message property conversion. See javax.jms.Message for details
*
* @author <a href="mailto:afu at novell.com">Alex Fu</a>
* @version <tt>$Revision$</tt>
- *
+ *
* $Id$
*/
public class MessagePropertyConversionTest extends JBMServerTestCase
@@ -48,7 +47,7 @@
private Session queueProducerSession, queueConsumerSession;
private MessageProducer queueProducer;
private MessageConsumer queueConsumer;
-
+
// Constructors --------------------------------------------------
public MessagePropertyConversionTest(String name)
@@ -65,8 +64,10 @@
producerConnection = getConnectionFactory().createConnection();
consumerConnection = getConnectionFactory().createConnection();
- queueProducerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- queueConsumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ queueProducerSession = producerConnection.createSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ queueConsumerSession = consumerConnection.createSession(false,
+ Session.AUTO_ACKNOWLEDGE);
queueProducer = queueProducerSession.createProducer(queue1);
queueConsumer = queueConsumerSession.createConsumer(queue1);
@@ -75,13 +76,13 @@
}
public void tearDown() throws Exception
- {
+ {
producerConnection.close();
consumerConnection.close();
-
+
super.tearDown();
}
-
+
public void testBooleanConversion() throws Exception
{
Message m1 = queueProducerSession.createMessage();
@@ -91,9 +92,10 @@
queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
-
- // Boolean property can be read as boolean and String but not anything else
+ // Boolean property can be read as boolean and String but not anything
+ // else
+
assertEquals(myBool, m2.getBooleanProperty("myBool"));
assertEquals(String.valueOf(myBool), m2.getStringProperty("myBool"));
@@ -101,39 +103,57 @@
{
m2.getByteProperty("myBool");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getShortProperty("myBool");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getIntProperty("myBool");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getLongProperty("myBool");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getFloatProperty("myBool");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getDoubleProperty("myBool");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
}
-
+
public void testByteConversion() throws Exception
{
Message m1 = queueProducerSession.createMessage();
@@ -143,34 +163,43 @@
queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
-
+
// Byte property can be read as byte, short, int, long or String
assertEquals(myByte, m2.getByteProperty("myByte"));
- assertEquals((short)myByte, m2.getShortProperty("myByte"));
- assertEquals((int)myByte, m2.getIntProperty("myByte"));
- assertEquals((long)myByte, m2.getLongProperty("myByte"));
+ assertEquals((short) myByte, m2.getShortProperty("myByte"));
+ assertEquals((int) myByte, m2.getIntProperty("myByte"));
+ assertEquals((long) myByte, m2.getLongProperty("myByte"));
assertEquals(String.valueOf(myByte), m2.getStringProperty("myByte"));
try
{
m2.getBooleanProperty("myByte");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getFloatProperty("myByte");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getDoubleProperty("myByte");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
}
-
+
public void testShortConversion() throws Exception
{
Message m1 = queueProducerSession.createMessage();
@@ -180,39 +209,51 @@
queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
-
+
// Short property can be read as short, int, long or String
assertEquals(myShort, m2.getShortProperty("myShort"));
- assertEquals((int)myShort, m2.getIntProperty("myShort"));
- assertEquals((long)myShort, m2.getLongProperty("myShort"));
+ assertEquals((int) myShort, m2.getIntProperty("myShort"));
+ assertEquals((long) myShort, m2.getLongProperty("myShort"));
assertEquals(String.valueOf(myShort), m2.getStringProperty("myShort"));
try
{
m2.getByteProperty("myShort");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getBooleanProperty("myShort");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getFloatProperty("myShort");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getDoubleProperty("myShort");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
}
-
+
public void testIntConversion() throws Exception
{
Message m1 = queueProducerSession.createMessage();
@@ -226,40 +267,55 @@
// Int property can be read as int, long or String
assertEquals(myInt, m2.getIntProperty("myInt"));
- assertEquals((long)myInt, m2.getLongProperty("myInt"));
+ assertEquals((long) myInt, m2.getLongProperty("myInt"));
assertEquals(String.valueOf(myInt), m2.getStringProperty("myInt"));
try
{
m2.getShortProperty("myInt");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getByteProperty("myInt");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getBooleanProperty("myInt");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getFloatProperty("myInt");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getDoubleProperty("myInt");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
}
-
+
public void testLongConversion() throws Exception
{
Message m1 = queueProducerSession.createMessage();
@@ -279,39 +335,57 @@
{
m2.getIntProperty("myLong");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getShortProperty("myLong");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getByteProperty("myLong");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getBooleanProperty("myLong");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getFloatProperty("myLong");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getDoubleProperty("myLong");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
}
-
+
public void testFloatConversion() throws Exception
{
Message m1 = queueProducerSession.createMessage();
@@ -321,44 +395,59 @@
queueProducer.send(queue1, m1);
Message m2 = queueConsumer.receive(2000);
-
+
// Float property can be read as float, double or String
assertEquals(myFloat, m2.getFloatProperty("myFloat"), 0);
assertEquals(String.valueOf(myFloat), m2.getStringProperty("myFloat"));
- assertEquals((double)myFloat, m2.getDoubleProperty("myFloat"), 0);
+ assertEquals((double) myFloat, m2.getDoubleProperty("myFloat"), 0);
try
{
m2.getIntProperty("myFloat");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getShortProperty("myFloat");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getLongProperty("myFloat");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getByteProperty("myFloat");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getBooleanProperty("myFloat");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
}
-
+
public void testDoubleConversion() throws Exception
{
Message m1 = queueProducerSession.createMessage();
@@ -378,37 +467,55 @@
{
m2.getFloatProperty("myDouble");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getIntProperty("myDouble");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getShortProperty("myDouble");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getByteProperty("myDouble");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getBooleanProperty("myDouble");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
try
{
m2.getFloatProperty("myDouble");
fail();
- } catch (MessageFormatException e) {}
+ }
+ catch (MessageFormatException e)
+ {
+ }
}
public void testStringConversion() throws Exception
@@ -423,7 +530,7 @@
float myFloat = Float.MAX_VALUE - 23465;
double myDouble = Double.MAX_VALUE - 72387633;
String myString = "abcdef&^*&!^ghijkl";
-
+
m1.setStringProperty("myString", myString);
queueProducer.send(queue1, m1);
@@ -432,10 +539,10 @@
assertEquals(myString, m2.getStringProperty("myString"));
// Test String -> Numeric and bool conversions.
-
- // String property can be read as boolean, byte, short,
+
+ // String property can be read as boolean, byte, short,
// int, long, float, double and String, with the possibility to
- // throw a runtime exception if the primitive's valueOf method does not
+ // throw a runtime exception if the primitive's valueOf method does not
// accept the String as a valid representation of the primitive
Message m3 = queueProducerSession.createMessage();
@@ -468,39 +575,51 @@
m4.getByteProperty("myIllegal");
fail();
}
- catch (NumberFormatException e) {}
+ catch (NumberFormatException e)
+ {
+ }
try
{
m4.getShortProperty("myIllegal");
fail();
}
- catch (NumberFormatException e) {}
+ catch (NumberFormatException e)
+ {
+ }
try
{
m4.getIntProperty("myIllegal");
fail();
}
- catch (NumberFormatException e) {}
+ catch (NumberFormatException e)
+ {
+ }
try
{
m4.getLongProperty("myIllegal");
fail();
}
- catch (NumberFormatException e) {}
+ catch (NumberFormatException e)
+ {
+ }
try
{
m4.getFloatProperty("myIllegal");
fail();
}
- catch (NumberFormatException e) {}
+ catch (NumberFormatException e)
+ {
+ }
try
{
m4.getDoubleProperty("myIllegal");
fail();
}
- catch (NumberFormatException e) {}
- }
-
+ catch (NumberFormatException e)
+ {
+ }
+ }
+
public void testJMSXDeliveryCountConversion() throws Exception
{
Message m1 = queueProducerSession.createMessage();
@@ -509,7 +628,8 @@
Message m2 = queueConsumer.receive(2000);
int count = m2.getIntProperty("JMSXDeliveryCount");
- assertEquals(String.valueOf(count), m2.getStringProperty("JMSXDeliveryCount"));
- assertEquals((long)count, m2.getLongProperty("JMSXDeliveryCount"));
+ assertEquals(String.valueOf(count), m2
+ .getStringProperty("JMSXDeliveryCount"));
+ assertEquals((long) count, m2.getLongProperty("JMSXDeliveryCount"));
}
}
Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageTestBase.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageTestBase.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/MessageTestBase.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -108,9 +108,6 @@
queueProd.setDeliveryMode(DeliveryMode.PERSISTENT);
- // make sure the message is serialized to and from the database
- //SoftMessageReference.keepSoftReference = false;
-
queueProd.send(message);
Message r = queueCons.receive();
@@ -166,7 +163,7 @@
m.setIntProperty("intProperty", 6);
m.setLongProperty("longProperty", 7);
m.setShortProperty("shortProperty", (short)8);
- m.setStringProperty("stringProperty", "this is a String property");
+ m.setStringProperty("stringProperty", "this is a String property");
m.setJMSCorrelationID("this is the correlation ID");
m.setJMSReplyTo(topic1);
Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/tools/container/LocalTestServer.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -127,6 +127,8 @@
return;
}
+ log.info("** deleting database?" + clearDatabase);
+
if (clearDatabase)
{
//Delete the BDB environment
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/CoreClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/CoreClientTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/CoreClientTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -1,6 +1,5 @@
package org.jboss.messaging.tests.integration;
-import static org.jboss.messaging.core.remoting.TransportType.INVM;
import junit.framework.TestCase;
import org.jboss.messaging.core.client.ClientConnection;
@@ -8,11 +7,13 @@
import org.jboss.messaging.core.client.ClientConsumer;
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.Location;
import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
import org.jboss.messaging.core.client.impl.LocationImpl;
import org.jboss.messaging.core.config.impl.ConfigurationImpl;
import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.remoting.TransportType;
import org.jboss.messaging.core.server.impl.MessagingServerImpl;
import org.jboss.messaging.jms.client.JBossTextMessage;
import org.jboss.messaging.util.SimpleString;
@@ -25,7 +26,7 @@
// Attributes ----------------------------------------------------
private ConfigurationImpl conf;
- private MessagingServerImpl invmServer;
+ private MessagingServerImpl server;
// Static --------------------------------------------------------
@@ -39,24 +40,26 @@
super.setUp();
conf = new ConfigurationImpl();
- conf.setInvmDisabled(false);
- conf.setTransport(INVM);
- invmServer = new MessagingServerImpl(conf);
- invmServer.start();
+ conf.setTransport(TransportType.TCP);
+ conf.setHost("localhost");
+ server = new MessagingServerImpl(conf);
+ server.start();
}
@Override
protected void tearDown() throws Exception
{
- invmServer.stop();
+ server.stop();
super.tearDown();
}
- public void testINVMCoreClient() throws Exception
+ public void testCoreClient() throws Exception
{
- ClientConnectionFactory cf = new ClientConnectionFactoryImpl(new LocationImpl(0));
+ Location location = new LocationImpl(TransportType.TCP, "localhost", ConfigurationImpl.DEFAULT_REMOTING_PORT);
+
+ ClientConnectionFactory cf = new ClientConnectionFactoryImpl(location);
ClientConnection conn = cf.createConnection();
ClientSession session = conn.createClientSession(false, true, true, -1, false, false);
@@ -66,15 +69,16 @@
Message message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
System.currentTimeMillis(), (byte) 1);
- message.setPayload("testINVMCoreClient".getBytes());
+ message.getBody().putString("testINVMCoreClient");
producer.send(message);
ClientConsumer consumer = session.createConsumer(QUEUE, null, false, false, true);
conn.start();
message = consumer.receive(1000);
- assertEquals("testINVMCoreClient", new String(message.getPayload()));
+ assertEquals("testINVMCoreClient", message.getBody().getString());
+
conn.close();
}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/ProducerFlowControlTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/ProducerFlowControlTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/ProducerFlowControlTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -1,279 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.messaging.tests.integration;
-
-import junit.framework.TestCase;
-
-import org.jboss.messaging.core.client.ClientProducer;
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.message.Message;
-import org.jboss.messaging.core.message.impl.MessageImpl;
-
-/**
- *
- * A ProducerFlowControlTest
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class ProducerFlowControlTest extends TestCase
-{
- private static final Logger log = Logger.getLogger(ProducerFlowControlTest.class);
-
-
-// public void testFlowControl() throws Exception
-// {
-// ClientConnection conn = null;
-//
-// MessagingServer server = null;
-//
-// try
-// {
-// RemotingConfiguration remotingConf = new RemotingConfiguration(TransportType.TCP, "localhost", 7654);
-//
-// remotingConf.setInvmDisabled(true);
-//
-// server = new MessagingServerImpl(remotingConf);
-//
-// QueueSettings settings = new QueueSettings();
-//
-// settings.setMaxSize(10);
-//
-// server.getQueueSettingsRepository().addMatch("queue1", settings);
-//
-// server.start();
-//
-// ClientConnectionFactory cf = new ClientConnectionFactoryImpl(0, remotingConf, server.getVersion());
-//
-// conn = cf.createConnection(null, null);
-//
-// final ClientSession session1 = conn.createClientSession(false, true, true, 1, false);
-//
-// session1.createQueue("queue1", "queue1", null, false, false);
-//
-// final ClientSession session2 = conn.createClientSession(false, true, true, 1, false);
-//
-// final ClientSession session3 = conn.createClientSession(false, true, true, 1, false);
-//
-// ClientProducer producer1 = session1.createProducer("queue1");
-//
-// ClientProducer producer2 = session2.createProducer("queue1");
-//
-// ClientProducer producer3 = session3.createProducer("queue1");
-//
-// ClientConsumer consumer =
-// session1.createConsumer("queue1", null, false, false, false);
-//
-// MessageHandler handler = new MessageHandler() {
-// public void onMessage(Message msg)
-// {
-// try
-// {
-// log.info("Got message " + msg.getHeader("count"));
-//
-// Thread.sleep(1000);
-//
-// session1.acknowledge();
-// }
-// catch(Exception e)
-// {
-// e.printStackTrace();
-// }
-// }
-// };
-//
-// consumer.setMessageHandler(handler);
-//
-// conn.start();
-//
-// Thread thread1 = new ProducerThread(producer1, "producer1");
-//
-// Thread thread2 = new ProducerThread(producer2, "producer2");
-//
-// Thread thread3 = new ProducerThread(producer3, "producer3");
-//
-// thread1.start();
-//
-// thread2.start();
-//
-// thread3.start();
-//
-// thread1.join();
-//
-// thread2.join();
-//
-// thread3.join();
-//
-// }
-// finally
-// {
-// if (conn != null)
-// {
-// conn.close();
-// }
-//
-// if (server != null)
-// {
-// server.stop();
-// }
-// }
-//
-//
-// }
-//
-
-// public void testFlowControlRate() throws Exception
-// {
-// ClientConnection conn = null;
-//
-// MessagingServer server = null;
-//
-// try
-// {
-// RemotingConfiguration remotingConf = new RemotingConfiguration(TransportType.TCP, "localhost", 7654);
-//
-// remotingConf.setInvmDisabled(true);
-//
-// server = new MessagingServerImpl(remotingConf);
-//
-// server.start();
-//
-// ClientConnectionFactory cf = new ClientConnectionFactoryImpl(0, remotingConf, server.getVersion());
-//
-// conn = cf.createConnection(null, null);
-//
-// final ClientSession session1 = conn.createClientSession(false, true, true, 1, false);
-//
-// session1.createQueue("queue1", "queue1", null, false, false);
-//
-// final ClientSession session2 = conn.createClientSession(false, true, true, 1, false);
-//
-// final ClientSession session3 = conn.createClientSession(false, true, true, 1, false);
-//
-// ClientProducer producer1 = session1.createRateLimitedProducer("queue1", 10);
-//
-// ClientProducer producer2 = session2.createRateLimitedProducer("queue1", 1);
-//
-// ClientProducer producer3 = session3.createRateLimitedProducer("queue1", 5);
-//
-// ClientConsumer consumer =
-// session1.createConsumer("queue1", null, false, false, false);
-//
-// MessageHandler handler = new MessageHandler() {
-// public void onMessage(Message msg)
-// {
-// try
-// {
-// log.info("Got message " + msg.getHeader("count"));
-//
-// Thread.sleep(1000);
-//
-// session1.acknowledge();
-// }
-// catch(Exception e)
-// {
-// e.printStackTrace();
-// }
-// }
-// };
-//
-// consumer.setMessageHandler(handler);
-//
-// conn.start();
-//
-// Thread thread1 = new ProducerThread(producer1, "producer1");
-//
-// Thread thread2 = new ProducerThread(producer2, "producer2");
-//
-// Thread thread3 = new ProducerThread(producer3, "producer3");
-//
-// thread1.start();
-//
-// thread2.start();
-//
-// thread3.start();
-//
-// thread1.join();
-//
-// thread2.join();
-//
-// thread3.join();
-//
-// }
-// finally
-// {
-// if (conn != null)
-// {
-// conn.close();
-// }
-//
-// if (server != null)
-// {
-// server.stop();
-// }
-// }
-//
-//
-// }
-
-
- public void testNull()
- {}
-
- class ProducerThread extends Thread
- {
- final ClientProducer producer;
-
- final String producerName;
-
- int count;
-
- ProducerThread(ClientProducer producer, String producerName)
- {
- this.producer = producer;
-
- this.producerName = producerName;
- }
-
- public void run()
- {
- try
- {
- while (true)
- {
- Message message = new MessageImpl(7, false, 0, System.currentTimeMillis(), (byte) 1);
-
- message.putHeader("count", count++);
-
- producer.send(message);
-
- log.info("Producer " + producerName + " sent message " + count);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
-
-}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientCrashTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientCrashTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientCrashTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -115,8 +115,7 @@
// send the message to the queue
Message messageFromClient = consumer.receive(5000);
assertNotNull("no message received", messageFromClient);
- assertEquals(MESSAGE_TEXT_FROM_CLIENT, new String(messageFromClient
- .getPayload()));
+ assertEquals(MESSAGE_TEXT_FROM_CLIENT, messageFromClient.getBody().getString());
// 1 local connection to the server
// + 1 per connection to the client
@@ -124,8 +123,7 @@
MessageImpl message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
System.currentTimeMillis(), (byte) 1);
- message
- .setPayload(ClientCrashTest.MESSAGE_TEXT_FROM_SERVER.getBytes());
+ message.getBody().putString(ClientCrashTest.MESSAGE_TEXT_FROM_SERVER);
producer.send(message);
log.info("waiting for the client VM to crash ...");
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientExitTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientExitTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientExitTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -85,7 +85,7 @@
Message message = consumer.receive(15000);
assertNotNull(message);
- assertEquals(MESSAGE_TEXT, new String(message.getPayload()));
+ assertEquals(MESSAGE_TEXT, message.getBody().getString());
// the client VM should exit by itself. If it doesn't, that means we have a problem
// and the test will timeout
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/CrashClient.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/CrashClient.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/CrashClient.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -90,7 +90,7 @@
MessageImpl message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
System.currentTimeMillis(), (byte) 1);
- message.setPayload(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT.getBytes());
+ message.getBody().putString(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT);
producer.send(message);
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/DummyInterceptor.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/DummyInterceptor.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/DummyInterceptor.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -14,6 +14,7 @@
import org.jboss.messaging.core.remoting.Interceptor;
import org.jboss.messaging.core.remoting.Packet;
import org.jboss.messaging.core.remoting.impl.wireformat.ReceiveMessage;
+import org.jboss.messaging.util.SimpleString;
public class DummyInterceptor implements Interceptor
{
@@ -47,7 +48,7 @@
{
ReceiveMessage deliver = (ReceiveMessage)packet;
log.info("msg = " + deliver.getMessage().getClass().getName());
- deliver.getMessage().getHeaders().put("DummyInterceptor", "was here");
+ deliver.getMessage().putStringProperty(new SimpleString("DummyInterceptor"), new SimpleString("was here"));
}
}
}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/GracefulClient.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/GracefulClient.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/GracefulClient.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -24,7 +24,12 @@
import static org.jboss.messaging.core.remoting.TransportType.TCP;
import static org.jboss.messaging.tests.integration.core.remoting.impl.ClientExitTest.QUEUE;
-import org.jboss.messaging.core.client.*;
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.Location;
import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
import org.jboss.messaging.core.client.impl.LocationImpl;
import org.jboss.messaging.core.config.impl.ConfigurationImpl;
@@ -64,7 +69,7 @@
MessageImpl message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
System.currentTimeMillis(), (byte) 1);
- message.setPayload(ClientExitTest.MESSAGE_TEXT.getBytes());
+ message.getBody().putString(ClientExitTest.MESSAGE_TEXT);
producer.send(message);
conn.start();
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/PacketFilterTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/PacketFilterTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/PacketFilterTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -7,8 +7,6 @@
package org.jboss.messaging.tests.integration.core.remoting.impl;
-import static org.jboss.messaging.core.remoting.TransportType.INVM;
-
import java.util.UUID;
import junit.framework.TestCase;
@@ -18,12 +16,14 @@
import org.jboss.messaging.core.client.ClientConsumer;
import org.jboss.messaging.core.client.ClientProducer;
import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.Location;
import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
import org.jboss.messaging.core.client.impl.LocationImpl;
import org.jboss.messaging.core.config.impl.ConfigurationImpl;
import org.jboss.messaging.core.logging.Logger;
import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.remoting.TransportType;
import org.jboss.messaging.core.server.impl.MessagingServerImpl;
import org.jboss.messaging.jms.client.JBossTextMessage;
import org.jboss.messaging.util.SimpleString;
@@ -45,7 +45,8 @@
protected void setUp() throws Exception
{
ConfigurationImpl config = new ConfigurationImpl();
- config.setTransport(INVM);
+ config.setTransport(TransportType.TCP);
+ config.setHost("localhost");
server = new MessagingServerImpl(config);
server.start();
}
@@ -64,7 +65,9 @@
DummyInterceptor interceptorA = null;
DummyInterceptorB interceptorB = null;
- ClientConnectionFactory cf = new ClientConnectionFactoryImpl(new LocationImpl(0));
+ Location location = new LocationImpl(TransportType.TCP, "localhost", ConfigurationImpl.DEFAULT_REMOTING_PORT);
+
+ ClientConnectionFactory cf = new ClientConnectionFactoryImpl(location);
ClientConnection conn = null;
try
{
@@ -170,8 +173,9 @@
interceptor.sendException=false;
-
- ClientConnectionFactory cf = new ClientConnectionFactoryImpl(new LocationImpl(0));
+ Location location = new LocationImpl(TransportType.TCP, "localhost", ConfigurationImpl.DEFAULT_REMOTING_PORT);
+
+ ClientConnectionFactory cf = new ClientConnectionFactoryImpl(location);
conn = cf.createConnection();
conn.start();
ClientSession session = conn.createClientSession(false, true, true, -1, false, false);
@@ -180,17 +184,17 @@
interceptor.changeMessage = true;
MessageImpl message = new MessageImpl(JBossTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte) 1);
- message.setPayload(msg.getBytes());
+ message.getBody().putString(msg);
producer.send(message);
ClientConsumer consumer = session.createConsumer(QUEUE1, null, false, false, true);
- Message jmsMsg = consumer.receive(100000);
- assertEquals(jmsMsg.getHeader("DummyInterceptor"), "was here");
+ Message m = consumer.receive(100000);
+ assertEquals(m.getProperty(new SimpleString("DummyInterceptor")), new SimpleString("was here"));
- assertNotNull(jmsMsg);
+ assertNotNull(m);
- assertEquals(msg, new String(jmsMsg.getPayload()));
+ assertEquals(msg, m.getBody().getString());
}
finally
{
Copied: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/BufferWrapperTest.java (from rev 4151, trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MinaRemotingBufferTest.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/BufferWrapperTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/BufferWrapperTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.tests.integration.core.remoting.mina;
+
+import static java.util.UUID.randomUUID;
+import junit.framework.TestCase;
+
+import org.apache.mina.common.IoBuffer;
+import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
+ *
+ * @version <tt>$Revision$</tt>
+ */
+public class BufferWrapperTest extends TestCase
+{
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ private BufferWrapper wrapper;
+ private IoBuffer buffer;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ buffer = IoBuffer.allocate(256);
+ buffer.setAutoExpand(true);
+ wrapper = new BufferWrapper(buffer);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ wrapper = null;
+ buffer = null;
+
+ }
+
+ public void testNullString() throws Exception
+ {
+ assertNull(putAndGetNullableString(null));
+ }
+
+ public void testEmptyString() throws Exception
+ {
+ String result = putAndGetNullableString("");
+
+ assertNotNull(result);
+ assertEquals("", result);
+ }
+
+ public void testNonEmptyString() throws Exception
+ {
+ String junk = randomUUID().toString();
+
+ String result = putAndGetNullableString(junk);
+
+ assertNotNull(result);
+ assertEquals(junk, result);
+ }
+
+ public void testPutTrueBoolean() throws Exception
+ {
+ wrapper.putBoolean(true);
+
+ buffer.flip();
+
+ assertTrue(wrapper.getBoolean());
+ }
+
+ public void testPutFalseBoolean() throws Exception
+ {
+ wrapper.putBoolean(false);
+
+ buffer.flip();
+
+ assertFalse(wrapper.getBoolean());
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ private String putAndGetNullableString(String nullableString) throws Exception
+ {
+ wrapper.putNullableString(nullableString);
+
+ buffer.flip();
+
+ return wrapper.getNullableString();
+ }
+ // Inner classes -------------------------------------------------
+}
Deleted: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MinaRemotingBufferTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MinaRemotingBufferTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/mina/MinaRemotingBufferTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -1,108 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.tests.integration.core.remoting.mina;
-
-import static java.util.UUID.randomUUID;
-import junit.framework.TestCase;
-
-import org.apache.mina.common.IoBuffer;
-import org.jboss.messaging.core.remoting.impl.codec.RemotingBuffer;
-import org.jboss.messaging.core.remoting.impl.mina.BufferWrapper;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>.
- *
- * @version <tt>$Revision$</tt>
- */
-public class MinaRemotingBufferTest extends TestCase
-{
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- private RemotingBuffer wrapper;
- private IoBuffer buffer;
-
- @Override
- protected void setUp() throws Exception
- {
- buffer = IoBuffer.allocate(256);
- buffer.setAutoExpand(true);
- wrapper = new BufferWrapper(buffer);
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- wrapper = null;
- buffer = null;
-
- }
-
- public void testNullString() throws Exception
- {
- assertNull(putAndGetNullableString(null));
- }
-
- public void testEmptyString() throws Exception
- {
- String result = putAndGetNullableString("");
-
- assertNotNull(result);
- assertEquals("", result);
- }
-
- public void testNonEmptyString() throws Exception
- {
- String junk = randomUUID().toString();
-
- String result = putAndGetNullableString(junk);
-
- assertNotNull(result);
- assertEquals(junk, result);
- }
-
- public void testPutTrueBoolean() throws Exception
- {
- wrapper.putBoolean(true);
-
- buffer.flip();
-
- assertTrue(wrapper.getBoolean());
- }
-
- public void testPutFalseBoolean() throws Exception
- {
- wrapper.putBoolean(false);
-
- buffer.flip();
-
- assertFalse(wrapper.getBoolean());
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- private String putAndGetNullableString(String nullableString) throws Exception
- {
- wrapper.putNullableString(nullableString);
-
- buffer.flip();
-
- return wrapper.getNullableString();
- }
- // Inner classes -------------------------------------------------
-}
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSL.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSL.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSL.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -78,7 +78,7 @@
MessageImpl message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
System.currentTimeMillis(), (byte) 1);
- message.setPayload(CoreClientOverSSLTest.MESSAGE_TEXT_FROM_CLIENT.getBytes());
+ message.getBody().putString(CoreClientOverSSLTest.MESSAGE_TEXT_FROM_CLIENT);
producer.send(message);
conn.close();
Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSLTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSLTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSLTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -82,7 +82,7 @@
Message m = consumer.receive(10000);
assertNotNull(m);
- assertEquals(MESSAGE_TEXT_FROM_CLIENT, new String(m.getPayload()));
+ assertEquals(MESSAGE_TEXT_FROM_CLIENT, m.getBody().getString());
log.info("waiting for the client VM to exit ...");
SpawnedVMSupport.assertProcessExits(true, 0, p);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/filter/impl/FilterTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/filter/impl/FilterTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/filter/impl/FilterTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -151,10 +151,10 @@
private void testBoolean(String name, boolean flag) throws Exception
{
- message.putHeader(name, flag);
+ message.putBooleanProperty(new SimpleString(name), flag);
assertTrue(filter.match(message));
- message.putHeader(name, !flag);
+ message.putBooleanProperty(new SimpleString(name), !flag);
assertTrue(!filter.match(message));
}
@@ -593,7 +593,7 @@
private void doPutStringProperty(String key, String value)
{
- message.putHeader(key, value);
+ message.putStringProperty(new SimpleString(key), new SimpleString(value));
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/message/impl/MessageTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/message/impl/MessageTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/message/impl/MessageTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -21,10 +21,6 @@
*/
package org.jboss.messaging.tests.unit.core.message.impl;
-import static org.jboss.messaging.tests.util.RandomUtil.randomByte;
-import static org.jboss.messaging.tests.util.RandomUtil.randomInt;
-import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
-
import org.jboss.messaging.core.message.Message;
import org.jboss.messaging.core.message.MessageReference;
import org.jboss.messaging.core.message.impl.MessageImpl;
@@ -33,7 +29,6 @@
import org.jboss.messaging.tests.unit.core.server.impl.fakes.FakeQueueFactory;
import org.jboss.messaging.tests.util.UnitTestCase;
import org.jboss.messaging.util.SimpleString;
-import org.jboss.messaging.util.StreamUtils;
/**
*
@@ -48,7 +43,7 @@
{
private QueueFactory queueFactory = new FakeQueueFactory();
- public void testCreateMessage()
+ public void testCreateMessageBeforeSending()
{
long id = 56465;
int type = 655;
@@ -81,26 +76,10 @@
public void testCreateMessageFromStorage() throws Exception
{
long id = 56465;
- int type = 655;
- boolean reliable = true;
- long expiration = 6712671;
- long timestamp = 82798172;
- byte priority = 32;
+
+ Message message = new MessageImpl(id);
- byte[] bytes = "blah blah blah".getBytes();
-
- Message message = new MessageImpl(id, type, reliable, expiration, timestamp, priority,
- null, bytes);
-
assertEquals(id, message.getMessageID());
- assertEquals(type, message.getType());
- assertEquals(reliable, message.isDurable());
- assertEquals(timestamp, message.getTimestamp());
- assertEquals(priority, message.getPriority());
-
- assertByteArraysEquivalent(bytes, message.getPayload());
-
- //TODO - headers - they should really be combined into single blob
}
public void testCopy()
@@ -192,60 +171,8 @@
assertEquals(connectionID, message.getConnectionID());
}
- public void testSetAndGetPayload()
- {
- Message message = new MessageImpl();
-
- assertNull(message.getPayload());
-
- byte[] bytes = "blah blah blah".getBytes();
- message.setPayload(bytes);
-
- assertByteArraysEquivalent(bytes, message.getPayload());
- }
+
- public void testHeaders()
- {
- Message message = new MessageImpl();
-
- assertNotNull(message.getHeaders());
- assertTrue(message.getHeaders().isEmpty());
-
- String key1 = "key1";
- String val1 = "wibble";
- String key2 = "key2";
- Object val2 = new Object();
- String key3 = "key3";
- Double val3 = new Double(123.456);
- Long val4 = new Long(77777);
- message.putHeader(key1, val1);
- assertEquals(val1, message.getHeaders().get(key1));
- assertEquals(1, message.getHeaders().size());
- assertTrue(message.containsHeader(key1));
- assertFalse(message.containsHeader("does not exist"));
- message.putHeader(key2, val2);
- assertEquals(val2, message.getHeaders().get(key2));
- assertEquals(2, message.getHeaders().size());
- assertTrue(message.containsHeader(key2));
- message.putHeader(key3, val3);
- assertEquals(val3, message.getHeaders().get(key3));
- assertEquals(3, message.getHeaders().size());
- assertTrue(message.containsHeader(key3));
- message.putHeader(key3, val4);
- assertEquals(val4, message.getHeaders().get(key3));
- assertEquals(3, message.getHeaders().size());
- assertEquals(val2, message.removeHeader(key2));
- assertEquals(2, message.getHeaders().size());
- assertFalse(message.containsHeader(key2));
- assertNull(message.removeHeader("does not exist"));
- assertEquals(val1, message.removeHeader(key1));
- assertFalse(message.containsHeader(key2));
- assertEquals(1, message.getHeaders().size());
- assertEquals(val4, message.removeHeader(key3));
- assertFalse(message.containsHeader(key3));
- assertTrue(message.getHeaders().isEmpty());
- }
-
public void testEquals()
{
Message message1 = new MessageImpl();
@@ -374,23 +301,5 @@
}
- public void testMarshalling() throws Exception
- {
- Message msg = new MessageImpl(randomLong(), randomInt(), true, randomLong(), randomLong(), randomByte(),null, null);
- msg.setDeliveryCount(randomInt());
-
- byte[] bytes = StreamUtils.toBytes(msg);
- Message unmarshalledMsg = new MessageImpl();
- StreamUtils.fromBytes(unmarshalledMsg, bytes);
-
- assertEquals(msg, unmarshalledMsg);
- assertEquals("messageID", msg.getMessageID(), unmarshalledMsg.getMessageID());
- assertEquals("type", msg.getType(), unmarshalledMsg.getType());
- assertEquals("durable", msg.isDurable(), unmarshalledMsg.isDurable());
- assertEquals("expiration", msg.getExpiration(), unmarshalledMsg.getExpiration());
- assertEquals("timestamp", msg.getTimestamp(), unmarshalledMsg.getTimestamp());
- assertEquals("priority", msg.getPriority(), unmarshalledMsg.getPriority());
- assertEquals("deliveryCount", msg.getDeliveryCount(), unmarshalledMsg.getDeliveryCount());
- }
}
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/remoting/impl/wireformat/PacketTypeTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -67,9 +67,7 @@
import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
import static org.jboss.messaging.tests.util.RandomUtil.randomString;
import static org.jboss.messaging.tests.util.RandomUtil.randomXid;
-import static org.jboss.messaging.util.DataConstants.FALSE;
import static org.jboss.messaging.util.DataConstants.SIZE_LONG;
-import static org.jboss.messaging.util.DataConstants.TRUE;
import java.util.ArrayList;
import java.util.List;
@@ -96,7 +94,6 @@
import org.jboss.messaging.core.remoting.impl.codec.ProducerReceiveTokensMessageCodec;
import org.jboss.messaging.core.remoting.impl.codec.ProducerSendMessageCodec;
import org.jboss.messaging.core.remoting.impl.codec.ReceiveMessageCodec;
-import org.jboss.messaging.core.remoting.impl.codec.RemotingBuffer;
import org.jboss.messaging.core.remoting.impl.codec.SessionAcknowledgeMessageCodec;
import org.jboss.messaging.core.remoting.impl.codec.SessionAddDestinationMessageCodec;
import org.jboss.messaging.core.remoting.impl.codec.SessionBindingQueryMessageCodec;
@@ -176,8 +173,8 @@
import org.jboss.messaging.core.remoting.impl.wireformat.TextPacket;
import org.jboss.messaging.core.version.impl.VersionImpl;
import org.jboss.messaging.tests.util.UnitTestCase;
+import org.jboss.messaging.util.MessagingBuffer;
import org.jboss.messaging.util.SimpleString;
-import org.jboss.messaging.util.StreamUtils;
/**
* @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -198,18 +195,18 @@
// Static --------------------------------------------------------
- private static RemotingBuffer encode(int length, Object... args)
+ private static MessagingBuffer encode(int length, Object... args)
throws Exception
{
BufferWrapper buffer = new BufferWrapper(IoBuffer.allocate(length));
for (Object arg : args)
{
if (arg instanceof Byte)
- buffer.put(((Byte) arg).byteValue());
+ buffer.putByte(((Byte) arg).byteValue());
else if (arg instanceof Boolean)
{
Boolean bool = (Boolean) arg;
- buffer.put(bool ? TRUE : FALSE);
+ buffer.putBoolean(bool);
} else if (arg instanceof Integer)
buffer.putInt(((Integer) arg).intValue());
else if (arg instanceof Long)
@@ -228,7 +225,7 @@
{
byte[] b = (byte[]) arg;
buffer.putInt(b.length);
- buffer.put(b);
+ buffer.putBytes(b);
} else if (arg instanceof long[])
{
long[] longs = (long[]) arg;
@@ -262,7 +259,7 @@
return buffer;
}
- private static void checkHeader(final RemotingBuffer buffer,
+ private static void checkHeader(final MessagingBuffer buffer,
final Packet packet, final int bodyLength) throws Exception
{
buffer.rewind();
@@ -270,7 +267,7 @@
assertEquals(AbstractPacketCodec.HEADER_LENGTH + bodyLength,
messageLength);
- assertEquals(buffer.get(), packet.getType().byteValue());
+ assertEquals(buffer.getByte(), packet.getType().byteValue());
long responseTargetID = buffer.getLong();
long targetID = buffer.getLong();
@@ -281,12 +278,12 @@
assertEquals(packet.getExecutorID(), executorID);
}
- private static void checkBody(RemotingBuffer buffer, int bodyLength,
+ private static void checkBody(MessagingBuffer buffer, int bodyLength,
Object... bodyObjects) throws Exception
{
byte[] actualBody = new byte[bodyLength];
- buffer.get(actualBody);
- RemotingBuffer expectedBody = encode(actualBody.length, bodyObjects);
+ buffer.getBytes(actualBody);
+ MessagingBuffer expectedBody = encode(actualBody.length, bodyObjects);
assertEqualsByteArrays(expectedBody.array(), actualBody);
// check the buffer has been wholly read
assertEquals(0, buffer.remaining());
@@ -295,8 +292,8 @@
private static Packet encodeAndCheckBytesAndDecode(Packet packet,
AbstractPacketCodec codec, Object... bodyObjects) throws Exception
{
- RemotingBuffer buffer = encode(packet, codec);
- int bodyLength = codec.getBodyLength(packet);
+ MessagingBuffer buffer = encode(packet, codec);
+ int bodyLength = buffer.position();
checkHeader(buffer, packet, bodyLength);
checkBody(buffer, bodyLength, bodyObjects);
buffer.rewind();
@@ -306,7 +303,7 @@
return decodedPacket;
}
- private static RemotingBuffer encode(final Packet packet,
+ private static MessagingBuffer encode(final Packet packet,
final AbstractPacketCodec<Packet> codec) throws Exception
{
SimpleProtocolEncoderOutput out = new SimpleProtocolEncoderOutput();
@@ -319,12 +316,12 @@
assertTrue(encodedMessage instanceof IoBuffer);
- RemotingBuffer buff = new BufferWrapper((IoBuffer) encodedMessage);
+ MessagingBuffer buff = new BufferWrapper((IoBuffer) encodedMessage);
return buff;
}
- private static Packet decode(final RemotingBuffer buffer,
+ private static Packet decode(final MessagingBuffer buffer,
final AbstractPacketCodec<Packet> codec, final int len)
throws Exception
{
@@ -334,7 +331,7 @@
assertEquals(len + HEADER_LENGTH, length);
- byte type = buffer.get();
+ byte type = buffer.getByte();
assertEquals(codec.getType().byteValue(), type);
@@ -352,890 +349,897 @@
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+//
+// public void testNullPacket() throws Exception
+// {
+// Packet packet = new PacketImpl(NULL);
+// long cid = randomLong();
+// packet.setResponseTargetID(cid);
+// packet.setTargetID(randomLong());
+// packet.setExecutorID(randomLong());
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(NULL);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec);
+// assertTrue(decodedPacket instanceof PacketImpl);
+//
+// assertEquals(NULL, decodedPacket.getType());
+// assertEquals(packet.getResponseTargetID(), decodedPacket.getResponseTargetID());
+// assertEquals(packet.getTargetID(), decodedPacket.getTargetID());
+// assertEquals(packet.getExecutorID(), decodedPacket.getExecutorID());
+// }
+//
+// public void testPing() throws Exception
+// {
+// Ping ping = new Ping(randomLong());
+// AbstractPacketCodec<Ping> codec = new PingCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(ping, codec, ping
+// .getSessionID());
+//
+// assertTrue(decodedPacket instanceof Ping);
+// Ping decodedPing = (Ping) decodedPacket;
+// assertEquals(PING, decodedPing.getType());
+// assertEquals(ping.getResponseTargetID(), decodedPacket.getResponseTargetID());
+// assertEquals(ping.getTargetID(), decodedPacket.getTargetID());
+// assertEquals(ping.getExecutorID(), decodedPacket.getExecutorID());
+// }
+//
+// public void testPong() throws Exception
+// {
+// Pong pong = new Pong(randomLong(), true);
+// AbstractPacketCodec<Pong> codec = new PongCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(pong, codec, pong
+// .getSessionID(), pong.isSessionFailed());
+//
+// assertTrue(decodedPacket instanceof Pong);
+// Pong decodedPong = (Pong) decodedPacket;
+// assertEquals(PONG, decodedPong.getType());
+// assertEquals(pong.getSessionID(), decodedPong.getSessionID());
+// assertEquals(pong.isSessionFailed(), decodedPong.isSessionFailed());
+// }
+//
+// public void testTextPacket() throws Exception
+// {
+// TextPacket packet = new TextPacket("testTextPacket");
+// AbstractPacketCodec<TextPacket> codec = new TextPacketCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec, packet
+// .getText());
+//
+// assertTrue(decodedPacket instanceof TextPacket);
+// TextPacket p = (TextPacket) decodedPacket;
+//
+// assertEquals(TEXT, p.getType());
+// assertEquals(packet.getText(), p.getText());
+// }
+//
+// public void testBytesPacket() throws Exception
+// {
+// BytesPacket packet = new BytesPacket(randomBytes());
+// AbstractPacketCodec<BytesPacket> codec = new BytesPacketCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec, packet
+// .getBytes());
+//
+// assertTrue(decodedPacket instanceof BytesPacket);
+// BytesPacket p = (BytesPacket) decodedPacket;
+//
+// assertEquals(BYTES, p.getType());
+// assertEqualsByteArrays(packet.getBytes(), p.getBytes());
+// }
+//
+// public void testCreateConnectionRequest() throws Exception
+// {
+// int version = randomInt();
+// long remotingSessionID = randomLong();
+// String username = null;
+// String password = null;
+// CreateConnectionRequest request = new CreateConnectionRequest(version,
+// remotingSessionID, username, password);
+// AbstractPacketCodec<CreateConnectionRequest> codec = new CreateConnectionMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec,
+// version, remotingSessionID, username, password);
+//
+// assertTrue(decodedPacket instanceof CreateConnectionRequest);
+// CreateConnectionRequest decodedRequest = (CreateConnectionRequest) decodedPacket;
+//
+// assertEquals(CREATECONNECTION, decodedPacket.getType());
+// assertEquals(request.getVersion(), decodedRequest.getVersion());
+// assertEquals(request.getRemotingSessionID(), decodedRequest
+// .getRemotingSessionID());
+// assertEquals(request.getUsername(), decodedRequest.getUsername());
+// assertEquals(request.getPassword(), decodedRequest.getPassword());
+// }
+//
+// public void testCreateConnectionResponse() throws Exception
+// {
+// CreateConnectionResponse response = new CreateConnectionResponse(
+// randomLong(), new VersionImpl("test", 1,2,3,4,"xxx"));
+// AbstractPacketCodec<CreateConnectionResponse> codec = new CreateConnectionResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
+// response.getConnectionTargetID(),
+// response.getServerVersion().getVersionName(),
+// response.getServerVersion().getMajorVersion(),
+// response.getServerVersion().getMinorVersion(),
+// response.getServerVersion().getMicroVersion(),
+// response.getServerVersion().getIncrementingVersion(),
+// response.getServerVersion().getVersionSuffix());
+//
+// assertTrue(decodedPacket instanceof CreateConnectionResponse);
+// CreateConnectionResponse decodedResponse = (CreateConnectionResponse) decodedPacket;
+// assertEquals(PacketType.CREATECONNECTION_RESP, decodedResponse.getType());
+// assertEquals(response.getConnectionTargetID(), decodedResponse
+// .getConnectionTargetID());
+// assertEquals(response.getServerVersion().getFullVersion(), decodedResponse.getServerVersion().getFullVersion());
+// }
+//
+// public void testConnectionCreateSessionMessage() throws Exception
+// {
+// ConnectionCreateSessionMessage request = new ConnectionCreateSessionMessage(
+// randomBoolean(), randomBoolean(), randomBoolean());
+// AbstractPacketCodec<ConnectionCreateSessionMessage> codec = new ConnectionCreateSessionMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec,
+// request.isXA(), request.isAutoCommitSends(), request
+// .isAutoCommitAcks());
+//
+// assertTrue(decodedPacket instanceof ConnectionCreateSessionMessage);
+// ConnectionCreateSessionMessage decodedRequest = (ConnectionCreateSessionMessage) decodedPacket;
+// assertEquals(PacketType.CONN_CREATESESSION, decodedRequest.getType());
+// assertEquals(request.isXA(), decodedRequest.isXA());
+// assertEquals(request.isAutoCommitSends(), decodedRequest
+// .isAutoCommitSends());
+// assertEquals(request.isAutoCommitAcks(), decodedRequest
+// .isAutoCommitAcks());
+// }
+//
+// public void testConnectionCreateSessionResponseMessage() throws Exception
+// {
+// ConnectionCreateSessionResponseMessage response = new ConnectionCreateSessionResponseMessage(
+// randomLong());
+// AbstractPacketCodec<ConnectionCreateSessionResponseMessage> codec = new ConnectionCreateSessionResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
+// response.getSessionID());
+//
+// assertTrue(decodedPacket instanceof ConnectionCreateSessionResponseMessage);
+// ConnectionCreateSessionResponseMessage decodedResponse = (ConnectionCreateSessionResponseMessage) decodedPacket;
+// assertEquals(PacketType.CONN_CREATESESSION_RESP, decodedResponse
+// .getType());
+// assertEquals(response.getSessionID(), decodedResponse.getSessionID());
+// }
+//
+// public void testProducerSendMessage() throws Exception
+// {
+// Message msg = new MessageImpl((byte)1, false, 1212212L, 761276712L, (byte)1);
+// msg.setDestination(new SimpleString("blah"));
+// ProducerSendMessage packet = new ProducerSendMessage(msg);
+// MessagingBuffer buff = packet.getMessage().encode();
+//
+// Message msg2 = new MessageImpl();
+// msg2.decode(buff);
+//
+//
+// byte[] messageBytes = buff.array();
+// byte[] data = new byte[buff.limit()];
+// System.arraycopy(messageBytes, 0, data, 0, buff.limit());
+// AbstractPacketCodec codec = new ProducerSendMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec, data);
+//
+// assertTrue(decodedPacket instanceof ProducerSendMessage);
+// ProducerSendMessage decodedMessage = (ProducerSendMessage) decodedPacket;
+// assertEquals(PacketType.PROD_SEND, decodedPacket.getType());
+// assertEquals(packet.getMessage().getMessageID(), decodedMessage
+// .getMessage().getMessageID());
+// }
+//
+// public void testSessionCreateConsumerMessage() throws Exception
+// {
+// SimpleString destination = new SimpleString("queue.SessionCreateConsumerMessage");
+// SessionCreateConsumerMessage request = new SessionCreateConsumerMessage(randomLong(),
+// destination, new SimpleString("color = 'red'"), false, false, randomInt(),
+// randomInt());
+// AbstractPacketCodec codec = new SessionCreateConsumerMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec, request.getClientTargetID(),
+// request.getQueueName(), new NullableStringHolder(request.getFilterString()), request
+// .isNoLocal(), request.isAutoDeleteQueue(), request
+// .getWindowSize(), request.getMaxRate());
+//
+// assertTrue(decodedPacket instanceof SessionCreateConsumerMessage);
+// SessionCreateConsumerMessage decodedRequest = (SessionCreateConsumerMessage) decodedPacket;
+// assertEquals(PacketType.SESS_CREATECONSUMER, decodedRequest.getType());
+// assertEquals(request.getClientTargetID(), decodedRequest.getClientTargetID());
+// assertEquals(request.getQueueName(), decodedRequest.getQueueName());
+// assertEquals(request.getFilterString(), decodedRequest.getFilterString());
+// assertEquals(request.isNoLocal(), decodedRequest.isNoLocal());
+// assertEquals(request.isAutoDeleteQueue(), decodedRequest
+// .isAutoDeleteQueue());
+// assertEquals(request.getWindowSize(), decodedRequest.getWindowSize());
+// assertEquals(request.getMaxRate(), decodedRequest.getMaxRate());
+// }
+//
+//
+//
+// public void testSessionCreateConsumerResponseMessage() throws Exception
+// {
+// SessionCreateConsumerResponseMessage response = new SessionCreateConsumerResponseMessage(
+// randomLong(), randomInt());
+// AbstractPacketCodec codec = new SessionCreateConsumerResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
+// response.getConsumerTargetID(), response.getWindowSize());
+//
+// assertTrue(decodedPacket instanceof SessionCreateConsumerResponseMessage);
+// SessionCreateConsumerResponseMessage decodedResponse = (SessionCreateConsumerResponseMessage) decodedPacket;
+// assertEquals(SESS_CREATECONSUMER_RESP, decodedResponse.getType());
+//
+// assertEquals(response.getConsumerTargetID(), decodedResponse
+// .getConsumerTargetID());
+// assertEquals(response.getWindowSize(), decodedResponse.getWindowSize());
+// }
+//
+// public void testSessionCreateProducerMessage() throws Exception
+// {
+// SimpleString destination = new SimpleString("queue.testSessionCreateProducerMessage");
+// int windowSize = randomInt();
+// int maxRate = randomInt();
+// SessionCreateProducerMessage request = new SessionCreateProducerMessage(randomLong(),
+// destination, windowSize, maxRate);
+// AbstractPacketCodec codec = new SessionCreateProducerMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec, request.getClientTargetID(),
+// new NullableStringHolder(request.getAddress()), request.getWindowSize(), request.getMaxRate());
+//
+// assertTrue(decodedPacket instanceof SessionCreateProducerMessage);
+// SessionCreateProducerMessage decodedRequest = (SessionCreateProducerMessage) decodedPacket;
+// assertEquals(SESS_CREATEPRODUCER, decodedRequest.getType());
+// assertEquals(request.getClientTargetID(), decodedRequest.getClientTargetID());
+// assertEquals(request.getAddress(), decodedRequest.getAddress());
+// assertEquals(request.getWindowSize(), decodedRequest.getWindowSize());
+// assertEquals(request.getMaxRate(), decodedRequest.getMaxRate());
+// }
+//
+// public void testSessionCreateProducerResponseMessage() throws Exception
+// {
+// SessionCreateProducerResponseMessage response = new SessionCreateProducerResponseMessage(
+// randomLong(), randomInt(), randomInt());
+// AbstractPacketCodec codec = new SessionCreateProducerResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
+// response.getProducerTargetID(), response.getWindowSize(), response
+// .getMaxRate());
+//
+// assertTrue(decodedPacket instanceof SessionCreateProducerResponseMessage);
+// SessionCreateProducerResponseMessage decodedResponse = (SessionCreateProducerResponseMessage) decodedPacket;
+// assertEquals(SESS_CREATEPRODUCER_RESP, decodedResponse.getType());
+// assertEquals(response.getProducerTargetID(), decodedResponse
+// .getProducerTargetID());
+// assertEquals(response.getWindowSize(), decodedResponse.getWindowSize());
+// assertEquals(response.getMaxRate(), decodedResponse.getMaxRate());
+// }
+//
+// public void testStartConnectionMessage() throws Exception
+// {
+// Packet packet = new PacketImpl(CONN_START);
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(CONN_START);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec);
+//
+// assertEquals(CONN_START, decodedPacket.getType());
+// }
+//
+// public void testStopConnectionMessage() throws Exception
+// {
+// Packet packet = new PacketImpl(CONN_STOP);
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(CONN_STOP);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec);
+//
+// assertEquals(CONN_STOP, decodedPacket.getType());
+// }
+//
+// public void testConsumerFlowTokenMessage() throws Exception
+// {
+// ConsumerFlowTokenMessage message = new ConsumerFlowTokenMessage(
+// randomInt());
+// AbstractPacketCodec codec = new ConsumerFlowTokenMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getTokens());
+//
+// assertTrue(decodedPacket instanceof ConsumerFlowTokenMessage);
+// ConsumerFlowTokenMessage decodedMessage = (ConsumerFlowTokenMessage) decodedPacket;
+// assertEquals(CONS_FLOWTOKEN, decodedMessage.getType());
+// assertEquals(message.getTokens(), decodedMessage.getTokens());
+// }
+//
+// public void testProducerReceiveTokensMessage() throws Exception
+// {
+// ProducerReceiveTokensMessage message = new ProducerReceiveTokensMessage(
+// randomInt());
+// AbstractPacketCodec codec = new ProducerReceiveTokensMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getTokens());
+//
+// assertTrue(decodedPacket instanceof ProducerReceiveTokensMessage);
+// ProducerReceiveTokensMessage decodedMessage = (ProducerReceiveTokensMessage) decodedPacket;
+// assertEquals(PROD_RECEIVETOKENS, decodedMessage.getType());
+// assertEquals(message.getTokens(), decodedMessage.getTokens());
+// }
+//
+// public void testReceiveMessage() throws Exception
+// {
+// Message msg = new MessageImpl();
+// ReceiveMessage message = new ReceiveMessage(msg);
+// AbstractPacketCodec codec = new ReceiveMessageCodec();
+//
+// byte[] messageBytes = message.getMessage().encode().array();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec, messageBytes);
+//
+// assertTrue(decodedPacket instanceof ReceiveMessage);
+// ReceiveMessage decodedMessage = (ReceiveMessage) decodedPacket;
+// assertEquals(RECEIVE_MSG, decodedMessage.getType());
+// assertEquals(message.getMessage().getMessageID(), decodedMessage
+// .getMessage().getMessageID());
+// }
+//
+// public void testSessionAcknowledgeMessage() throws Exception
+// {
+// SessionAcknowledgeMessage message = new SessionAcknowledgeMessage(
+// randomLong(), randomBoolean());
+// AbstractPacketCodec codec = new SessionAcknowledgeMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getDeliveryID(), message.isAllUpTo());
+//
+// assertTrue(decodedPacket instanceof SessionAcknowledgeMessage);
+// SessionAcknowledgeMessage decodedMessage = (SessionAcknowledgeMessage) decodedPacket;
+// assertEquals(SESS_ACKNOWLEDGE, decodedMessage.getType());
+// assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
+// assertEquals(message.isAllUpTo(), decodedMessage.isAllUpTo());
+// }
+//
+// public void testSessionCancelMessage() throws Exception
+// {
+// SessionCancelMessage message = new SessionCancelMessage(randomLong(),
+// randomBoolean());
+// AbstractPacketCodec codec = new SessionCancelMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getDeliveryID(), message.isExpired());
+//
+// assertTrue(decodedPacket instanceof SessionCancelMessage);
+// SessionCancelMessage decodedMessage = (SessionCancelMessage) decodedPacket;
+// assertEquals(SESS_CANCEL, decodedMessage.getType());
+// assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
+// assertEquals(message.isExpired(), decodedMessage.isExpired());
+// }
+//
+// public void testSessionCommitMessage() throws Exception
+// {
+// Packet message = new PacketImpl(SESS_COMMIT);
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(SESS_COMMIT);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
+//
+// assertEquals(SESS_COMMIT, decodedPacket.getType());
+// }
+//
+// public void testSessionRollbackMessage() throws Exception
+// {
+// Packet message = new PacketImpl(SESS_ROLLBACK);
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(SESS_ROLLBACK);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
+//
+// assertEquals(SESS_ROLLBACK, decodedPacket.getType());
+// }
+//
+// public void testSessionRecoverMessage() throws Exception
+// {
+// Packet message = new PacketImpl(SESS_RECOVER);
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(SESS_RECOVER);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
+//
+// assertEquals(SESS_RECOVER, decodedPacket.getType());
+// }
+//
+// public void testCloseMessage() throws Exception
+// {
+// Packet message = new PacketImpl(CLOSE);
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(CLOSE);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
+//
+// assertEquals(CLOSE, decodedPacket.getType());
+// }
+//
+// public void testSessionCreateBrowserMessage() throws Exception
+// {
+// SimpleString destination = new SimpleString("queue.testCreateBrowserRequest");
+// SessionCreateBrowserMessage request = new SessionCreateBrowserMessage(
+// destination, new SimpleString("color = 'red'"));
+// AbstractPacketCodec codec = new SessionCreateBrowserMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec,
+// request.getQueueName(), new NullableStringHolder(request.getFilterString()));
+//
+// assertTrue(decodedPacket instanceof SessionCreateBrowserMessage);
+// SessionCreateBrowserMessage decodedRequest = (SessionCreateBrowserMessage) decodedPacket;
+// assertEquals(SESS_CREATEBROWSER, decodedRequest.getType());
+// assertEquals(request.getQueueName(), decodedRequest.getQueueName());
+// assertEquals(request.getFilterString(), decodedRequest.getFilterString());
+// }
+//
+// public void testSessionCreateBrowserResponseMessage() throws Exception
+// {
+// SessionCreateBrowserResponseMessage response = new SessionCreateBrowserResponseMessage(
+// randomLong());
+// AbstractPacketCodec codec = new SessionCreateBrowserResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
+// response.getBrowserTargetID());
+//
+// assertTrue(decodedPacket instanceof SessionCreateBrowserResponseMessage);
+// SessionCreateBrowserResponseMessage decodedResponse = (SessionCreateBrowserResponseMessage) decodedPacket;
+// assertEquals(SESS_CREATEBROWSER_RESP, decodedResponse.getType());
+// assertEquals(response.getBrowserTargetID(), decodedResponse
+// .getBrowserTargetID());
+// }
+//
+// public void testBrowserResetMessage() throws Exception
+// {
+// Packet message = new PacketImpl(SESS_BROWSER_RESET);
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(SESS_BROWSER_RESET);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
+//
+// assertEquals(SESS_BROWSER_RESET, decodedPacket.getType());
+// }
+//
+// public void testBrowserHasNextMessageRequest() throws Exception
+// {
+// Packet request = new PacketImpl(SESS_BROWSER_HASNEXTMESSAGE);
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(SESS_BROWSER_HASNEXTMESSAGE);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec);
+//
+// assertEquals(SESS_BROWSER_HASNEXTMESSAGE, decodedPacket.getType());
+// }
+//
+// public void testSessionBrowserHasNextMessageResponseMessage()
+// throws Exception
+// {
+// SessionBrowserHasNextMessageResponseMessage response = new SessionBrowserHasNextMessageResponseMessage(
+// randomBoolean());
+// AbstractPacketCodec codec = new SessionBrowserHasNextMessageResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
+// response.hasNext());
+//
+// assertTrue(decodedPacket instanceof SessionBrowserHasNextMessageResponseMessage);
+// SessionBrowserHasNextMessageResponseMessage decodedResponse = (SessionBrowserHasNextMessageResponseMessage) decodedPacket;
+// assertEquals(SESS_BROWSER_HASNEXTMESSAGE_RESP, decodedResponse.getType());
+// assertEquals(response.hasNext(), decodedResponse.hasNext());
+// }
+//
+// public void testBrowserNextMessageRequest() throws Exception
+// {
+// Packet request = new PacketImpl(SESS_BROWSER_NEXTMESSAGE);
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(SESS_BROWSER_NEXTMESSAGE);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec);
+//
+// assertEquals(SESS_BROWSER_NEXTMESSAGE, decodedPacket.getType());
+// }
+//
+// public void testSessionXACommitMessage() throws Exception
+// {
+// SessionXACommitMessage message = new SessionXACommitMessage(randomXid(),
+// randomBoolean());
+// AbstractPacketCodec codec = new SessionXACommitMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getXid(), message.isOnePhase());
+//
+// assertTrue(decodedPacket instanceof SessionXACommitMessage);
+// SessionXACommitMessage decodedMessage = (SessionXACommitMessage) decodedPacket;
+// assertEquals(SESS_XA_COMMIT, decodedMessage.getType());
+// assertEquals(message.getXid(), decodedMessage.getXid());
+// assertEquals(message.isOnePhase(), decodedMessage.isOnePhase());
+// }
+//
+// public void testSessionXAEndMessage() throws Exception
+// {
+// SessionXAEndMessage message = new SessionXAEndMessage(randomXid(),
+// randomBoolean());
+// AbstractPacketCodec codec = new SessionXAEndMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getXid(), message.isFailed());
+//
+// assertTrue(decodedPacket instanceof SessionXAEndMessage);
+// SessionXAEndMessage decodedMessage = (SessionXAEndMessage) decodedPacket;
+// assertEquals(SESS_XA_END, decodedMessage.getType());
+// assertEquals(message.getXid(), decodedMessage.getXid());
+// assertEquals(message.isFailed(), decodedMessage.isFailed());
+// }
+//
+// public void testSessionXAForgetMessage() throws Exception
+// {
+// SessionXAForgetMessage message = new SessionXAForgetMessage(randomXid());
+// AbstractPacketCodec codec = new SessionXAForgetMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getXid());
+//
+// assertTrue(decodedPacket instanceof SessionXAForgetMessage);
+// SessionXAForgetMessage decodedMessage = (SessionXAForgetMessage) decodedPacket;
+// assertEquals(SESS_XA_FORGET, decodedMessage.getType());
+// assertEquals(message.getXid(), decodedMessage.getXid());
+// }
+//
+// public void testSessionXAGetInDoubtXidsMessage() throws Exception
+// {
+// Packet request = new PacketImpl(SESS_XA_INDOUBT_XIDS);
+// AbstractPacketCodec codec = createCodecForEmptyPacket(SESS_XA_INDOUBT_XIDS);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec);
+//
+// assertEquals(SESS_XA_INDOUBT_XIDS, decodedPacket.getType());
+// }
+//
+// public void testSessionXAGetInDoubtXidsResponseMessage() throws Exception
+// {
+// final int numXids = 10;
+// List<Xid> xids = new ArrayList<Xid>();
+// for (int i = 0; i < numXids; i++)
+// {
+// xids.add(randomXid());
+// }
+// SessionXAGetInDoubtXidsResponseMessage message = new SessionXAGetInDoubtXidsResponseMessage(
+// xids);
+// AbstractPacketCodec codec = new SessionXAGetInDoubtXidsResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec, xids);
+//
+// assertTrue(decodedPacket instanceof SessionXAGetInDoubtXidsResponseMessage);
+// SessionXAGetInDoubtXidsResponseMessage decodedMessage = (SessionXAGetInDoubtXidsResponseMessage) decodedPacket;
+// assertEquals(SESS_XA_INDOUBT_XIDS_RESP, decodedMessage.getType());
+//
+// assertSameXids(message.getXids(), decodedMessage.getXids());
+// }
+//
+// public void testSessionXAGetTimeoutMessage() throws Exception
+// {
+// Packet message = new PacketImpl(SESS_XA_GET_TIMEOUT);
+// AbstractPacketCodec codec = createCodecForEmptyPacket(PacketType.SESS_XA_GET_TIMEOUT);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
+//
+// assertEquals(SESS_XA_GET_TIMEOUT, decodedPacket.getType());
+// }
+//
+// public void testSessionXAGetTimeoutResponseMessage() throws Exception
+// {
+// SessionXAGetTimeoutResponseMessage message = new SessionXAGetTimeoutResponseMessage(
+// randomInt());
+// AbstractPacketCodec codec = new SessionXAGetTimeoutResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getTimeoutSeconds());
+//
+// assertTrue(decodedPacket instanceof SessionXAGetTimeoutResponseMessage);
+// SessionXAGetTimeoutResponseMessage decodedMessage = (SessionXAGetTimeoutResponseMessage) decodedPacket;
+// assertEquals(SESS_XA_GET_TIMEOUT_RESP, decodedMessage.getType());
+// assertEquals(message.getTimeoutSeconds(), decodedMessage
+// .getTimeoutSeconds());
+// }
+//
+// public void testSessionXAJoinMessage() throws Exception
+// {
+// SessionXAJoinMessage message = new SessionXAJoinMessage(randomXid());
+// AbstractPacketCodec codec = new SessionXAJoinMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getXid());
+//
+// assertTrue(decodedPacket instanceof SessionXAJoinMessage);
+// SessionXAJoinMessage decodedMessage = (SessionXAJoinMessage) decodedPacket;
+// assertEquals(SESS_XA_JOIN, decodedMessage.getType());
+// assertEquals(message.getXid(), decodedMessage.getXid());
+// }
+//
+// public void testSessionXAPrepareMessage() throws Exception
+// {
+// SessionXAPrepareMessage message = new SessionXAPrepareMessage(randomXid());
+// AbstractPacketCodec codec = new SessionXAPrepareMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getXid());
+//
+// assertTrue(decodedPacket instanceof SessionXAPrepareMessage);
+// SessionXAPrepareMessage decodedMessage = (SessionXAPrepareMessage) decodedPacket;
+// assertEquals(SESS_XA_PREPARE, decodedMessage.getType());
+// assertEquals(message.getXid(), decodedMessage.getXid());
+// }
+//
+// public void testSessionXAResponseMessage() throws Exception
+// {
+// SessionXAResponseMessage message = new SessionXAResponseMessage(
+// randomBoolean(), randomInt(), randomString());
+// AbstractPacketCodec codec = new SessionXAResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.isError(), message.getResponseCode(), message.getMessage());
+//
+// assertTrue(decodedPacket instanceof SessionXAResponseMessage);
+// SessionXAResponseMessage decodedMessage = (SessionXAResponseMessage) decodedPacket;
+// assertEquals(SESS_XA_RESP, decodedMessage.getType());
+// assertEquals(message.isError(), decodedMessage.isError());
+// assertEquals(message.getResponseCode(), decodedMessage.getResponseCode());
+// assertEquals(message.getMessage(), decodedMessage.getMessage());
+// }
+//
+// public void testSessionXAResumeMessage() throws Exception
+// {
+// SessionXAResumeMessage message = new SessionXAResumeMessage(randomXid());
+// AbstractPacketCodec codec = new SessionXAResumeMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getXid());
+//
+// assertTrue(decodedPacket instanceof SessionXAResumeMessage);
+// SessionXAResumeMessage decodedMessage = (SessionXAResumeMessage) decodedPacket;
+// assertEquals(SESS_XA_RESUME, decodedMessage.getType());
+// assertEquals(message.getXid(), decodedMessage.getXid());
+// }
+//
+// public void testSessionXARollbackMessage() throws Exception
+// {
+// SessionXARollbackMessage message = new SessionXARollbackMessage(
+// randomXid());
+// AbstractPacketCodec codec = new SessionXARollbackMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getXid());
+//
+// assertTrue(decodedPacket instanceof SessionXARollbackMessage);
+// SessionXARollbackMessage decodedMessage = (SessionXARollbackMessage) decodedPacket;
+// assertEquals(SESS_XA_ROLLBACK, decodedMessage.getType());
+// assertEquals(message.getXid(), decodedMessage.getXid());
+// }
+//
+// public void testSessionXASetTimeoutMessage() throws Exception
+// {
+// SessionXASetTimeoutMessage message = new SessionXASetTimeoutMessage(
+// randomInt());
+// AbstractPacketCodec codec = new SessionXASetTimeoutMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getTimeoutSeconds());
+//
+// assertTrue(decodedPacket instanceof SessionXASetTimeoutMessage);
+// SessionXASetTimeoutMessage decodedMessage = (SessionXASetTimeoutMessage) decodedPacket;
+// assertEquals(SESS_XA_SET_TIMEOUT, decodedMessage.getType());
+// assertEquals(message.getTimeoutSeconds(), decodedMessage
+// .getTimeoutSeconds());
+// }
+//
+// public void testSessionXASetTimeoutResponseMessage() throws Exception
+// {
+// SessionXASetTimeoutResponseMessage message = new SessionXASetTimeoutResponseMessage(
+// randomBoolean());
+// AbstractPacketCodec codec = new SessionXASetTimeoutResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.isOK());
+//
+// assertTrue(decodedPacket instanceof SessionXASetTimeoutResponseMessage);
+// SessionXASetTimeoutResponseMessage decodedMessage = (SessionXASetTimeoutResponseMessage) decodedPacket;
+// assertEquals(SESS_XA_SET_TIMEOUT_RESP, decodedMessage.getType());
+// assertEquals(message.isOK(), decodedMessage.isOK());
+// }
+//
+// public void testSessionXAStartMessage() throws Exception
+// {
+// SessionXAStartMessage message = new SessionXAStartMessage(randomXid());
+// AbstractPacketCodec codec = new SessionXAStartMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getXid());
+//
+// assertTrue(decodedPacket instanceof SessionXAStartMessage);
+// SessionXAStartMessage decodedMessage = (SessionXAStartMessage) decodedPacket;
+// assertEquals(SESS_XA_START, decodedMessage.getType());
+// assertEquals(message.getXid(), decodedMessage.getXid());
+// }
+//
+// public void testSessionXASuspendMessage() throws Exception
+// {
+// Packet message = new PacketImpl(SESS_XA_SUSPEND);
+// AbstractPacketCodec codec = PacketCodecFactory
+// .createCodecForEmptyPacket(PacketType.SESS_XA_SUSPEND);
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
+//
+// assertEquals(SESS_XA_SUSPEND, decodedPacket.getType());
+// }
+//
+// public void testSessionRemoveDestinationMessage() throws Exception
+// {
+// SessionRemoveDestinationMessage message = new SessionRemoveDestinationMessage(
+// new SimpleString(randomString()), randomBoolean());
+// AbstractPacketCodec codec = new SessionRemoveDestinationMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getAddress(), message.isTemporary());
+//
+// assertTrue(decodedPacket instanceof SessionRemoveDestinationMessage);
+// SessionRemoveDestinationMessage decodedMessage = (SessionRemoveDestinationMessage) decodedPacket;
+// assertEquals(SESS_REMOVE_DESTINATION, decodedMessage.getType());
+// assertEquals(message.getAddress(), decodedMessage.getAddress());
+// assertEquals(message.isTemporary(), decodedMessage.isTemporary());
+// }
+//
+// public void testSessionCreateQueueMessage() throws Exception
+// {
+// SessionCreateQueueMessage message = new SessionCreateQueueMessage(
+// new SimpleString(randomString()), new SimpleString(randomString()),
+// new SimpleString(randomString()), randomBoolean(),
+// randomBoolean());
+// AbstractPacketCodec codec = new SessionCreateQueueMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getAddress(), message.getQueueName(), new NullableStringHolder(message.getFilterString()), message.isDurable(), message
+// .isTemporary());
+//
+// assertTrue(decodedPacket instanceof SessionCreateQueueMessage);
+// SessionCreateQueueMessage decodedMessage = (SessionCreateQueueMessage) decodedPacket;
+// assertEquals(SESS_CREATEQUEUE, decodedMessage.getType());
+//
+// assertEquals(message.getAddress(), decodedMessage.getAddress());
+// assertEquals(message.getQueueName(), decodedMessage.getQueueName());
+// assertEquals(message.getFilterString(), decodedMessage.getFilterString());
+// assertEquals(message.isDurable(), decodedMessage.isDurable());
+// assertEquals(message.isTemporary(), decodedMessage.isTemporary());
+//
+// }
+//
+// public void testSessionQueueQueryMessage() throws Exception
+// {
+// SessionQueueQueryMessage message = new SessionQueueQueryMessage(
+// new SimpleString(randomString()));
+// AbstractPacketCodec codec = new SessionQueueQueryMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getQueueName());
+//
+// assertTrue(decodedPacket instanceof SessionQueueQueryMessage);
+// SessionQueueQueryMessage decodedMessage = (SessionQueueQueryMessage) decodedPacket;
+// assertEquals(SESS_QUEUEQUERY, decodedMessage.getType());
+// assertEquals(message.getQueueName(), decodedMessage.getQueueName());
+// }
+//
+// public void testSessionQueueQueryResponseMessage() throws Exception
+// {
+// SessionQueueQueryResponseMessage message = new SessionQueueQueryResponseMessage(
+// randomBoolean(), randomBoolean(), randomInt(), randomInt(),
+// randomInt(), new SimpleString(randomString()), new SimpleString(randomString()));
+// AbstractPacketCodec codec = new SessionQueueQueryResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.isExists(), message.isDurable(), message.isTemporary(),
+// message.getMaxSize(), message.getConsumerCount(), message
+// .getMessageCount(), new NullableStringHolder(message.getFilterString()),
+// new NullableStringHolder(message.getAddress()));
+//
+// assertTrue(decodedPacket instanceof SessionQueueQueryResponseMessage);
+// SessionQueueQueryResponseMessage decodedMessage = (SessionQueueQueryResponseMessage) decodedPacket;
+// assertEquals(SESS_QUEUEQUERY_RESP, decodedMessage.getType());
+//
+// assertEquals(message.isExists(), decodedMessage.isExists());
+// assertEquals(message.isDurable(), decodedMessage.isDurable());
+// assertEquals(message.isTemporary(), decodedMessage.isTemporary());
+// assertEquals(message.getConsumerCount(), decodedMessage
+// .getConsumerCount());
+// assertEquals(message.getMessageCount(), decodedMessage.getMessageCount());
+// assertEquals(message.getFilterString(), decodedMessage.getFilterString());
+// assertEquals(message.getAddress(), decodedMessage.getAddress());
+// }
+//
+// public void testSessionAddAddressMessage() throws Exception
+// {
+// SessionAddDestinationMessage message = new SessionAddDestinationMessage(
+// new SimpleString(randomString()), randomBoolean());
+// AbstractPacketCodec<SessionAddDestinationMessage> codec = new SessionAddDestinationMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getAddress(), message.isTemporary());
+//
+// assertTrue(decodedPacket instanceof SessionAddDestinationMessage);
+// SessionAddDestinationMessage decodedMessage = (SessionAddDestinationMessage) decodedPacket;
+// assertEquals(SESS_ADD_DESTINATION, decodedMessage.getType());
+// assertEquals(message.getAddress(), decodedMessage.getAddress());
+// assertEquals(message.isTemporary(), decodedMessage.isTemporary());
+// }
+//
+// public void testSessionBindingQueryMessage() throws Exception
+// {
+// SessionBindingQueryMessage message = new SessionBindingQueryMessage(
+// new SimpleString(randomString()));
+// AbstractPacketCodec codec = new SessionBindingQueryMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getAddress());
+//
+// assertTrue(decodedPacket instanceof SessionBindingQueryMessage);
+// SessionBindingQueryMessage decodedMessage = (SessionBindingQueryMessage) decodedPacket;
+// assertEquals(SESS_BINDINGQUERY, decodedMessage.getType());
+//
+// assertEquals(message.getAddress(), decodedMessage.getAddress());
+// }
+//
+// public void testSessionBindingQueryResponseMessage() throws Exception
+// {
+// boolean exists = true;
+// List<SimpleString> queueNames = new ArrayList<SimpleString>();
+// queueNames.add(new SimpleString(randomString()));
+// queueNames.add(new SimpleString(randomString()));
+// queueNames.add(new SimpleString(randomString()));
+// SessionBindingQueryResponseMessage message = new SessionBindingQueryResponseMessage(
+// exists, queueNames);
+// AbstractPacketCodec codec = new SessionBindingQueryResponseMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.isExists(), message.getQueueNames());
+//
+// assertTrue(decodedPacket instanceof SessionBindingQueryResponseMessage);
+// SessionBindingQueryResponseMessage decodedMessage = (SessionBindingQueryResponseMessage) decodedPacket;
+// assertEquals(SESS_BINDINGQUERY_RESP, decodedMessage.getType());
+// assertEquals(message.isExists(), decodedMessage.isExists());
+//
+// List<SimpleString> decodedNames = decodedMessage.getQueueNames();
+// assertEquals(queueNames.size(), decodedNames.size());
+// for (int i = 0; i < queueNames.size(); i++)
+// {
+// assertEquals(queueNames.get(i), decodedNames.get(i));
+// }
+// }
+//
+// public void testDeleteQueueRequest() throws Exception
+// {
+// SessionDeleteQueueMessage message = new SessionDeleteQueueMessage(
+// new SimpleString(randomString()));
+// AbstractPacketCodec codec = new SessionDeleteQueueMessageCodec();
+//
+// Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
+// message.getQueueName());
+//
+// assertTrue(decodedPacket instanceof SessionDeleteQueueMessage);
+// SessionDeleteQueueMessage decodedMessage = (SessionDeleteQueueMessage) decodedPacket;
+// assertEquals(SESS_DELETE_QUEUE, decodedMessage.getType());
+// assertEquals(message.getQueueName(), decodedMessage.getQueueName());
+// }
- public void testNullPacket() throws Exception
- {
- Packet packet = new PacketImpl(NULL);
- long cid = randomLong();
- packet.setResponseTargetID(cid);
- packet.setTargetID(randomLong());
- packet.setExecutorID(randomLong());
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(NULL);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec);
- assertTrue(decodedPacket instanceof PacketImpl);
-
- assertEquals(NULL, decodedPacket.getType());
- assertEquals(packet.getResponseTargetID(), decodedPacket.getResponseTargetID());
- assertEquals(packet.getTargetID(), decodedPacket.getTargetID());
- assertEquals(packet.getExecutorID(), decodedPacket.getExecutorID());
- }
-
- public void testPing() throws Exception
- {
- Ping ping = new Ping(randomLong());
- int bodyLength = SIZE_LONG;
- AbstractPacketCodec<Ping> codec = new PingCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(ping, codec, ping
- .getSessionID());
-
- assertTrue(decodedPacket instanceof Ping);
- Ping decodedPing = (Ping) decodedPacket;
- assertEquals(PING, decodedPing.getType());
- assertEquals(ping.getResponseTargetID(), decodedPacket.getResponseTargetID());
- assertEquals(ping.getTargetID(), decodedPacket.getTargetID());
- assertEquals(ping.getExecutorID(), decodedPacket.getExecutorID());
- }
-
- public void testPong() throws Exception
- {
- Pong pong = new Pong(randomLong(), true);
- AbstractPacketCodec<Pong> codec = new PongCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(pong, codec, pong
- .getSessionID(), pong.isSessionFailed());
-
- assertTrue(decodedPacket instanceof Pong);
- Pong decodedPong = (Pong) decodedPacket;
- assertEquals(PONG, decodedPong.getType());
- assertEquals(pong.getSessionID(), decodedPong.getSessionID());
- assertEquals(pong.isSessionFailed(), decodedPong.isSessionFailed());
- }
-
- public void testTextPacket() throws Exception
- {
- TextPacket packet = new TextPacket("testTextPacket");
- AbstractPacketCodec<TextPacket> codec = new TextPacketCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec, packet
- .getText());
-
- assertTrue(decodedPacket instanceof TextPacket);
- TextPacket p = (TextPacket) decodedPacket;
-
- assertEquals(TEXT, p.getType());
- assertEquals(packet.getText(), p.getText());
- }
-
- public void testBytesPacket() throws Exception
- {
- BytesPacket packet = new BytesPacket(randomBytes());
- AbstractPacketCodec<BytesPacket> codec = new BytesPacketCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec, packet
- .getBytes());
-
- assertTrue(decodedPacket instanceof BytesPacket);
- BytesPacket p = (BytesPacket) decodedPacket;
-
- assertEquals(BYTES, p.getType());
- assertEqualsByteArrays(packet.getBytes(), p.getBytes());
- }
-
- public void testCreateConnectionRequest() throws Exception
- {
- int version = randomInt();
- long remotingSessionID = randomLong();
- String username = null;
- String password = null;
- CreateConnectionRequest request = new CreateConnectionRequest(version,
- remotingSessionID, username, password);
- AbstractPacketCodec<CreateConnectionRequest> codec = new CreateConnectionMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec,
- version, remotingSessionID, username, password);
-
- assertTrue(decodedPacket instanceof CreateConnectionRequest);
- CreateConnectionRequest decodedRequest = (CreateConnectionRequest) decodedPacket;
-
- assertEquals(CREATECONNECTION, decodedPacket.getType());
- assertEquals(request.getVersion(), decodedRequest.getVersion());
- assertEquals(request.getRemotingSessionID(), decodedRequest
- .getRemotingSessionID());
- assertEquals(request.getUsername(), decodedRequest.getUsername());
- assertEquals(request.getPassword(), decodedRequest.getPassword());
- }
-
- public void testCreateConnectionResponse() throws Exception
- {
- CreateConnectionResponse response = new CreateConnectionResponse(
- randomLong(), new VersionImpl("test", 1,2,3,4,"xxx"));
- AbstractPacketCodec<CreateConnectionResponse> codec = new CreateConnectionResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
- response.getConnectionTargetID(),
- response.getServerVersion().getVersionName(),
- response.getServerVersion().getMajorVersion(),
- response.getServerVersion().getMinorVersion(),
- response.getServerVersion().getMicroVersion(),
- response.getServerVersion().getIncrementingVersion(),
- response.getServerVersion().getVersionSuffix());
-
- assertTrue(decodedPacket instanceof CreateConnectionResponse);
- CreateConnectionResponse decodedResponse = (CreateConnectionResponse) decodedPacket;
- assertEquals(PacketType.CREATECONNECTION_RESP, decodedResponse.getType());
- assertEquals(response.getConnectionTargetID(), decodedResponse
- .getConnectionTargetID());
- assertEquals(response.getServerVersion().getFullVersion(), decodedResponse.getServerVersion().getFullVersion());
- }
-
- public void testConnectionCreateSessionMessage() throws Exception
- {
- ConnectionCreateSessionMessage request = new ConnectionCreateSessionMessage(
- randomBoolean(), randomBoolean(), randomBoolean());
- AbstractPacketCodec<ConnectionCreateSessionMessage> codec = new ConnectionCreateSessionMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec,
- request.isXA(), request.isAutoCommitSends(), request
- .isAutoCommitAcks());
-
- assertTrue(decodedPacket instanceof ConnectionCreateSessionMessage);
- ConnectionCreateSessionMessage decodedRequest = (ConnectionCreateSessionMessage) decodedPacket;
- assertEquals(PacketType.CONN_CREATESESSION, decodedRequest.getType());
- assertEquals(request.isXA(), decodedRequest.isXA());
- assertEquals(request.isAutoCommitSends(), decodedRequest
- .isAutoCommitSends());
- assertEquals(request.isAutoCommitAcks(), decodedRequest
- .isAutoCommitAcks());
- }
-
- public void testConnectionCreateSessionResponseMessage() throws Exception
- {
- ConnectionCreateSessionResponseMessage response = new ConnectionCreateSessionResponseMessage(
- randomLong());
- AbstractPacketCodec<ConnectionCreateSessionResponseMessage> codec = new ConnectionCreateSessionResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
- response.getSessionID());
-
- assertTrue(decodedPacket instanceof ConnectionCreateSessionResponseMessage);
- ConnectionCreateSessionResponseMessage decodedResponse = (ConnectionCreateSessionResponseMessage) decodedPacket;
- assertEquals(PacketType.CONN_CREATESESSION_RESP, decodedResponse
- .getType());
- assertEquals(response.getSessionID(), decodedResponse.getSessionID());
- }
-
- public void testProducerSendMessage() throws Exception
- {
- ProducerSendMessage packet = new ProducerSendMessage(new SimpleString(randomString()),
- new MessageImpl());
- byte[] messageBytes = StreamUtils.toBytes(packet.getMessage());
- AbstractPacketCodec codec = new ProducerSendMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec, new NullableStringHolder(packet
- .getAddress()), StreamUtils.toBytes(packet.getMessage()));
-
- assertTrue(decodedPacket instanceof ProducerSendMessage);
- ProducerSendMessage decodedMessage = (ProducerSendMessage) decodedPacket;
- assertEquals(PacketType.PROD_SEND, decodedPacket.getType());
- assertEquals(packet.getAddress(), decodedMessage.getAddress());
- assertEquals(packet.getMessage().getMessageID(), decodedMessage
- .getMessage().getMessageID());
- }
-
- public void testSessionCreateConsumerMessage() throws Exception
- {
- SimpleString destination = new SimpleString("queue.SessionCreateConsumerMessage");
- SessionCreateConsumerMessage request = new SessionCreateConsumerMessage(randomLong(),
- destination, new SimpleString("color = 'red'"), false, false, randomInt(),
- randomInt());
- AbstractPacketCodec codec = new SessionCreateConsumerMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec, request.getClientTargetID(),
- request.getQueueName(), new NullableStringHolder(request.getFilterString()), request
- .isNoLocal(), request.isAutoDeleteQueue(), request
- .getWindowSize(), request.getMaxRate());
-
- assertTrue(decodedPacket instanceof SessionCreateConsumerMessage);
- SessionCreateConsumerMessage decodedRequest = (SessionCreateConsumerMessage) decodedPacket;
- assertEquals(PacketType.SESS_CREATECONSUMER, decodedRequest.getType());
- assertEquals(request.getClientTargetID(), decodedRequest.getClientTargetID());
- assertEquals(request.getQueueName(), decodedRequest.getQueueName());
- assertEquals(request.getFilterString(), decodedRequest.getFilterString());
- assertEquals(request.isNoLocal(), decodedRequest.isNoLocal());
- assertEquals(request.isAutoDeleteQueue(), decodedRequest
- .isAutoDeleteQueue());
- assertEquals(request.getWindowSize(), decodedRequest.getWindowSize());
- assertEquals(request.getMaxRate(), decodedRequest.getMaxRate());
- }
-
-
-
- public void testSessionCreateConsumerResponseMessage() throws Exception
- {
- SessionCreateConsumerResponseMessage response = new SessionCreateConsumerResponseMessage(
- randomLong(), randomInt());
- AbstractPacketCodec codec = new SessionCreateConsumerResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
- response.getConsumerTargetID(), response.getWindowSize());
-
- assertTrue(decodedPacket instanceof SessionCreateConsumerResponseMessage);
- SessionCreateConsumerResponseMessage decodedResponse = (SessionCreateConsumerResponseMessage) decodedPacket;
- assertEquals(SESS_CREATECONSUMER_RESP, decodedResponse.getType());
-
- assertEquals(response.getConsumerTargetID(), decodedResponse
- .getConsumerTargetID());
- assertEquals(response.getWindowSize(), decodedResponse.getWindowSize());
- }
-
- public void testSessionCreateProducerMessage() throws Exception
- {
- SimpleString destination = new SimpleString("queue.testSessionCreateProducerMessage");
- int windowSize = randomInt();
- int maxRate = randomInt();
- SessionCreateProducerMessage request = new SessionCreateProducerMessage(randomLong(),
- destination, windowSize, maxRate);
- AbstractPacketCodec codec = new SessionCreateProducerMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec, request.getClientTargetID(),
- new NullableStringHolder(request.getAddress()), request.getWindowSize(), request.getMaxRate());
-
- assertTrue(decodedPacket instanceof SessionCreateProducerMessage);
- SessionCreateProducerMessage decodedRequest = (SessionCreateProducerMessage) decodedPacket;
- assertEquals(SESS_CREATEPRODUCER, decodedRequest.getType());
- assertEquals(request.getClientTargetID(), decodedRequest.getClientTargetID());
- assertEquals(request.getAddress(), decodedRequest.getAddress());
- assertEquals(request.getWindowSize(), decodedRequest.getWindowSize());
- assertEquals(request.getMaxRate(), decodedRequest.getMaxRate());
- }
-
- public void testSessionCreateProducerResponseMessage() throws Exception
- {
- SessionCreateProducerResponseMessage response = new SessionCreateProducerResponseMessage(
- randomLong(), randomInt(), randomInt());
- AbstractPacketCodec codec = new SessionCreateProducerResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
- response.getProducerTargetID(), response.getWindowSize(), response
- .getMaxRate());
-
- assertTrue(decodedPacket instanceof SessionCreateProducerResponseMessage);
- SessionCreateProducerResponseMessage decodedResponse = (SessionCreateProducerResponseMessage) decodedPacket;
- assertEquals(SESS_CREATEPRODUCER_RESP, decodedResponse.getType());
- assertEquals(response.getProducerTargetID(), decodedResponse
- .getProducerTargetID());
- assertEquals(response.getWindowSize(), decodedResponse.getWindowSize());
- assertEquals(response.getMaxRate(), decodedResponse.getMaxRate());
- }
-
- public void testStartConnectionMessage() throws Exception
- {
- Packet packet = new PacketImpl(CONN_START);
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(CONN_START);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec);
-
- assertEquals(CONN_START, decodedPacket.getType());
- }
-
- public void testStopConnectionMessage() throws Exception
- {
- Packet packet = new PacketImpl(CONN_STOP);
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(CONN_STOP);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(packet, codec);
-
- assertEquals(CONN_STOP, decodedPacket.getType());
- }
-
- public void testConsumerFlowTokenMessage() throws Exception
- {
- ConsumerFlowTokenMessage message = new ConsumerFlowTokenMessage(
- randomInt());
- AbstractPacketCodec codec = new ConsumerFlowTokenMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getTokens());
-
- assertTrue(decodedPacket instanceof ConsumerFlowTokenMessage);
- ConsumerFlowTokenMessage decodedMessage = (ConsumerFlowTokenMessage) decodedPacket;
- assertEquals(CONS_FLOWTOKEN, decodedMessage.getType());
- assertEquals(message.getTokens(), decodedMessage.getTokens());
- }
-
- public void testProducerReceiveTokensMessage() throws Exception
- {
- ProducerReceiveTokensMessage message = new ProducerReceiveTokensMessage(
- randomInt());
- AbstractPacketCodec codec = new ProducerReceiveTokensMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getTokens());
-
- assertTrue(decodedPacket instanceof ProducerReceiveTokensMessage);
- ProducerReceiveTokensMessage decodedMessage = (ProducerReceiveTokensMessage) decodedPacket;
- assertEquals(PROD_RECEIVETOKENS, decodedMessage.getType());
- assertEquals(message.getTokens(), decodedMessage.getTokens());
- }
-
- public void testReceiveMessage() throws Exception
- {
- Message msg = new MessageImpl();
- ReceiveMessage message = new ReceiveMessage(msg);
- AbstractPacketCodec codec = new ReceiveMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- StreamUtils.toBytes(msg));
-
- assertTrue(decodedPacket instanceof ReceiveMessage);
- ReceiveMessage decodedMessage = (ReceiveMessage) decodedPacket;
- assertEquals(RECEIVE_MSG, decodedMessage.getType());
- assertEquals(message.getMessage().getMessageID(), decodedMessage
- .getMessage().getMessageID());
- }
-
- public void testSessionAcknowledgeMessage() throws Exception
- {
- SessionAcknowledgeMessage message = new SessionAcknowledgeMessage(
- randomLong(), randomBoolean());
- AbstractPacketCodec codec = new SessionAcknowledgeMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getDeliveryID(), message.isAllUpTo());
-
- assertTrue(decodedPacket instanceof SessionAcknowledgeMessage);
- SessionAcknowledgeMessage decodedMessage = (SessionAcknowledgeMessage) decodedPacket;
- assertEquals(SESS_ACKNOWLEDGE, decodedMessage.getType());
- assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
- assertEquals(message.isAllUpTo(), decodedMessage.isAllUpTo());
- }
-
- public void testSessionCancelMessage() throws Exception
- {
- SessionCancelMessage message = new SessionCancelMessage(randomLong(),
- randomBoolean());
- AbstractPacketCodec codec = new SessionCancelMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getDeliveryID(), message.isExpired());
-
- assertTrue(decodedPacket instanceof SessionCancelMessage);
- SessionCancelMessage decodedMessage = (SessionCancelMessage) decodedPacket;
- assertEquals(SESS_CANCEL, decodedMessage.getType());
- assertEquals(message.getDeliveryID(), decodedMessage.getDeliveryID());
- assertEquals(message.isExpired(), decodedMessage.isExpired());
- }
-
- public void testSessionCommitMessage() throws Exception
- {
- Packet message = new PacketImpl(SESS_COMMIT);
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(SESS_COMMIT);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
-
- assertEquals(SESS_COMMIT, decodedPacket.getType());
- }
-
- public void testSessionRollbackMessage() throws Exception
- {
- Packet message = new PacketImpl(SESS_ROLLBACK);
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(SESS_ROLLBACK);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
-
- assertEquals(SESS_ROLLBACK, decodedPacket.getType());
- }
-
- public void testSessionRecoverMessage() throws Exception
- {
- Packet message = new PacketImpl(SESS_RECOVER);
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(SESS_RECOVER);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
-
- assertEquals(SESS_RECOVER, decodedPacket.getType());
- }
-
- public void testCloseMessage() throws Exception
- {
- Packet message = new PacketImpl(CLOSE);
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(CLOSE);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
-
- assertEquals(CLOSE, decodedPacket.getType());
- }
-
- public void testSessionCreateBrowserMessage() throws Exception
- {
- SimpleString destination = new SimpleString("queue.testCreateBrowserRequest");
- SessionCreateBrowserMessage request = new SessionCreateBrowserMessage(
- destination, new SimpleString("color = 'red'"));
- AbstractPacketCodec codec = new SessionCreateBrowserMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec,
- request.getQueueName(), new NullableStringHolder(request.getFilterString()));
-
- assertTrue(decodedPacket instanceof SessionCreateBrowserMessage);
- SessionCreateBrowserMessage decodedRequest = (SessionCreateBrowserMessage) decodedPacket;
- assertEquals(SESS_CREATEBROWSER, decodedRequest.getType());
- assertEquals(request.getQueueName(), decodedRequest.getQueueName());
- assertEquals(request.getFilterString(), decodedRequest.getFilterString());
- }
-
- public void testSessionCreateBrowserResponseMessage() throws Exception
- {
- SessionCreateBrowserResponseMessage response = new SessionCreateBrowserResponseMessage(
- randomLong());
- AbstractPacketCodec codec = new SessionCreateBrowserResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
- response.getBrowserTargetID());
-
- assertTrue(decodedPacket instanceof SessionCreateBrowserResponseMessage);
- SessionCreateBrowserResponseMessage decodedResponse = (SessionCreateBrowserResponseMessage) decodedPacket;
- assertEquals(SESS_CREATEBROWSER_RESP, decodedResponse.getType());
- assertEquals(response.getBrowserTargetID(), decodedResponse
- .getBrowserTargetID());
- }
-
- public void testBrowserResetMessage() throws Exception
- {
- Packet message = new PacketImpl(SESS_BROWSER_RESET);
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(SESS_BROWSER_RESET);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
-
- assertEquals(SESS_BROWSER_RESET, decodedPacket.getType());
- }
-
- public void testBrowserHasNextMessageRequest() throws Exception
- {
- Packet request = new PacketImpl(SESS_BROWSER_HASNEXTMESSAGE);
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(SESS_BROWSER_HASNEXTMESSAGE);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec);
-
- assertEquals(SESS_BROWSER_HASNEXTMESSAGE, decodedPacket.getType());
- }
-
- public void testSessionBrowserHasNextMessageResponseMessage()
- throws Exception
- {
- SessionBrowserHasNextMessageResponseMessage response = new SessionBrowserHasNextMessageResponseMessage(
- randomBoolean());
- AbstractPacketCodec codec = new SessionBrowserHasNextMessageResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(response, codec,
- response.hasNext());
-
- assertTrue(decodedPacket instanceof SessionBrowserHasNextMessageResponseMessage);
- SessionBrowserHasNextMessageResponseMessage decodedResponse = (SessionBrowserHasNextMessageResponseMessage) decodedPacket;
- assertEquals(SESS_BROWSER_HASNEXTMESSAGE_RESP, decodedResponse.getType());
- assertEquals(response.hasNext(), decodedResponse.hasNext());
- }
-
- public void testBrowserNextMessageRequest() throws Exception
- {
- Packet request = new PacketImpl(SESS_BROWSER_NEXTMESSAGE);
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(SESS_BROWSER_NEXTMESSAGE);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec);
-
- assertEquals(SESS_BROWSER_NEXTMESSAGE, decodedPacket.getType());
- }
-
- public void testSessionXACommitMessage() throws Exception
- {
- SessionXACommitMessage message = new SessionXACommitMessage(randomXid(),
- randomBoolean());
- AbstractPacketCodec codec = new SessionXACommitMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getXid(), message.isOnePhase());
-
- assertTrue(decodedPacket instanceof SessionXACommitMessage);
- SessionXACommitMessage decodedMessage = (SessionXACommitMessage) decodedPacket;
- assertEquals(SESS_XA_COMMIT, decodedMessage.getType());
- assertEquals(message.getXid(), decodedMessage.getXid());
- assertEquals(message.isOnePhase(), decodedMessage.isOnePhase());
- }
-
- public void testSessionXAEndMessage() throws Exception
- {
- SessionXAEndMessage message = new SessionXAEndMessage(randomXid(),
- randomBoolean());
- AbstractPacketCodec codec = new SessionXAEndMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getXid(), message.isFailed());
-
- assertTrue(decodedPacket instanceof SessionXAEndMessage);
- SessionXAEndMessage decodedMessage = (SessionXAEndMessage) decodedPacket;
- assertEquals(SESS_XA_END, decodedMessage.getType());
- assertEquals(message.getXid(), decodedMessage.getXid());
- assertEquals(message.isFailed(), decodedMessage.isFailed());
- }
-
- public void testSessionXAForgetMessage() throws Exception
- {
- SessionXAForgetMessage message = new SessionXAForgetMessage(randomXid());
- AbstractPacketCodec codec = new SessionXAForgetMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getXid());
-
- assertTrue(decodedPacket instanceof SessionXAForgetMessage);
- SessionXAForgetMessage decodedMessage = (SessionXAForgetMessage) decodedPacket;
- assertEquals(SESS_XA_FORGET, decodedMessage.getType());
- assertEquals(message.getXid(), decodedMessage.getXid());
- }
-
- public void testSessionXAGetInDoubtXidsMessage() throws Exception
- {
- Packet request = new PacketImpl(SESS_XA_INDOUBT_XIDS);
- AbstractPacketCodec codec = createCodecForEmptyPacket(SESS_XA_INDOUBT_XIDS);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(request, codec);
-
- assertEquals(SESS_XA_INDOUBT_XIDS, decodedPacket.getType());
- }
-
- public void testSessionXAGetInDoubtXidsResponseMessage() throws Exception
- {
- final int numXids = 10;
- List<Xid> xids = new ArrayList<Xid>();
- for (int i = 0; i < numXids; i++)
- {
- xids.add(randomXid());
- }
- SessionXAGetInDoubtXidsResponseMessage message = new SessionXAGetInDoubtXidsResponseMessage(
- xids);
- AbstractPacketCodec codec = new SessionXAGetInDoubtXidsResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec, xids);
-
- assertTrue(decodedPacket instanceof SessionXAGetInDoubtXidsResponseMessage);
- SessionXAGetInDoubtXidsResponseMessage decodedMessage = (SessionXAGetInDoubtXidsResponseMessage) decodedPacket;
- assertEquals(SESS_XA_INDOUBT_XIDS_RESP, decodedMessage.getType());
-
- assertSameXids(message.getXids(), decodedMessage.getXids());
- }
-
- public void testSessionXAGetTimeoutMessage() throws Exception
- {
- Packet message = new PacketImpl(SESS_XA_GET_TIMEOUT);
- AbstractPacketCodec codec = createCodecForEmptyPacket(PacketType.SESS_XA_GET_TIMEOUT);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
-
- assertEquals(SESS_XA_GET_TIMEOUT, decodedPacket.getType());
- }
-
- public void testSessionXAGetTimeoutResponseMessage() throws Exception
- {
- SessionXAGetTimeoutResponseMessage message = new SessionXAGetTimeoutResponseMessage(
- randomInt());
- AbstractPacketCodec codec = new SessionXAGetTimeoutResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getTimeoutSeconds());
-
- assertTrue(decodedPacket instanceof SessionXAGetTimeoutResponseMessage);
- SessionXAGetTimeoutResponseMessage decodedMessage = (SessionXAGetTimeoutResponseMessage) decodedPacket;
- assertEquals(SESS_XA_GET_TIMEOUT_RESP, decodedMessage.getType());
- assertEquals(message.getTimeoutSeconds(), decodedMessage
- .getTimeoutSeconds());
- }
-
- public void testSessionXAJoinMessage() throws Exception
- {
- SessionXAJoinMessage message = new SessionXAJoinMessage(randomXid());
- AbstractPacketCodec codec = new SessionXAJoinMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getXid());
-
- assertTrue(decodedPacket instanceof SessionXAJoinMessage);
- SessionXAJoinMessage decodedMessage = (SessionXAJoinMessage) decodedPacket;
- assertEquals(SESS_XA_JOIN, decodedMessage.getType());
- assertEquals(message.getXid(), decodedMessage.getXid());
- }
-
- public void testSessionXAPrepareMessage() throws Exception
- {
- SessionXAPrepareMessage message = new SessionXAPrepareMessage(randomXid());
- AbstractPacketCodec codec = new SessionXAPrepareMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getXid());
-
- assertTrue(decodedPacket instanceof SessionXAPrepareMessage);
- SessionXAPrepareMessage decodedMessage = (SessionXAPrepareMessage) decodedPacket;
- assertEquals(SESS_XA_PREPARE, decodedMessage.getType());
- assertEquals(message.getXid(), decodedMessage.getXid());
- }
-
- public void testSessionXAResponseMessage() throws Exception
- {
- SessionXAResponseMessage message = new SessionXAResponseMessage(
- randomBoolean(), randomInt(), randomString());
- AbstractPacketCodec codec = new SessionXAResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.isError(), message.getResponseCode(), message.getMessage());
-
- assertTrue(decodedPacket instanceof SessionXAResponseMessage);
- SessionXAResponseMessage decodedMessage = (SessionXAResponseMessage) decodedPacket;
- assertEquals(SESS_XA_RESP, decodedMessage.getType());
- assertEquals(message.isError(), decodedMessage.isError());
- assertEquals(message.getResponseCode(), decodedMessage.getResponseCode());
- assertEquals(message.getMessage(), decodedMessage.getMessage());
- }
-
- public void testSessionXAResumeMessage() throws Exception
- {
- SessionXAResumeMessage message = new SessionXAResumeMessage(randomXid());
- AbstractPacketCodec codec = new SessionXAResumeMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getXid());
-
- assertTrue(decodedPacket instanceof SessionXAResumeMessage);
- SessionXAResumeMessage decodedMessage = (SessionXAResumeMessage) decodedPacket;
- assertEquals(SESS_XA_RESUME, decodedMessage.getType());
- assertEquals(message.getXid(), decodedMessage.getXid());
- }
-
- public void testSessionXARollbackMessage() throws Exception
- {
- SessionXARollbackMessage message = new SessionXARollbackMessage(
- randomXid());
- AbstractPacketCodec codec = new SessionXARollbackMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getXid());
-
- assertTrue(decodedPacket instanceof SessionXARollbackMessage);
- SessionXARollbackMessage decodedMessage = (SessionXARollbackMessage) decodedPacket;
- assertEquals(SESS_XA_ROLLBACK, decodedMessage.getType());
- assertEquals(message.getXid(), decodedMessage.getXid());
- }
-
- public void testSessionXASetTimeoutMessage() throws Exception
- {
- SessionXASetTimeoutMessage message = new SessionXASetTimeoutMessage(
- randomInt());
- AbstractPacketCodec codec = new SessionXASetTimeoutMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getTimeoutSeconds());
-
- assertTrue(decodedPacket instanceof SessionXASetTimeoutMessage);
- SessionXASetTimeoutMessage decodedMessage = (SessionXASetTimeoutMessage) decodedPacket;
- assertEquals(SESS_XA_SET_TIMEOUT, decodedMessage.getType());
- assertEquals(message.getTimeoutSeconds(), decodedMessage
- .getTimeoutSeconds());
- }
-
- public void testSessionXASetTimeoutResponseMessage() throws Exception
- {
- SessionXASetTimeoutResponseMessage message = new SessionXASetTimeoutResponseMessage(
- randomBoolean());
- AbstractPacketCodec codec = new SessionXASetTimeoutResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.isOK());
-
- assertTrue(decodedPacket instanceof SessionXASetTimeoutResponseMessage);
- SessionXASetTimeoutResponseMessage decodedMessage = (SessionXASetTimeoutResponseMessage) decodedPacket;
- assertEquals(SESS_XA_SET_TIMEOUT_RESP, decodedMessage.getType());
- assertEquals(message.isOK(), decodedMessage.isOK());
- }
-
- public void testSessionXAStartMessage() throws Exception
- {
- SessionXAStartMessage message = new SessionXAStartMessage(randomXid());
- AbstractPacketCodec codec = new SessionXAStartMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getXid());
-
- assertTrue(decodedPacket instanceof SessionXAStartMessage);
- SessionXAStartMessage decodedMessage = (SessionXAStartMessage) decodedPacket;
- assertEquals(SESS_XA_START, decodedMessage.getType());
- assertEquals(message.getXid(), decodedMessage.getXid());
- }
-
- public void testSessionXASuspendMessage() throws Exception
- {
- Packet message = new PacketImpl(SESS_XA_SUSPEND);
- AbstractPacketCodec codec = PacketCodecFactory
- .createCodecForEmptyPacket(PacketType.SESS_XA_SUSPEND);
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec);
-
- assertEquals(SESS_XA_SUSPEND, decodedPacket.getType());
- }
-
- public void testSessionRemoveDestinationMessage() throws Exception
- {
- SessionRemoveDestinationMessage message = new SessionRemoveDestinationMessage(
- new SimpleString(randomString()), randomBoolean());
- AbstractPacketCodec codec = new SessionRemoveDestinationMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getAddress(), message.isTemporary());
-
- assertTrue(decodedPacket instanceof SessionRemoveDestinationMessage);
- SessionRemoveDestinationMessage decodedMessage = (SessionRemoveDestinationMessage) decodedPacket;
- assertEquals(SESS_REMOVE_DESTINATION, decodedMessage.getType());
- assertEquals(message.getAddress(), decodedMessage.getAddress());
- assertEquals(message.isTemporary(), decodedMessage.isTemporary());
- }
-
- public void testSessionCreateQueueMessage() throws Exception
- {
- SessionCreateQueueMessage message = new SessionCreateQueueMessage(
- new SimpleString(randomString()), new SimpleString(randomString()),
- new SimpleString(randomString()), randomBoolean(),
- randomBoolean());
- AbstractPacketCodec codec = new SessionCreateQueueMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getAddress(), message.getQueueName(), new NullableStringHolder(message.getFilterString()), message.isDurable(), message
- .isTemporary());
-
- assertTrue(decodedPacket instanceof SessionCreateQueueMessage);
- SessionCreateQueueMessage decodedMessage = (SessionCreateQueueMessage) decodedPacket;
- assertEquals(SESS_CREATEQUEUE, decodedMessage.getType());
-
- assertEquals(message.getAddress(), decodedMessage.getAddress());
- assertEquals(message.getQueueName(), decodedMessage.getQueueName());
- assertEquals(message.getFilterString(), decodedMessage.getFilterString());
- assertEquals(message.isDurable(), decodedMessage.isDurable());
- assertEquals(message.isTemporary(), decodedMessage.isTemporary());
-
- }
-
- public void testSessionQueueQueryMessage() throws Exception
- {
- SessionQueueQueryMessage message = new SessionQueueQueryMessage(
- new SimpleString(randomString()));
- AbstractPacketCodec codec = new SessionQueueQueryMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getQueueName());
-
- assertTrue(decodedPacket instanceof SessionQueueQueryMessage);
- SessionQueueQueryMessage decodedMessage = (SessionQueueQueryMessage) decodedPacket;
- assertEquals(SESS_QUEUEQUERY, decodedMessage.getType());
- assertEquals(message.getQueueName(), decodedMessage.getQueueName());
- }
-
- public void testSessionQueueQueryResponseMessage() throws Exception
- {
- SessionQueueQueryResponseMessage message = new SessionQueueQueryResponseMessage(
- randomBoolean(), randomBoolean(), randomInt(), randomInt(),
- randomInt(), new SimpleString(randomString()), new SimpleString(randomString()));
- AbstractPacketCodec codec = new SessionQueueQueryResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.isExists(), message.isDurable(), message.isTemporary(),
- message.getMaxSize(), message.getConsumerCount(), message
- .getMessageCount(), new NullableStringHolder(message.getFilterString()),
- new NullableStringHolder(message.getAddress()));
-
- assertTrue(decodedPacket instanceof SessionQueueQueryResponseMessage);
- SessionQueueQueryResponseMessage decodedMessage = (SessionQueueQueryResponseMessage) decodedPacket;
- assertEquals(SESS_QUEUEQUERY_RESP, decodedMessage.getType());
-
- assertEquals(message.isExists(), decodedMessage.isExists());
- assertEquals(message.isDurable(), decodedMessage.isDurable());
- assertEquals(message.isTemporary(), decodedMessage.isTemporary());
- assertEquals(message.getConsumerCount(), decodedMessage
- .getConsumerCount());
- assertEquals(message.getMessageCount(), decodedMessage.getMessageCount());
- assertEquals(message.getFilterString(), decodedMessage.getFilterString());
- assertEquals(message.getAddress(), decodedMessage.getAddress());
- }
-
- public void testSessionAddAddressMessage() throws Exception
- {
- SessionAddDestinationMessage message = new SessionAddDestinationMessage(
- new SimpleString(randomString()), randomBoolean());
- AbstractPacketCodec<SessionAddDestinationMessage> codec = new SessionAddDestinationMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getAddress(), message.isTemporary());
-
- assertTrue(decodedPacket instanceof SessionAddDestinationMessage);
- SessionAddDestinationMessage decodedMessage = (SessionAddDestinationMessage) decodedPacket;
- assertEquals(SESS_ADD_DESTINATION, decodedMessage.getType());
- assertEquals(message.getAddress(), decodedMessage.getAddress());
- assertEquals(message.isTemporary(), decodedMessage.isTemporary());
- }
-
- public void testSessionBindingQueryMessage() throws Exception
- {
- SessionBindingQueryMessage message = new SessionBindingQueryMessage(
- new SimpleString(randomString()));
- AbstractPacketCodec codec = new SessionBindingQueryMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getAddress());
-
- assertTrue(decodedPacket instanceof SessionBindingQueryMessage);
- SessionBindingQueryMessage decodedMessage = (SessionBindingQueryMessage) decodedPacket;
- assertEquals(SESS_BINDINGQUERY, decodedMessage.getType());
-
- assertEquals(message.getAddress(), decodedMessage.getAddress());
- }
-
- public void testSessionBindingQueryResponseMessage() throws Exception
- {
- boolean exists = true;
- List<SimpleString> queueNames = new ArrayList<SimpleString>();
- queueNames.add(new SimpleString(randomString()));
- queueNames.add(new SimpleString(randomString()));
- queueNames.add(new SimpleString(randomString()));
- SessionBindingQueryResponseMessage message = new SessionBindingQueryResponseMessage(
- exists, queueNames);
- AbstractPacketCodec codec = new SessionBindingQueryResponseMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.isExists(), message.getQueueNames());
-
- assertTrue(decodedPacket instanceof SessionBindingQueryResponseMessage);
- SessionBindingQueryResponseMessage decodedMessage = (SessionBindingQueryResponseMessage) decodedPacket;
- assertEquals(SESS_BINDINGQUERY_RESP, decodedMessage.getType());
- assertEquals(message.isExists(), decodedMessage.isExists());
-
- List<SimpleString> decodedNames = decodedMessage.getQueueNames();
- assertEquals(queueNames.size(), decodedNames.size());
- for (int i = 0; i < queueNames.size(); i++)
- {
- assertEquals(queueNames.get(i), decodedNames.get(i));
- }
- }
-
- public void testDeleteQueueRequest() throws Exception
- {
- SessionDeleteQueueMessage message = new SessionDeleteQueueMessage(
- new SimpleString(randomString()));
- AbstractPacketCodec codec = new SessionDeleteQueueMessageCodec();
-
- Packet decodedPacket = encodeAndCheckBytesAndDecode(message, codec,
- message.getQueueName());
-
- assertTrue(decodedPacket instanceof SessionDeleteQueueMessage);
- SessionDeleteQueueMessage decodedMessage = (SessionDeleteQueueMessage) decodedPacket;
- assertEquals(SESS_DELETE_QUEUE, decodedMessage.getType());
- assertEquals(message.getQueueName(), decodedMessage.getQueueName());
- }
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/QueueTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -1011,7 +1011,7 @@
if (i % 2 == 0)
{
- ref.getMessage().putHeader("god", "dog");
+ ref.getMessage().putStringProperty(new SimpleString("god"), new SimpleString("dog"));
}
queue.addLast(ref);
@@ -1077,13 +1077,13 @@
MessageReference ref1 = generateReference(queue, 1);
- ref1.getMessage().putHeader("fruit", "banana");
+ ref1.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("banana"));
assertEquals(HandleStatus.HANDLED, queue.addLast(ref1));
MessageReference ref2 = generateReference(queue, 2);
- ref2.getMessage().putHeader("fruit", "orange");
+ ref2.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));
assertEquals(HandleStatus.HANDLED, queue.addLast(ref2));
@@ -1113,13 +1113,13 @@
MessageReference ref3 = generateReference(queue, 3);
- ref3.getMessage().putHeader("fruit", "banana");
+ ref3.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("banana"));
assertEquals(HandleStatus.HANDLED, queue.addLast(ref3));
MessageReference ref4 = generateReference(queue, 4);
- ref4.getMessage().putHeader("fruit", "orange");
+ ref4.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));
assertEquals(HandleStatus.HANDLED, queue.addLast(ref4));
@@ -1153,25 +1153,25 @@
MessageReference ref1 = generateReference(queue, 1);
- ref1.getMessage().putHeader("fruit", "banana");
+ ref1.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("banana"));
assertEquals(HandleStatus.HANDLED, queue.addLast(ref1));
MessageReference ref2 = generateReference(queue, 2);
- ref2.getMessage().putHeader("cheese", "stilton");
+ ref2.getMessage().putStringProperty(new SimpleString("cheese"), new SimpleString("stilton"));
assertEquals(HandleStatus.HANDLED, queue.addLast(ref2));
MessageReference ref3 = generateReference(queue, 3);
- ref3.getMessage().putHeader("cake", "sponge");
+ ref3.getMessage().putStringProperty(new SimpleString("cake"), new SimpleString("sponge"));
assertEquals(HandleStatus.HANDLED, queue.addLast(ref3));
MessageReference ref4 = generateReference(queue, 4);
- ref4.getMessage().putHeader("fruit", "orange");
+ ref4.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));
refs.add(ref4);
@@ -1179,13 +1179,13 @@
MessageReference ref5 = generateReference(queue, 5);
- ref5.getMessage().putHeader("fruit", "apple");
+ ref5.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("apple"));
assertEquals(HandleStatus.HANDLED, queue.addLast(ref5));
MessageReference ref6 = generateReference(queue, 6);
- ref6.getMessage().putHeader("fruit", "orange");
+ ref6.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));
refs.add(ref6);
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeFilter.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeFilter.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/server/impl/fakes/FakeFilter.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -53,8 +53,13 @@
{
if (headerName != null)
{
- Object value = message.getHeader(headerName);
+ Object value = message.getProperty(new SimpleString(headerName));
+ if (value instanceof SimpleString)
+ {
+ value = ((SimpleString)value).toString();
+ }
+
if (value != null && headerValue.equals(value))
{
return true;
Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/transaction/impl/TransactionTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/transaction/impl/TransactionTest.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/transaction/impl/TransactionTest.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -378,116 +378,116 @@
}
}
- public void testSendCommit() throws Exception
- {
- //Durable queue
- Queue queue1 = new QueueImpl(12, new SimpleString("queue1"), null, false, true, false, -1, scheduledExecutor);
-
- //Durable queue
- Queue queue2 = new QueueImpl(34, new SimpleString("queue2"), null, false, true, false, -1, scheduledExecutor);
-
- //Non durable queue
- Queue queue3 = new QueueImpl(65, new SimpleString("queue3"), null, false, false, false, -1, scheduledExecutor);
-
- //Durable message to send
-
- Message message1 = this.generateMessage(1);
-
- // Non durable message to send
-
- Message message2 = this.generateMessage(2);
-
- message2.setDurable(false);
-
-
- StorageManager sm = EasyMock.createStrictMock(StorageManager.class);
-
- PostOffice po= EasyMock.createStrictMock(PostOffice.class);
-
- final long txID = 123;
-
- EasyMock.expect(sm.generateTransactionID()).andReturn(txID);
-
- EasyMock.replay(sm);
-
- Transaction tx = new TransactionImpl(sm, po);
-
- assertTrue(tx.isEmpty());
- assertFalse(tx.isContainsPersistent());
-
- EasyMock.verify(sm);
-
- EasyMock.reset(sm);
-
- final SimpleString address1 = new SimpleString("topic1");
-
- //Expect:
-
- MessageReference ref5 = message1.createReference(queue1);
- MessageReference ref6 = message1.createReference(queue2);
- List<MessageReference> message1Refs = new ArrayList<MessageReference>();
- message1Refs.add(ref5);
- message1Refs.add(ref6);
-
- EasyMock.expect(po.route(address1, message1)).andReturn(message1Refs);
-
- sm.storeMessageTransactional(txID, address1, message1);
-
- EasyMock.replay(po);
-
- EasyMock.replay(sm);
-
- tx.addMessage(address1, message1);
-
- assertFalse(tx.isEmpty());
- assertTrue(tx.isContainsPersistent());
-
-
- EasyMock.verify(po);
-
- EasyMock.verify(sm);
-
- EasyMock.reset(po);
-
- EasyMock.reset(sm);
-
-
- //Expect:
-
- final SimpleString address2 = new SimpleString("queue3");
-
- MessageReference ref7 = message2.createReference(queue3);
- List<MessageReference> message2Refs = new ArrayList<MessageReference>();
- message2Refs.add(ref7);
-
- EasyMock.expect(po.route(address2, message2)).andReturn(message1Refs);
-
- EasyMock.replay(po);
-
- EasyMock.replay(sm);
-
- tx.addMessage(address2, message2);
-
- EasyMock.verify(po);
-
- EasyMock.verify(sm);
-
- EasyMock.reset(po);
-
- EasyMock.reset(sm);
-
- //Expect :
-
- sm.commit(txID);
-
- EasyMock.replay(sm);
-
- tx.commit();
-
- EasyMock.verify(sm);
-
- //TODO test messages are routed and refs count reduced
- }
+// public void testSendCommit() throws Exception
+// {
+// //Durable queue
+// Queue queue1 = new QueueImpl(12, new SimpleString("queue1"), null, false, true, false, -1, scheduledExecutor);
+//
+// //Durable queue
+// Queue queue2 = new QueueImpl(34, new SimpleString("queue2"), null, false, true, false, -1, scheduledExecutor);
+//
+// //Non durable queue
+// Queue queue3 = new QueueImpl(65, new SimpleString("queue3"), null, false, false, false, -1, scheduledExecutor);
+//
+// //Durable message to send
+//
+// Message message1 = this.generateMessage(1);
+//
+// // Non durable message to send
+//
+// Message message2 = this.generateMessage(2);
+//
+// message2.setDurable(false);
+//
+//
+// StorageManager sm = EasyMock.createStrictMock(StorageManager.class);
+//
+// PostOffice po= EasyMock.createStrictMock(PostOffice.class);
+//
+// final long txID = 123;
+//
+// EasyMock.expect(sm.generateTransactionID()).andReturn(txID);
+//
+// EasyMock.replay(sm);
+//
+// Transaction tx = new TransactionImpl(sm, po);
+//
+// assertTrue(tx.isEmpty());
+// assertFalse(tx.isContainsPersistent());
+//
+// EasyMock.verify(sm);
+//
+// EasyMock.reset(sm);
+//
+// final SimpleString address1 = new SimpleString("topic1");
+//
+// //Expect:
+//
+// MessageReference ref5 = message1.createReference(queue1);
+// MessageReference ref6 = message1.createReference(queue2);
+// List<MessageReference> message1Refs = new ArrayList<MessageReference>();
+// message1Refs.add(ref5);
+// message1Refs.add(ref6);
+//
+// EasyMock.expect(po.route(address1, message1)).andReturn(message1Refs);
+//
+// sm.storeMessageTransactional(txID, address1, message1);
+//
+// EasyMock.replay(po);
+//
+// EasyMock.replay(sm);
+//
+// tx.addMessage(address1, message1);
+//
+// assertFalse(tx.isEmpty());
+// assertTrue(tx.isContainsPersistent());
+//
+//
+// EasyMock.verify(po);
+//
+// EasyMock.verify(sm);
+//
+// EasyMock.reset(po);
+//
+// EasyMock.reset(sm);
+//
+//
+// //Expect:
+//
+// final SimpleString address2 = new SimpleString("queue3");
+//
+// MessageReference ref7 = message2.createReference(queue3);
+// List<MessageReference> message2Refs = new ArrayList<MessageReference>();
+// message2Refs.add(ref7);
+//
+// EasyMock.expect(po.route(address2, message2)).andReturn(message1Refs);
+//
+// EasyMock.replay(po);
+//
+// EasyMock.replay(sm);
+//
+// tx.addMessage(address2, message2);
+//
+// EasyMock.verify(po);
+//
+// EasyMock.verify(sm);
+//
+// EasyMock.reset(po);
+//
+// EasyMock.reset(sm);
+//
+// //Expect :
+//
+// sm.commit(txID);
+//
+// EasyMock.replay(sm);
+//
+// tx.commit();
+//
+// EasyMock.verify(sm);
+//
+// //TODO test messages are routed and refs count reduced
+// }
Modified: trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java 2008-05-07 15:48:30 UTC (rev 4158)
+++ trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java 2008-05-08 08:48:10 UTC (rev 4159)
@@ -31,6 +31,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import junit.framework.TestCase;
@@ -210,8 +211,10 @@
bytes[i] = (byte)i;
}
- message.setPayload(bytes);
+ //message.setPayload(bytes);
+ message.getBody().putString(UUID.randomUUID().toString());
+
return message;
}
@@ -241,17 +244,8 @@
assertEquals(msg1.getType(), msg2.getType());
- if (msg1.getPayload() == null)
- {
- assertNull(msg2.getPayload());
- }
- else
- {
- assertByteArraysEquivalent(msg1.getPayload(), msg2.getPayload());
- }
-
- assertMapsEquivalent(msg1.getHeaders(), msg2.getHeaders());
-
+ assertByteArraysEquivalent(msg1.getBody().array(), msg2.getBody().array());
+
assertEquals(msg1.getDurableRefCount(), msg2.getDurableRefCount());
}
More information about the jboss-cvs-commits
mailing list