JBoss hornetq SVN: r8341 - trunk/tests/src/org/hornetq/tests/integration/cluster/bridge.
by do-not-reply@jboss.org
Author: jmesnil
Date: 2009-11-20 10:00:41 -0500 (Fri, 20 Nov 2009)
New Revision: 8341
Modified:
trunk/tests/src/org/hornetq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java
Log:
increased receive() timeout value
* 500ms could be not enough in case of a full GC... set it to 2000ms instead
Modified: trunk/tests/src/org/hornetq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java 2009-11-20 14:43:39 UTC (rev 8340)
+++ trunk/tests/src/org/hornetq/tests/integration/cluster/bridge/BridgeWithDiscoveryGroupStartTest.java 2009-11-20 15:00:41 UTC (rev 8341)
@@ -50,6 +50,8 @@
public class BridgeWithDiscoveryGroupStartTest extends ServiceTestBase
{
+ private static final int TIMEOUT = 2000;
+
protected boolean isNetty()
{
return false;
@@ -165,7 +167,7 @@
for (int i = 0; i < numMessages; i++)
{
- ClientMessage message = consumer1.receive(500);
+ ClientMessage message = consumer1.receive(TIMEOUT);
assertNotNull(message);
@@ -195,7 +197,7 @@
for (int i = 0; i < numMessages; i++)
{
- ClientMessage message = consumer1.receive(1000);
+ ClientMessage message = consumer1.receive(TIMEOUT);
assertNotNull(message);
15 years, 1 month
JBoss hornetq SVN: r8340 - branches/20-optimisation/src/main/org/hornetq/integration/transports/netty.
by do-not-reply@jboss.org
Author: trustin
Date: 2009-11-20 09:43:39 -0500 (Fri, 20 Nov 2009)
New Revision: 8340
Modified:
branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java
Log:
HornetQFrameDecoder2 always generates a dynamic buffer now.
Modified: branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java 2009-11-20 14:38:08 UTC (rev 8339)
+++ branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java 2009-11-20 14:43:39 UTC (rev 8340)
@@ -110,9 +110,9 @@
// because previousData will be reassigned to
// EMPTY_BUFFER or 'in' later.
previousData.writeBytes(in, length + 4 - previousData.readableBytes());
- frame = previousData.slice();
+ frame = previousData;
} else {
- frame = ChannelBuffers.buffer(length + 4);
+ frame = ChannelBuffers.dynamicBuffer(length + 4);
frame.writeBytes(previousData, previousData.readerIndex(), previousData.readableBytes());
frame.writeBytes(in, length + 4 - frame.writerIndex());
}
@@ -155,8 +155,9 @@
break;
}
- ChannelBuffer frame = in.slice(in.readerIndex(), length + SIZE_INT);
- in.skipBytes(SIZE_INT + length);
+ // Convert to dynamic buffer (this requires copy)
+ ChannelBuffer frame = ChannelBuffers.dynamicBuffer(length + SIZE_INT);
+ frame.writeBytes(in, length + SIZE_INT);
frame.skipBytes(SIZE_INT);
Channels.fireMessageReceived(ctx, frame);
}
@@ -174,81 +175,11 @@
else
{
ChannelBuffer newPreviousData =
- ChannelBuffers.dynamicBuffer(
- Math.max(previousData.readableBytes() + in.readableBytes(), length + 4));
+ ChannelBuffers.dynamicBuffer(
+ Math.max(previousData.readableBytes() + in.readableBytes(), length + 4));
newPreviousData.writeBytes(previousData);
newPreviousData.writeBytes(in);
previousData = newPreviousData;
}
}
-
- public static void main(String[] args) throws Exception {
- final boolean useNextGeneration = true;
- final ChannelUpstreamHandler handler;
-
- if (useNextGeneration) {
- handler = new HornetQFrameDecoder2();
- } else {
- handler = new HornetQFrameDecoder(new AbstractBufferHandler()
- {
- public void bufferReceived(Object connectionID, HornetQBuffer buffer)
- { // noop
- }
- });
- }
-
- final int MSG_LEN = 40;
-
- final DecoderEmbedder<ChannelBuffer> decoder =
- new DecoderEmbedder<ChannelBuffer>(handler);
-
- ChannelBuffer src = ChannelBuffers.buffer(30000 * (MSG_LEN + 4));
- while (src.writerIndex() < src.capacity()) {
- src.writeInt(MSG_LEN);
- for (int i = 0; i < MSG_LEN; i ++) {
- src.writeByte((byte) i);
- }
- //src.writeZero(1000);
- }
-
- Random rand = new Random();
- List<ChannelBuffer> packets = new ArrayList<ChannelBuffer>();
- for (int i = 0; i < src.capacity();) {
- int length = Math.min(rand.nextInt(10000), src.capacity() - i);
- packets.add(src.copy(i, length));
- i += length;
- }
-
- long startTime = System.nanoTime();
-
- for (int i = 0; i < 10; i ++) {
- int cnt = 0;
- for (ChannelBuffer p: packets) {
- decoder.offer(p.duplicate());
- for (;;) {
- ChannelBuffer frame = decoder.poll();
- if (frame == null) {
- break;
- }
- if (frame.readableBytes() != MSG_LEN) {
- System.out.println("ARGH 1: " + frame.readableBytes());
- }
- for (int j = 0; j < MSG_LEN; j ++) {
- if (frame.readByte() != (byte) j) {
- System.out.println("ARGH 3");
- }
- }
- cnt ++;
- }
- }
- if (cnt != 30000) {
- System.out.println("ARGH 2: " + cnt);
- }
- }
-
- long endTime = System.nanoTime();
- System.out.println(
- handler.getClass().getSimpleName() + ": " +
- (endTime - startTime) / 1000000);
- }
}
15 years, 1 month
JBoss hornetq SVN: r8339 - trunk/src/main/org/hornetq/core/client.
by do-not-reply@jboss.org
Author: jmesnil
Date: 2009-11-20 09:38:08 -0500 (Fri, 20 Nov 2009)
New Revision: 8339
Modified:
trunk/src/main/org/hornetq/core/client/ClientProducer.java
Log:
HORNETQ-186: Javadoc for Core API
* added javadoc to ClientProducer interface
Modified: trunk/src/main/org/hornetq/core/client/ClientProducer.java
===================================================================
--- trunk/src/main/org/hornetq/core/client/ClientProducer.java 2009-11-20 14:35:17 UTC (rev 8338)
+++ trunk/src/main/org/hornetq/core/client/ClientProducer.java 2009-11-20 14:38:08 UTC (rev 8339)
@@ -9,7 +9,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
- */
+ */
package org.hornetq.core.client;
@@ -22,22 +22,74 @@
* @author <a href="mailto:ataylor@redhat.com">Andy Taylor</a>
*/
public interface ClientProducer
-{
- SimpleString getAddress();
-
- void send(Message message) throws HornetQException;
-
+{
+ /**
+ * Return the address where messages will be sent to.
+ * The address can be <code>null</code> if the ClientProducer
+ * was creating without specifying an address with {@link ClientSession#createProducer()}.
+ *
+ * @return the address where messages will be sent
+ */
+ SimpleString getAddress();
+
+ /**
+ * Send a message.
+ *
+ * @param message the message to send
+ * @throws HornetQException if an exception occurs while sending the message
+ */
+ void send(Message message) throws HornetQException;
+
+ /**
+ * Send a message to the specified address instead of the ClientProducer's address.
+ *
+ * @param address the address where the message will be sent
+ * @param message the message to send
+ * @throws HornetQException if an exception occurs while sending the message
+ */
void send(SimpleString address, Message message) throws HornetQException;
-
+
+ /**
+ * Send a message to the specified address instead of the ClientProducer's address.
+ *
+ * @param address the address where the message will be sent
+ * @param message the message to send
+ * @throws HornetQException if an exception occurs while sending the message
+ */
void send(String address, Message message) throws HornetQException;
+ /**
+ * Close the ClientProducer.
+ *
+ * @throws HornetQException if an exception occurs while closing the producer
+ */
void close() throws HornetQException;
-
- boolean isClosed();
-
+
+ /**
+ * Return whether the producer is closed or not.
+ *
+ * @return <code>true</code> if the producer is closed, <code>false</code> else
+ */
+ boolean isClosed();
+
+ /**
+ * Return whether the producer will block when sending <em>persistent</em> messages.
+ *
+ * @return <code>true</code> if the producer blocks when sending persistent, <code>false</code> else
+ */
boolean isBlockOnPersistentSend();
-
+
+ /**
+ * Return whether the producer will block when sending <em>non-persistent</em> messages.
+ *
+ * @return <code>true</code> if the producer blocks when sending non-persistent, <code>false</code> else
+ */
boolean isBlockOnNonPersistentSend();
-
+
+ /**
+ * Return the producer maximum rate.
+ *
+ * @return the producer maximum rate
+ */
int getMaxRate();
}
15 years, 1 month
JBoss hornetq SVN: r8338 - branches/20-optimisation/src/main/org/hornetq/integration/transports/netty.
by do-not-reply@jboss.org
Author: trustin
Date: 2009-11-20 09:35:17 -0500 (Fri, 20 Nov 2009)
New Revision: 8338
Modified:
branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java
Log:
Fixed a bug in HornetQFrameDecoder2 where the first four bytes length header is omitted
Modified: branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java 2009-11-20 14:20:03 UTC (rev 8337)
+++ branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java 2009-11-20 14:35:17 UTC (rev 8338)
@@ -64,7 +64,6 @@
// treatment because it is the only message that spans over the two
// buffers.
final int length;
- final ChannelBuffer frame;
switch (previousData.readableBytes()) {
case 1:
length = (previousData.getUnsignedByte(previousData.readerIndex()) << 24) |
@@ -72,9 +71,6 @@
if (in.readableBytes() - 3 < length) {
append(in, length);
return;
- } else {
- frame = in.slice(in.readerIndex() + 3, length);
- in.skipBytes(length + 3);
}
break;
case 2:
@@ -83,9 +79,6 @@
if (in.readableBytes() - 2 < length) {
append(in, length);
return;
- } else {
- frame = in.slice(in.readerIndex() + 2, length);
- in.skipBytes(length + 2);
}
break;
case 3:
@@ -94,9 +87,6 @@
if (in.readableBytes() - 1 < length) {
append(in, length);
return;
- } else {
- frame = in.slice(in.readerIndex() + 1, length);
- in.skipBytes(length + 1);
}
break;
case 4:
@@ -104,9 +94,6 @@
if (in.readableBytes() - 4 < length) {
append(in, length);
return;
- } else {
- frame = in.slice(in.readerIndex(), length);
- in.skipBytes(length);
}
break;
default:
@@ -114,22 +101,23 @@
if (in.readableBytes() + previousData.readableBytes() - 4 < length) {
append(in, length);
return;
- } else {
- if (previousData instanceof DynamicChannelBuffer) {
- // It's safe to reuse the current dynamic buffer
- // because previousData will be reassigned to
- // EMPTY_BUFFER or 'in' later.
- previousData.skipBytes(4);
- previousData.writeBytes(in, length - previousData.readableBytes());
- frame = previousData.slice();
- } else {
- frame = ChannelBuffers.buffer(length);
- frame.writeBytes(previousData, previousData.readerIndex() + 4, previousData.readableBytes() - 4);
- frame.writeBytes(in, length - frame.writerIndex());
- }
}
}
+ final ChannelBuffer frame;
+ if (previousData instanceof DynamicChannelBuffer) {
+ // It's safe to reuse the current dynamic buffer
+ // because previousData will be reassigned to
+ // EMPTY_BUFFER or 'in' later.
+ previousData.writeBytes(in, length + 4 - previousData.readableBytes());
+ frame = previousData.slice();
+ } else {
+ frame = ChannelBuffers.buffer(length + 4);
+ frame.writeBytes(previousData, previousData.readerIndex(), previousData.readableBytes());
+ frame.writeBytes(in, length + 4 - frame.writerIndex());
+ }
+
+ frame.skipBytes(4);
Channels.fireMessageReceived(ctx, frame);
if (!in.readable()) {
@@ -167,8 +155,9 @@
break;
}
- ChannelBuffer frame = in.slice(in.readerIndex() + SIZE_INT, length);
+ ChannelBuffer frame = in.slice(in.readerIndex(), length + SIZE_INT);
in.skipBytes(SIZE_INT + length);
+ frame.skipBytes(SIZE_INT);
Channels.fireMessageReceived(ctx, frame);
}
}
@@ -179,6 +168,7 @@
// a client is very slow. (e.g.sending each byte one by one)
if (previousData instanceof DynamicChannelBuffer)
{
+ previousData.discardReadBytes();
previousData.writeBytes(in);
}
else
@@ -206,27 +196,32 @@
}
});
}
+
+ final int MSG_LEN = 40;
final DecoderEmbedder<ChannelBuffer> decoder =
new DecoderEmbedder<ChannelBuffer>(handler);
- ChannelBuffer src = ChannelBuffers.buffer(30000 * 1004);
+ ChannelBuffer src = ChannelBuffers.buffer(30000 * (MSG_LEN + 4));
while (src.writerIndex() < src.capacity()) {
- src.writeInt(1000);
- src.writeZero(1000);
+ src.writeInt(MSG_LEN);
+ for (int i = 0; i < MSG_LEN; i ++) {
+ src.writeByte((byte) i);
+ }
+ //src.writeZero(1000);
}
Random rand = new Random();
List<ChannelBuffer> packets = new ArrayList<ChannelBuffer>();
for (int i = 0; i < src.capacity();) {
- int length = Math.min(rand.nextInt(3000), src.capacity() - i);
+ int length = Math.min(rand.nextInt(10000), src.capacity() - i);
packets.add(src.copy(i, length));
i += length;
}
long startTime = System.nanoTime();
- for (int i = 0; i < 100; i ++) {
+ for (int i = 0; i < 10; i ++) {
int cnt = 0;
for (ChannelBuffer p: packets) {
decoder.offer(p.duplicate());
@@ -235,9 +230,14 @@
if (frame == null) {
break;
}
- if (frame.readableBytes() != 1000) {
+ if (frame.readableBytes() != MSG_LEN) {
System.out.println("ARGH 1: " + frame.readableBytes());
}
+ for (int j = 0; j < MSG_LEN; j ++) {
+ if (frame.readByte() != (byte) j) {
+ System.out.println("ARGH 3");
+ }
+ }
cnt ++;
}
}
15 years, 1 month
JBoss hornetq SVN: r8337 - trunk/src/main/org/hornetq/core/client.
by do-not-reply@jboss.org
Author: jmesnil
Date: 2009-11-20 09:20:03 -0500 (Fri, 20 Nov 2009)
New Revision: 8337
Modified:
trunk/src/main/org/hornetq/core/client/ClientSession.java
Log:
HORNETQ-186: Javadoc for Core API
* added javadoc to ClientSession interface
Modified: trunk/src/main/org/hornetq/core/client/ClientSession.java
===================================================================
--- trunk/src/main/org/hornetq/core/client/ClientSession.java 2009-11-20 12:47:17 UTC (rev 8336)
+++ trunk/src/main/org/hornetq/core/client/ClientSession.java 2009-11-20 14:20:03 UTC (rev 8337)
@@ -16,153 +16,527 @@
import javax.transaction.xa.XAResource;
import org.hornetq.core.exception.HornetQException;
-import org.hornetq.core.remoting.FailureListener;
import org.hornetq.core.remoting.impl.wireformat.SessionBindingQueryResponseMessage;
import org.hornetq.core.remoting.impl.wireformat.SessionQueueQueryResponseMessage;
import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.SimpleString;
-/*
- *
+/**
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
- *
* @author <a href="mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
- *
* @author <a href="mailto:ataylor@redhat.com">Andy Taylor</a>
- *
* @author <a href="jmesnil(a)redhat.com">Jeff Mesnil</a>
*/
public interface ClientSession extends XAResource
{
+ // Lifecycle operations ------------------------------------------
+
/**
- * Queues created by this method are <em>not</em> temporary
+ * Start the session.
+ * The session must be started before ClientConsumers created by the session can consume messages from the queue.
+ *
+ * @throws HornetQException if an exception occurs while starting the session
*/
+ void start() throws HornetQException;
+
+ /**
+ * Stop the session.
+ * ClientConsumers created by the session can not consume messages when the session is stopped.
+ *
+ * @throws HornetQException if an exception occurs while stopping the session
+ */
+ void stop() throws HornetQException;
+
+ /**
+ * Close the session.
+ *
+ * @throws HornetQException if an exception occurs while closing the session
+ */
+ void close() throws HornetQException;
+
+ /**
+ * Indicate if the session is closed or not.
+ *
+ * @return <code>true</code> if the session is closed, <code>false</code> else
+ */
+ boolean isClosed();
+
+ /**
+ * Add a FailureListener to the session which is notified if a failure occurs on the session.
+ *
+ * @param listener the listener to add
+ */
+ void addFailureListener(SessionFailureListener listener);
+
+ /**
+ * Remove a FailureListener to the session.
+ *
+ * @param listener the listener to remove
+ * @return <code>true</code> if the listener was removed, <code>false</code> else
+ */
+ boolean removeFailureListener(SessionFailureListener listener);
+
+ /**
+ * Returns the server's incrementingVersion.
+ *
+ * @return the server's <code>incrementingVersion</code>
+ */
+ int getVersion();
+
+ // Queue Operations ----------------------------------------------
+
+ /**
+ * Create a queue. The created queue is <em>not</em> temporary.
+ *
+ * @param address the queue will be bound to this address
+ * @param queueName the name of the queue
+ * @param durable whether the queue is durable or not
+ * @throws HornetQException in an exception occurs while creating the queue
+ */
void createQueue(SimpleString address, SimpleString queueName, boolean durable) throws HornetQException;
/**
- * Queues created by this method are <em>not</em> temporary
+ * Create a queue. The created queue is <em>not</em> temporary.
+ *
+ * @param address the queue will be bound to this address
+ * @param queueName the name of the queue
+ * @param durable whether the queue is durable or not
+ * @throws HornetQException in an exception occurs while creating the queue
*/
+ void createQueue(String address, String queueName, boolean durable) throws HornetQException;
+
+ /**
+ * Create a queue. The created queue is <em>not</em> temporary and <em>not</em> durable.
+ *
+ * @param address the queue will be bound to this address
+ * @param queueName the name of the queue
+ * @throws HornetQException in an exception occurs while creating the queue
+ */
void createQueue(String address, String queueName) throws HornetQException;
- void createQueue(String address, String queueName, boolean durable) throws HornetQException;
+ /**
+ * Create a queue. The created queue is <em>not</em> temporary.
+ *
+ * @param address the queue will be bound to this address
+ * @param queueName the name of the queue
+ * @param durable whether the queue is durable or not
+ * @param filter only messages which match this filter will be put in the queue
+ * @throws HornetQException in an exception occurs while creating the queue
+ */
+ void createQueue(SimpleString address, SimpleString queueName, SimpleString filter, boolean durable) throws HornetQException;
- void createQueue(SimpleString address, SimpleString queueName, SimpleString filterString, boolean durable) throws HornetQException;
+ /**
+ * Create a queue. The created queue is <em>not</em> temporary.
+ *
+ * @param address the queue will be bound to this address
+ * @param queueName the name of the queue
+ * @param durable whether the queue is durable or not
+ * @param filter only messages which match this filter will be put in the queue
+ * @throws HornetQException in an exception occurs while creating the queue
+ */
+ void createQueue(String address, String queueName, String filter, boolean durable) throws HornetQException;
- void createQueue(String address, String queueName, String filterString, boolean durable) throws HornetQException;
-
+ /**
+ * Create a <em>temporary</em> queue.
+ *
+ * @param address the queue will be bound to this address
+ * @param queueName the name of the queue
+ * @throws HornetQException in an exception occurs while creating the queue
+ */
void createTemporaryQueue(SimpleString address, SimpleString queueName) throws HornetQException;
+ /**
+ * Create a <em>temporary</em> queue.
+ *
+ * @param address the queue will be bound to this address
+ * @param queueName the name of the queue
+ * @throws HornetQException in an exception occurs while creating the queue
+ */
void createTemporaryQueue(String address, String queueName) throws HornetQException;
+ /**
+ * Create a <em>temporary</em> queue with a filter.
+ *
+ * @param address the queue will be bound to this address
+ * @param queueName the name of the queue
+ * @param filterString only messages which match this filter will be put in the queue
+ * @throws HornetQException in an exception occurs while creating the queue
+ */
void createTemporaryQueue(SimpleString address, SimpleString queueName, SimpleString filter) throws HornetQException;
+ /**
+ * Create a <em>temporary</em> queue with a filter.
+ *
+ * @param address the queue will be bound to this address
+ * @param queueName the name of the queue
+ * @param filterString only messages which match this filter will be put in the queue
+ * @throws HornetQException in an exception occurs while creating the queue
+ */
void createTemporaryQueue(String address, String queueName, String filter) throws HornetQException;
+ /**
+ * Delete the queue.
+ *
+ * @param queueName the name of the queue to delete
+ * @throws HornetQException if there is no queue for the given name or if the queue has consumers
+ */
void deleteQueue(SimpleString queueName) throws HornetQException;
+ /**
+ * Delete the queue.
+ *
+ * @param queueName the name of the queue to delete
+ * @throws HornetQException if there is no queue for the given name or if the queue has consumers
+ */
void deleteQueue(String queueName) throws HornetQException;
+ // Consumer Operations -------------------------------------------
+
+ /**
+ * Create a ClientConsumer to consume message from the queue with the given name.
+ *
+ * @param queueName name of the queue to consume messages from
+ * @return a ClientConsumer
+ * @throws HornetQException if an exception occurs while creating the ClientConsumer
+ */
ClientConsumer createConsumer(SimpleString queueName) throws HornetQException;
+ /**
+ * Create a ClientConsumer to consume messages from the queue with the given name.
+ *
+ * @param queueName name of the queue to consume messages from
+ * @return a ClientConsumer
+ * @throws HornetQException if an exception occurs while creating the ClientConsumer
+ */
+ ClientConsumer createConsumer(String queueName) throws HornetQException;
+
+ /**
+ * Create a ClientConsumer to consume messages matching the filter from the queue with the given name.
+ *
+ * @param queueName name of the queue to consume messages from
+ * @param filter only messages which match this filter will be consumed
+ * @return a ClientConsumer
+ * @throws HornetQException if an exception occurs while creating the ClientConsumer
+ */
ClientConsumer createConsumer(SimpleString queueName, SimpleString filterString) throws HornetQException;
- ClientConsumer createConsumer(SimpleString queueName, SimpleString filterString, boolean browseOnly) throws HornetQException;
+ /**
+ * Create a ClientConsumer to consume messages matching the filter from the queue with the given name.
+ *
+ * @param queueName name of the queue to consume messages from
+ * @param filter only messages which match this filter will be consumed
+ * @return a ClientConsumer
+ * @throws HornetQException if an exception occurs while creating the ClientConsumer
+ */
+ ClientConsumer createConsumer(String queueName, String filterString) throws HornetQException;
+ /**
+ * Create a ClientConsumer to consume or browse messages from the queue with the given name.
+ * If <code>browseOnly</code> is <code>true</code>, the ClientConsumer will receive the messages from the queue
+ * but they will not be consumed (the messages will remain in the queue).
+ * If <code>browseOnly</code> is <code>false</code>, the ClientConsumer will behave like consume the messages from the queue and
+ * the messages will effectively be removed from the queue.
+ *
+ * @param queueName name of the queue to consume messages from
+ * @param browseOnly whether the ClientConsumer will only browse the queue or consume messages.
+ * @return a ClientConsumer
+ * @throws HornetQException if an exception occurs while creating the ClientConsumer
+ */
ClientConsumer createConsumer(SimpleString queueName, boolean browseOnly) throws HornetQException;
+ /**
+ * Create a ClientConsumer to consume or browse messages from the queue with the given name.
+ * If <code>browseOnly</code> is <code>true</code>, the ClientConsumer will receive the messages from the queue
+ * but they will not be consumed (the messages will remain in the queue).
+ * If <code>browseOnly</code> is <code>false</code>, the ClientConsumer will behave like consume the messages from the queue and
+ * the messages will effectively be removed from the queue.
+ *
+ * @param queueName name of the queue to consume messages from
+ * @param browseOnly whether the ClientConsumer will only browse the queue or consume messages.
+ * @return a ClientConsumer
+ * @throws HornetQException if an exception occurs while creating the ClientConsumer
+ */
+ ClientConsumer createConsumer(String queueName, boolean browseOnly) throws HornetQException;
+
+ /**
+ * Create a ClientConsumer to consume or browse messages matching the filter from the queue with the given name.
+ * If <code>browseOnly</code> is <code>true</code>, the ClientConsumer will receive the messages from the queue
+ * but they will not be consumed (the messages will remain in the queue).
+ * If <code>browseOnly</code> is <code>false</code>, the ClientConsumer will behave like consume the messages from the queue and
+ * the messages will effectively be removed from the queue.
+ *
+ * @param queueName name of the queue to consume messages from
+ * @param filter only messages which match this filter will be consumed
+ * @param browseOnly whether the ClientConsumer will only browse the queue or consume messages.
+ * @return a ClientConsumer
+ * @throws HornetQException if an exception occurs while creating the ClientConsumer
+ */
+ ClientConsumer createConsumer(String queueName, String filter, boolean browseOnly) throws HornetQException;
+
+ /**
+ * Create a ClientConsumer to consume or browse messages matching the filter from the queue with the given name.
+ * If <code>browseOnly</code> is <code>true</code>, the ClientConsumer will receive the messages from the queue
+ * but they will not be consumed (the messages will remain in the queue).
+ * If <code>browseOnly</code> is <code>false</code>, the ClientConsumer will behave like consume the messages from the queue and
+ * the messages will effectively be removed from the queue.
+ *
+ * @param queueName name of the queue to consume messages from
+ * @param filter only messages which match this filter will be consumed
+ * @param browseOnly whether the ClientConsumer will only browse the queue or consume messages.
+ * @return a ClientConsumer
+ * @throws HornetQException if an exception occurs while creating the ClientConsumer
+ */
+ ClientConsumer createConsumer(SimpleString queueName, SimpleString filterString, boolean browseOnly) throws HornetQException;
+
+ /**
+ * Create a ClientConsumer to consume or browse messages matching the filter from the queue with the given name.
+ * If <code>browseOnly</code> is <code>true</code>, the ClientConsumer will receive the messages from the queue
+ * but they will not be consumed (the messages will remain in the queue).
+ * If <code>browseOnly</code> is <code>false</code>, the ClientConsumer will behave like consume the messages from the queue and
+ * the messages will effectively be removed from the queue.
+ *
+ * @param queueName name of the queue to consume messages from
+ * @param filter only messages which match this filter will be consumed
+ * @param windowSize the consumer window size
+ * @param maxRate the maximum rate to consume messages
+ * @param browseOnly whether the ClientConsumer will only browse the queue or consume messages.
+ * @return a ClientConsumer
+ * @throws HornetQException if an exception occurs while creating the ClientConsumer
+ */
ClientConsumer createConsumer(SimpleString queueName,
- SimpleString filterString,
+ SimpleString filter,
int windowSize,
int maxRate,
boolean browseOnly) throws HornetQException;
- ClientConsumer createConsumer(String queueName) throws HornetQException;
+ /**
+ * Create a ClientConsumer to consume or browse messages matching the filter from the queue with the given name.
+ * If <code>browseOnly</code> is <code>true</code>, the ClientConsumer will receive the messages from the queue
+ * but they will not be consumed (the messages will remain in the queue).
+ * If <code>browseOnly</code> is <code>false</code>, the ClientConsumer will behave like consume the messages from the queue and
+ * the messages will effectively be removed from the queue.
+ *
+ * @param queueName name of the queue to consume messages from
+ * @param filter only messages which match this filter will be consumed
+ * @param windowSize the consumer window size
+ * @param maxRate the maximum rate to consume messages
+ * @param browseOnly whether the ClientConsumer will only browse the queue or consume messages.
+ * @return a ClientConsumer
+ * @throws HornetQException if an exception occurs while creating the ClientConsumer
+ */
+ ClientConsumer createConsumer(String queueName, String filter, int windowSize, int maxRate, boolean browseOnly) throws HornetQException;
- ClientConsumer createConsumer(String queueName, String filterString) throws HornetQException;
+ // Producer Operations -------------------------------------------
- ClientConsumer createConsumer(String queueName, String filterString, boolean browseOnly) throws HornetQException;
-
- ClientConsumer createConsumer(String queueName, boolean browseOnly) throws HornetQException;
-
- ClientConsumer createConsumer(String queueName, String filterString, int windowSize, int maxRate, boolean browseOnly) throws HornetQException;
-
/**
* Create a producer with no default address.
* Address must be specified every time a message is sent
*
+ * @return a ClientProducer
+ *
* @see ClientProducer#send(SimpleString, org.hornetq.core.message.Message)
*/
ClientProducer createProducer() throws HornetQException;
+ /**
+ * Create a produce which sends messages to the given address
+ *
+ * @param address the address to send messages to
+ * @return a ClientProducer
+ * @throws HornetQException if an exception occurs while creating the ClientProducer
+ */
ClientProducer createProducer(SimpleString address) throws HornetQException;
+ /**
+ * Create a produce which sends messages to the given address
+ *
+ * @param address the address to send messages to
+ * @return a ClientProducer
+ * @throws HornetQException if an exception occurs while creating the ClientProducer
+ */
+ ClientProducer createProducer(String address) throws HornetQException;
+
+ /**
+ * Create a produce which sends messages to the given address
+ *
+ * @param address the address to send messages to
+ * @param rate the producer rate
+ * @return a ClientProducer
+ * @throws HornetQException if an exception occurs while creating the ClientProducer
+ */
ClientProducer createProducer(SimpleString address, int rate) throws HornetQException;
+ /**
+ * Create a produce which sends messages to the given address
+ *
+ * @param address the address to send messages to
+ * @param rate the producer rate
+ * @return a ClientProducer
+ * @throws HornetQException if an exception occurs while creating the ClientProducer
+ */
+ ClientProducer createProducer(String address, int rate) throws HornetQException;
+
+ /**
+ * Create a produce which sends messages to the given address
+ *
+ * @param address the address to send messages to
+ * @param rate the producer rate
+ * @param blockOnNonPersistentSend whether to block when sending <em>non-persistent</em> messages or not
+ * @param blockOnPersistentSend whether to block when sending <em>persistent</em> messages or not
+ * @return a ClientProducer
+ * @throws HornetQException if an exception occurs while creating the ClientProducer
+ */
ClientProducer createProducer(SimpleString address,
int maxRate,
boolean blockOnNonPersistentSend,
boolean blockOnPersistentSend) throws HornetQException;
- ClientProducer createProducer(String address) throws HornetQException;
-
- ClientProducer createProducer(String address, int rate) throws HornetQException;
-
+ /**
+ * Create a produce which sends messages to the given address
+ *
+ * @param address the address to send messages to
+ * @param rate the producer rate
+ * @param blockOnNonPersistentSend whether to block when sending <em>non-persistent</em> messages or not
+ * @param blockOnPersistentSend whether to block when sending <em>persistent</em> messages or not
+ * @return a ClientProducer
+ * @throws HornetQException if an exception occurs while creating the ClientProducer
+ */
ClientProducer createProducer(String address,
int maxRate,
boolean blockOnNonPersistentSend,
boolean blockOnPersistentSend) throws HornetQException;
- SessionQueueQueryResponseMessage queueQuery(SimpleString queueName) throws HornetQException;
+ // Message operations --------------------------------------------
- SessionBindingQueryResponseMessage bindingQuery(SimpleString address) throws HornetQException;
+ /**
+ * Create a ClientMessage.
+ *
+ * @param durable whether the created message is durable or not
+ * @return a ClientMessage
+ */
+ ClientMessage createClientMessage(boolean durable);
- XAResource getXAResource();
+ /**
+ * Create a ClientMessage.
+ *
+ * @param type type of the message
+ * @param durable whether the created message is durable or not
+ * @return a ClientMessage
+ */
+ ClientMessage createClientMessage(byte type, boolean durable);
- boolean isRollbackOnly();
+ /**
+ * Create a ClientMessage with the given HornetQBuffer as its body.
+ *
+ * @param durable whether the created message is durable or not
+ * @param buffer a HornetQBuffer which will be used as the messages's body
+ * @return a ClientMessage
+ */
+ ClientMessage createClientMessage(boolean durable, HornetQBuffer buffer);
- void commit() throws HornetQException;
+ /**
+ * Create a ClientMessage with the given HornetQBuffer as its body.
+ *
+ * @param durable whether the created message is durable or not
+ * @param expiration the message expiration
+ * @param timestamp the message timestamp
+ * @param priority the message priority (between 0 and 9 inclusive)
+ * @return a ClientMessage
+ */
+ ClientMessage createClientMessage(byte type, boolean durable, long expiration, long timestamp, byte priority);
- void rollback() throws HornetQException;
+ /**
+ * Create a HornetQBuffer containing the given bytes.
+ *
+ * @param bytes the buffer will be filled with these bytes
+ * @return a HornetQBuffer containing the given bytes
+ */
+ HornetQBuffer createBuffer(byte[] bytes);
/**
- * @param considerLastMessageAsDelivered the first message on deliveringMessage Buffer is considered as delivered
- * @throws HornetQException
+ * Create a HornetQBuffer of the given size.
+ *
+ * @param size size of the buffer to create
+ * @return a HornetQBuffer
*/
- void rollback(boolean considerLastMessageAsDelivered) throws HornetQException;
+ HornetQBuffer createBuffer(int size);
- void close() throws HornetQException;
+ // Query operations ----------------------------------------------
- boolean isClosed();
+ SessionQueueQueryResponseMessage queueQuery(SimpleString queueName) throws HornetQException;
- boolean isAutoCommitSends();
+ SessionBindingQueryResponseMessage bindingQuery(SimpleString address) throws HornetQException;
- boolean isAutoCommitAcks();
+ // Transaction operations ----------------------------------------
- boolean isBlockOnAcknowledge();
+ /**
+ * Returns the XAResource associated to the session.
+ *
+ * @return the XAResource associated to the session
+ */
+ XAResource getXAResource();
+ /**
+ * Return <code>true</code> if the session supports XA, <code>false</code> else.
+ *
+ * @return <code>true</code> if the session supports XA, <code>false</code> else.
+ */
boolean isXA();
- ClientMessage createClientMessage(byte type, boolean durable, long expiration, long timestamp, byte priority);
- ClientMessage createClientMessage(byte type, boolean durable);
+ /**
+ * Commit the current transaction.
+ *
+ * @throws HornetQException if an exception occurs while committing the transaction
+ */
+ void commit() throws HornetQException;
- ClientMessage createClientMessage(boolean durable);
+ /**
+ * Rollback the current transaction.
+ *
+ * @throws HornetQException if an exception occurs while rolling back the transaction
+ */
+ void rollback() throws HornetQException;
- ClientMessage createClientMessage(boolean durable, HornetQBuffer buffer);
+ /**
+ * Rollback the current transaction.
+ *
+ * @param considerLastMessageAsDelivered the first message on deliveringMessage Buffer is considered as delivered
+ *
+ * @throws HornetQException if an exception occurs while rolling back the transaction
+ */
+ void rollback(boolean considerLastMessageAsDelivered) throws HornetQException;
- HornetQBuffer createBuffer(byte[] bytes);
+ /**
+ * Return <code>true</code> if the current transaction has been flagged to rollback, <code>false</code> else.
+ *
+ * @return <code>true</code> if the current transaction has been flagged to rollback, <code>false</code> else.
+ */
+ boolean isRollbackOnly();
- HornetQBuffer createBuffer(int size);
+ /**
+ * Return whether the session will <em>automatically</em> commit its transaction every time a message is sent
+ * by a ClientProducer created by this session, <code>false</code> else
+ *
+ * @return <code>true</code> if the session <em>automatically</em> commit its transaction every time a message is sent, <code>false</code> else
+ */
+ boolean isAutoCommitSends();
- void start() throws HornetQException;
+ /**
+ * Return whether the session will <em>automatically</em> commit its transaction every time a message is acknowledged
+ * by a ClientConsumer created by this session, <code>false</code> else
+ *
+ * @return <code>true</code> if the session <em>automatically</em> commit its transaction every time a message is acknowledged, <code>false</code> else
+ */
+ boolean isAutoCommitAcks();
- void stop() throws HornetQException;
+ /**
+ * Return whether the ClientConsumer created by the session will <em>block</em> when they acknowledge a message.
+ *
+ * @return <code>true</code> if the session's ClientConsumer block when they acknowledge a message, <code>false</code> else
+ */
+ boolean isBlockOnAcknowledge();
- void addFailureListener(SessionFailureListener listener);
+ void setSendAcknowledgementHandler(SendAcknowledgementHandler handler);
- boolean removeFailureListener(SessionFailureListener listener);
-
- int getVersion();
-
- void setSendAcknowledgementHandler(SendAcknowledgementHandler handler);
}
15 years, 1 month
JBoss hornetq SVN: r8336 - trunk/tests/src/org/hornetq/tests/integration/cluster/failover.
by do-not-reply@jboss.org
Author: jmesnil
Date: 2009-11-20 07:47:17 -0500 (Fri, 20 Nov 2009)
New Revision: 8336
Modified:
trunk/tests/src/org/hornetq/tests/integration/cluster/failover/AsynchronousFailoverTest.java
Log:
fixed AsynchronousFailoverTest.testNonTransactional
* retried the consumer creation in case failover occurs when the consumer is created
Modified: trunk/tests/src/org/hornetq/tests/integration/cluster/failover/AsynchronousFailoverTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/cluster/failover/AsynchronousFailoverTest.java 2009-11-20 10:05:37 UTC (rev 8335)
+++ trunk/tests/src/org/hornetq/tests/integration/cluster/failover/AsynchronousFailoverTest.java 2009-11-20 12:47:17 UTC (rev 8336)
@@ -241,8 +241,27 @@
}
while (retry);
}
+
+ // create the consumer with retry if failover occurs during createConsumer call
+ ClientConsumer consumer = null;
+ boolean retry = false;
+ do
+ {
+ try
+ {
+ consumer = session.createConsumer(ADDRESS);
+
+ retry = false;
+ }
+ catch (HornetQException e)
+ {
+ log.info("exception when creating consumer");
+ assertEquals(e.getCode(), HornetQException.UNBLOCKED);
- ClientConsumer consumer = session.createConsumer(ADDRESS);
+ retry = true;
+ }
+ }
+ while (retry);
session.start();
15 years, 1 month
JBoss hornetq SVN: r8335 - in branches/20-optimisation: src/main/org/hornetq/integration/transports/netty and 2 other directories.
by do-not-reply@jboss.org
Author: timfox
Date: 2009-11-20 05:05:37 -0500 (Fri, 20 Nov 2009)
New Revision: 8335
Added:
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveLargeMessage.java
branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java
branches/20-optimisation/tests/src/org/hornetq/tests/opt/
branches/20-optimisation/tests/src/org/hornetq/tests/opt/SendTest.java
Log:
optimisation
Added: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveLargeMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveLargeMessage.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveLargeMessage.java 2009-11-20 10:05:37 UTC (rev 8335)
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.core.remoting.impl.wireformat;
+
+import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.utils.DataConstants;
+
+/**
+ * A SessionReceiveLargeMessage
+ *
+ * @author Clebert Suconic
+ *
+ *
+ */
+public class SessionReceiveLargeMessage extends PacketImpl
+{
+ private byte[] largeMessageHeader;
+
+ /** Since we receive the message before the entire message was received, */
+ private long largeMessageSize;
+
+ private long consumerID;
+
+ private int deliveryCount;
+
+ public SessionReceiveLargeMessage()
+ {
+ super(SESS_RECEIVE_LARGE_MSG);
+ }
+
+ public SessionReceiveLargeMessage(final long consumerID,
+ final byte[] largeMessageHeader,
+ final long largeMessageSize,
+ final int deliveryCount)
+ {
+ super(SESS_RECEIVE_LARGE_MSG);
+
+ this.consumerID = consumerID;
+
+ this.largeMessageHeader = largeMessageHeader;
+
+ this.deliveryCount = deliveryCount;
+
+ this.largeMessageSize = largeMessageSize;
+ }
+
+ public byte[] getLargeMessageHeader()
+ {
+ return largeMessageHeader;
+ }
+
+ public long getConsumerID()
+ {
+ return consumerID;
+ }
+
+ public int getDeliveryCount()
+ {
+ return deliveryCount;
+ }
+
+ /**
+ * @return the largeMessageSize
+ */
+ public long getLargeMessageSize()
+ {
+ return largeMessageSize;
+ }
+
+ public void encodeRest(final HornetQBuffer buffer)
+ {
+ buffer.writeLong(consumerID);
+ buffer.writeInt(deliveryCount);
+ buffer.writeLong(largeMessageSize);
+ buffer.writeInt(largeMessageHeader.length);
+ buffer.writeBytes(largeMessageHeader);
+ }
+
+ public void decodeRest(final HornetQBuffer buffer)
+ {
+ consumerID = buffer.readLong();
+ deliveryCount = buffer.readInt();
+ largeMessageSize = buffer.readLong();
+ int size = buffer.readInt();
+ largeMessageHeader = new byte[size];
+ buffer.readBytes(largeMessageHeader);
+ }
+
+}
Added: branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder2.java 2009-11-20 10:05:37 UTC (rev 8335)
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.integration.transports.netty;
+
+import static org.hornetq.utils.DataConstants.SIZE_INT;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import org.hornetq.core.remoting.impl.AbstractBufferHandler;
+import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.buffer.DynamicChannelBuffer;
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipelineCoverage;
+import org.jboss.netty.channel.ChannelUpstreamHandler;
+import org.jboss.netty.channel.Channels;
+import org.jboss.netty.channel.MessageEvent;
+import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import org.jboss.netty.handler.codec.embedder.DecoderEmbedder;
+
+/**
+ * A Netty decoder used to decode messages.
+ *
+ * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
+ * @author <a href="ataylor(a)redhat.com">Andy Taylor</a>
+ * @author <a href="tlee(a)redhat.com">Trustin Lee</a>
+ *
+ * @version $Revision: 7839 $, $Date: 2009-08-21 02:26:39 +0900 (2009-08-21, 금) $
+ */
+@ChannelPipelineCoverage("one")
+public class HornetQFrameDecoder2 extends SimpleChannelUpstreamHandler
+{
+ private ChannelBuffer previousData = ChannelBuffers.EMPTY_BUFFER;
+
+ // SimpleChannelUpstreamHandler overrides
+ // -------------------------------------------------------------------------------------
+
+ @Override
+ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception
+ {
+ ChannelBuffer in = (ChannelBuffer) e.getMessage();
+ if (previousData.readable())
+ {
+ if (previousData.readableBytes() + in.readableBytes() < SIZE_INT) {
+ append(in, 512); // Length is unknown. Bet at 512.
+ return;
+ }
+
+ // Decode the first message. The first message requires a special
+ // treatment because it is the only message that spans over the two
+ // buffers.
+ final int length;
+ final ChannelBuffer frame;
+ switch (previousData.readableBytes()) {
+ case 1:
+ length = (previousData.getUnsignedByte(previousData.readerIndex()) << 24) |
+ in.getMedium(in.readerIndex());
+ if (in.readableBytes() - 3 < length) {
+ append(in, length);
+ return;
+ } else {
+ frame = in.slice(in.readerIndex() + 3, length);
+ in.skipBytes(length + 3);
+ }
+ break;
+ case 2:
+ length = (previousData.getUnsignedShort(previousData.readerIndex()) << 16) |
+ in.getUnsignedShort(in.readerIndex());
+ if (in.readableBytes() - 2 < length) {
+ append(in, length);
+ return;
+ } else {
+ frame = in.slice(in.readerIndex() + 2, length);
+ in.skipBytes(length + 2);
+ }
+ break;
+ case 3:
+ length = (previousData.getUnsignedMedium(previousData.readerIndex()) << 8) |
+ in.getUnsignedByte(in.readerIndex());
+ if (in.readableBytes() - 1 < length) {
+ append(in, length);
+ return;
+ } else {
+ frame = in.slice(in.readerIndex() + 1, length);
+ in.skipBytes(length + 1);
+ }
+ break;
+ case 4:
+ length = previousData.getInt(previousData.readerIndex());
+ if (in.readableBytes() - 4 < length) {
+ append(in, length);
+ return;
+ } else {
+ frame = in.slice(in.readerIndex(), length);
+ in.skipBytes(length);
+ }
+ break;
+ default:
+ length = previousData.getInt(previousData.readerIndex());
+ if (in.readableBytes() + previousData.readableBytes() - 4 < length) {
+ append(in, length);
+ return;
+ } else {
+ if (previousData instanceof DynamicChannelBuffer) {
+ // It's safe to reuse the current dynamic buffer
+ // because previousData will be reassigned to
+ // EMPTY_BUFFER or 'in' later.
+ previousData.skipBytes(4);
+ previousData.writeBytes(in, length - previousData.readableBytes());
+ frame = previousData.slice();
+ } else {
+ frame = ChannelBuffers.buffer(length);
+ frame.writeBytes(previousData, previousData.readerIndex() + 4, previousData.readableBytes() - 4);
+ frame.writeBytes(in, length - frame.writerIndex());
+ }
+ }
+ }
+
+ Channels.fireMessageReceived(ctx, frame);
+
+ if (!in.readable()) {
+ previousData = ChannelBuffers.EMPTY_BUFFER;
+ return;
+ }
+ }
+
+ // And then handle the rest - we don't need to deal with the
+ // composite buffer anymore because the second or later messages
+ // always belong to the second buffer.
+ decode(ctx, in);
+
+ // Handle the leftover.
+ if (in.readable())
+ {
+ previousData = in;
+ }
+ else
+ {
+ previousData = ChannelBuffers.EMPTY_BUFFER;
+ }
+ }
+
+ private void decode(ChannelHandlerContext ctx, ChannelBuffer in)
+ {
+ for (;;) {
+ final int readableBytes = in.readableBytes();
+ if (readableBytes < SIZE_INT) {
+ break;
+ }
+
+ final int length = in.getInt(in.readerIndex());
+ if (readableBytes < length + SIZE_INT) {
+ break;
+ }
+
+ ChannelBuffer frame = in.slice(in.readerIndex() + SIZE_INT, length);
+ in.skipBytes(SIZE_INT + length);
+ Channels.fireMessageReceived(ctx, frame);
+ }
+ }
+
+ private void append(ChannelBuffer in, int length)
+ {
+ // Need more data to decode the first message. This can happen when
+ // a client is very slow. (e.g.sending each byte one by one)
+ if (previousData instanceof DynamicChannelBuffer)
+ {
+ previousData.writeBytes(in);
+ }
+ else
+ {
+ ChannelBuffer newPreviousData =
+ ChannelBuffers.dynamicBuffer(
+ Math.max(previousData.readableBytes() + in.readableBytes(), length + 4));
+ newPreviousData.writeBytes(previousData);
+ newPreviousData.writeBytes(in);
+ previousData = newPreviousData;
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ final boolean useNextGeneration = true;
+ final ChannelUpstreamHandler handler;
+
+ if (useNextGeneration) {
+ handler = new HornetQFrameDecoder2();
+ } else {
+ handler = new HornetQFrameDecoder(new AbstractBufferHandler()
+ {
+ public void bufferReceived(Object connectionID, HornetQBuffer buffer)
+ { // noop
+ }
+ });
+ }
+
+ final DecoderEmbedder<ChannelBuffer> decoder =
+ new DecoderEmbedder<ChannelBuffer>(handler);
+
+ ChannelBuffer src = ChannelBuffers.buffer(30000 * 1004);
+ while (src.writerIndex() < src.capacity()) {
+ src.writeInt(1000);
+ src.writeZero(1000);
+ }
+
+ Random rand = new Random();
+ List<ChannelBuffer> packets = new ArrayList<ChannelBuffer>();
+ for (int i = 0; i < src.capacity();) {
+ int length = Math.min(rand.nextInt(3000), src.capacity() - i);
+ packets.add(src.copy(i, length));
+ i += length;
+ }
+
+ long startTime = System.nanoTime();
+
+ for (int i = 0; i < 100; i ++) {
+ int cnt = 0;
+ for (ChannelBuffer p: packets) {
+ decoder.offer(p.duplicate());
+ for (;;) {
+ ChannelBuffer frame = decoder.poll();
+ if (frame == null) {
+ break;
+ }
+ if (frame.readableBytes() != 1000) {
+ System.out.println("ARGH 1: " + frame.readableBytes());
+ }
+ cnt ++;
+ }
+ }
+ if (cnt != 30000) {
+ System.out.println("ARGH 2: " + cnt);
+ }
+ }
+
+ long endTime = System.nanoTime();
+ System.out.println(
+ handler.getClass().getSimpleName() + ": " +
+ (endTime - startTime) / 1000000);
+ }
+}
Added: branches/20-optimisation/tests/src/org/hornetq/tests/opt/SendTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/opt/SendTest.java (rev 0)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/opt/SendTest.java 2009-11-20 10:05:37 UTC (rev 8335)
@@ -0,0 +1,305 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.tests.opt;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageProducer;
+import javax.jms.ObjectMessage;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.hornetq.core.client.ClientSession;
+import org.hornetq.core.config.Configuration;
+import org.hornetq.core.config.TransportConfiguration;
+import org.hornetq.core.config.impl.ConfigurationImpl;
+import org.hornetq.core.logging.Logger;
+import org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory;
+import org.hornetq.core.server.HornetQ;
+import org.hornetq.core.server.HornetQServer;
+import org.hornetq.core.server.JournalType;
+import org.hornetq.integration.transports.netty.NettyAcceptorFactory;
+import org.hornetq.integration.transports.netty.NettyConnectorFactory;
+import org.hornetq.integration.transports.netty.TransportConstants;
+import org.hornetq.jms.HornetQQueue;
+import org.hornetq.jms.client.HornetQConnectionFactory;
+import org.hornetq.jms.client.HornetQSession;
+import org.hornetq.tests.util.RandomUtil;
+
+/**
+ * A SendTest
+ *
+ * @author tim
+ *
+ *
+ */
+public class SendTest
+{
+ private static final Logger log = Logger.getLogger(SendTest.class);
+
+ public static void main(String[] args)
+ {
+ try
+ {
+ new SendTest().runTextMessage();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private HornetQServer server;
+
+ private void startServer() throws Exception
+ {
+ log.info("*** Starting server");
+
+ System.setProperty("org.hornetq.opt.dontadd", "true");
+ // System.setProperty("org.hornetq.opt.routeblast", "true");
+
+ Configuration configuration = new ConfigurationImpl();
+ configuration.setSecurityEnabled(false);
+ configuration.setJMXManagementEnabled(false);
+ configuration.setJournalMinFiles(10);
+
+ configuration.setPersistenceEnabled(false);
+ configuration.setFileDeploymentEnabled(false);
+ //configuration.setJournalFlushOnSync(true);
+ // configuration.setRunSyncSpeedTest(true);
+ //configuration.setJournalPerfBlastPages(10000);
+
+ configuration.setJournalType(JournalType.NIO);
+
+ //configuration.setLogJournalWriteRate(true);
+ //configuration.setRunSyncSpeedTest(true);
+
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put(TransportConstants.USE_NIO_PROP_NAME, Boolean.FALSE);
+
+ TransportConfiguration transportConfig1 = new TransportConfiguration(NettyAcceptorFactory.class.getCanonicalName(),
+ params);
+ TransportConfiguration transportConfig2 = new TransportConfiguration(InVMAcceptorFactory.class.getCanonicalName(),
+ null);
+ configuration.getAcceptorConfigurations().add(transportConfig1);
+ configuration.getAcceptorConfigurations().add(transportConfig2);
+
+ server = HornetQ.newHornetQServer(configuration);
+
+ server.start();
+
+ log.info("Started server");
+
+ }
+
+ public void runRouteBlast() throws Exception
+ {
+ this.startServer();
+ }
+
+ public void runTextMessage() throws Exception
+ {
+ startServer();
+
+ Map<String, Object> params = new HashMap<String, Object>();
+
+ // params.put(TransportConstants.HOST_PROP_NAME, "localhost");
+
+ // params.put(TransportConstants.PORT_PROP_NAME, 5445);
+
+ params.put(TransportConstants.TCP_NODELAY_PROPNAME, Boolean.FALSE);
+ //params.put(TransportConstants.USE_NIO_PROP_NAME, Boolean.FALSE);
+
+ TransportConfiguration tc = new TransportConfiguration(NettyConnectorFactory.class.getCanonicalName(), params);
+
+ //TransportConfiguration tc = new TransportConfiguration(InVMConnectorFactory.class.getCanonicalName(), params);
+
+ HornetQConnectionFactory cf = new HornetQConnectionFactory(tc);
+
+ cf.setProducerWindowSize(1024 * 1024);
+
+ Connection conn = cf.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ ClientSession coreSession = ((HornetQSession)sess).getCoreSession();
+
+ coreSession.createQueue("jms.queue.test_queue", "jms.queue.test_queue");
+
+ Queue queue = new HornetQQueue("test_queue");
+
+ MessageProducer prod = sess.createProducer(queue);
+
+ prod.setDisableMessageID(true);
+
+ prod.setDisableMessageTimestamp(true);
+
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ byte[] bytes1 = new byte[] { (byte)'A', (byte)'B',(byte)'C',(byte)'D'};
+
+ String s = new String(bytes1);
+
+ System.out.println("Str is " + s);
+
+ byte[] bytes = RandomUtil.randomBytes(512);
+
+ String str = new String(bytes);
+
+ final int warmup = 50000;
+
+ log.info("Warming up");
+
+ TextMessage tm = sess.createTextMessage();
+
+ tm.setText(str);
+
+ for (int i = 0; i < warmup; i++)
+ {
+ prod.send(tm);
+
+ if (i % 10000 == 0)
+ {
+ log.info("sent " + i);
+ }
+ }
+
+ log.info("** WARMUP DONE");
+
+ final int numMessages = 1000000;
+
+ tm = sess.createTextMessage();
+
+ tm.setText(str);
+
+ long start = System.currentTimeMillis();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ prod.send(tm);
+
+ if (i % 10000 == 0)
+ {
+ log.info("sent " + i);
+ }
+ }
+
+ sess.close();
+
+ long end = System.currentTimeMillis();
+
+ double rate = 1000 * (double)numMessages / (end - start);
+
+ System.out.println("Rate of " + rate + " msgs / sec");
+
+ server.stop();
+ }
+
+ public void runObjectMessage() throws Exception
+ {
+ startServer();
+
+ Map<String, Object> params = new HashMap<String, Object>();
+
+ // params.put(TransportConstants.HOST_PROP_NAME, "localhost");
+
+ // params.put(TransportConstants.PORT_PROP_NAME, 5445);
+
+ params.put(TransportConstants.TCP_NODELAY_PROPNAME, Boolean.FALSE);
+ //params.put(TransportConstants.USE_NIO_PROP_NAME, Boolean.FALSE);
+
+ TransportConfiguration tc = new TransportConfiguration(NettyConnectorFactory.class.getCanonicalName(), params);
+
+ //TransportConfiguration tc = new TransportConfiguration(InVMConnectorFactory.class.getCanonicalName(), params);
+
+ HornetQConnectionFactory cf = new HornetQConnectionFactory(tc);
+
+ cf.setProducerWindowSize(1024 * 1024);
+
+ Connection conn = cf.createConnection();
+
+ Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ ClientSession coreSession = ((HornetQSession)sess).getCoreSession();
+
+ coreSession.createQueue("jms.queue.test_queue", "jms.queue.test_queue");
+
+ Queue queue = new HornetQQueue("test_queue");
+
+ MessageProducer prod = sess.createProducer(queue);
+
+ prod.setDisableMessageID(true);
+
+ prod.setDisableMessageTimestamp(true);
+
+ prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ byte[] bytes = RandomUtil.randomBytes(512);
+
+ String str = new String(bytes);
+
+ log.info("str length " + str.length());
+
+ final int warmup = 50000;
+
+ log.info("sending messages");
+
+ for (int i = 0; i < warmup; i++)
+ {
+ ObjectMessage om = sess.createObjectMessage(str);
+
+ prod.send(om);
+
+ if (i % 10000 == 0)
+ {
+ log.info("sent " + i);
+ }
+
+ om.setObject(str);
+ }
+
+ log.info("** WARMUP DONE");
+
+ final int numMessages = 500000;
+
+ long start = System.currentTimeMillis();
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ObjectMessage om = sess.createObjectMessage(str);
+
+ prod.send(om);
+
+ if (i % 10000 == 0)
+ {
+ log.info("sent " + i);
+ }
+
+ om.setObject(str);
+ }
+
+ long end = System.currentTimeMillis();
+
+ double rate = 1000 * (double)numMessages / (end - start);
+
+ System.out.println("Rate of " + rate + " msgs / sec");
+
+ server.stop();
+ }
+
+}
15 years, 1 month
JBoss hornetq SVN: r8334 - in branches/20-optimisation: src/main/org/hornetq/core/client and 39 other directories.
by do-not-reply@jboss.org
Author: timfox
Date: 2009-11-20 05:04:40 -0500 (Fri, 20 Nov 2009)
New Revision: 8334
Added:
branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQAbstractChannelBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQByteBufferBackedChannelBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffers.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQDynamicChannelBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQHeapChannelBuffer.java
Removed:
branches/20-optimisation/src/main/org/hornetq/core/buffers/AbstractChannelBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/ByteBufferBackedChannelBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/ChannelBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/ChannelBuffers.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/DynamicChannelBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/HeapChannelBuffer.java
Modified:
branches/20-optimisation/src/main/org/hornetq/core/client/ClientMessage.java
branches/20-optimisation/src/main/org/hornetq/core/client/ClientSessionFactory.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientMessageImpl.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientMessageInternal.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientProducerCreditsImpl.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientProducerImpl.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/FailoverManager.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/LargeMessageBufferImpl.java
branches/20-optimisation/src/main/org/hornetq/core/cluster/impl/DiscoveryGroupImpl.java
branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AbstractJournalUpdateTask.java
branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalCompactor.java
branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalImpl.java
branches/20-optimisation/src/main/org/hornetq/core/journal/impl/TimedBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/management/impl/ManagementServiceImpl.java
branches/20-optimisation/src/main/org/hornetq/core/message/Message.java
branches/20-optimisation/src/main/org/hornetq/core/message/impl/MessageImpl.java
branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PageImpl.java
branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PagedMessageImpl.java
branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/JournalStorageManager.java
branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java
branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageManager.java
branches/20-optimisation/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/Packet.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/invm/InVMConnection.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateQueueMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateReplicationSessionMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateSessionMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateSessionResponseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/HornetQExceptionMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/NullResponseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/PacketImpl.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/PacketsConfirmedMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/Ping.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReattachSessionMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReattachSessionResponseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationAddMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationAddTXMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationCommitMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationCompareDataMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationDeleteMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationDeleteTXMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargeMessageBeingMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargeMessageWriteMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargemessageEndMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPageEventMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPageWriteMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPrepareMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationResponseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationSyncContextMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/RollbackMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionAcknowledgeMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionBindingQueryMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionBindingQueryResponseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionCloseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionConsumerCloseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionConsumerFlowCreditMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionContinuationMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionCreateConsumerMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionDeleteQueueMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionExpiredMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionForceConsumerDelivery.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionProducerCreditsMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionQueueQueryMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionQueueQueryResponseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveContinuationMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionRequestProducerCreditsMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendContinuationMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendLargeMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXACommitMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAEndMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAForgetMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAGetInDoubtXidsResponseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAGetTimeoutResponseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAJoinMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAPrepareMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAResponseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAResumeMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXARollbackMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXASetTimeoutMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXASetTimeoutResponseMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAStartMessage.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/HornetQBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/server/cluster/impl/BroadcastGroupImpl.java
branches/20-optimisation/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerConsumerImpl.java
branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerMessageImpl.java
branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java
branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/ChannelBufferWrapper.java
branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQBytesMessage.java
branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java
branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQMapMessage.java
branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQMessage.java
branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQObjectMessage.java
branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQStreamMessage.java
branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQTextMessage.java
branches/20-optimisation/tests/jms-tests/src/org/hornetq/jms/tests/message/MessageHeaderTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/EncodeSizeTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/AckBatchSizeTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/CoreClientTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/LargeMessageTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/PagingTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/bridge/BridgeTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/PagingFailoverTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/ReplicatedDistributionTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/management/ManagementHelperTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/management/ManagementServiceImplTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/performance/persistence/StorageManagerTimingTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/CompactingStressTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/LargeJournalStressTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/MultiThreadConsumerStressTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/NIOMultiThreadCompactorStressTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/timing/util/UTF8Test.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/ByteBufferBackedHeapChannelBufferTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/ChannelBuffersTestBase.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/DynamicChannelBufferTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/HeapChannelBufferTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/client/impl/LargeMessageBufferTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/filter/impl/FilterTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/message/impl/MessageImplTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PageImplTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingManagerImplTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingStoreImplTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/persistence/impl/BatchIDGeneratorUnitTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/ByteBufferWrapperTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/ChannelBufferWrapper2Test.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/util/TypedPropertiesTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/util/UTF8Test.java
branches/20-optimisation/tests/src/org/hornetq/tests/util/UnitTestCase.java
Log:
optimisation
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/AbstractChannelBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/AbstractChannelBuffer.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/AbstractChannelBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -1,788 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat licenses this file to you under the Apache License, version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package org.hornetq.core.buffers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.GatheringByteChannel;
-import java.nio.channels.ScatteringByteChannel;
-
-import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
-import org.hornetq.utils.DataConstants;
-import org.hornetq.utils.SimpleString;
-import org.hornetq.utils.UTF8Util;
-
-/**
- * A skeletal implementation of a buffer.
- *
- * @author The Netty Project (netty-dev(a)lists.jboss.org)
- * @author Trustin Lee (tlee(a)redhat.com)
- *
- * @version $Rev: 303 $, $Date: 2008-09-24 18:48:32 +0900 (Wed, 24 Sep 2008) $
- */
-public abstract class AbstractChannelBuffer implements ChannelBuffer
-{
- private static final Logger log = Logger.getLogger(AbstractChannelBuffer.class);
-
-
- private int readerIndex;
-
- private int writerIndex;
-
- private int markedReaderIndex;
-
- private int markedWriterIndex;
-
- public int readerIndex()
- {
- return readerIndex;
- }
-
- public void readerIndex(final int readerIndex)
- {
- if (readerIndex < 0 || readerIndex > writerIndex)
- {
- throw new IndexOutOfBoundsException();
- }
- this.readerIndex = readerIndex;
- }
-
- public int writerIndex()
- {
- return writerIndex;
- }
-
- public void writerIndex(final int writerIndex)
- {
- if (writerIndex < readerIndex || writerIndex > capacity())
- {
- throw new IndexOutOfBoundsException();
- }
- this.writerIndex = writerIndex;
- }
-
- public void setIndex(final int readerIndex, final int writerIndex)
- {
- if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity())
- {
- throw new IndexOutOfBoundsException();
- }
- this.readerIndex = readerIndex;
- this.writerIndex = writerIndex;
- }
-
- public void clear()
- {
- readerIndex = writerIndex = 0;
- }
-
- public boolean readable()
- {
- return readableBytes() > 0;
- }
-
- public boolean writable()
- {
- return writableBytes() > 0;
- }
-
- public int readableBytes()
- {
- return writerIndex - readerIndex;
- }
-
- public int writableBytes()
- {
- return capacity() - writerIndex;
- }
-
- public void markReaderIndex()
- {
- markedReaderIndex = readerIndex;
- }
-
- public void resetReaderIndex()
- {
- readerIndex(markedReaderIndex);
- }
-
- public void markWriterIndex()
- {
- markedWriterIndex = writerIndex;
- }
-
- public void resetWriterIndex()
- {
- writerIndex = markedWriterIndex;
- }
-
- public void discardReadBytes()
- {
- if (readerIndex == 0)
- {
- return;
- }
- setBytes(0, this, readerIndex, writerIndex - readerIndex);
- writerIndex -= readerIndex;
- markedReaderIndex = Math.max(markedReaderIndex - readerIndex, 0);
- markedWriterIndex = Math.max(markedWriterIndex - readerIndex, 0);
- readerIndex = 0;
- }
-
- public short getUnsignedByte(final int index)
- {
- return (short)(getByte(index) & 0xFF);
- }
-
- public int getUnsignedShort(final int index)
- {
- return getShort(index) & 0xFFFF;
- }
-
- public int getMedium(final int index)
- {
- int value = getUnsignedMedium(index);
- if ((value & 0x800000) != 0)
- {
- value |= 0xff000000;
- }
- return value;
- }
-
- public long getUnsignedInt(final int index)
- {
- return getInt(index) & 0xFFFFFFFFL;
- }
-
- public void getBytes(final int index, final byte[] dst)
- {
- getBytes(index, dst, 0, dst.length);
- }
-
- public void getBytes(final int index, final ChannelBuffer dst)
- {
- getBytes(index, dst, dst.writableBytes());
- }
-
- public void getBytes(final int index, final ChannelBuffer dst, final int length)
- {
- if (length > dst.writableBytes())
- {
- throw new IndexOutOfBoundsException();
- }
- getBytes(index, dst, dst.writerIndex(), length);
- dst.writerIndex(dst.writerIndex() + length);
- }
-
- public void setBytes(final int index, final byte[] src)
- {
- setBytes(index, src, 0, src.length);
- }
-
- public void setBytes(final int index, final ChannelBuffer src)
- {
- setBytes(index, src, src.readableBytes());
- }
-
- public void setBytes(final int index, final ChannelBuffer src, final int length)
- {
- if (length > src.readableBytes())
- {
- throw new IndexOutOfBoundsException();
- }
- setBytes(index, src, src.readerIndex(), length);
- src.readerIndex(src.readerIndex() + length);
- }
-
- public void setZero(int index, final int length)
- {
- if (length == 0)
- {
- return;
- }
- if (length < 0)
- {
- throw new IllegalArgumentException("length must be 0 or greater than 0.");
- }
-
- int nLong = length >>> 3;
- int nBytes = length & 7;
- for (int i = nLong; i > 0; i--)
- {
- setLong(index, 0);
- index += 8;
- }
- if (nBytes == 4)
- {
- setInt(index, 0);
- }
- else if (nBytes < 4)
- {
- for (int i = nBytes; i > 0; i--)
- {
- setByte(index, (byte)0);
- index++;
- }
- }
- else
- {
- setInt(index, 0);
- index += 4;
- for (int i = nBytes - 4; i > 0; i--)
- {
- setByte(index, (byte)0);
- index++;
- }
- }
- }
-
- public byte readByte()
- {
- if (readerIndex == writerIndex)
- {
- throw new IndexOutOfBoundsException();
- }
- return getByte(readerIndex++);
- }
-
- public short readUnsignedByte()
- {
- return (short)(readByte() & 0xFF);
- }
-
- public short readShort()
- {
- checkReadableBytes(2);
- short v = getShort(readerIndex);
- readerIndex += 2;
- return v;
- }
-
- public int readUnsignedShort()
- {
- return readShort() & 0xFFFF;
- }
-
- public int readMedium()
- {
- int value = readUnsignedMedium();
- if ((value & 0x800000) != 0)
- {
- value |= 0xff000000;
- }
- return value;
- }
-
- public int readUnsignedMedium()
- {
- checkReadableBytes(3);
- int v = getUnsignedMedium(readerIndex);
- readerIndex += 3;
- return v;
- }
-
- public int readInt()
- {
- checkReadableBytes(4);
- int v = getInt(readerIndex);
- readerIndex += 4;
- return v;
- }
-
- public int readInt(final int pos)
- {
- checkReadableBytes(4);
- int v = getInt(pos);
- return v;
- }
-
- public long readUnsignedInt()
- {
- return readInt() & 0xFFFFFFFFL;
- }
-
- public long readLong()
- {
- checkReadableBytes(8);
- long v = getLong(readerIndex);
- readerIndex += 8;
- return v;
- }
-
- public void readBytes(final byte[] dst, final int dstIndex, final int length)
- {
- checkReadableBytes(length);
- getBytes(readerIndex, dst, dstIndex, length);
- readerIndex += length;
- }
-
- public void readBytes(final byte[] dst)
- {
- readBytes(dst, 0, dst.length);
- }
-
- public void readBytes(final ChannelBuffer dst)
- {
- readBytes(dst, dst.writableBytes());
- }
-
- public void readBytes(final ChannelBuffer dst, final int length)
- {
- if (length > dst.writableBytes())
- {
- throw new IndexOutOfBoundsException();
- }
- readBytes(dst, dst.writerIndex(), length);
- dst.writerIndex(dst.writerIndex() + length);
- }
-
- public void readBytes(final ChannelBuffer dst, final int dstIndex, final int length)
- {
- checkReadableBytes(length);
- getBytes(readerIndex, dst, dstIndex, length);
- readerIndex += length;
- }
-
- public void readBytes(final ByteBuffer dst)
- {
- int length = dst.remaining();
- checkReadableBytes(length);
- getBytes(readerIndex, dst);
- readerIndex += length;
- }
-
- public int readBytes(final GatheringByteChannel out, final int length) throws IOException
- {
- checkReadableBytes(length);
- int readBytes = getBytes(readerIndex, out, length);
- readerIndex += readBytes;
- return readBytes;
- }
-
- public void readBytes(final OutputStream out, final int length) throws IOException
- {
- checkReadableBytes(length);
- getBytes(readerIndex, out, length);
- readerIndex += length;
- }
-
- public void skipBytes(final int length)
- {
- int newReaderIndex = readerIndex + length;
- if (newReaderIndex > writerIndex)
- {
- throw new IndexOutOfBoundsException();
- }
- readerIndex = newReaderIndex;
- }
-
- public void writeByte(final byte value)
- {
- setByte(writerIndex++, value);
- }
-
- public void writeShort(final short value)
- {
- setShort(writerIndex, value);
- writerIndex += 2;
- }
-
- public void writeMedium(final int value)
- {
- setMedium(writerIndex, value);
- writerIndex += 3;
- }
-
- public void writeInt(final int value)
- {
- setInt(writerIndex, value);
- writerIndex += 4;
- }
-
- public void writeLong(final long value)
- {
- setLong(writerIndex, value);
- writerIndex += 8;
- }
-
- public void writeBytes(final byte[] src, final int srcIndex, final int length)
- {
- setBytes(writerIndex, src, srcIndex, length);
- writerIndex += length;
- }
-
- public void writeBytes(final byte[] src)
- {
- writeBytes(src, 0, src.length);
- }
-
- public void writeBytes(final ChannelBuffer src)
- {
- writeBytes(src, src.readableBytes());
- }
-
- public void writeBytes(final ChannelBuffer src, final int length)
- {
- if (length > src.readableBytes())
- {
- throw new IndexOutOfBoundsException();
- }
- writeBytes(src, src.readerIndex(), length);
- src.readerIndex(src.readerIndex() + length);
- }
-
- public void writeBytes(final ChannelBuffer src, final int srcIndex, final int length)
- {
- setBytes(writerIndex, src, srcIndex, length);
- writerIndex += length;
- }
-
-
- public void writeBytes(final HornetQBuffer src, final int srcIndex, final int length)
- {
- writeBytes((ChannelBuffer)src, srcIndex, length);
- }
-
- public void writeBytes(final ByteBuffer src)
- {
- int length = src.remaining();
- setBytes(writerIndex, src);
- writerIndex += length;
- }
-
- public void writeBytes(final InputStream in, final int length) throws IOException
- {
- setBytes(writerIndex, in, length);
- writerIndex += length;
- }
-
- public int writeBytes(final ScatteringByteChannel in, final int length) throws IOException
- {
- int writtenBytes = setBytes(writerIndex, in, length);
- if (writtenBytes > 0)
- {
- writerIndex += writtenBytes;
- }
- return writtenBytes;
- }
-
- public void writeZero(final int length)
- {
- if (length == 0)
- {
- return;
- }
- if (length < 0)
- {
- throw new IllegalArgumentException("length must be 0 or greater than 0.");
- }
- int nLong = length >>> 3;
- int nBytes = length & 7;
- for (int i = nLong; i > 0; i--)
- {
- writeLong(0);
- }
- if (nBytes == 4)
- {
- writeInt(0);
- }
- else if (nBytes < 4)
- {
- for (int i = nBytes; i > 0; i--)
- {
- writeByte((byte)0);
- }
- }
- else
- {
- writeInt(0);
- for (int i = nBytes - 4; i > 0; i--)
- {
- writeByte((byte)0);
- }
- }
- }
-
- public ByteBuffer toByteBuffer()
- {
- return toByteBuffer(readerIndex, readableBytes());
- }
-
- public ByteBuffer[] toByteBuffers()
- {
- return toByteBuffers(readerIndex, readableBytes());
- }
-
- public ByteBuffer[] toByteBuffers(final int index, final int length)
- {
- return new ByteBuffer[] { toByteBuffer(index, length) };
- }
-
- public String toString(final String charsetName)
- {
- return toString(readerIndex, readableBytes(), charsetName);
- }
-
- @Override
- public int hashCode()
- {
- return ChannelBuffers.hashCode(this);
- }
-
- @Override
- public boolean equals(final Object o)
- {
- if (!(o instanceof ChannelBuffer))
- {
- return false;
- }
- return ChannelBuffers.equals(this, (ChannelBuffer)o);
- }
-
- public int compareTo(final ChannelBuffer that)
- {
- return ChannelBuffers.compare(this, that);
- }
-
- @Override
- public String toString()
- {
- return getClass().getSimpleName() + '(' +
- "ridx=" +
- readerIndex +
- ", " +
- "widx=" +
- writerIndex +
- ", " +
- "cap=" +
- capacity() +
- ')';
- }
-
- /**
- * Throws an {@link IndexOutOfBoundsException} if the current
- * {@linkplain #readableBytes() readable bytes} of this buffer is less
- * than the specified value.
- */
- protected void checkReadableBytes(final int minimumReadableBytes)
- {
- if (readableBytes() < minimumReadableBytes)
- {
- throw new IndexOutOfBoundsException();
- }
- }
-
- public Object getUnderlyingBuffer()
- {
- return this;
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#readBoolean()
- */
- public boolean readBoolean()
- {
- return readByte() != 0;
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#readChar()
- */
- public char readChar()
- {
- return (char)readShort();
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#readDouble()
- */
- public double readDouble()
- {
- return Double.longBitsToDouble(readLong());
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#readFloat()
- */
- public float readFloat()
- {
- return Float.intBitsToFloat(readInt());
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#readNullableSimpleString()
- */
- public SimpleString readNullableSimpleString()
- {
- int b = readByte();
- if (b == DataConstants.NULL)
- {
- return null;
- }
- else
- {
- return readSimpleString();
- }
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#readNullableString()
- */
- public String readNullableString()
- {
- int b = readByte();
- if (b == DataConstants.NULL)
- {
- return null;
- }
- else
- {
- return readString();
- }
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#readSimpleString()
- */
- public SimpleString readSimpleString()
- {
- int len = readInt();
- byte[] data = new byte[len];
- readBytes(data);
- return new SimpleString(data);
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#readString()
- */
- public String readString()
- {
- int len = readInt();
-
- char[] chars = new char[len];
- for (int i = 0; i < len; i++)
- {
- chars[i] = readChar();
- }
- return new String(chars);
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#readUTF()
- */
- public String readUTF() throws Exception
- {
- return UTF8Util.readUTF(this);
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeBoolean(boolean)
- */
- public void writeBoolean(final boolean val)
- {
- writeByte((byte)(val ? -1 : 0));
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeChar(char)
- */
- public void writeChar(final char val)
- {
- writeShort((short)val);
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeDouble(double)
- */
- public void writeDouble(final double val)
- {
- writeLong(Double.doubleToLongBits(val));
-
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeFloat(float)
- */
- public void writeFloat(final float val)
- {
- writeInt(Float.floatToIntBits(val));
-
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeNullableSimpleString(org.hornetq.util.SimpleString)
- */
- public void writeNullableSimpleString(final SimpleString val)
- {
- if (val == null)
- {
- writeByte(DataConstants.NULL);
- }
- else
- {
- writeByte(DataConstants.NOT_NULL);
- writeSimpleString(val);
- }
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeNullableString(java.lang.String)
- */
- public void writeNullableString(final String val)
- {
- if (val == null)
- {
- writeByte(DataConstants.NULL);
- }
- else
- {
- writeByte(DataConstants.NOT_NULL);
- writeString(val);
- }
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeSimpleString(org.hornetq.util.SimpleString)
- */
- public void writeSimpleString(final SimpleString val)
- {
- byte[] data = val.getData();
- writeInt(data.length);
- writeBytes(data);
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeString(java.lang.String)
- */
- public void writeString(final String val)
- {
- writeInt(val.length());
- for (int i = 0; i < val.length(); i++)
- {
- writeShort((short)val.charAt(i));
- }
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeUTF(java.lang.String)
- */
- public void writeUTF(final String utf) throws Exception
- {
- UTF8Util.saveUTF(this, utf);
- }
-
-}
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/ByteBufferBackedChannelBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/ByteBufferBackedChannelBuffer.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/ByteBufferBackedChannelBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -1,374 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat licenses this file to you under the Apache License, version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package org.hornetq.core.buffers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.GatheringByteChannel;
-import java.nio.channels.ScatteringByteChannel;
-import java.nio.charset.UnsupportedCharsetException;
-
-/**
- * A NIO {@link ByteBuffer} based buffer. It is recommended to use {@link ChannelBuffers#directBuffer(int)}
- * and {@link ChannelBuffers#wrappedBuffer(ByteBuffer)} instead of calling the
- * constructor explicitly.
- *
- * @author The Netty Project (netty-dev(a)lists.jboss.org)
- * @author Trustin Lee (tlee(a)redhat.com)
- *
- * @version $Rev: 486 $, $Date: 2008-11-16 22:52:47 +0900 (Sun, 16 Nov 2008) $
- *
- */
-public class ByteBufferBackedChannelBuffer extends AbstractChannelBuffer
-{
-
- private final ByteBuffer buffer;
-
- private final int capacity;
-
- /**
- * Creates a new buffer which wraps the specified buffer's slice.
- */
- ByteBufferBackedChannelBuffer(final ByteBuffer buffer)
- {
- if (buffer == null)
- {
- throw new NullPointerException("buffer");
- }
-
- this.buffer = buffer;
- capacity = buffer.remaining();
- }
-
- public int capacity()
- {
- return capacity;
- }
-
- public byte getByte(final int index)
- {
- return buffer.get(index);
- }
-
- public short getShort(final int index)
- {
- return buffer.getShort(index);
- }
-
- public int getUnsignedMedium(final int index)
- {
- return (getByte(index) & 0xff) << 16 | (getByte(index + 1) & 0xff) << 8 | (getByte(index + 2) & 0xff) << 0;
- }
-
- public int getInt(final int index)
- {
- return buffer.getInt(index);
- }
-
- public long getLong(final int index)
- {
- return buffer.getLong(index);
- }
-
- public void getBytes(final int index, final ChannelBuffer dst, final int dstIndex, final int length)
- {
- if (dst instanceof ByteBufferBackedChannelBuffer)
- {
- ByteBufferBackedChannelBuffer bbdst = (ByteBufferBackedChannelBuffer)dst;
- ByteBuffer data = bbdst.buffer.duplicate();
-
- data.limit(dstIndex + length).position(dstIndex);
- getBytes(index, data);
- }
- else if (buffer.hasArray())
- {
- dst.setBytes(dstIndex, buffer.array(), index + buffer.arrayOffset(), length);
- }
- else
- {
- dst.setBytes(dstIndex, this, index, length);
- }
- }
-
- public void getBytes(final int index, final byte[] dst, final int dstIndex, final int length)
- {
- ByteBuffer data = buffer.duplicate();
- try
- {
- data.limit(index + length).position(index);
- }
- catch (IllegalArgumentException e)
- {
- throw new IndexOutOfBoundsException();
- }
- data.get(dst, dstIndex, length);
- }
-
- public void getBytes(final int index, final ByteBuffer dst)
- {
- ByteBuffer data = buffer.duplicate();
- int bytesToCopy = Math.min(capacity() - index, dst.remaining());
- try
- {
- data.limit(index + bytesToCopy).position(index);
- }
- catch (IllegalArgumentException e)
- {
- throw new IndexOutOfBoundsException();
- }
- dst.put(data);
- }
-
- public void setByte(final int index, final byte value)
- {
- buffer.put(index, value);
- }
-
- public void setShort(final int index, final short value)
- {
- buffer.putShort(index, value);
- }
-
- public void setMedium(final int index, final int value)
- {
- setByte(index, (byte)(value >>> 16));
- setByte(index + 1, (byte)(value >>> 8));
- setByte(index + 2, (byte)(value >>> 0));
- }
-
- public void setInt(final int index, final int value)
- {
- buffer.putInt(index, value);
- }
-
- public void setLong(final int index, final long value)
- {
- buffer.putLong(index, value);
- }
-
- public void setBytes(final int index, final ChannelBuffer src, final int srcIndex, final int length)
- {
- if (src instanceof ByteBufferBackedChannelBuffer)
- {
- ByteBufferBackedChannelBuffer bbsrc = (ByteBufferBackedChannelBuffer)src;
- ByteBuffer data = bbsrc.buffer.duplicate();
-
- data.limit(srcIndex + length).position(srcIndex);
- setBytes(index, data);
- }
- else if (buffer.hasArray())
- {
- src.getBytes(srcIndex, buffer.array(), index + buffer.arrayOffset(), length);
- }
- else
- {
- src.getBytes(srcIndex, this, index, length);
- }
- }
-
- public void setBytes(final int index, final byte[] src, final int srcIndex, final int length)
- {
- ByteBuffer data = buffer.duplicate();
- data.limit(index + length).position(index);
- data.put(src, srcIndex, length);
- }
-
- public void setBytes(final int index, final ByteBuffer src)
- {
- ByteBuffer data = buffer.duplicate();
- data.limit(index + src.remaining()).position(index);
- data.put(src);
- }
-
- public void getBytes(final int index, final OutputStream out, final int length) throws IOException
- {
- if (length == 0)
- {
- return;
- }
-
- if (!buffer.isReadOnly() && buffer.hasArray())
- {
- out.write(buffer.array(), index + buffer.arrayOffset(), length);
- }
- else
- {
- byte[] tmp = new byte[length];
- ((ByteBuffer)buffer.duplicate().position(index)).get(tmp);
- out.write(tmp);
- }
- }
-
- public int getBytes(final int index, final GatheringByteChannel out, final int length) throws IOException
- {
- if (length == 0)
- {
- return 0;
- }
-
- return out.write((ByteBuffer)buffer.duplicate().position(index).limit(index + length));
- }
-
- public int setBytes(int index, final InputStream in, int length) throws IOException
- {
-
- int readBytes = 0;
-
- if (!buffer.isReadOnly() && buffer.hasArray())
- {
- index += buffer.arrayOffset();
- do
- {
- int localReadBytes = in.read(buffer.array(), index, length);
- if (localReadBytes < 0)
- {
- if (readBytes == 0)
- {
- return -1;
- }
- else
- {
- break;
- }
- }
- readBytes += localReadBytes;
- index += localReadBytes;
- length -= localReadBytes;
- }
- while (length > 0);
- }
- else
- {
- byte[] tmp = new byte[length];
- int i = 0;
- do
- {
- int localReadBytes = in.read(tmp, i, tmp.length - i);
- if (localReadBytes < 0)
- {
- if (readBytes == 0)
- {
- return -1;
- }
- else
- {
- break;
- }
- }
- readBytes += localReadBytes;
- i += readBytes;
- }
- while (i < tmp.length);
- ((ByteBuffer)buffer.duplicate().position(index)).put(tmp);
- }
-
- return readBytes;
- }
-
- public int setBytes(final int index, final ScatteringByteChannel in, final int length) throws IOException
- {
-
- ByteBuffer slice = (ByteBuffer)buffer.duplicate().limit(index + length).position(index);
- int readBytes = 0;
-
- while (readBytes < length)
- {
- int localReadBytes;
- try
- {
- localReadBytes = in.read(slice);
- }
- catch (ClosedChannelException e)
- {
- localReadBytes = -1;
- }
- if (localReadBytes < 0)
- {
- if (readBytes == 0)
- {
- return -1;
- }
- else
- {
- return readBytes;
- }
- }
- else if (localReadBytes == 0)
- {
- break;
- }
- readBytes += localReadBytes;
- }
-
- return readBytes;
- }
-
- public ByteBuffer toByteBuffer(final int index, final int length)
- {
- if (index == 0 && length == capacity())
- {
- return buffer.duplicate();
- }
- else
- {
- return ((ByteBuffer)buffer.duplicate().position(index).limit(index + length)).slice();
- }
- }
-
- @Override
- public ByteBuffer toByteBuffer()
- {
- return buffer;
- }
-
- public String toString(final int index, final int length, final String charsetName)
- {
- if (!buffer.isReadOnly() && buffer.hasArray())
- {
- try
- {
- return new String(buffer.array(), index + buffer.arrayOffset(), length, charsetName);
- }
- catch (UnsupportedEncodingException e)
- {
- throw new UnsupportedCharsetException(charsetName);
- }
- }
- else
- {
- byte[] tmp = new byte[length];
- ((ByteBuffer)buffer.duplicate().position(index)).get(tmp);
- try
- {
- return new String(tmp, charsetName);
- }
- catch (UnsupportedEncodingException e)
- {
- throw new UnsupportedCharsetException(charsetName);
- }
- }
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.buffers.ChannelBuffer#array()
- */
- public byte[] array()
- {
- return buffer.array();
- }
-}
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/ChannelBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/ChannelBuffer.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/ChannelBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -1,1256 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat licenses this file to you under the Apache License, version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package org.hornetq.core.buffers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.GatheringByteChannel;
-import java.nio.channels.ScatteringByteChannel;
-import java.nio.charset.UnsupportedCharsetException;
-
-import org.hornetq.core.remoting.spi.HornetQBuffer;
-
-/**
- * A random and sequential accessible sequence of zero or more bytes (octets).
- * This interface provides an abstract view for one or more primitive byte
- * arrays ({@code byte[]}) and {@linkplain ByteBuffer NIO buffers}.
- *
- * <h3>Creation of a buffer</h3>
- *
- * It is recommended to create a new buffer using the helper methods in
- * {@link ChannelBuffers} rather than calling an individual implementation's
- * constructor.
- *
- * <h3>Random Access Indexing</h3>
- *
- * Just like an ordinary primitive byte array, {@link ChannelBuffer} uses
- * <a href="http://en.wikipedia.org/wiki/Index_(information_technology)#Array_element...">zero-based indexing</a>.
- * It means the index of the first byte is always {@code 0} and the index of
- * the last byte is always {@link #capacity() capacity - 1}. For example, to
- * iterate all bytes of a buffer, you can do the following, regardless of
- * its internal implementation:
- *
- * <pre>
- * ChannelBuffer buffer = ...;
- * for (int i = 0; i < buffer.capacity(); i ++</strong>) {
- * byte b = array.getByte(i);
- * System.out.println((char) b);
- * }
- * </pre>
- *
- * <h3>Sequential Access Indexing</h3>
- *
- * {@link ChannelBuffer} provides two pointer variables to support sequential
- * read and write operations - {@link #readerIndex() readerIndex} for a read
- * operation and {@link #writerIndex() writerIndex} for a write operation
- * respectively. The following diagram shows how a buffer is segmented into
- * three areas by the two pointers:
- *
- * <pre>
- * +-------------------+------------------+------------------+
- * | discardable bytes | readable bytes | writable bytes |
- * | | (CONTENT) | |
- * +-------------------+------------------+------------------+
- * | | | |
- * 0 <= readerIndex <= writerIndex <= capacity
- * </pre>
- *
- * <h4>Readable bytes (the actual content)</h4>
- *
- * This segment is where the actual data is stored. Any operation whose name
- * starts with {@code read} or {@code skip} will get or skip the data at the
- * current {@link #readerIndex() readerIndex} and increase it by the number of
- * read bytes. If the argument of the read operation is also a
- * {@link ChannelBuffer} and no start index is specified, the specified
- * buffer's {@link #readerIndex() readerIndex} is increased together.
- * <p>
- * If there's not enough content left, {@link IndexOutOfBoundsException} is
- * raised. The default value of newly allocated, wrapped or copied buffer's
- * {@link #readerIndex() readerIndex} is {@code 0}.
- *
- * <pre>
- * // Iterates the readable bytes of a buffer.
- * ChannelBuffer buffer = ...;
- * while (buffer.readable()) {
- * System.out.println(buffer.readByte());
- * }
- * </pre>
- *
- * <h4>Writable bytes</h4>
- *
- * This segment is a undefined space which needs to be filled. Any operation
- * whose name ends with {@code write} will write the data at the current
- * {@link #writerIndex() writerIndex} and increase it by the number of written
- * bytes. If the argument of the write operation is also a {@link ChannelBuffer},
- * and no start index is specified, the specified buffer's
- * {@link #readerIndex() readerIndex} is increased together.
- * <p>
- * If there's not enough writable bytes left, {@link IndexOutOfBoundsException}
- * is raised. The default value of newly allocated buffer's
- * {@link #writerIndex() writerIndex} is {@code 0}. The default value of
- * wrapped or copied buffer's {@link #writerIndex() writerIndex} is the
- * {@link #capacity() capacity} of the buffer.
- *
- * <pre>
- * // Fills the writable bytes of a buffer with random integers.
- * ChannelBuffer buffer = ...;
- * while (buffer.writableBytes() >= 4) {
- * buffer.writeInt(random.nextInt());
- * }
- * </pre>
- *
- * <h4>Discardable bytes</h4>
- *
- * This segment contains the bytes which were read already by a read operation.
- * Initially, the size of this segment is {@code 0}, but its size increases up
- * to the {@link #writerIndex() writerIndex} as read operations are executed.
- * The read bytes can be discarded by calling {@link #discardReadBytes()} to
- * reclaim unused area as depicted by the following diagram:
- *
- * <pre>
- * BEFORE discardReadBytes()
- *
- * +-------------------+------------------+------------------+
- * | discardable bytes | readable bytes | writable bytes |
- * +-------------------+------------------+------------------+
- * | | | |
- * 0 <= readerIndex <= writerIndex <= capacity
- *
- *
- * AFTER discardReadBytes()
- *
- * +------------------+--------------------------------------+
- * | readable bytes | writable bytes (got more space) |
- * +------------------+--------------------------------------+
- * | | |
- * readerIndex (0) <= writerIndex (decreased) <= capacity
- * </pre>
- *
- * <h4>Clearing the buffer indexes</h4>
- *
- * You can set both {@link #readerIndex() readerIndex} and
- * {@link #writerIndex() writerIndex} to {@code 0} by calling {@link #clear()}.
- * It does not clear the buffer content (e.g. filling with {@code 0}) but just
- * clears the two pointers. Please also note that the semantic of this
- * operation is different from {@link ByteBuffer#clear()}.
- *
- * <pre>
- * BEFORE clear()
- *
- * +-------------------+------------------+------------------+
- * | discardable bytes | readable bytes | writable bytes |
- * +-------------------+------------------+------------------+
- * | | | |
- * 0 <= readerIndex <= writerIndex <= capacity
- *
- *
- * AFTER clear()
- *
- * +---------------------------------------------------------+
- * | writable bytes (got more space) |
- * +---------------------------------------------------------+
- * | |
- * 0 = readerIndex = writerIndex <= capacity
- * </pre>
- *
- * <h3>Search operations</h3>
- *
- * Various {@code indexOf()} methods help you locate an index of a value which
- * meets a certain criteria. Complicated dynamic sequential search can be done
- * with {@link ChannelBufferIndexFinder} as well as simple static single byte
- * search.
- *
- * <h3>Mark and reset</h3>
- *
- * There are two marker indexes in every buffer. One is for storing
- * {@link #readerIndex() readerIndex} and the other is for storing
- * {@link #writerIndex() writerIndex}. You can always reposition one of the
- * two indexes by calling a reset method. It works in a similar fashion to
- * the mark and reset methods in {@link InputStream} except that there's no
- * {@code readlimit}.
- *
- * <h3>Derived buffers</h3>
- *
- * You can create a view of an existing buffer by calling either
- * {@link #duplicate()}, {@link #slice()} or {@link #slice(int, int)}.
- * A derived buffer will have an independent {@link #readerIndex() readerIndex},
- * {@link #writerIndex() writerIndex} and marker indexes, while it shares
- * other internal data representation, just like a NIO buffer does.
- * <p>
- * In case a completely fresh copy of an existing buffer is required, please
- * call {@link #copy()} method instead.
- *
- * <h3>Conversion to existing JDK types</h3>
- *
- * <h4>NIO Buffers</h4>
- *
- * Various {@link #toByteBuffer()} and {@link #toByteBuffers()} methods convert
- * a {@link ChannelBuffer} into one or more NIO buffers. These methods avoid
- * buffer allocation and memory copy whenever possible, but there's no
- * guarantee that memory copy will not be involved or that an explicit memory
- * copy will be involved.
- *
- * <h4>Strings</h4>
- *
- * Various {@link #toString(String)} methods convert a {@link ChannelBuffer}
- * into a {@link String}. Plesae note that {@link #toString()} is not a
- * conversion method.
- *
- * <h4>I/O Streams</h4>
- *
- * Please refer to {@link ChannelBufferInputStream} and
- * {@link ChannelBufferOutputStream}.
- *
- * @author The Netty Project (netty-dev(a)lists.jboss.org)
- * @author Trustin Lee (tlee(a)redhat.com)
- *
- * @version $Rev: 472 $, $Date: 2008-11-14 16:45:53 +0900 (Fri, 14 Nov 2008) $
- *
- * @apiviz.landmark
- */
-public interface ChannelBuffer extends Comparable<ChannelBuffer>, HornetQBuffer
-{
-
- /**
- * Returns the number of bytes (octets) this buffer can contain.
- */
- int capacity();
-
- byte[] array();
-
- /**
- * Returns the {@code readerIndex} of this buffer.
- */
- int readerIndex();
-
- /**
- * Sets the {@code readerIndex} of this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code readerIndex} is
- * less than {@code 0} or
- * greater than {@code this.writerIndex}
- */
- void readerIndex(int readerIndex);
-
- /**
- * Returns the {@code writerIndex} of this buffer.
- */
- int writerIndex();
-
- /**
- * Sets the {@code writerIndex} of this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code writerIndex} is
- * less than {@code this.readerIndex} or
- * greater than {@code this.capacity}
- */
- void writerIndex(int writerIndex);
-
- /**
- * Sets the {@code readerIndex} and {@code writerIndex} of this buffer
- * in one shot. This method is useful when you have to worry about the
- * invocation order of {@link #readerIndex(int)} and {@link #writerIndex(int)}
- * methods. For example, the following code will fail:
- *
- * <pre>
- * // Create a buffer whose readerIndex, writerIndex and capacity are
- * // 0, 0 and 8 respectively.
- * ChannelBuffer buf = ChannelBuffers.buffer(8);
- *
- * // IndexOutOfBoundsException is thrown because the specified
- * // readerIndex (2) cannot be greater than the current writerIndex (0).
- * buf.readerIndex(2);
- * buf.writerIndex(4);
- * </pre>
- *
- * The following code will also fail:
- *
- * <pre>
- * // Create a buffer whose readerIndex, writerIndex and capacity are
- * // 0, 8 and 8 respectively.
- * ChannelBuffer buf = ChannelBuffers.wrappedBuffer(new byte[8]);
- *
- * // readerIndex becomes 8.
- * buf.readLong();
- *
- * // IndexOutOfBoundsException is thrown because the specified
- * // writerIndex (4) cannot be less than the current readerIndex (8).
- * buf.writerIndex(4);
- * buf.readerIndex(2);
- * </pre>
- *
- * By contrast, {@link #setIndex(int, int)} guarantees that it never
- * throws an {@link IndexOutOfBoundsException} as long as the specified
- * indexes meet basic constraints, regardless what the current index
- * values of the buffer are:
- *
- * <pre>
- * // No matter what the current state of the buffer is, the following
- * // call always succeeds as long as the capacity of the buffer is not
- * // less than 4.
- * buf.setIndex(2, 4);
- * </pre>
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code readerIndex} is less than 0,
- * if the specified {@code writerIndex} is less than the specified
- * {@code readerIndex} or if the specified {@code writerIndex} is
- * greater than {@code this.capacity}
- */
- void setIndex(int readerIndex, int writerIndex);
-
- /**
- * Returns the number of readable bytes which is equal to
- * {@code (this.writerIndex - this.readerIndex)}.
- */
- int readableBytes();
-
- /**
- * Returns the number of writable bytes which is equal to
- * {@code (this.capacity - this.writerIndex)}.
- */
- int writableBytes();
-
- /**
- * Returns {@code true}
- * if and only if {@code (this.writerIndex - this.readerIndex)} is greater
- * than {@code 0}.
- */
- boolean readable();
-
- /**
- * Returns {@code true}
- * if and only if {@code (this.capacity - this.writerIndex)} is greater
- * than {@code 0}.
- */
- boolean writable();
-
- /**
- * Sets the {@code readerIndex} and {@code writerIndex} of this buffer to
- * {@code 0}.
- * This method is identical to {@link #setIndex(int, int) setIndex(0, 0)}.
- * <p>
- * Please note that the behavior of this method is different
- * from that of NIO buffer, which sets the {@code limit} to
- * the {@code capacity} of the buffer.
- */
- void clear();
-
- /**
- * Marks the current {@code readerIndex} in this buffer. You can
- * reposition the current {@code readerIndex} to the marked
- * {@code readerIndex} by calling {@link #resetReaderIndex()}.
- * The initial value of the marked {@code readerIndex} is {@code 0}.
- */
- void markReaderIndex();
-
- /**
- * Repositions the current {@code readerIndex} to the marked
- * {@code readerIndex} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the current {@code writerIndex} is less than the marked
- * {@code readerIndex}
- */
- void resetReaderIndex();
-
- /**
- * Marks the current {@code writerIndex} in this buffer. You can
- * reposition the current {@code writerIndex} to the marked
- * {@code writerIndex} by calling {@link #resetWriterIndex()}.
- * The initial value of the marked {@code writerIndex} is {@code 0}.
- */
- void markWriterIndex();
-
- /**
- * Repositions the current {@code writerIndex} to the marked
- * {@code writerIndex} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the current {@code readerIndex} is greater than the marked
- * {@code writerIndex}
- */
- void resetWriterIndex();
-
- /**
- * Discards the bytes between the 0th index and {@code readerIndex}.
- * It moves the bytes between {@code readerIndex} and {@code writerIndex}
- * to the 0th index, and sets {@code readerIndex} and {@code writerIndex}
- * to {@code 0} and {@code oldWriterIndex - oldReaderIndex} respectively.
- * <p>
- * Please refer to the class documentation for more detailed explanation.
- */
- void discardReadBytes();
-
- /**
- * Gets a byte at the specified absolute {@code index} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 1} is greater than {@code this.capacity}
- */
- byte getByte(int index);
-
- /**
- * Gets an unsigned byte at the specified absolute {@code index} in this
- * buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 1} is greater than {@code this.capacity}
- */
- short getUnsignedByte(int index);
-
- /**
- * Gets a 16-bit short integer at the specified absolute {@code index} in
- * this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 2} is greater than {@code this.capacity}
- */
- short getShort(int index);
-
- /**
- * Gets an unsigned 16-bit short integer at the specified absolute
- * {@code index} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 2} is greater than {@code this.capacity}
- */
- int getUnsignedShort(int index);
-
- /**
- * Gets a 24-bit medium integer at the specified absolute {@code index} in
- * this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 3} is greater than {@code this.capacity}
- */
- int getMedium(int index);
-
- /**
- * Gets an unsigned 24-bit medium integer at the specified absolute
- * {@code index} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 3} is greater than {@code this.capacity}
- */
- int getUnsignedMedium(int index);
-
- /**
- * Gets a 32-bit integer at the specified absolute {@code index} in
- * this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 4} is greater than {@code this.capacity}
- */
- int getInt(int index);
-
- /**
- * Gets an unsigned 32-bit integer at the specified absolute {@code index}
- * in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 4} is greater than {@code this.capacity}
- */
- long getUnsignedInt(int index);
-
- /**
- * Gets a 64-bit long integer at the specified absolute {@code index} in
- * this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 8} is greater than {@code this.capacity}
- */
- long getLong(int index);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the specified absolute {@code index} until the destination becomes
- * non-writable. This method is basically same with
- * {@link #getBytes(int, ChannelBuffer, int, int)}, except that this
- * method increases the {@code writerIndex} of the destination by the
- * number of the transferred bytes while
- * {@link #getBytes(int, ChannelBuffer, int, int)} does not.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + dst.writableBytes} is greater than
- * {@code this.capacity}
- */
- void getBytes(int index, ChannelBuffer dst);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the specified absolute {@code index}. This method is basically same
- * with {@link #getBytes(int, ChannelBuffer, int, int)}, except that this
- * method increases the {@code writerIndex} of the destination by the
- * number of the transferred bytes while
- * {@link #getBytes(int, ChannelBuffer, int, int)} does not.
- *
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0},
- * if {@code index + length} is greater than
- * {@code this.capacity}, or
- * if {@code length} is greater than {@code dst.writableBytes}
- */
- void getBytes(int index, ChannelBuffer dst, int length);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the specified absolute {@code index}.
- *
- * @param dstIndex the first index of the destination
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0},
- * if the specified {@code dstIndex} is less than {@code 0},
- * if {@code index + length} is greater than
- * {@code this.capacity}, or
- * if {@code dstIndex + length} is greater than
- * {@code dst.capacity}
- */
- void getBytes(int index, ChannelBuffer dst, int dstIndex, int length);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the specified absolute {@code index}.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + dst.length} is greater than
- * {@code this.capacity}
- */
- void getBytes(int index, byte[] dst);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the specified absolute {@code index}.
- *
- * @param dstIndex the first index of the destination
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0},
- * if the specified {@code dstIndex} is less than {@code 0},
- * if {@code index + length} is greater than
- * {@code this.capacity}, or
- * if {@code dstIndex + length} is greater than
- * {@code dst.length}
- */
- void getBytes(int index, byte[] dst, int dstIndex, int length);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the specified absolute {@code index} until the destination's position
- * reaches its limit.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + dst.remaining()} is greater than
- * {@code this.capacity}
- */
- void getBytes(int index, ByteBuffer dst);
-
- /**
- * Transfers this buffer's data to the specified stream starting at the
- * specified absolute {@code index}.
- *
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + length} is greater than
- * {@code this.capacity}
- * @throws IOException
- * if the specified stream threw an exception during I/O
- */
- void getBytes(int index, OutputStream out, int length) throws IOException;
-
- /**
- * Transfers this buffer's data to the specified channel starting at the
- * specified absolute {@code index}.
- *
- * @param length the maximum number of bytes to transfer
- *
- * @return the actual number of bytes written out to the specified channel
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + length} is greater than
- * {@code this.capacity}
- * @throws IOException
- * if the specified channel threw an exception during I/O
- */
- int getBytes(int index, GatheringByteChannel out, int length) throws IOException;
-
- /**
- * Sets the specified byte at the specified absolute {@code index} in this
- * buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 1} is greater than {@code this.capacity}
- */
- void setByte(int index, byte value);
-
- /**
- * Sets the specified 16-bit short integer at the specified absolute
- * {@code index} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 2} is greater than {@code this.capacity}
- */
- void setShort(int index, short value);
-
- /**
- * Sets the specified 24-bit medium integer at the specified absolute
- * {@code index} in this buffer. Please note that the most significant
- * byte is ignored in the specified value.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 3} is greater than {@code this.capacity}
- */
- void setMedium(int index, int value);
-
- /**
- * Sets the specified 32-bit integer at the specified absolute
- * {@code index} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 4} is greater than {@code this.capacity}
- */
- void setInt(int index, int value);
-
- /**
- * Sets the specified 64-bit long integer at the specified absolute
- * {@code index} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * {@code index + 8} is greater than {@code this.capacity}
- */
- void setLong(int index, long value);
-
- /**
- * Transfers the specified source buffer's data to this buffer starting at
- * the specified absolute {@code index} until the destination becomes
- * unreadable. This method is basically same with
- * {@link #setBytes(int, ChannelBuffer, int, int)}, except that this
- * method increases the {@code readerIndex} of the source buffer by
- * the number of the transferred bytes while
- * {@link #getBytes(int, ChannelBuffer, int, int)} does not.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + src.readableBytes} is greater than
- * {@code this.capacity}
- */
- void setBytes(int index, ChannelBuffer src);
-
- /**
- * Transfers the specified source buffer's data to this buffer starting at
- * the specified absolute {@code index}. This method is basically same
- * with {@link #setBytes(int, ChannelBuffer, int, int)}, except that this
- * method increases the {@code readerIndex} of the source buffer by
- * the number of the transferred bytes while
- * {@link #getBytes(int, ChannelBuffer, int, int)} does not.
- *
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0},
- * if {@code index + length} is greater than
- * {@code this.capacity}, or
- * if {@code length} is greater than {@code src.readableBytes}
- */
- void setBytes(int index, ChannelBuffer src, int length);
-
- /**
- * Transfers the specified source buffer's data to this buffer starting at
- * the specified absolute {@code index}.
- *
- * @param srcIndex the first index of the source
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0},
- * if the specified {@code srcIndex} is less than {@code 0},
- * if {@code index + length} is greater than
- * {@code this.capacity}, or
- * if {@code srcIndex + length} is greater than
- * {@code src.capacity}
- */
- void setBytes(int index, ChannelBuffer src, int srcIndex, int length);
-
- /**
- * Transfers the specified source array's data to this buffer starting at
- * the specified absolute {@code index}.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + src.length} is greater than
- * {@code this.capacity}
- */
- void setBytes(int index, byte[] src);
-
- /**
- * Transfers the specified source array's data to this buffer starting at
- * the specified absolute {@code index}.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0},
- * if the specified {@code srcIndex} is less than {@code 0},
- * if {@code index + length} is greater than
- * {@code this.capacity}, or
- * if {@code srcIndex + length} is greater than {@code src.length}
- */
- void setBytes(int index, byte[] src, int srcIndex, int length);
-
- /**
- * Transfers the specified source buffer's data to this buffer starting at
- * the specified absolute {@code index} until the source buffer's position
- * reaches its limit.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + src.remaining()} is greater than
- * {@code this.capacity}
- */
- void setBytes(int index, ByteBuffer src);
-
- /**
- * Transfers the content of the specified source stream to this buffer
- * starting at the specified absolute {@code index}.
- *
- * @param length the number of bytes to transfer
- *
- * @return the actual number of bytes read in from the specified channel.
- * {@code -1} if the specified channel is closed.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + length} is greater than {@code this.capacity}
- * @throws IOException
- * if the specified stream threw an exception during I/O
- */
- int setBytes(int index, InputStream in, int length) throws IOException;
-
- /**
- * Transfers the content of the specified source channel to this buffer
- * starting at the specified absolute {@code index}.
- *
- * @param length the maximum number of bytes to transfer
- *
- * @return the actual number of bytes read in from the specified channel.
- * {@code -1} if the specified channel is closed.
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + length} is greater than {@code this.capacity}
- * @throws IOException
- * if the specified channel threw an exception during I/O
- */
- int setBytes(int index, ScatteringByteChannel in, int length) throws IOException;
-
- /**
- * Fills this buffer with <tt>NUL (0x00)</tt> starting at the specified
- * absolute {@code index}.
- *
- * @param length the number of <tt>NUL</tt>s to write to the buffer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code index} is less than {@code 0} or
- * if {@code index + length} is greater than {@code this.capacity}
- */
- void setZero(int index, int length);
-
- /**
- * Gets a byte at the current {@code readerIndex} and increases
- * the {@code readerIndex} by {@code 1} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.readableBytes} is less than {@code 1}
- */
- byte readByte();
-
- /**
- * Gets an unsigned byte at the current {@code readerIndex} and increases
- * the {@code readerIndex} by {@code 1} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.readableBytes} is less than {@code 1}
- */
- short readUnsignedByte();
-
- /**
- * Gets a 16-bit short integer at the current {@code readerIndex}
- * and increases the {@code readerIndex} by {@code 2} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.readableBytes} is less than {@code 2}
- */
- short readShort();
-
- /**
- * Gets an unsigned 16-bit short integer at the current {@code readerIndex}
- * and increases the {@code readerIndex} by {@code 2} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.readableBytes} is less than {@code 2}
- */
- int readUnsignedShort();
-
- /**
- * Gets a 24-bit medium integer at the current {@code readerIndex}
- * and increases the {@code readerIndex} by {@code 3} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.readableBytes} is less than {@code 3}
- */
- int readMedium();
-
- /**
- * Gets an unsigned 24-bit medium integer at the current {@code readerIndex}
- * and increases the {@code readerIndex} by {@code 3} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.readableBytes} is less than {@code 3}
- */
- int readUnsignedMedium();
-
- /**
- * Gets a 32-bit integer at the current {@code readerIndex}
- * and increases the {@code readerIndex} by {@code 4} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.readableBytes} is less than {@code 4}
- */
- int readInt();
-
- /**
- * Gets an unsigned 32-bit integer at the current {@code readerIndex}
- * and increases the {@code readerIndex} by {@code 4} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.readableBytes} is less than {@code 4}
- */
- long readUnsignedInt();
-
- /**
- * Gets a 64-bit integer at the current {@code readerIndex}
- * and increases the {@code readerIndex} by {@code 8} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.readableBytes} is less than {@code 8}
- */
- long readLong();
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the current {@code readerIndex} until the destination becomes
- * non-writable, and increases the {@code readerIndex} by the number of the
- * transferred bytes. This method is basically same with
- * {@link #readBytes(ChannelBuffer, int, int)}, except that this method
- * increases the {@code writerIndex} of the destination by the number of
- * the transferred bytes while {@link #readBytes(ChannelBuffer, int, int)}
- * does not.
- *
- * @throws IndexOutOfBoundsException
- * if {@code dst.writableBytes} is greater than
- * {@code this.readableBytes}
- */
- void readBytes(ChannelBuffer dst);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the current {@code readerIndex} and increases the {@code readerIndex}
- * by the number of the transferred bytes (= {@code length}). This method
- * is basically same with {@link #readBytes(ChannelBuffer, int, int)},
- * except that this method increases the {@code writerIndex} of the
- * destination by the number of the transferred bytes (= {@code length})
- * while {@link #readBytes(ChannelBuffer, int, int)} does not.
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.readableBytes} or
- * if {@code length} is greater than {@code dst.writableBytes}
- */
- void readBytes(ChannelBuffer dst, int length);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the current {@code readerIndex} and increases the {@code readerIndex}
- * by the number of the transferred bytes (= {@code length}).
- *
- * @param dstIndex the first index of the destination
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code dstIndex} is less than {@code 0},
- * if {@code length} is greater than {@code this.readableBytes}, or
- * if {@code dstIndex + length} is greater than
- * {@code dst.capacity}
- */
- void readBytes(ChannelBuffer dst, int dstIndex, int length);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the current {@code readerIndex} and increases the {@code readerIndex}
- * by the number of the transferred bytes (= {@code dst.length}).
- *
- * @throws IndexOutOfBoundsException
- * if {@code dst.length} is greater than {@code this.readableBytes}
- */
- void readBytes(byte[] dst);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the current {@code readerIndex} and increases the {@code readerIndex}
- * by the number of the transferred bytes (= {@code length}).
- *
- * @param dstIndex the first index of the destination
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code dstIndex} is less than {@code 0},
- * if {@code length} is greater than {@code this.readableBytes}, or
- * if {@code dstIndex + length} is greater than {@code dst.length}
- */
- void readBytes(byte[] dst, int dstIndex, int length);
-
- /**
- * Transfers this buffer's data to the specified destination starting at
- * the current {@code readerIndex} until the destination's position
- * reaches its limit, and increases the {@code readerIndex} by the
- * number of the transferred bytes.
- *
- * @throws IndexOutOfBoundsException
- * if {@code dst.remaining()} is greater than
- * {@code this.readableBytes}
- */
- void readBytes(ByteBuffer dst);
-
- /**
- * Transfers this buffer's data to the specified stream starting at the
- * current {@code readerIndex}.
- *
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.readableBytes}
- * @throws IOException
- * if the specified stream threw an exception during I/O
- */
- void readBytes(OutputStream out, int length) throws IOException;
-
- /**
- * Transfers this buffer's data to the specified stream starting at the
- * current {@code readerIndex}.
- *
- * @param length the maximum number of bytes to transfer
- *
- * @return the actual number of bytes written out to the specified channel
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.readableBytes}
- * @throws IOException
- * if the specified channel threw an exception during I/O
- */
- int readBytes(GatheringByteChannel out, int length) throws IOException;
-
- /**
- * Increases the current {@code readerIndex} by the specified
- * {@code length} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.readableBytes}
- */
- void skipBytes(int length);
-
- /**
- * Sets the specified byte at the current {@code writerIndex}
- * and increases the {@code writerIndex} by {@code 1} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.writableBytes} is less than {@code 1}
- */
- void writeByte(byte value);
-
- /**
- * Sets the specified 16-bit short integer at the current
- * {@code writerIndex} and increases the {@code writerIndex} by {@code 2}
- * in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.writableBytes} is less than {@code 2}
- */
- void writeShort(short value);
-
- /**
- * Sets the specified 24-bit medium integer at the current
- * {@code writerIndex} and increases the {@code writerIndex} by {@code 3}
- * in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.writableBytes} is less than {@code 3}
- */
- void writeMedium(int value);
-
- /**
- * Sets the specified 32-bit integer at the current {@code writerIndex}
- * and increases the {@code writerIndex} by {@code 4} in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.writableBytes} is less than {@code 4}
- */
- void writeInt(int value);
-
- /**
- * Sets the specified 64-bit long integer at the current
- * {@code writerIndex} and increases the {@code writerIndex} by {@code 8}
- * in this buffer.
- *
- * @throws IndexOutOfBoundsException
- * if {@code this.writableBytes} is less than {@code 8}
- */
- void writeLong(long value);
-
- /**
- * Transfers the specified source buffer's data to this buffer starting at
- * the current {@code writerIndex} until the source buffer becomes
- * unreadable, and increases the {@code writerIndex} by the number of
- * the transferred bytes. This method is basically same with
- * {@link #writeBytes(ChannelBuffer, int, int)}, except that this method
- * increases the {@code readerIndex} of the source buffer by the number of
- * the transferred bytes while {@link #writeBytes(ChannelBuffer, int, int)}
- * does not.
- *
- * @throws IndexOutOfBoundsException
- * if {@code src.readableBytes} is greater than
- * {@code this.writableBytes}
- *
- */
- void writeBytes(ChannelBuffer src);
-
- /**
- * Transfers the specified source buffer's data to this buffer starting at
- * the current {@code writerIndex} and increases the {@code writerIndex}
- * by the number of the transferred bytes (= {@code length}). This method
- * is basically same with {@link #writeBytes(ChannelBuffer, int, int)},
- * except that this method increases the {@code readerIndex} of the source
- * buffer by the number of the transferred bytes (= {@code length}) while
- * {@link #writeBytes(ChannelBuffer, int, int)} does not.
- *
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.writableBytes} or
- * if {@code length} is greater then {@code src.readableBytes}
- */
- void writeBytes(ChannelBuffer src, int length);
-
- /**
- * Transfers the specified source buffer's data to this buffer starting at
- * the current {@code writerIndex} and increases the {@code writerIndex}
- * by the number of the transferred bytes (= {@code length}).
- *
- * @param srcIndex the first index of the source
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code srcIndex} is less than {@code 0},
- * if {@code srcIndex + length} is greater than
- * {@code src.capacity}, or
- * if {@code length} is greater than {@code this.writableBytes}
- */
- void writeBytes(ChannelBuffer src, int srcIndex, int length);
-
- /**
- * Transfers the specified source array's data to this buffer starting at
- * the current {@code writerIndex} and increases the {@code writerIndex}
- * by the number of the transferred bytes (= {@code src.length}).
- *
- * @throws IndexOutOfBoundsException
- * if {@code src.length} is greater than {@code this.writableBytes}
- */
- void writeBytes(byte[] src);
-
- /**
- * Transfers the specified source array's data to this buffer starting at
- * the current {@code writerIndex} and increases the {@code writerIndex}
- * by the number of the transferred bytes (= {@code length}).
- *
- * @param srcIndex the first index of the source
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if the specified {@code srcIndex} is less than {@code 0},
- * if {@code srcIndex + length} is greater than
- * {@code src.length}, or
- * if {@code length} is greater than {@code this.writableBytes}
- */
- void writeBytes(byte[] src, int srcIndex, int length);
-
- /**
- * Transfers the specified source buffer's data to this buffer starting at
- * the current {@code writerIndex} until the source buffer's position
- * reaches its limit, and increases the {@code writerIndex} by the
- * number of the transferred bytes.
- *
- * @throws IndexOutOfBoundsException
- * if {@code src.remaining()} is greater than
- * {@code this.writableBytes}
- */
- void writeBytes(ByteBuffer src);
-
- /**
- * Transfers the content of the specified stream to this buffer
- * starting at the current {@code writerIndex} and increases the
- * {@code writerIndex} by the number of the transferred bytes.
- *
- * @param length the number of bytes to transfer
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.writableBytes}
- * @throws IOException
- * if the specified stream threw an exception during I/O
- */
- void writeBytes(InputStream in, int length) throws IOException;
-
- /**
- * Transfers the content of the specified channel to this buffer
- * starting at the current {@code writerIndex} and increases the
- * {@code writerIndex} by the number of the transferred bytes.
- *
- * @param length the maximum number of bytes to transfer
- *
- * @return the actual number of bytes read in from the specified channel
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.writableBytes}
- * @throws IOException
- * if the specified channel threw an exception during I/O
- */
- int writeBytes(ScatteringByteChannel in, int length) throws IOException;
-
- /**
- * Fills this buffer with <tt>NUL (0x00)</tt> starting at the current
- * {@code writerIndex} and increases the {@code writerIndex} by the
- * specified {@code length}.
- *
- * @param length the number of <tt>NUL</tt>s to write to the buffer
- *
- * @throws IndexOutOfBoundsException
- * if {@code length} is greater than {@code this.writableBytes}
- */
- void writeZero(int length);
-
- /**
- * Converts this buffer's readable bytes into a NIO buffer. The returned
- * buffer might or might not share the content with this buffer, while
- * they have separate indexes and marks. This method is identical to
- * {@code buf.toByteBuffer(buf.readerIndex(), buf.readableBytes())}.
- */
- ByteBuffer toByteBuffer();
-
- /**
- * Converts this buffer's sub-region into a NIO buffer. The returned
- * buffer might or might not share the content with this buffer, while
- * they have separate indexes and marks.
- */
- ByteBuffer toByteBuffer(int index, int length);
-
- /**
- * Converts this buffer's sub-region into an array of NIO buffers.
- * The returned buffers might or might not share the content with this
- * buffer, while they have separate indexes and marks.
- */
- ByteBuffer[] toByteBuffers(int index, int length);
-
- /**
- * Decodes this buffer's readable bytes into a string with the specified
- * character set name. This method is identical to
- * {@code buf.toString(buf.readerIndex(), buf.readableBytes(), charsetName)}.
- *
- * @throws UnsupportedCharsetException
- * if the specified character set name is not supported by the
- * current VM
- */
- String toString(String charsetName);
-
- /**
- * Decodes this buffer's sub-region into a string with the specified
- * character set name.
- *
- * @throws UnsupportedCharsetException
- * if the specified character set name is not supported by the
- * current VM
- */
- String toString(int index, int length, String charsetName);
-
- /**
- * Returns a hash code which was calculated from the content of this
- * buffer. If there's a byte array which is
- * {@linkplain #equals(Object) equal to} this array, both arrays should
- * return the same value.
- */
- int hashCode();
-
- /**
- * Determines if the content of the specified buffer is identical to the
- * content of this array. 'Identical' here means:
- * <ul>
- * <li>the size of the contents of the two buffers are same and</li>
- * <li>every single byte of the content of the two buffers are same.</li>
- * </ul>
- * Please note that it does not compare {@link #readerIndex()} nor
- * {@link #writerIndex()}. This method also returns {@code false} for
- * {@code null} and an object which is not an instance of
- * {@link ChannelBuffer} type.
- */
- boolean equals(Object obj);
-
- /**
- * Compares the content of the specified buffer to the content of this
- * buffer. Comparison is performed in the same manner with the string
- * comparison functions of various languages such as {@code strcmp},
- * {@code memcmp} and {@link String#compareTo(String)}.
- */
- int compareTo(ChannelBuffer buffer);
-
- /**
- * Returns the string representation of this buffer. This method does not
- * necessarily return the whole content of the buffer but returns
- * the values of the key properties such as {@link #readerIndex()},
- * {@link #writerIndex()} and {@link #capacity()}.
- */
- String toString();
-}
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/ChannelBuffers.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/ChannelBuffers.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/ChannelBuffers.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -1,469 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat licenses this file to you under the Apache License, version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package org.hornetq.core.buffers;
-
-import java.nio.ByteBuffer;
-
-/**
- * Creates a new {@link ChannelBuffer} by allocating new space or by wrapping
- * or copying existing byte arrays, byte buffers and a string.
- *
- * <h3>Use static import</h3>
- * This classes is intended to be used with Java 5 static import statement:
- *
- * <pre>
- * import static org.jboss.netty.buffer.ChannelBuffers.*;
- *
- * ChannelBuffer heapBuffer = buffer(128);
- * ChannelBuffer directBuffer = directBuffer(256);
- * ChannelBuffer dynamicBuffer = dynamicBuffer(512);
- * ChannelBuffer wrappedBuffer = wrappedBuffer(new byte[128], new byte[256]);
- * ChannelBuffer copiedBuffer = copiedBuffer(ByteBuffer.allocate(128));
- * </pre>
- *
- * <h3>Allocating a new buffer</h3>
- *
- * Three buffer types are provided out of the box.
- *
- * <ul>
- * <li>{@link #buffer(int)} allocates a new fixed-capacity heap buffer.</li>
- * <li>{@link #directBuffer(int)} allocates a new fixed-capacity direct buffer.</li>
- * <li>{@link #dynamicBuffer(int)} allocates a new dynamic-capacity heap
- * buffer, whose capacity increases automatically as needed by a write
- * operation.</li>
- * </ul>
- *
- * <h3>Creating a wrapped buffer</h3>
- *
- * Wrapped buffer is a buffer which is a view of one or more existing
- * byte arrays and byte buffers. Any changes in the content of the original
- * array or buffer will be reflected in the wrapped buffer. Various wrapper
- * methods are provided and their name is all {@code wrappedBuffer()}.
- * You might want to take a look at this method closely if you want to create
- * a buffer which is composed of more than one array to reduce the number of
- * memory copy.
- *
- * <h3>Creating a copied buffer</h3>
- *
- * Copied buffer is a deep copy of one or more existing byte arrays, byte
- * buffers or a string. Unlike a wrapped buffer, there's no shared data
- * between the original data and the copied buffer. Various copy methods are
- * provided and their name is all {@code copiedBuffer()}. It is also convenient
- * to use this operation to merge multiple buffers into one buffer.
- *
- * <h3>Miscellaneous utility methods</h3>
- *
- * This class also provides various utility methods to help implementation
- * of a new buffer type, generation of hex dump and swapping an integer's
- * byte order.
- *
- * @author The Netty Project (netty-dev(a)lists.jboss.org)
- * @author Trustin Lee (tlee(a)redhat.com)
- *
- * @version $Rev: 472 $, $Date: 2008-11-14 16:45:53 +0900 (Fri, 14 Nov 2008) $
- *
- * @apiviz.landmark
- */
-public class ChannelBuffers
-{
-
- /**
- * A buffer whose capacity is {@code 0}.
- */
- public static final HeapChannelBuffer EMPTY_BUFFER = new HeapChannelBuffer(0);
-
- private static final char[] HEXDUMP_TABLE = new char[65536 * 4];
-
- static
- {
- final char[] DIGITS = "0123456789abcdef".toCharArray();
- for (int i = 0; i < 65536; i++)
- {
- HEXDUMP_TABLE[(i << 2) + 0] = DIGITS[i >>> 12 & 0x0F];
- HEXDUMP_TABLE[(i << 2) + 1] = DIGITS[i >>> 8 & 0x0F];
- HEXDUMP_TABLE[(i << 2) + 2] = DIGITS[i >>> 4 & 0x0F];
- HEXDUMP_TABLE[(i << 2) + 3] = DIGITS[i >>> 0 & 0x0F];
- }
- }
-
- /**
- * Creates a new Java heap buffer with the specified {@code endianness}
- * and {@code capacity}. The new buffer's {@code readerIndex} and
- * {@code writerIndex} are {@code 0}.
- */
- public static ChannelBuffer buffer(final int capacity)
- {
- if (capacity == 0)
- {
- return EMPTY_BUFFER;
- }
- else
- {
- return new HeapChannelBuffer(capacity);
- }
- }
-
- /**
- * Reuses the initialBuffer on the creation of the DynamicBuffer.
- * This avoids a copy, but you should only call this method if the buffer is not being modified after the call of this method.
- *
- * @author Clebert
- */
- public static ChannelBuffer dynamicBuffer(final byte[] initialBuffer)
- {
- return new DynamicChannelBuffer(initialBuffer);
- }
-
- /**
- * Creates a new dynamic buffer with the specified endianness and
- * the specified estimated data length. More accurate estimation yields
- * less unexpected reallocation overhead. The new buffer's
- * {@code readerIndex} and {@code writerIndex} are {@code 0}.
- */
- public static ChannelBuffer dynamicBuffer(final int estimatedLength)
- {
- return new DynamicChannelBuffer(estimatedLength);
- }
-
- /**
- * Creates a new buffer which wraps the specified {@code array} with the
- * specified {@code endianness}. A modification on the specified array's
- * content will be visible to the returned buffer.
- */
- public static ChannelBuffer wrappedBuffer(final byte[] array)
- {
- return new HeapChannelBuffer(array);
- }
-
- /**
- * Creates a new buffer which wraps the specified NIO buffer's current
- * slice. A modification on the specified buffer's content and endianness
- * will be visible to the returned buffer.
- * The new buffer's {@code readerIndex}
- * and {@code writerIndex} are {@code 0} and {@code buffer.remaining}
- * respectively.
- *
- * Note: This method differs from the Original Netty version.
- *
- * @author Clebert
- */
- public static ChannelBuffer wrappedBuffer(final ByteBuffer buffer)
- {
-
- ChannelBuffer newbuffer = new ByteBufferBackedChannelBuffer(buffer);
- newbuffer.clear();
- return newbuffer;
- }
-
- /**
- * Creates a new buffer with the specified {@code endianness} whose
- * content is a copy of the specified {@code array}. The new buffer's
- * {@code readerIndex} and {@code writerIndex} are {@code 0} and
- * {@code array.length} respectively.
- */
- public static ChannelBuffer copiedBuffer(final byte[] array)
- {
- if (array.length == 0)
- {
- return EMPTY_BUFFER;
- }
- else
- {
- return new HeapChannelBuffer(array.clone());
- }
- }
-
- /**
- * Creates a new buffer whose content is a copy of the specified
- * {@code buffer}'s current slice. The new buffer's {@code readerIndex}
- * and {@code writerIndex} are {@code 0} and {@code buffer.remaining}
- * respectively.
- */
- public static ChannelBuffer copiedBuffer(final ByteBuffer buffer)
- {
- int length = buffer.remaining();
- if (length == 0)
- {
- return EMPTY_BUFFER;
- }
- byte[] copy = new byte[length];
- int position = buffer.position();
- try
- {
- buffer.get(copy);
- }
- finally
- {
- buffer.position(position);
- }
- return wrappedBuffer(copy);
- }
-
- /**
- * Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a>
- * of the specified buffer's readable bytes.
- */
- public static String hexDump(final ChannelBuffer buffer)
- {
- return hexDump(buffer, buffer.readerIndex(), buffer.readableBytes());
- }
-
- /**
- * Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a>
- * of the specified buffer's sub-region.
- */
- public static String hexDump(final ChannelBuffer buffer, final int fromIndex, final int length)
- {
- if (length < 0)
- {
- throw new IllegalArgumentException("length: " + length);
- }
- if (length == 0)
- {
- return "";
- }
-
- int endIndex = fromIndex + (length >>> 1 << 1);
- boolean oddLength = length % 2 != 0;
- char[] buf = new char[length << 1];
-
- int srcIdx = fromIndex;
- int dstIdx = 0;
- for (; srcIdx < endIndex; srcIdx += 2, dstIdx += 4)
- {
- System.arraycopy(HEXDUMP_TABLE, buffer.getUnsignedShort(srcIdx) << 2, buf, dstIdx, 4);
- }
-
- if (oddLength)
- {
- System.arraycopy(HEXDUMP_TABLE, (buffer.getUnsignedByte(srcIdx) << 2) + 2, buf, dstIdx, 2);
- }
-
- return new String(buf);
- }
-
- /**
- * Calculates the hash code of the specified buffer. This method is
- * useful when implementing a new buffer type.
- */
- public static int hashCode(final ChannelBuffer buffer)
- {
- final int aLen = buffer.readableBytes();
- final int intCount = aLen >>> 2;
- final int byteCount = aLen & 3;
-
- int hashCode = 1;
- int arrayIndex = buffer.readerIndex();
- for (int i = intCount; i > 0; i--)
- {
- hashCode = 31 * hashCode + buffer.getInt(arrayIndex);
- arrayIndex += 4;
- }
-
- for (int i = byteCount; i > 0; i--)
- {
- hashCode = 31 * hashCode + buffer.getByte(arrayIndex++);
- }
-
- if (hashCode == 0)
- {
- hashCode = 1;
- }
-
- return hashCode;
- }
-
- /**
- * Returns {@code true} if and only if the two specified buffers are
- * identical to each other as described in {@code ChannelBuffer#equals(Object)}.
- * This method is useful when implementing a new buffer type.
- */
- public static boolean equals(final ChannelBuffer bufferA, final ChannelBuffer bufferB)
- {
- final int aLen = bufferA.readableBytes();
- if (aLen != bufferB.readableBytes())
- {
- return false;
- }
-
- final int longCount = aLen >>> 3;
- final int byteCount = aLen & 7;
-
- int aIndex = bufferA.readerIndex();
- int bIndex = bufferB.readerIndex();
-
- for (int i = longCount; i > 0; i--)
- {
- if (bufferA.getLong(aIndex) != bufferB.getLong(bIndex))
- {
- return false;
- }
- aIndex += 8;
- bIndex += 8;
- }
-
- for (int i = byteCount; i > 0; i--)
- {
- if (bufferA.getByte(aIndex) != bufferB.getByte(bIndex))
- {
- return false;
- }
- aIndex++;
- bIndex++;
- }
-
- return true;
- }
-
- /**
- * Compares the two specified buffers as described in {@link ChannelBuffer#compareTo(ChannelBuffer)}.
- * This method is useful when implementing a new buffer type.
- */
- public static int compare(final ChannelBuffer bufferA, final ChannelBuffer bufferB)
- {
- final int aLen = bufferA.readableBytes();
- final int bLen = bufferB.readableBytes();
- final int minLength = Math.min(aLen, bLen);
- final int uintCount = minLength >>> 2;
- final int byteCount = minLength & 3;
-
- int aIndex = bufferA.readerIndex();
- int bIndex = bufferB.readerIndex();
-
- for (int i = uintCount; i > 0; i--)
- {
- long va = bufferA.getUnsignedInt(aIndex);
- long vb = bufferB.getUnsignedInt(bIndex);
- if (va > vb)
- {
- return 1;
- }
- else if (va < vb)
- {
- return -1;
- }
- aIndex += 4;
- bIndex += 4;
- }
-
- for (int i = byteCount; i > 0; i--)
- {
- byte va = bufferA.getByte(aIndex);
- byte vb = bufferB.getByte(bIndex);
- if (va > vb)
- {
- return 1;
- }
- else if (va < vb)
- {
- return -1;
- }
- aIndex++;
- bIndex++;
- }
-
- return aLen - bLen;
- }
-
- /**
- * The default implementation of {@link ChannelBuffer#indexOf(int, int, byte)}.
- * This method is useful when implementing a new buffer type.
- */
- public static int indexOf(final ChannelBuffer buffer, final int fromIndex, final int toIndex, final byte value)
- {
- if (fromIndex <= toIndex)
- {
- return firstIndexOf(buffer, fromIndex, toIndex, value);
- }
- else
- {
- return lastIndexOf(buffer, fromIndex, toIndex, value);
- }
- }
-
- /**
- * Toggles the endianness of the specified 16-bit short integer.
- */
- public static short swapShort(final short value)
- {
- return (short)(value << 8 | value >>> 8 & 0xff);
- }
-
- /**
- * Toggles the endianness of the specified 24-bit medium integer.
- */
- public static int swapMedium(final int value)
- {
- return value << 16 & 0xff0000 | value & 0xff00 | value >>> 16 & 0xff;
- }
-
- /**
- * Toggles the endianness of the specified 32-bit integer.
- */
- public static int swapInt(final int value)
- {
- return swapShort((short)value) << 16 | swapShort((short)(value >>> 16)) & 0xffff;
- }
-
- /**
- * Toggles the endianness of the specified 64-bit long integer.
- */
- public static long swapLong(final long value)
- {
- return (long)swapInt((int)value) << 32 | swapInt((int)(value >>> 32)) & 0xffffffffL;
- }
-
- private static int firstIndexOf(final ChannelBuffer buffer, int fromIndex, final int toIndex, final byte value)
- {
- fromIndex = Math.max(fromIndex, 0);
- if (fromIndex >= toIndex || buffer.capacity() == 0)
- {
- return -1;
- }
-
- for (int i = fromIndex; i < toIndex; i++)
- {
- if (buffer.getByte(i) == value)
- {
- return i;
- }
- }
-
- return -1;
- }
-
- private static int lastIndexOf(final ChannelBuffer buffer, int fromIndex, final int toIndex, final byte value)
- {
- fromIndex = Math.min(fromIndex, buffer.capacity());
- if (fromIndex < 0 || buffer.capacity() == 0)
- {
- return -1;
- }
-
- for (int i = fromIndex - 1; i >= toIndex; i--)
- {
- if (buffer.getByte(i) == value)
- {
- return i;
- }
- }
-
- return -1;
- }
-
- private ChannelBuffers()
- {
- // Unused
- }
-}
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/DynamicChannelBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/DynamicChannelBuffer.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/DynamicChannelBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -1,275 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat licenses this file to you under the Apache License, version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package org.hornetq.core.buffers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.nio.channels.GatheringByteChannel;
-import java.nio.channels.ScatteringByteChannel;
-
-/**
- * A dynamic capacity buffer which increases its capacity as needed. It is
- * recommended to use {@link ChannelBuffers#dynamicBuffer(int)} instead of
- * calling the constructor explicitly.
- *
- * @author The Netty Project (netty-dev(a)lists.jboss.org)
- * @author Trustin Lee (tlee(a)redhat.com)
- *
- * @version $Rev: 237 $, $Date: 2008-09-04 20:53:44 +0900 (Thu, 04 Sep 2008) $
- *
- */
-public class DynamicChannelBuffer extends AbstractChannelBuffer
-{
-
- private final int initialCapacity;
-
- private ChannelBuffer buffer = ChannelBuffers.EMPTY_BUFFER;
-
- DynamicChannelBuffer(final int estimatedLength)
- {
- if (estimatedLength < 0)
- {
- throw new IllegalArgumentException("estimatedLength: " + estimatedLength);
- }
- initialCapacity = estimatedLength;
- }
-
- DynamicChannelBuffer(final byte[] initialBuffer)
- {
- initialCapacity = initialBuffer.length;
-
- buffer = new HeapChannelBuffer(initialBuffer);
-
- writerIndex(initialBuffer.length);
- }
-
- public int capacity()
- {
- return buffer.capacity();
- }
-
- public byte getByte(final int index)
- {
- return buffer.getByte(index);
- }
-
- public short getShort(final int index)
- {
- return buffer.getShort(index);
- }
-
- public int getUnsignedMedium(final int index)
- {
- return buffer.getUnsignedMedium(index);
- }
-
- public int getInt(final int index)
- {
- return buffer.getInt(index);
- }
-
- public long getLong(final int index)
- {
- return buffer.getLong(index);
- }
-
- public void getBytes(final int index, final byte[] dst, final int dstIndex, final int length)
- {
- buffer.getBytes(index, dst, dstIndex, length);
- }
-
- public void getBytes(final int index, final ChannelBuffer dst, final int dstIndex, final int length)
- {
- buffer.getBytes(index, dst, dstIndex, length);
- }
-
- public void getBytes(final int index, final ByteBuffer dst)
- {
- buffer.getBytes(index, dst);
- }
-
- public int getBytes(final int index, final GatheringByteChannel out, final int length) throws IOException
- {
- return buffer.getBytes(index, out, length);
- }
-
- public void getBytes(final int index, final OutputStream out, final int length) throws IOException
- {
- buffer.getBytes(index, out, length);
- }
-
- public void setByte(final int index, final byte value)
- {
- buffer.setByte(index, value);
- }
-
- public void setShort(final int index, final short value)
- {
- buffer.setShort(index, value);
- }
-
- public void setMedium(final int index, final int value)
- {
- buffer.setMedium(index, value);
- }
-
- public void setInt(final int index, final int value)
- {
- buffer.setInt(index, value);
- }
-
- public void setLong(final int index, final long value)
- {
- buffer.setLong(index, value);
- }
-
- public void setBytes(final int index, final byte[] src, final int srcIndex, final int length)
- {
- buffer.setBytes(index, src, srcIndex, length);
- }
-
- public void setBytes(final int index, final ChannelBuffer src, final int srcIndex, final int length)
- {
- buffer.setBytes(index, src, srcIndex, length);
- }
-
- public void setBytes(final int index, final ByteBuffer src)
- {
- buffer.setBytes(index, src);
- }
-
- public int setBytes(final int index, final InputStream in, final int length) throws IOException
- {
- return buffer.setBytes(index, in, length);
- }
-
- public int setBytes(final int index, final ScatteringByteChannel in, final int length) throws IOException
- {
- return buffer.setBytes(index, in, length);
- }
-
- @Override
- public void writeByte(final byte value)
- {
- ensureWritableBytes(1);
- super.writeByte(value);
- }
-
- @Override
- public void writeShort(final short value)
- {
- ensureWritableBytes(2);
- super.writeShort(value);
- }
-
- @Override
- public void writeMedium(final int value)
- {
- ensureWritableBytes(3);
- super.writeMedium(value);
- }
-
- @Override
- public void writeInt(final int value)
- {
- ensureWritableBytes(4);
- super.writeInt(value);
- }
-
- @Override
- public void writeLong(final long value)
- {
- ensureWritableBytes(8);
- super.writeLong(value);
- }
-
- @Override
- public void writeBytes(final byte[] src, final int srcIndex, final int length)
- {
- ensureWritableBytes(length);
- super.writeBytes(src, srcIndex, length);
- }
-
- @Override
- public void writeBytes(final ChannelBuffer src, final int srcIndex, final int length)
- {
- ensureWritableBytes(length);
- super.writeBytes(src, srcIndex, length);
- }
-
- @Override
- public void writeBytes(final ByteBuffer src)
- {
- ensureWritableBytes(src.remaining());
- super.writeBytes(src);
- }
-
- @Override
- public void writeZero(final int length)
- {
- ensureWritableBytes(length);
- super.writeZero(length);
- }
-
- public ByteBuffer toByteBuffer(final int index, final int length)
- {
- return buffer.toByteBuffer(index, length);
- }
-
- public String toString(final int index, final int length, final String charsetName)
- {
- return buffer.toString(index, length, charsetName);
- }
-
- private void ensureWritableBytes(final int requestedBytes)
- {
- if (requestedBytes <= writableBytes())
- {
- return;
- }
-
- int newCapacity;
- if (capacity() == 0)
- {
- newCapacity = initialCapacity;
- if (newCapacity == 0)
- {
- newCapacity = 1;
- }
- }
- else
- {
- newCapacity = capacity();
- }
- int minNewCapacity = writerIndex() + requestedBytes;
- while (newCapacity < minNewCapacity)
- {
- newCapacity <<= 1;
- }
-
- ChannelBuffer newBuffer = ChannelBuffers.buffer(newCapacity);
- newBuffer.writeBytes(buffer, 0, writerIndex());
- buffer = newBuffer;
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.buffers.AbstractChannelBuffer#array()
- */
- public byte[] array()
- {
- return buffer.array();
- }
-}
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/HeapChannelBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HeapChannelBuffer.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HeapChannelBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -1,315 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat licenses this file to you under the Apache License, version
- * 2.0 (the "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package org.hornetq.core.buffers;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.GatheringByteChannel;
-import java.nio.channels.ScatteringByteChannel;
-import java.nio.charset.UnsupportedCharsetException;
-
-/**
- * A skeletal implementation for Java heap buffers.
- *
- * @author The Netty Project (netty-dev(a)lists.jboss.org)
- * @author Trustin Lee (tlee(a)redhat.com)
- *
- * @version $Rev: 486 $, $Date: 2008-11-16 22:52:47 +0900 (Sun, 16 Nov 2008) $
- */
-public class HeapChannelBuffer extends AbstractChannelBuffer
-{
-
- /**
- * The underlying heap byte array that this buffer is wrapping.
- */
- protected final byte[] array;
-
- /**
- * Creates a new heap buffer with a newly allocated byte array.
- *
- * @param length the length of the new byte array
- */
- HeapChannelBuffer(final int length)
- {
- this(new byte[length], 0, 0);
- }
-
- /**
- * Creates a new heap buffer with an existing byte array.
- *
- * @param array the byte array to wrap
- */
- HeapChannelBuffer(final byte[] array)
- {
- this(array, 0, array.length);
- }
-
- /**
- * Creates a new heap buffer with an existing byte array.
- *
- * @param array the byte array to wrap
- * @param readerIndex the initial reader index of this buffer
- * @param writerIndex the initial writer index of this buffer
- */
- protected HeapChannelBuffer(final byte[] array, final int readerIndex, final int writerIndex)
- {
- if (array == null)
- {
- throw new NullPointerException("array");
- }
- this.array = array;
- setIndex(readerIndex, writerIndex);
- }
-
- public int capacity()
- {
- return array.length;
- }
-
- public byte getByte(final int index)
- {
- return array[index];
- }
-
- public void getBytes(final int index, final ChannelBuffer dst, final int dstIndex, final int length)
- {
- if (dst instanceof HeapChannelBuffer)
- {
- getBytes(index, ((HeapChannelBuffer)dst).array, dstIndex, length);
- }
- else
- {
- dst.setBytes(dstIndex, array, index, length);
- }
- }
-
- public void getBytes(final int index, final byte[] dst, final int dstIndex, final int length)
- {
- System.arraycopy(array, index, dst, dstIndex, length);
- }
-
- public void getBytes(final int index, final ByteBuffer dst)
- {
- dst.put(array, index, Math.min(capacity() - index, dst.remaining()));
- }
-
- public void getBytes(final int index, final OutputStream out, final int length) throws IOException
- {
- out.write(array, index, length);
- }
-
- public int getBytes(final int index, final GatheringByteChannel out, final int length) throws IOException
- {
- return out.write(ByteBuffer.wrap(array, index, length));
- }
-
- public void setByte(final int index, final byte value)
- {
- array[index] = value;
- }
-
- public void setBytes(final int index, final ChannelBuffer src, final int srcIndex, final int length)
- {
- if (src instanceof HeapChannelBuffer)
- {
- setBytes(index, ((HeapChannelBuffer)src).array, srcIndex, length);
- }
- else
- {
- src.getBytes(srcIndex, array, index, length);
- }
- }
-
- public void setBytes(final int index, final byte[] src, final int srcIndex, final int length)
- {
- System.arraycopy(src, srcIndex, array, index, length);
- }
-
- public void setBytes(final int index, final ByteBuffer src)
- {
- src.get(array, index, src.remaining());
- }
-
- public int setBytes(int index, final InputStream in, int length) throws IOException
- {
- int readBytes = 0;
- do
- {
- int localReadBytes = in.read(array, index, length);
- if (localReadBytes < 0)
- {
- if (readBytes == 0)
- {
- return -1;
- }
- else
- {
- break;
- }
- }
- readBytes += localReadBytes;
- index += localReadBytes;
- length -= localReadBytes;
- }
- while (length > 0);
-
- return readBytes;
- }
-
- public int setBytes(final int index, final ScatteringByteChannel in, final int length) throws IOException
- {
- ByteBuffer buf = ByteBuffer.wrap(array, index, length);
- int readBytes = 0;
-
- do
- {
- int localReadBytes;
- try
- {
- localReadBytes = in.read(buf);
- }
- catch (ClosedChannelException e)
- {
- localReadBytes = -1;
- }
- if (localReadBytes < 0)
- {
- if (readBytes == 0)
- {
- return -1;
- }
- else
- {
- break;
- }
- }
- else if (localReadBytes == 0)
- {
- break;
- }
- readBytes += localReadBytes;
- }
- while (readBytes < length);
-
- return readBytes;
- }
-
- public short getShort(final int index)
- {
- return (short)(array[index] << 8 | array[index + 1] & 0xFF);
- }
-
- public int getUnsignedMedium(final int index)
- {
- return (array[index] & 0xff) << 16 | (array[index + 1] & 0xff) << 8 | (array[index + 2] & 0xff) << 0;
- }
-
- public int getInt(final int index)
- {
- return (array[index] & 0xff) << 24 | (array[index + 1] & 0xff) << 16 |
- (array[index + 2] & 0xff) << 8 |
- (array[index + 3] & 0xff) << 0;
- }
-
- public long getLong(final int index)
- {
- return ((long)array[index] & 0xff) << 56 | ((long)array[index + 1] & 0xff) << 48 |
- ((long)array[index + 2] & 0xff) << 40 |
- ((long)array[index + 3] & 0xff) << 32 |
- ((long)array[index + 4] & 0xff) << 24 |
- ((long)array[index + 5] & 0xff) << 16 |
- ((long)array[index + 6] & 0xff) << 8 |
- ((long)array[index + 7] & 0xff) << 0;
- }
-
- public void setShort(final int index, final short value)
- {
- array[index] = (byte)(value >>> 8);
- array[index + 1] = (byte)(value >>> 0);
- }
-
- public void setMedium(final int index, final int value)
- {
- array[index] = (byte)(value >>> 16);
- array[index + 1] = (byte)(value >>> 8);
- array[index + 2] = (byte)(value >>> 0);
- }
-
- public void setInt(final int index, final int value)
- {
- array[index] = (byte)(value >>> 24);
- array[index + 1] = (byte)(value >>> 16);
- array[index + 2] = (byte)(value >>> 8);
- array[index + 3] = (byte)(value >>> 0);
- }
-
- public void setLong(final int index, final long value)
- {
- array[index] = (byte)(value >>> 56);
- array[index + 1] = (byte)(value >>> 48);
- array[index + 2] = (byte)(value >>> 40);
- array[index + 3] = (byte)(value >>> 32);
- array[index + 4] = (byte)(value >>> 24);
- array[index + 5] = (byte)(value >>> 16);
- array[index + 6] = (byte)(value >>> 8);
- array[index + 7] = (byte)(value >>> 0);
- }
-
- public ChannelBuffer copy(final int index, final int length)
- {
- if (index < 0 || length < 0 || index + length > array.length)
- {
- throw new IndexOutOfBoundsException();
- }
-
- byte[] copiedArray = new byte[length];
- System.arraycopy(array, index, copiedArray, 0, length);
- return new HeapChannelBuffer(copiedArray);
- }
-
- public ChannelBuffer duplicate()
- {
- return new HeapChannelBuffer(array, readerIndex(), writerIndex());
- }
-
- public ByteBuffer toByteBuffer(final int index, final int length)
- {
- return ByteBuffer.wrap(array, index, length);
- }
-
- public String toString(final int index, final int length, final String charsetName)
- {
- try
- {
- return new String(array, index, length, charsetName);
- }
- catch (UnsupportedEncodingException e)
- {
- throw new UnsupportedCharsetException(charsetName);
- }
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#array()
- */
- public byte[] array()
- {
- return array;
- }
-
-}
Copied: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQAbstractChannelBuffer.java (from rev 8314, branches/20-optimisation/src/main/org/hornetq/core/buffers/AbstractChannelBuffer.java)
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQAbstractChannelBuffer.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQAbstractChannelBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -0,0 +1,788 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.core.buffers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.GatheringByteChannel;
+import java.nio.channels.ScatteringByteChannel;
+
+import org.hornetq.core.logging.Logger;
+import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.utils.DataConstants;
+import org.hornetq.utils.SimpleString;
+import org.hornetq.utils.UTF8Util;
+
+/**
+ * A skeletal implementation of a buffer.
+ *
+ * @author The Netty Project (netty-dev(a)lists.jboss.org)
+ * @author Trustin Lee (tlee(a)redhat.com)
+ *
+ * @version $Rev: 303 $, $Date: 2008-09-24 18:48:32 +0900 (Wed, 24 Sep 2008) $
+ */
+public abstract class HornetQAbstractChannelBuffer implements HornetQChannelBuffer
+{
+ private static final Logger log = Logger.getLogger(HornetQAbstractChannelBuffer.class);
+
+
+ private int readerIndex;
+
+ private int writerIndex;
+
+ private int markedReaderIndex;
+
+ private int markedWriterIndex;
+
+ public int readerIndex()
+ {
+ return readerIndex;
+ }
+
+ public void readerIndex(final int readerIndex)
+ {
+ if (readerIndex < 0 || readerIndex > writerIndex)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ this.readerIndex = readerIndex;
+ }
+
+ public int writerIndex()
+ {
+ return writerIndex;
+ }
+
+ public void writerIndex(final int writerIndex)
+ {
+ if (writerIndex < readerIndex || writerIndex > capacity())
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ this.writerIndex = writerIndex;
+ }
+
+ public void setIndex(final int readerIndex, final int writerIndex)
+ {
+ if (readerIndex < 0 || readerIndex > writerIndex || writerIndex > capacity())
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ this.readerIndex = readerIndex;
+ this.writerIndex = writerIndex;
+ }
+
+ public void clear()
+ {
+ readerIndex = writerIndex = 0;
+ }
+
+ public boolean readable()
+ {
+ return readableBytes() > 0;
+ }
+
+ public boolean writable()
+ {
+ return writableBytes() > 0;
+ }
+
+ public int readableBytes()
+ {
+ return writerIndex - readerIndex;
+ }
+
+ public int writableBytes()
+ {
+ return capacity() - writerIndex;
+ }
+
+ public void markReaderIndex()
+ {
+ markedReaderIndex = readerIndex;
+ }
+
+ public void resetReaderIndex()
+ {
+ readerIndex(markedReaderIndex);
+ }
+
+ public void markWriterIndex()
+ {
+ markedWriterIndex = writerIndex;
+ }
+
+ public void resetWriterIndex()
+ {
+ writerIndex = markedWriterIndex;
+ }
+
+ public void discardReadBytes()
+ {
+ if (readerIndex == 0)
+ {
+ return;
+ }
+ setBytes(0, this, readerIndex, writerIndex - readerIndex);
+ writerIndex -= readerIndex;
+ markedReaderIndex = Math.max(markedReaderIndex - readerIndex, 0);
+ markedWriterIndex = Math.max(markedWriterIndex - readerIndex, 0);
+ readerIndex = 0;
+ }
+
+ public short getUnsignedByte(final int index)
+ {
+ return (short)(getByte(index) & 0xFF);
+ }
+
+ public int getUnsignedShort(final int index)
+ {
+ return getShort(index) & 0xFFFF;
+ }
+
+ public int getMedium(final int index)
+ {
+ int value = getUnsignedMedium(index);
+ if ((value & 0x800000) != 0)
+ {
+ value |= 0xff000000;
+ }
+ return value;
+ }
+
+ public long getUnsignedInt(final int index)
+ {
+ return getInt(index) & 0xFFFFFFFFL;
+ }
+
+ public void getBytes(final int index, final byte[] dst)
+ {
+ getBytes(index, dst, 0, dst.length);
+ }
+
+ public void getBytes(final int index, final HornetQChannelBuffer dst)
+ {
+ getBytes(index, dst, dst.writableBytes());
+ }
+
+ public void getBytes(final int index, final HornetQChannelBuffer dst, final int length)
+ {
+ if (length > dst.writableBytes())
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ getBytes(index, dst, dst.writerIndex(), length);
+ dst.writerIndex(dst.writerIndex() + length);
+ }
+
+ public void setBytes(final int index, final byte[] src)
+ {
+ setBytes(index, src, 0, src.length);
+ }
+
+ public void setBytes(final int index, final HornetQChannelBuffer src)
+ {
+ setBytes(index, src, src.readableBytes());
+ }
+
+ public void setBytes(final int index, final HornetQChannelBuffer src, final int length)
+ {
+ if (length > src.readableBytes())
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ setBytes(index, src, src.readerIndex(), length);
+ src.readerIndex(src.readerIndex() + length);
+ }
+
+ public void setZero(int index, final int length)
+ {
+ if (length == 0)
+ {
+ return;
+ }
+ if (length < 0)
+ {
+ throw new IllegalArgumentException("length must be 0 or greater than 0.");
+ }
+
+ int nLong = length >>> 3;
+ int nBytes = length & 7;
+ for (int i = nLong; i > 0; i--)
+ {
+ setLong(index, 0);
+ index += 8;
+ }
+ if (nBytes == 4)
+ {
+ setInt(index, 0);
+ }
+ else if (nBytes < 4)
+ {
+ for (int i = nBytes; i > 0; i--)
+ {
+ setByte(index, (byte)0);
+ index++;
+ }
+ }
+ else
+ {
+ setInt(index, 0);
+ index += 4;
+ for (int i = nBytes - 4; i > 0; i--)
+ {
+ setByte(index, (byte)0);
+ index++;
+ }
+ }
+ }
+
+ public byte readByte()
+ {
+ if (readerIndex == writerIndex)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ return getByte(readerIndex++);
+ }
+
+ public short readUnsignedByte()
+ {
+ return (short)(readByte() & 0xFF);
+ }
+
+ public short readShort()
+ {
+ checkReadableBytes(2);
+ short v = getShort(readerIndex);
+ readerIndex += 2;
+ return v;
+ }
+
+ public int readUnsignedShort()
+ {
+ return readShort() & 0xFFFF;
+ }
+
+ public int readMedium()
+ {
+ int value = readUnsignedMedium();
+ if ((value & 0x800000) != 0)
+ {
+ value |= 0xff000000;
+ }
+ return value;
+ }
+
+ public int readUnsignedMedium()
+ {
+ checkReadableBytes(3);
+ int v = getUnsignedMedium(readerIndex);
+ readerIndex += 3;
+ return v;
+ }
+
+ public int readInt()
+ {
+ checkReadableBytes(4);
+ int v = getInt(readerIndex);
+ readerIndex += 4;
+ return v;
+ }
+
+ public int readInt(final int pos)
+ {
+ checkReadableBytes(4);
+ int v = getInt(pos);
+ return v;
+ }
+
+ public long readUnsignedInt()
+ {
+ return readInt() & 0xFFFFFFFFL;
+ }
+
+ public long readLong()
+ {
+ checkReadableBytes(8);
+ long v = getLong(readerIndex);
+ readerIndex += 8;
+ return v;
+ }
+
+ public void readBytes(final byte[] dst, final int dstIndex, final int length)
+ {
+ checkReadableBytes(length);
+ getBytes(readerIndex, dst, dstIndex, length);
+ readerIndex += length;
+ }
+
+ public void readBytes(final byte[] dst)
+ {
+ readBytes(dst, 0, dst.length);
+ }
+
+ public void readBytes(final HornetQChannelBuffer dst)
+ {
+ readBytes(dst, dst.writableBytes());
+ }
+
+ public void readBytes(final HornetQChannelBuffer dst, final int length)
+ {
+ if (length > dst.writableBytes())
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ readBytes(dst, dst.writerIndex(), length);
+ dst.writerIndex(dst.writerIndex() + length);
+ }
+
+ public void readBytes(final HornetQChannelBuffer dst, final int dstIndex, final int length)
+ {
+ checkReadableBytes(length);
+ getBytes(readerIndex, dst, dstIndex, length);
+ readerIndex += length;
+ }
+
+ public void readBytes(final ByteBuffer dst)
+ {
+ int length = dst.remaining();
+ checkReadableBytes(length);
+ getBytes(readerIndex, dst);
+ readerIndex += length;
+ }
+
+ public int readBytes(final GatheringByteChannel out, final int length) throws IOException
+ {
+ checkReadableBytes(length);
+ int readBytes = getBytes(readerIndex, out, length);
+ readerIndex += readBytes;
+ return readBytes;
+ }
+
+ public void readBytes(final OutputStream out, final int length) throws IOException
+ {
+ checkReadableBytes(length);
+ getBytes(readerIndex, out, length);
+ readerIndex += length;
+ }
+
+ public void skipBytes(final int length)
+ {
+ int newReaderIndex = readerIndex + length;
+ if (newReaderIndex > writerIndex)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ readerIndex = newReaderIndex;
+ }
+
+ public void writeByte(final byte value)
+ {
+ setByte(writerIndex++, value);
+ }
+
+ public void writeShort(final short value)
+ {
+ setShort(writerIndex, value);
+ writerIndex += 2;
+ }
+
+ public void writeMedium(final int value)
+ {
+ setMedium(writerIndex, value);
+ writerIndex += 3;
+ }
+
+ public void writeInt(final int value)
+ {
+ setInt(writerIndex, value);
+ writerIndex += 4;
+ }
+
+ public void writeLong(final long value)
+ {
+ setLong(writerIndex, value);
+ writerIndex += 8;
+ }
+
+ public void writeBytes(final byte[] src, final int srcIndex, final int length)
+ {
+ setBytes(writerIndex, src, srcIndex, length);
+ writerIndex += length;
+ }
+
+ public void writeBytes(final byte[] src)
+ {
+ writeBytes(src, 0, src.length);
+ }
+
+ public void writeBytes(final HornetQChannelBuffer src)
+ {
+ writeBytes(src, src.readableBytes());
+ }
+
+ public void writeBytes(final HornetQChannelBuffer src, final int length)
+ {
+ if (length > src.readableBytes())
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ writeBytes(src, src.readerIndex(), length);
+ src.readerIndex(src.readerIndex() + length);
+ }
+
+ public void writeBytes(final HornetQChannelBuffer src, final int srcIndex, final int length)
+ {
+ setBytes(writerIndex, src, srcIndex, length);
+ writerIndex += length;
+ }
+
+
+ public void writeBytes(final HornetQBuffer src, final int srcIndex, final int length)
+ {
+ writeBytes((HornetQChannelBuffer)src, srcIndex, length);
+ }
+
+ public void writeBytes(final ByteBuffer src)
+ {
+ int length = src.remaining();
+ setBytes(writerIndex, src);
+ writerIndex += length;
+ }
+
+ public void writeBytes(final InputStream in, final int length) throws IOException
+ {
+ setBytes(writerIndex, in, length);
+ writerIndex += length;
+ }
+
+ public int writeBytes(final ScatteringByteChannel in, final int length) throws IOException
+ {
+ int writtenBytes = setBytes(writerIndex, in, length);
+ if (writtenBytes > 0)
+ {
+ writerIndex += writtenBytes;
+ }
+ return writtenBytes;
+ }
+
+ public void writeZero(final int length)
+ {
+ if (length == 0)
+ {
+ return;
+ }
+ if (length < 0)
+ {
+ throw new IllegalArgumentException("length must be 0 or greater than 0.");
+ }
+ int nLong = length >>> 3;
+ int nBytes = length & 7;
+ for (int i = nLong; i > 0; i--)
+ {
+ writeLong(0);
+ }
+ if (nBytes == 4)
+ {
+ writeInt(0);
+ }
+ else if (nBytes < 4)
+ {
+ for (int i = nBytes; i > 0; i--)
+ {
+ writeByte((byte)0);
+ }
+ }
+ else
+ {
+ writeInt(0);
+ for (int i = nBytes - 4; i > 0; i--)
+ {
+ writeByte((byte)0);
+ }
+ }
+ }
+
+ public ByteBuffer toByteBuffer()
+ {
+ return toByteBuffer(readerIndex, readableBytes());
+ }
+
+ public ByteBuffer[] toByteBuffers()
+ {
+ return toByteBuffers(readerIndex, readableBytes());
+ }
+
+ public ByteBuffer[] toByteBuffers(final int index, final int length)
+ {
+ return new ByteBuffer[] { toByteBuffer(index, length) };
+ }
+
+ public String toString(final String charsetName)
+ {
+ return toString(readerIndex, readableBytes(), charsetName);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return HornetQChannelBuffers.hashCode(this);
+ }
+
+ @Override
+ public boolean equals(final Object o)
+ {
+ if (!(o instanceof HornetQChannelBuffer))
+ {
+ return false;
+ }
+ return HornetQChannelBuffers.equals(this, (HornetQChannelBuffer)o);
+ }
+
+ public int compareTo(final HornetQChannelBuffer that)
+ {
+ return HornetQChannelBuffers.compare(this, that);
+ }
+
+ @Override
+ public String toString()
+ {
+ return getClass().getSimpleName() + '(' +
+ "ridx=" +
+ readerIndex +
+ ", " +
+ "widx=" +
+ writerIndex +
+ ", " +
+ "cap=" +
+ capacity() +
+ ')';
+ }
+
+ /**
+ * Throws an {@link IndexOutOfBoundsException} if the current
+ * {@linkplain #readableBytes() readable bytes} of this buffer is less
+ * than the specified value.
+ */
+ protected void checkReadableBytes(final int minimumReadableBytes)
+ {
+ if (readableBytes() < minimumReadableBytes)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ public Object getUnderlyingBuffer()
+ {
+ return this;
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#readBoolean()
+ */
+ public boolean readBoolean()
+ {
+ return readByte() != 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#readChar()
+ */
+ public char readChar()
+ {
+ return (char)readShort();
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#readDouble()
+ */
+ public double readDouble()
+ {
+ return Double.longBitsToDouble(readLong());
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#readFloat()
+ */
+ public float readFloat()
+ {
+ return Float.intBitsToFloat(readInt());
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#readNullableSimpleString()
+ */
+ public SimpleString readNullableSimpleString()
+ {
+ int b = readByte();
+ if (b == DataConstants.NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return readSimpleString();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#readNullableString()
+ */
+ public String readNullableString()
+ {
+ int b = readByte();
+ if (b == DataConstants.NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return readString();
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#readSimpleString()
+ */
+ public SimpleString readSimpleString()
+ {
+ int len = readInt();
+ byte[] data = new byte[len];
+ readBytes(data);
+ return new SimpleString(data);
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#readString()
+ */
+ public String readString()
+ {
+ int len = readInt();
+
+ char[] chars = new char[len];
+ for (int i = 0; i < len; i++)
+ {
+ chars[i] = readChar();
+ }
+ return new String(chars);
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#readUTF()
+ */
+ public String readUTF() throws Exception
+ {
+ return UTF8Util.readUTF(this);
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeBoolean(boolean)
+ */
+ public void writeBoolean(final boolean val)
+ {
+ writeByte((byte)(val ? -1 : 0));
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeChar(char)
+ */
+ public void writeChar(final char val)
+ {
+ writeShort((short)val);
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeDouble(double)
+ */
+ public void writeDouble(final double val)
+ {
+ writeLong(Double.doubleToLongBits(val));
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeFloat(float)
+ */
+ public void writeFloat(final float val)
+ {
+ writeInt(Float.floatToIntBits(val));
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeNullableSimpleString(org.hornetq.util.SimpleString)
+ */
+ public void writeNullableSimpleString(final SimpleString val)
+ {
+ if (val == null)
+ {
+ writeByte(DataConstants.NULL);
+ }
+ else
+ {
+ writeByte(DataConstants.NOT_NULL);
+ writeSimpleString(val);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeNullableString(java.lang.String)
+ */
+ public void writeNullableString(final String val)
+ {
+ if (val == null)
+ {
+ writeByte(DataConstants.NULL);
+ }
+ else
+ {
+ writeByte(DataConstants.NOT_NULL);
+ writeString(val);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeSimpleString(org.hornetq.util.SimpleString)
+ */
+ public void writeSimpleString(final SimpleString val)
+ {
+ byte[] data = val.getData();
+ writeInt(data.length);
+ writeBytes(data);
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeString(java.lang.String)
+ */
+ public void writeString(final String val)
+ {
+ writeInt(val.length());
+ for (int i = 0; i < val.length(); i++)
+ {
+ writeShort((short)val.charAt(i));
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#writeUTF(java.lang.String)
+ */
+ public void writeUTF(final String utf) throws Exception
+ {
+ UTF8Util.saveUTF(this, utf);
+ }
+
+}
Copied: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQByteBufferBackedChannelBuffer.java (from rev 8288, branches/20-optimisation/src/main/org/hornetq/core/buffers/ByteBufferBackedChannelBuffer.java)
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQByteBufferBackedChannelBuffer.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQByteBufferBackedChannelBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -0,0 +1,381 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.core.buffers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.GatheringByteChannel;
+import java.nio.channels.ScatteringByteChannel;
+import java.nio.charset.UnsupportedCharsetException;
+
+import org.hornetq.core.remoting.spi.HornetQBuffer;
+
+/**
+ * A NIO {@link ByteBuffer} based buffer. It is recommended to use {@link HornetQChannelBuffers#directBuffer(int)}
+ * and {@link HornetQChannelBuffers#wrappedBuffer(ByteBuffer)} instead of calling the
+ * constructor explicitly.
+ *
+ * @author The Netty Project (netty-dev(a)lists.jboss.org)
+ * @author Trustin Lee (tlee(a)redhat.com)
+ *
+ * @version $Rev: 486 $, $Date: 2008-11-16 22:52:47 +0900 (Sun, 16 Nov 2008) $
+ *
+ */
+public class HornetQByteBufferBackedChannelBuffer extends HornetQAbstractChannelBuffer
+{
+
+ private final ByteBuffer buffer;
+
+ private final int capacity;
+
+ /**
+ * Creates a new buffer which wraps the specified buffer's slice.
+ */
+ HornetQByteBufferBackedChannelBuffer(final ByteBuffer buffer)
+ {
+ if (buffer == null)
+ {
+ throw new NullPointerException("buffer");
+ }
+
+ this.buffer = buffer;
+ capacity = buffer.remaining();
+ }
+
+ public int capacity()
+ {
+ return capacity;
+ }
+
+ public byte getByte(final int index)
+ {
+ return buffer.get(index);
+ }
+
+ public short getShort(final int index)
+ {
+ return buffer.getShort(index);
+ }
+
+ public int getUnsignedMedium(final int index)
+ {
+ return (getByte(index) & 0xff) << 16 | (getByte(index + 1) & 0xff) << 8 | (getByte(index + 2) & 0xff) << 0;
+ }
+
+ public int getInt(final int index)
+ {
+ return buffer.getInt(index);
+ }
+
+ public long getLong(final int index)
+ {
+ return buffer.getLong(index);
+ }
+
+ public void getBytes(final int index, final HornetQChannelBuffer dst, final int dstIndex, final int length)
+ {
+ if (dst instanceof HornetQByteBufferBackedChannelBuffer)
+ {
+ HornetQByteBufferBackedChannelBuffer bbdst = (HornetQByteBufferBackedChannelBuffer)dst;
+ ByteBuffer data = bbdst.buffer.duplicate();
+
+ data.limit(dstIndex + length).position(dstIndex);
+ getBytes(index, data);
+ }
+ else if (buffer.hasArray())
+ {
+ dst.setBytes(dstIndex, buffer.array(), index + buffer.arrayOffset(), length);
+ }
+ else
+ {
+ dst.setBytes(dstIndex, this, index, length);
+ }
+ }
+
+ public void getBytes(final int index, final byte[] dst, final int dstIndex, final int length)
+ {
+ ByteBuffer data = buffer.duplicate();
+ try
+ {
+ data.limit(index + length).position(index);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ data.get(dst, dstIndex, length);
+ }
+
+ public void getBytes(final int index, final ByteBuffer dst)
+ {
+ ByteBuffer data = buffer.duplicate();
+ int bytesToCopy = Math.min(capacity() - index, dst.remaining());
+ try
+ {
+ data.limit(index + bytesToCopy).position(index);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ dst.put(data);
+ }
+
+ public void setByte(final int index, final byte value)
+ {
+ buffer.put(index, value);
+ }
+
+ public void setShort(final int index, final short value)
+ {
+ buffer.putShort(index, value);
+ }
+
+ public void setMedium(final int index, final int value)
+ {
+ setByte(index, (byte)(value >>> 16));
+ setByte(index + 1, (byte)(value >>> 8));
+ setByte(index + 2, (byte)(value >>> 0));
+ }
+
+ public void setInt(final int index, final int value)
+ {
+ buffer.putInt(index, value);
+ }
+
+ public void setLong(final int index, final long value)
+ {
+ buffer.putLong(index, value);
+ }
+
+ public void setBytes(final int index, final HornetQChannelBuffer src, final int srcIndex, final int length)
+ {
+ if (src instanceof HornetQByteBufferBackedChannelBuffer)
+ {
+ HornetQByteBufferBackedChannelBuffer bbsrc = (HornetQByteBufferBackedChannelBuffer)src;
+ ByteBuffer data = bbsrc.buffer.duplicate();
+
+ data.limit(srcIndex + length).position(srcIndex);
+ setBytes(index, data);
+ }
+ else if (buffer.hasArray())
+ {
+ src.getBytes(srcIndex, buffer.array(), index + buffer.arrayOffset(), length);
+ }
+ else
+ {
+ src.getBytes(srcIndex, this, index, length);
+ }
+ }
+
+ public void setBytes(final int index, final byte[] src, final int srcIndex, final int length)
+ {
+ ByteBuffer data = buffer.duplicate();
+ data.limit(index + length).position(index);
+ data.put(src, srcIndex, length);
+ }
+
+ public void setBytes(final int index, final ByteBuffer src)
+ {
+ ByteBuffer data = buffer.duplicate();
+ data.limit(index + src.remaining()).position(index);
+ data.put(src);
+ }
+
+ public void getBytes(final int index, final OutputStream out, final int length) throws IOException
+ {
+ if (length == 0)
+ {
+ return;
+ }
+
+ if (!buffer.isReadOnly() && buffer.hasArray())
+ {
+ out.write(buffer.array(), index + buffer.arrayOffset(), length);
+ }
+ else
+ {
+ byte[] tmp = new byte[length];
+ ((ByteBuffer)buffer.duplicate().position(index)).get(tmp);
+ out.write(tmp);
+ }
+ }
+
+ public int getBytes(final int index, final GatheringByteChannel out, final int length) throws IOException
+ {
+ if (length == 0)
+ {
+ return 0;
+ }
+
+ return out.write((ByteBuffer)buffer.duplicate().position(index).limit(index + length));
+ }
+
+ public int setBytes(int index, final InputStream in, int length) throws IOException
+ {
+
+ int readBytes = 0;
+
+ if (!buffer.isReadOnly() && buffer.hasArray())
+ {
+ index += buffer.arrayOffset();
+ do
+ {
+ int localReadBytes = in.read(buffer.array(), index, length);
+ if (localReadBytes < 0)
+ {
+ if (readBytes == 0)
+ {
+ return -1;
+ }
+ else
+ {
+ break;
+ }
+ }
+ readBytes += localReadBytes;
+ index += localReadBytes;
+ length -= localReadBytes;
+ }
+ while (length > 0);
+ }
+ else
+ {
+ byte[] tmp = new byte[length];
+ int i = 0;
+ do
+ {
+ int localReadBytes = in.read(tmp, i, tmp.length - i);
+ if (localReadBytes < 0)
+ {
+ if (readBytes == 0)
+ {
+ return -1;
+ }
+ else
+ {
+ break;
+ }
+ }
+ readBytes += localReadBytes;
+ i += readBytes;
+ }
+ while (i < tmp.length);
+ ((ByteBuffer)buffer.duplicate().position(index)).put(tmp);
+ }
+
+ return readBytes;
+ }
+
+ public int setBytes(final int index, final ScatteringByteChannel in, final int length) throws IOException
+ {
+
+ ByteBuffer slice = (ByteBuffer)buffer.duplicate().limit(index + length).position(index);
+ int readBytes = 0;
+
+ while (readBytes < length)
+ {
+ int localReadBytes;
+ try
+ {
+ localReadBytes = in.read(slice);
+ }
+ catch (ClosedChannelException e)
+ {
+ localReadBytes = -1;
+ }
+ if (localReadBytes < 0)
+ {
+ if (readBytes == 0)
+ {
+ return -1;
+ }
+ else
+ {
+ return readBytes;
+ }
+ }
+ else if (localReadBytes == 0)
+ {
+ break;
+ }
+ readBytes += localReadBytes;
+ }
+
+ return readBytes;
+ }
+
+ public ByteBuffer toByteBuffer(final int index, final int length)
+ {
+ if (index == 0 && length == capacity())
+ {
+ return buffer.duplicate();
+ }
+ else
+ {
+ return ((ByteBuffer)buffer.duplicate().position(index).limit(index + length)).slice();
+ }
+ }
+
+ @Override
+ public ByteBuffer toByteBuffer()
+ {
+ return buffer;
+ }
+
+ public String toString(final int index, final int length, final String charsetName)
+ {
+ if (!buffer.isReadOnly() && buffer.hasArray())
+ {
+ try
+ {
+ return new String(buffer.array(), index + buffer.arrayOffset(), length, charsetName);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new UnsupportedCharsetException(charsetName);
+ }
+ }
+ else
+ {
+ byte[] tmp = new byte[length];
+ ((ByteBuffer)buffer.duplicate().position(index)).get(tmp);
+ try
+ {
+ return new String(tmp, charsetName);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new UnsupportedCharsetException(charsetName);
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.buffers.ChannelBuffer#array()
+ */
+ public byte[] array()
+ {
+ return buffer.array();
+ }
+
+ public HornetQBuffer copy()
+ {
+ return new HornetQByteBufferBackedChannelBuffer(ByteBuffer.wrap(buffer.array().clone()));
+ }
+}
Copied: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffer.java (from rev 8288, branches/20-optimisation/src/main/org/hornetq/core/buffers/ChannelBuffer.java)
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffer.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -0,0 +1,1256 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.core.buffers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.GatheringByteChannel;
+import java.nio.channels.ScatteringByteChannel;
+import java.nio.charset.UnsupportedCharsetException;
+
+import org.hornetq.core.remoting.spi.HornetQBuffer;
+
+/**
+ * A random and sequential accessible sequence of zero or more bytes (octets).
+ * This interface provides an abstract view for one or more primitive byte
+ * arrays ({@code byte[]}) and {@linkplain ByteBuffer NIO buffers}.
+ *
+ * <h3>Creation of a buffer</h3>
+ *
+ * It is recommended to create a new buffer using the helper methods in
+ * {@link HornetQChannelBuffers} rather than calling an individual implementation's
+ * constructor.
+ *
+ * <h3>Random Access Indexing</h3>
+ *
+ * Just like an ordinary primitive byte array, {@link HornetQChannelBuffer} uses
+ * <a href="http://en.wikipedia.org/wiki/Index_(information_technology)#Array_element...">zero-based indexing</a>.
+ * It means the index of the first byte is always {@code 0} and the index of
+ * the last byte is always {@link #capacity() capacity - 1}. For example, to
+ * iterate all bytes of a buffer, you can do the following, regardless of
+ * its internal implementation:
+ *
+ * <pre>
+ * ChannelBuffer buffer = ...;
+ * for (int i = 0; i < buffer.capacity(); i ++</strong>) {
+ * byte b = array.getByte(i);
+ * System.out.println((char) b);
+ * }
+ * </pre>
+ *
+ * <h3>Sequential Access Indexing</h3>
+ *
+ * {@link HornetQChannelBuffer} provides two pointer variables to support sequential
+ * read and write operations - {@link #readerIndex() readerIndex} for a read
+ * operation and {@link #writerIndex() writerIndex} for a write operation
+ * respectively. The following diagram shows how a buffer is segmented into
+ * three areas by the two pointers:
+ *
+ * <pre>
+ * +-------------------+------------------+------------------+
+ * | discardable bytes | readable bytes | writable bytes |
+ * | | (CONTENT) | |
+ * +-------------------+------------------+------------------+
+ * | | | |
+ * 0 <= readerIndex <= writerIndex <= capacity
+ * </pre>
+ *
+ * <h4>Readable bytes (the actual content)</h4>
+ *
+ * This segment is where the actual data is stored. Any operation whose name
+ * starts with {@code read} or {@code skip} will get or skip the data at the
+ * current {@link #readerIndex() readerIndex} and increase it by the number of
+ * read bytes. If the argument of the read operation is also a
+ * {@link HornetQChannelBuffer} and no start index is specified, the specified
+ * buffer's {@link #readerIndex() readerIndex} is increased together.
+ * <p>
+ * If there's not enough content left, {@link IndexOutOfBoundsException} is
+ * raised. The default value of newly allocated, wrapped or copied buffer's
+ * {@link #readerIndex() readerIndex} is {@code 0}.
+ *
+ * <pre>
+ * // Iterates the readable bytes of a buffer.
+ * ChannelBuffer buffer = ...;
+ * while (buffer.readable()) {
+ * System.out.println(buffer.readByte());
+ * }
+ * </pre>
+ *
+ * <h4>Writable bytes</h4>
+ *
+ * This segment is a undefined space which needs to be filled. Any operation
+ * whose name ends with {@code write} will write the data at the current
+ * {@link #writerIndex() writerIndex} and increase it by the number of written
+ * bytes. If the argument of the write operation is also a {@link HornetQChannelBuffer},
+ * and no start index is specified, the specified buffer's
+ * {@link #readerIndex() readerIndex} is increased together.
+ * <p>
+ * If there's not enough writable bytes left, {@link IndexOutOfBoundsException}
+ * is raised. The default value of newly allocated buffer's
+ * {@link #writerIndex() writerIndex} is {@code 0}. The default value of
+ * wrapped or copied buffer's {@link #writerIndex() writerIndex} is the
+ * {@link #capacity() capacity} of the buffer.
+ *
+ * <pre>
+ * // Fills the writable bytes of a buffer with random integers.
+ * ChannelBuffer buffer = ...;
+ * while (buffer.writableBytes() >= 4) {
+ * buffer.writeInt(random.nextInt());
+ * }
+ * </pre>
+ *
+ * <h4>Discardable bytes</h4>
+ *
+ * This segment contains the bytes which were read already by a read operation.
+ * Initially, the size of this segment is {@code 0}, but its size increases up
+ * to the {@link #writerIndex() writerIndex} as read operations are executed.
+ * The read bytes can be discarded by calling {@link #discardReadBytes()} to
+ * reclaim unused area as depicted by the following diagram:
+ *
+ * <pre>
+ * BEFORE discardReadBytes()
+ *
+ * +-------------------+------------------+------------------+
+ * | discardable bytes | readable bytes | writable bytes |
+ * +-------------------+------------------+------------------+
+ * | | | |
+ * 0 <= readerIndex <= writerIndex <= capacity
+ *
+ *
+ * AFTER discardReadBytes()
+ *
+ * +------------------+--------------------------------------+
+ * | readable bytes | writable bytes (got more space) |
+ * +------------------+--------------------------------------+
+ * | | |
+ * readerIndex (0) <= writerIndex (decreased) <= capacity
+ * </pre>
+ *
+ * <h4>Clearing the buffer indexes</h4>
+ *
+ * You can set both {@link #readerIndex() readerIndex} and
+ * {@link #writerIndex() writerIndex} to {@code 0} by calling {@link #clear()}.
+ * It does not clear the buffer content (e.g. filling with {@code 0}) but just
+ * clears the two pointers. Please also note that the semantic of this
+ * operation is different from {@link ByteBuffer#clear()}.
+ *
+ * <pre>
+ * BEFORE clear()
+ *
+ * +-------------------+------------------+------------------+
+ * | discardable bytes | readable bytes | writable bytes |
+ * +-------------------+------------------+------------------+
+ * | | | |
+ * 0 <= readerIndex <= writerIndex <= capacity
+ *
+ *
+ * AFTER clear()
+ *
+ * +---------------------------------------------------------+
+ * | writable bytes (got more space) |
+ * +---------------------------------------------------------+
+ * | |
+ * 0 = readerIndex = writerIndex <= capacity
+ * </pre>
+ *
+ * <h3>Search operations</h3>
+ *
+ * Various {@code indexOf()} methods help you locate an index of a value which
+ * meets a certain criteria. Complicated dynamic sequential search can be done
+ * with {@link ChannelBufferIndexFinder} as well as simple static single byte
+ * search.
+ *
+ * <h3>Mark and reset</h3>
+ *
+ * There are two marker indexes in every buffer. One is for storing
+ * {@link #readerIndex() readerIndex} and the other is for storing
+ * {@link #writerIndex() writerIndex}. You can always reposition one of the
+ * two indexes by calling a reset method. It works in a similar fashion to
+ * the mark and reset methods in {@link InputStream} except that there's no
+ * {@code readlimit}.
+ *
+ * <h3>Derived buffers</h3>
+ *
+ * You can create a view of an existing buffer by calling either
+ * {@link #duplicate()}, {@link #slice()} or {@link #slice(int, int)}.
+ * A derived buffer will have an independent {@link #readerIndex() readerIndex},
+ * {@link #writerIndex() writerIndex} and marker indexes, while it shares
+ * other internal data representation, just like a NIO buffer does.
+ * <p>
+ * In case a completely fresh copy of an existing buffer is required, please
+ * call {@link #copy()} method instead.
+ *
+ * <h3>Conversion to existing JDK types</h3>
+ *
+ * <h4>NIO Buffers</h4>
+ *
+ * Various {@link #toByteBuffer()} and {@link #toByteBuffers()} methods convert
+ * a {@link HornetQChannelBuffer} into one or more NIO buffers. These methods avoid
+ * buffer allocation and memory copy whenever possible, but there's no
+ * guarantee that memory copy will not be involved or that an explicit memory
+ * copy will be involved.
+ *
+ * <h4>Strings</h4>
+ *
+ * Various {@link #toString(String)} methods convert a {@link HornetQChannelBuffer}
+ * into a {@link String}. Plesae note that {@link #toString()} is not a
+ * conversion method.
+ *
+ * <h4>I/O Streams</h4>
+ *
+ * Please refer to {@link ChannelBufferInputStream} and
+ * {@link ChannelBufferOutputStream}.
+ *
+ * @author The Netty Project (netty-dev(a)lists.jboss.org)
+ * @author Trustin Lee (tlee(a)redhat.com)
+ *
+ * @version $Rev: 472 $, $Date: 2008-11-14 16:45:53 +0900 (Fri, 14 Nov 2008) $
+ *
+ * @apiviz.landmark
+ */
+public interface HornetQChannelBuffer extends Comparable<HornetQChannelBuffer>, HornetQBuffer
+{
+
+ /**
+ * Returns the number of bytes (octets) this buffer can contain.
+ */
+ int capacity();
+
+ byte[] array();
+
+ /**
+ * Returns the {@code readerIndex} of this buffer.
+ */
+ int readerIndex();
+
+ /**
+ * Sets the {@code readerIndex} of this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code readerIndex} is
+ * less than {@code 0} or
+ * greater than {@code this.writerIndex}
+ */
+ void readerIndex(int readerIndex);
+
+ /**
+ * Returns the {@code writerIndex} of this buffer.
+ */
+ int writerIndex();
+
+ /**
+ * Sets the {@code writerIndex} of this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code writerIndex} is
+ * less than {@code this.readerIndex} or
+ * greater than {@code this.capacity}
+ */
+ void writerIndex(int writerIndex);
+
+ /**
+ * Sets the {@code readerIndex} and {@code writerIndex} of this buffer
+ * in one shot. This method is useful when you have to worry about the
+ * invocation order of {@link #readerIndex(int)} and {@link #writerIndex(int)}
+ * methods. For example, the following code will fail:
+ *
+ * <pre>
+ * // Create a buffer whose readerIndex, writerIndex and capacity are
+ * // 0, 0 and 8 respectively.
+ * ChannelBuffer buf = ChannelBuffers.buffer(8);
+ *
+ * // IndexOutOfBoundsException is thrown because the specified
+ * // readerIndex (2) cannot be greater than the current writerIndex (0).
+ * buf.readerIndex(2);
+ * buf.writerIndex(4);
+ * </pre>
+ *
+ * The following code will also fail:
+ *
+ * <pre>
+ * // Create a buffer whose readerIndex, writerIndex and capacity are
+ * // 0, 8 and 8 respectively.
+ * ChannelBuffer buf = ChannelBuffers.wrappedBuffer(new byte[8]);
+ *
+ * // readerIndex becomes 8.
+ * buf.readLong();
+ *
+ * // IndexOutOfBoundsException is thrown because the specified
+ * // writerIndex (4) cannot be less than the current readerIndex (8).
+ * buf.writerIndex(4);
+ * buf.readerIndex(2);
+ * </pre>
+ *
+ * By contrast, {@link #setIndex(int, int)} guarantees that it never
+ * throws an {@link IndexOutOfBoundsException} as long as the specified
+ * indexes meet basic constraints, regardless what the current index
+ * values of the buffer are:
+ *
+ * <pre>
+ * // No matter what the current state of the buffer is, the following
+ * // call always succeeds as long as the capacity of the buffer is not
+ * // less than 4.
+ * buf.setIndex(2, 4);
+ * </pre>
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code readerIndex} is less than 0,
+ * if the specified {@code writerIndex} is less than the specified
+ * {@code readerIndex} or if the specified {@code writerIndex} is
+ * greater than {@code this.capacity}
+ */
+ void setIndex(int readerIndex, int writerIndex);
+
+ /**
+ * Returns the number of readable bytes which is equal to
+ * {@code (this.writerIndex - this.readerIndex)}.
+ */
+ int readableBytes();
+
+ /**
+ * Returns the number of writable bytes which is equal to
+ * {@code (this.capacity - this.writerIndex)}.
+ */
+ int writableBytes();
+
+ /**
+ * Returns {@code true}
+ * if and only if {@code (this.writerIndex - this.readerIndex)} is greater
+ * than {@code 0}.
+ */
+ boolean readable();
+
+ /**
+ * Returns {@code true}
+ * if and only if {@code (this.capacity - this.writerIndex)} is greater
+ * than {@code 0}.
+ */
+ boolean writable();
+
+ /**
+ * Sets the {@code readerIndex} and {@code writerIndex} of this buffer to
+ * {@code 0}.
+ * This method is identical to {@link #setIndex(int, int) setIndex(0, 0)}.
+ * <p>
+ * Please note that the behavior of this method is different
+ * from that of NIO buffer, which sets the {@code limit} to
+ * the {@code capacity} of the buffer.
+ */
+ void clear();
+
+ /**
+ * Marks the current {@code readerIndex} in this buffer. You can
+ * reposition the current {@code readerIndex} to the marked
+ * {@code readerIndex} by calling {@link #resetReaderIndex()}.
+ * The initial value of the marked {@code readerIndex} is {@code 0}.
+ */
+ void markReaderIndex();
+
+ /**
+ * Repositions the current {@code readerIndex} to the marked
+ * {@code readerIndex} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the current {@code writerIndex} is less than the marked
+ * {@code readerIndex}
+ */
+ void resetReaderIndex();
+
+ /**
+ * Marks the current {@code writerIndex} in this buffer. You can
+ * reposition the current {@code writerIndex} to the marked
+ * {@code writerIndex} by calling {@link #resetWriterIndex()}.
+ * The initial value of the marked {@code writerIndex} is {@code 0}.
+ */
+ void markWriterIndex();
+
+ /**
+ * Repositions the current {@code writerIndex} to the marked
+ * {@code writerIndex} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the current {@code readerIndex} is greater than the marked
+ * {@code writerIndex}
+ */
+ void resetWriterIndex();
+
+ /**
+ * Discards the bytes between the 0th index and {@code readerIndex}.
+ * It moves the bytes between {@code readerIndex} and {@code writerIndex}
+ * to the 0th index, and sets {@code readerIndex} and {@code writerIndex}
+ * to {@code 0} and {@code oldWriterIndex - oldReaderIndex} respectively.
+ * <p>
+ * Please refer to the class documentation for more detailed explanation.
+ */
+ void discardReadBytes();
+
+ /**
+ * Gets a byte at the specified absolute {@code index} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 1} is greater than {@code this.capacity}
+ */
+ byte getByte(int index);
+
+ /**
+ * Gets an unsigned byte at the specified absolute {@code index} in this
+ * buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 1} is greater than {@code this.capacity}
+ */
+ short getUnsignedByte(int index);
+
+ /**
+ * Gets a 16-bit short integer at the specified absolute {@code index} in
+ * this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 2} is greater than {@code this.capacity}
+ */
+ short getShort(int index);
+
+ /**
+ * Gets an unsigned 16-bit short integer at the specified absolute
+ * {@code index} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 2} is greater than {@code this.capacity}
+ */
+ int getUnsignedShort(int index);
+
+ /**
+ * Gets a 24-bit medium integer at the specified absolute {@code index} in
+ * this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 3} is greater than {@code this.capacity}
+ */
+ int getMedium(int index);
+
+ /**
+ * Gets an unsigned 24-bit medium integer at the specified absolute
+ * {@code index} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 3} is greater than {@code this.capacity}
+ */
+ int getUnsignedMedium(int index);
+
+ /**
+ * Gets a 32-bit integer at the specified absolute {@code index} in
+ * this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 4} is greater than {@code this.capacity}
+ */
+ int getInt(int index);
+
+ /**
+ * Gets an unsigned 32-bit integer at the specified absolute {@code index}
+ * in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 4} is greater than {@code this.capacity}
+ */
+ long getUnsignedInt(int index);
+
+ /**
+ * Gets a 64-bit long integer at the specified absolute {@code index} in
+ * this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 8} is greater than {@code this.capacity}
+ */
+ long getLong(int index);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the specified absolute {@code index} until the destination becomes
+ * non-writable. This method is basically same with
+ * {@link #getBytes(int, HornetQChannelBuffer, int, int)}, except that this
+ * method increases the {@code writerIndex} of the destination by the
+ * number of the transferred bytes while
+ * {@link #getBytes(int, HornetQChannelBuffer, int, int)} does not.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + dst.writableBytes} is greater than
+ * {@code this.capacity}
+ */
+ void getBytes(int index, HornetQChannelBuffer dst);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the specified absolute {@code index}. This method is basically same
+ * with {@link #getBytes(int, HornetQChannelBuffer, int, int)}, except that this
+ * method increases the {@code writerIndex} of the destination by the
+ * number of the transferred bytes while
+ * {@link #getBytes(int, HornetQChannelBuffer, int, int)} does not.
+ *
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0},
+ * if {@code index + length} is greater than
+ * {@code this.capacity}, or
+ * if {@code length} is greater than {@code dst.writableBytes}
+ */
+ void getBytes(int index, HornetQChannelBuffer dst, int length);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the specified absolute {@code index}.
+ *
+ * @param dstIndex the first index of the destination
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0},
+ * if the specified {@code dstIndex} is less than {@code 0},
+ * if {@code index + length} is greater than
+ * {@code this.capacity}, or
+ * if {@code dstIndex + length} is greater than
+ * {@code dst.capacity}
+ */
+ void getBytes(int index, HornetQChannelBuffer dst, int dstIndex, int length);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the specified absolute {@code index}.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + dst.length} is greater than
+ * {@code this.capacity}
+ */
+ void getBytes(int index, byte[] dst);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the specified absolute {@code index}.
+ *
+ * @param dstIndex the first index of the destination
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0},
+ * if the specified {@code dstIndex} is less than {@code 0},
+ * if {@code index + length} is greater than
+ * {@code this.capacity}, or
+ * if {@code dstIndex + length} is greater than
+ * {@code dst.length}
+ */
+ void getBytes(int index, byte[] dst, int dstIndex, int length);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the specified absolute {@code index} until the destination's position
+ * reaches its limit.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + dst.remaining()} is greater than
+ * {@code this.capacity}
+ */
+ void getBytes(int index, ByteBuffer dst);
+
+ /**
+ * Transfers this buffer's data to the specified stream starting at the
+ * specified absolute {@code index}.
+ *
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + length} is greater than
+ * {@code this.capacity}
+ * @throws IOException
+ * if the specified stream threw an exception during I/O
+ */
+ void getBytes(int index, OutputStream out, int length) throws IOException;
+
+ /**
+ * Transfers this buffer's data to the specified channel starting at the
+ * specified absolute {@code index}.
+ *
+ * @param length the maximum number of bytes to transfer
+ *
+ * @return the actual number of bytes written out to the specified channel
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + length} is greater than
+ * {@code this.capacity}
+ * @throws IOException
+ * if the specified channel threw an exception during I/O
+ */
+ int getBytes(int index, GatheringByteChannel out, int length) throws IOException;
+
+ /**
+ * Sets the specified byte at the specified absolute {@code index} in this
+ * buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 1} is greater than {@code this.capacity}
+ */
+ void setByte(int index, byte value);
+
+ /**
+ * Sets the specified 16-bit short integer at the specified absolute
+ * {@code index} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 2} is greater than {@code this.capacity}
+ */
+ void setShort(int index, short value);
+
+ /**
+ * Sets the specified 24-bit medium integer at the specified absolute
+ * {@code index} in this buffer. Please note that the most significant
+ * byte is ignored in the specified value.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 3} is greater than {@code this.capacity}
+ */
+ void setMedium(int index, int value);
+
+ /**
+ * Sets the specified 32-bit integer at the specified absolute
+ * {@code index} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 4} is greater than {@code this.capacity}
+ */
+ void setInt(int index, int value);
+
+ /**
+ * Sets the specified 64-bit long integer at the specified absolute
+ * {@code index} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * {@code index + 8} is greater than {@code this.capacity}
+ */
+ void setLong(int index, long value);
+
+ /**
+ * Transfers the specified source buffer's data to this buffer starting at
+ * the specified absolute {@code index} until the destination becomes
+ * unreadable. This method is basically same with
+ * {@link #setBytes(int, HornetQChannelBuffer, int, int)}, except that this
+ * method increases the {@code readerIndex} of the source buffer by
+ * the number of the transferred bytes while
+ * {@link #getBytes(int, HornetQChannelBuffer, int, int)} does not.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + src.readableBytes} is greater than
+ * {@code this.capacity}
+ */
+ void setBytes(int index, HornetQChannelBuffer src);
+
+ /**
+ * Transfers the specified source buffer's data to this buffer starting at
+ * the specified absolute {@code index}. This method is basically same
+ * with {@link #setBytes(int, HornetQChannelBuffer, int, int)}, except that this
+ * method increases the {@code readerIndex} of the source buffer by
+ * the number of the transferred bytes while
+ * {@link #getBytes(int, HornetQChannelBuffer, int, int)} does not.
+ *
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0},
+ * if {@code index + length} is greater than
+ * {@code this.capacity}, or
+ * if {@code length} is greater than {@code src.readableBytes}
+ */
+ void setBytes(int index, HornetQChannelBuffer src, int length);
+
+ /**
+ * Transfers the specified source buffer's data to this buffer starting at
+ * the specified absolute {@code index}.
+ *
+ * @param srcIndex the first index of the source
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0},
+ * if the specified {@code srcIndex} is less than {@code 0},
+ * if {@code index + length} is greater than
+ * {@code this.capacity}, or
+ * if {@code srcIndex + length} is greater than
+ * {@code src.capacity}
+ */
+ void setBytes(int index, HornetQChannelBuffer src, int srcIndex, int length);
+
+ /**
+ * Transfers the specified source array's data to this buffer starting at
+ * the specified absolute {@code index}.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + src.length} is greater than
+ * {@code this.capacity}
+ */
+ void setBytes(int index, byte[] src);
+
+ /**
+ * Transfers the specified source array's data to this buffer starting at
+ * the specified absolute {@code index}.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0},
+ * if the specified {@code srcIndex} is less than {@code 0},
+ * if {@code index + length} is greater than
+ * {@code this.capacity}, or
+ * if {@code srcIndex + length} is greater than {@code src.length}
+ */
+ void setBytes(int index, byte[] src, int srcIndex, int length);
+
+ /**
+ * Transfers the specified source buffer's data to this buffer starting at
+ * the specified absolute {@code index} until the source buffer's position
+ * reaches its limit.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + src.remaining()} is greater than
+ * {@code this.capacity}
+ */
+ void setBytes(int index, ByteBuffer src);
+
+ /**
+ * Transfers the content of the specified source stream to this buffer
+ * starting at the specified absolute {@code index}.
+ *
+ * @param length the number of bytes to transfer
+ *
+ * @return the actual number of bytes read in from the specified channel.
+ * {@code -1} if the specified channel is closed.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + length} is greater than {@code this.capacity}
+ * @throws IOException
+ * if the specified stream threw an exception during I/O
+ */
+ int setBytes(int index, InputStream in, int length) throws IOException;
+
+ /**
+ * Transfers the content of the specified source channel to this buffer
+ * starting at the specified absolute {@code index}.
+ *
+ * @param length the maximum number of bytes to transfer
+ *
+ * @return the actual number of bytes read in from the specified channel.
+ * {@code -1} if the specified channel is closed.
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + length} is greater than {@code this.capacity}
+ * @throws IOException
+ * if the specified channel threw an exception during I/O
+ */
+ int setBytes(int index, ScatteringByteChannel in, int length) throws IOException;
+
+ /**
+ * Fills this buffer with <tt>NUL (0x00)</tt> starting at the specified
+ * absolute {@code index}.
+ *
+ * @param length the number of <tt>NUL</tt>s to write to the buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code index} is less than {@code 0} or
+ * if {@code index + length} is greater than {@code this.capacity}
+ */
+ void setZero(int index, int length);
+
+ /**
+ * Gets a byte at the current {@code readerIndex} and increases
+ * the {@code readerIndex} by {@code 1} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.readableBytes} is less than {@code 1}
+ */
+ byte readByte();
+
+ /**
+ * Gets an unsigned byte at the current {@code readerIndex} and increases
+ * the {@code readerIndex} by {@code 1} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.readableBytes} is less than {@code 1}
+ */
+ short readUnsignedByte();
+
+ /**
+ * Gets a 16-bit short integer at the current {@code readerIndex}
+ * and increases the {@code readerIndex} by {@code 2} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.readableBytes} is less than {@code 2}
+ */
+ short readShort();
+
+ /**
+ * Gets an unsigned 16-bit short integer at the current {@code readerIndex}
+ * and increases the {@code readerIndex} by {@code 2} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.readableBytes} is less than {@code 2}
+ */
+ int readUnsignedShort();
+
+ /**
+ * Gets a 24-bit medium integer at the current {@code readerIndex}
+ * and increases the {@code readerIndex} by {@code 3} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.readableBytes} is less than {@code 3}
+ */
+ int readMedium();
+
+ /**
+ * Gets an unsigned 24-bit medium integer at the current {@code readerIndex}
+ * and increases the {@code readerIndex} by {@code 3} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.readableBytes} is less than {@code 3}
+ */
+ int readUnsignedMedium();
+
+ /**
+ * Gets a 32-bit integer at the current {@code readerIndex}
+ * and increases the {@code readerIndex} by {@code 4} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.readableBytes} is less than {@code 4}
+ */
+ int readInt();
+
+ /**
+ * Gets an unsigned 32-bit integer at the current {@code readerIndex}
+ * and increases the {@code readerIndex} by {@code 4} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.readableBytes} is less than {@code 4}
+ */
+ long readUnsignedInt();
+
+ /**
+ * Gets a 64-bit integer at the current {@code readerIndex}
+ * and increases the {@code readerIndex} by {@code 8} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.readableBytes} is less than {@code 8}
+ */
+ long readLong();
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the current {@code readerIndex} until the destination becomes
+ * non-writable, and increases the {@code readerIndex} by the number of the
+ * transferred bytes. This method is basically same with
+ * {@link #readBytes(HornetQChannelBuffer, int, int)}, except that this method
+ * increases the {@code writerIndex} of the destination by the number of
+ * the transferred bytes while {@link #readBytes(HornetQChannelBuffer, int, int)}
+ * does not.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code dst.writableBytes} is greater than
+ * {@code this.readableBytes}
+ */
+ void readBytes(HornetQChannelBuffer dst);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the current {@code readerIndex} and increases the {@code readerIndex}
+ * by the number of the transferred bytes (= {@code length}). This method
+ * is basically same with {@link #readBytes(HornetQChannelBuffer, int, int)},
+ * except that this method increases the {@code writerIndex} of the
+ * destination by the number of the transferred bytes (= {@code length})
+ * while {@link #readBytes(HornetQChannelBuffer, int, int)} does not.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code length} is greater than {@code this.readableBytes} or
+ * if {@code length} is greater than {@code dst.writableBytes}
+ */
+ void readBytes(HornetQChannelBuffer dst, int length);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the current {@code readerIndex} and increases the {@code readerIndex}
+ * by the number of the transferred bytes (= {@code length}).
+ *
+ * @param dstIndex the first index of the destination
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code dstIndex} is less than {@code 0},
+ * if {@code length} is greater than {@code this.readableBytes}, or
+ * if {@code dstIndex + length} is greater than
+ * {@code dst.capacity}
+ */
+ void readBytes(HornetQChannelBuffer dst, int dstIndex, int length);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the current {@code readerIndex} and increases the {@code readerIndex}
+ * by the number of the transferred bytes (= {@code dst.length}).
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code dst.length} is greater than {@code this.readableBytes}
+ */
+ void readBytes(byte[] dst);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the current {@code readerIndex} and increases the {@code readerIndex}
+ * by the number of the transferred bytes (= {@code length}).
+ *
+ * @param dstIndex the first index of the destination
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code dstIndex} is less than {@code 0},
+ * if {@code length} is greater than {@code this.readableBytes}, or
+ * if {@code dstIndex + length} is greater than {@code dst.length}
+ */
+ void readBytes(byte[] dst, int dstIndex, int length);
+
+ /**
+ * Transfers this buffer's data to the specified destination starting at
+ * the current {@code readerIndex} until the destination's position
+ * reaches its limit, and increases the {@code readerIndex} by the
+ * number of the transferred bytes.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code dst.remaining()} is greater than
+ * {@code this.readableBytes}
+ */
+ void readBytes(ByteBuffer dst);
+
+ /**
+ * Transfers this buffer's data to the specified stream starting at the
+ * current {@code readerIndex}.
+ *
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code length} is greater than {@code this.readableBytes}
+ * @throws IOException
+ * if the specified stream threw an exception during I/O
+ */
+ void readBytes(OutputStream out, int length) throws IOException;
+
+ /**
+ * Transfers this buffer's data to the specified stream starting at the
+ * current {@code readerIndex}.
+ *
+ * @param length the maximum number of bytes to transfer
+ *
+ * @return the actual number of bytes written out to the specified channel
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code length} is greater than {@code this.readableBytes}
+ * @throws IOException
+ * if the specified channel threw an exception during I/O
+ */
+ int readBytes(GatheringByteChannel out, int length) throws IOException;
+
+ /**
+ * Increases the current {@code readerIndex} by the specified
+ * {@code length} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code length} is greater than {@code this.readableBytes}
+ */
+ void skipBytes(int length);
+
+ /**
+ * Sets the specified byte at the current {@code writerIndex}
+ * and increases the {@code writerIndex} by {@code 1} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.writableBytes} is less than {@code 1}
+ */
+ void writeByte(byte value);
+
+ /**
+ * Sets the specified 16-bit short integer at the current
+ * {@code writerIndex} and increases the {@code writerIndex} by {@code 2}
+ * in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.writableBytes} is less than {@code 2}
+ */
+ void writeShort(short value);
+
+ /**
+ * Sets the specified 24-bit medium integer at the current
+ * {@code writerIndex} and increases the {@code writerIndex} by {@code 3}
+ * in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.writableBytes} is less than {@code 3}
+ */
+ void writeMedium(int value);
+
+ /**
+ * Sets the specified 32-bit integer at the current {@code writerIndex}
+ * and increases the {@code writerIndex} by {@code 4} in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.writableBytes} is less than {@code 4}
+ */
+ void writeInt(int value);
+
+ /**
+ * Sets the specified 64-bit long integer at the current
+ * {@code writerIndex} and increases the {@code writerIndex} by {@code 8}
+ * in this buffer.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code this.writableBytes} is less than {@code 8}
+ */
+ void writeLong(long value);
+
+ /**
+ * Transfers the specified source buffer's data to this buffer starting at
+ * the current {@code writerIndex} until the source buffer becomes
+ * unreadable, and increases the {@code writerIndex} by the number of
+ * the transferred bytes. This method is basically same with
+ * {@link #writeBytes(HornetQChannelBuffer, int, int)}, except that this method
+ * increases the {@code readerIndex} of the source buffer by the number of
+ * the transferred bytes while {@link #writeBytes(HornetQChannelBuffer, int, int)}
+ * does not.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code src.readableBytes} is greater than
+ * {@code this.writableBytes}
+ *
+ */
+ void writeBytes(HornetQChannelBuffer src);
+
+ /**
+ * Transfers the specified source buffer's data to this buffer starting at
+ * the current {@code writerIndex} and increases the {@code writerIndex}
+ * by the number of the transferred bytes (= {@code length}). This method
+ * is basically same with {@link #writeBytes(HornetQChannelBuffer, int, int)},
+ * except that this method increases the {@code readerIndex} of the source
+ * buffer by the number of the transferred bytes (= {@code length}) while
+ * {@link #writeBytes(HornetQChannelBuffer, int, int)} does not.
+ *
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code length} is greater than {@code this.writableBytes} or
+ * if {@code length} is greater then {@code src.readableBytes}
+ */
+ void writeBytes(HornetQChannelBuffer src, int length);
+
+ /**
+ * Transfers the specified source buffer's data to this buffer starting at
+ * the current {@code writerIndex} and increases the {@code writerIndex}
+ * by the number of the transferred bytes (= {@code length}).
+ *
+ * @param srcIndex the first index of the source
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code srcIndex} is less than {@code 0},
+ * if {@code srcIndex + length} is greater than
+ * {@code src.capacity}, or
+ * if {@code length} is greater than {@code this.writableBytes}
+ */
+ void writeBytes(HornetQChannelBuffer src, int srcIndex, int length);
+
+ /**
+ * Transfers the specified source array's data to this buffer starting at
+ * the current {@code writerIndex} and increases the {@code writerIndex}
+ * by the number of the transferred bytes (= {@code src.length}).
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code src.length} is greater than {@code this.writableBytes}
+ */
+ void writeBytes(byte[] src);
+
+ /**
+ * Transfers the specified source array's data to this buffer starting at
+ * the current {@code writerIndex} and increases the {@code writerIndex}
+ * by the number of the transferred bytes (= {@code length}).
+ *
+ * @param srcIndex the first index of the source
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if the specified {@code srcIndex} is less than {@code 0},
+ * if {@code srcIndex + length} is greater than
+ * {@code src.length}, or
+ * if {@code length} is greater than {@code this.writableBytes}
+ */
+ void writeBytes(byte[] src, int srcIndex, int length);
+
+ /**
+ * Transfers the specified source buffer's data to this buffer starting at
+ * the current {@code writerIndex} until the source buffer's position
+ * reaches its limit, and increases the {@code writerIndex} by the
+ * number of the transferred bytes.
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code src.remaining()} is greater than
+ * {@code this.writableBytes}
+ */
+ void writeBytes(ByteBuffer src);
+
+ /**
+ * Transfers the content of the specified stream to this buffer
+ * starting at the current {@code writerIndex} and increases the
+ * {@code writerIndex} by the number of the transferred bytes.
+ *
+ * @param length the number of bytes to transfer
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code length} is greater than {@code this.writableBytes}
+ * @throws IOException
+ * if the specified stream threw an exception during I/O
+ */
+ void writeBytes(InputStream in, int length) throws IOException;
+
+ /**
+ * Transfers the content of the specified channel to this buffer
+ * starting at the current {@code writerIndex} and increases the
+ * {@code writerIndex} by the number of the transferred bytes.
+ *
+ * @param length the maximum number of bytes to transfer
+ *
+ * @return the actual number of bytes read in from the specified channel
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code length} is greater than {@code this.writableBytes}
+ * @throws IOException
+ * if the specified channel threw an exception during I/O
+ */
+ int writeBytes(ScatteringByteChannel in, int length) throws IOException;
+
+ /**
+ * Fills this buffer with <tt>NUL (0x00)</tt> starting at the current
+ * {@code writerIndex} and increases the {@code writerIndex} by the
+ * specified {@code length}.
+ *
+ * @param length the number of <tt>NUL</tt>s to write to the buffer
+ *
+ * @throws IndexOutOfBoundsException
+ * if {@code length} is greater than {@code this.writableBytes}
+ */
+ void writeZero(int length);
+
+ /**
+ * Converts this buffer's readable bytes into a NIO buffer. The returned
+ * buffer might or might not share the content with this buffer, while
+ * they have separate indexes and marks. This method is identical to
+ * {@code buf.toByteBuffer(buf.readerIndex(), buf.readableBytes())}.
+ */
+ ByteBuffer toByteBuffer();
+
+ /**
+ * Converts this buffer's sub-region into a NIO buffer. The returned
+ * buffer might or might not share the content with this buffer, while
+ * they have separate indexes and marks.
+ */
+ ByteBuffer toByteBuffer(int index, int length);
+
+ /**
+ * Converts this buffer's sub-region into an array of NIO buffers.
+ * The returned buffers might or might not share the content with this
+ * buffer, while they have separate indexes and marks.
+ */
+ ByteBuffer[] toByteBuffers(int index, int length);
+
+ /**
+ * Decodes this buffer's readable bytes into a string with the specified
+ * character set name. This method is identical to
+ * {@code buf.toString(buf.readerIndex(), buf.readableBytes(), charsetName)}.
+ *
+ * @throws UnsupportedCharsetException
+ * if the specified character set name is not supported by the
+ * current VM
+ */
+ String toString(String charsetName);
+
+ /**
+ * Decodes this buffer's sub-region into a string with the specified
+ * character set name.
+ *
+ * @throws UnsupportedCharsetException
+ * if the specified character set name is not supported by the
+ * current VM
+ */
+ String toString(int index, int length, String charsetName);
+
+ /**
+ * Returns a hash code which was calculated from the content of this
+ * buffer. If there's a byte array which is
+ * {@linkplain #equals(Object) equal to} this array, both arrays should
+ * return the same value.
+ */
+ int hashCode();
+
+ /**
+ * Determines if the content of the specified buffer is identical to the
+ * content of this array. 'Identical' here means:
+ * <ul>
+ * <li>the size of the contents of the two buffers are same and</li>
+ * <li>every single byte of the content of the two buffers are same.</li>
+ * </ul>
+ * Please note that it does not compare {@link #readerIndex()} nor
+ * {@link #writerIndex()}. This method also returns {@code false} for
+ * {@code null} and an object which is not an instance of
+ * {@link HornetQChannelBuffer} type.
+ */
+ boolean equals(Object obj);
+
+ /**
+ * Compares the content of the specified buffer to the content of this
+ * buffer. Comparison is performed in the same manner with the string
+ * comparison functions of various languages such as {@code strcmp},
+ * {@code memcmp} and {@link String#compareTo(String)}.
+ */
+ int compareTo(HornetQChannelBuffer buffer);
+
+ /**
+ * Returns the string representation of this buffer. This method does not
+ * necessarily return the whole content of the buffer but returns
+ * the values of the key properties such as {@link #readerIndex()},
+ * {@link #writerIndex()} and {@link #capacity()}.
+ */
+ String toString();
+}
Copied: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffers.java (from rev 8288, branches/20-optimisation/src/main/org/hornetq/core/buffers/ChannelBuffers.java)
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffers.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffers.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -0,0 +1,469 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.core.buffers;
+
+import java.nio.ByteBuffer;
+
+/**
+ * Creates a new {@link HornetQChannelBuffer} by allocating new space or by wrapping
+ * or copying existing byte arrays, byte buffers and a string.
+ *
+ * <h3>Use static import</h3>
+ * This classes is intended to be used with Java 5 static import statement:
+ *
+ * <pre>
+ * import static org.jboss.netty.buffer.ChannelBuffers.*;
+ *
+ * ChannelBuffer heapBuffer = buffer(128);
+ * ChannelBuffer directBuffer = directBuffer(256);
+ * ChannelBuffer dynamicBuffer = dynamicBuffer(512);
+ * ChannelBuffer wrappedBuffer = wrappedBuffer(new byte[128], new byte[256]);
+ * ChannelBuffer copiedBuffer = copiedBuffer(ByteBuffer.allocate(128));
+ * </pre>
+ *
+ * <h3>Allocating a new buffer</h3>
+ *
+ * Three buffer types are provided out of the box.
+ *
+ * <ul>
+ * <li>{@link #buffer(int)} allocates a new fixed-capacity heap buffer.</li>
+ * <li>{@link #directBuffer(int)} allocates a new fixed-capacity direct buffer.</li>
+ * <li>{@link #dynamicBuffer(int)} allocates a new dynamic-capacity heap
+ * buffer, whose capacity increases automatically as needed by a write
+ * operation.</li>
+ * </ul>
+ *
+ * <h3>Creating a wrapped buffer</h3>
+ *
+ * Wrapped buffer is a buffer which is a view of one or more existing
+ * byte arrays and byte buffers. Any changes in the content of the original
+ * array or buffer will be reflected in the wrapped buffer. Various wrapper
+ * methods are provided and their name is all {@code wrappedBuffer()}.
+ * You might want to take a look at this method closely if you want to create
+ * a buffer which is composed of more than one array to reduce the number of
+ * memory copy.
+ *
+ * <h3>Creating a copied buffer</h3>
+ *
+ * Copied buffer is a deep copy of one or more existing byte arrays, byte
+ * buffers or a string. Unlike a wrapped buffer, there's no shared data
+ * between the original data and the copied buffer. Various copy methods are
+ * provided and their name is all {@code copiedBuffer()}. It is also convenient
+ * to use this operation to merge multiple buffers into one buffer.
+ *
+ * <h3>Miscellaneous utility methods</h3>
+ *
+ * This class also provides various utility methods to help implementation
+ * of a new buffer type, generation of hex dump and swapping an integer's
+ * byte order.
+ *
+ * @author The Netty Project (netty-dev(a)lists.jboss.org)
+ * @author Trustin Lee (tlee(a)redhat.com)
+ *
+ * @version $Rev: 472 $, $Date: 2008-11-14 16:45:53 +0900 (Fri, 14 Nov 2008) $
+ *
+ * @apiviz.landmark
+ */
+public class HornetQChannelBuffers
+{
+
+ /**
+ * A buffer whose capacity is {@code 0}.
+ */
+ public static final HornetQHeapChannelBuffer EMPTY_BUFFER = new HornetQHeapChannelBuffer(0);
+
+ private static final char[] HEXDUMP_TABLE = new char[65536 * 4];
+
+ static
+ {
+ final char[] DIGITS = "0123456789abcdef".toCharArray();
+ for (int i = 0; i < 65536; i++)
+ {
+ HEXDUMP_TABLE[(i << 2) + 0] = DIGITS[i >>> 12 & 0x0F];
+ HEXDUMP_TABLE[(i << 2) + 1] = DIGITS[i >>> 8 & 0x0F];
+ HEXDUMP_TABLE[(i << 2) + 2] = DIGITS[i >>> 4 & 0x0F];
+ HEXDUMP_TABLE[(i << 2) + 3] = DIGITS[i >>> 0 & 0x0F];
+ }
+ }
+
+ /**
+ * Creates a new Java heap buffer with the specified {@code endianness}
+ * and {@code capacity}. The new buffer's {@code readerIndex} and
+ * {@code writerIndex} are {@code 0}.
+ */
+ public static HornetQChannelBuffer buffer(final int capacity)
+ {
+ if (capacity == 0)
+ {
+ return EMPTY_BUFFER;
+ }
+ else
+ {
+ return new HornetQHeapChannelBuffer(capacity);
+ }
+ }
+
+ /**
+ * Reuses the initialBuffer on the creation of the DynamicBuffer.
+ * This avoids a copy, but you should only call this method if the buffer is not being modified after the call of this method.
+ *
+ * @author Clebert
+ */
+ public static HornetQChannelBuffer dynamicBuffer(final byte[] initialBuffer)
+ {
+ return new HornetQDynamicChannelBuffer(initialBuffer);
+ }
+
+ /**
+ * Creates a new dynamic buffer with the specified endianness and
+ * the specified estimated data length. More accurate estimation yields
+ * less unexpected reallocation overhead. The new buffer's
+ * {@code readerIndex} and {@code writerIndex} are {@code 0}.
+ */
+ public static HornetQChannelBuffer dynamicBuffer(final int estimatedLength)
+ {
+ return new HornetQDynamicChannelBuffer(estimatedLength);
+ }
+
+ /**
+ * Creates a new buffer which wraps the specified {@code array} with the
+ * specified {@code endianness}. A modification on the specified array's
+ * content will be visible to the returned buffer.
+ */
+ public static HornetQChannelBuffer wrappedBuffer(final byte[] array)
+ {
+ return new HornetQHeapChannelBuffer(array);
+ }
+
+ /**
+ * Creates a new buffer which wraps the specified NIO buffer's current
+ * slice. A modification on the specified buffer's content and endianness
+ * will be visible to the returned buffer.
+ * The new buffer's {@code readerIndex}
+ * and {@code writerIndex} are {@code 0} and {@code buffer.remaining}
+ * respectively.
+ *
+ * Note: This method differs from the Original Netty version.
+ *
+ * @author Clebert
+ */
+ public static HornetQChannelBuffer wrappedBuffer(final ByteBuffer buffer)
+ {
+
+ HornetQChannelBuffer newbuffer = new HornetQByteBufferBackedChannelBuffer(buffer);
+ newbuffer.clear();
+ return newbuffer;
+ }
+
+ /**
+ * Creates a new buffer with the specified {@code endianness} whose
+ * content is a copy of the specified {@code array}. The new buffer's
+ * {@code readerIndex} and {@code writerIndex} are {@code 0} and
+ * {@code array.length} respectively.
+ */
+// public static HornetQChannelBuffer copiedBuffer(final byte[] array)
+// {
+// if (array.length == 0)
+// {
+// return EMPTY_BUFFER;
+// }
+// else
+// {
+// return new HornetQHeapChannelBuffer(array.clone());
+// }
+// }
+//
+// /**
+// * Creates a new buffer whose content is a copy of the specified
+// * {@code buffer}'s current slice. The new buffer's {@code readerIndex}
+// * and {@code writerIndex} are {@code 0} and {@code buffer.remaining}
+// * respectively.
+// */
+// public static HornetQChannelBuffer copiedBuffer(final ByteBuffer buffer)
+// {
+// int length = buffer.remaining();
+// if (length == 0)
+// {
+// return EMPTY_BUFFER;
+// }
+// byte[] copy = new byte[length];
+// int position = buffer.position();
+// try
+// {
+// buffer.get(copy);
+// }
+// finally
+// {
+// buffer.position(position);
+// }
+// return wrappedBuffer(copy);
+// }
+//
+// /**
+// * Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a>
+// * of the specified buffer's readable bytes.
+// */
+// public static String hexDump(final HornetQChannelBuffer buffer)
+// {
+// return hexDump(buffer, buffer.readerIndex(), buffer.readableBytes());
+// }
+//
+// /**
+// * Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a>
+// * of the specified buffer's sub-region.
+// */
+// public static String hexDump(final HornetQChannelBuffer buffer, final int fromIndex, final int length)
+// {
+// if (length < 0)
+// {
+// throw new IllegalArgumentException("length: " + length);
+// }
+// if (length == 0)
+// {
+// return "";
+// }
+//
+// int endIndex = fromIndex + (length >>> 1 << 1);
+// boolean oddLength = length % 2 != 0;
+// char[] buf = new char[length << 1];
+//
+// int srcIdx = fromIndex;
+// int dstIdx = 0;
+// for (; srcIdx < endIndex; srcIdx += 2, dstIdx += 4)
+// {
+// System.arraycopy(HEXDUMP_TABLE, buffer.getUnsignedShort(srcIdx) << 2, buf, dstIdx, 4);
+// }
+//
+// if (oddLength)
+// {
+// System.arraycopy(HEXDUMP_TABLE, (buffer.getUnsignedByte(srcIdx) << 2) + 2, buf, dstIdx, 2);
+// }
+//
+// return new String(buf);
+// }
+//
+ /**
+ * Calculates the hash code of the specified buffer. This method is
+ * useful when implementing a new buffer type.
+ */
+ public static int hashCode(final HornetQChannelBuffer buffer)
+ {
+ final int aLen = buffer.readableBytes();
+ final int intCount = aLen >>> 2;
+ final int byteCount = aLen & 3;
+
+ int hashCode = 1;
+ int arrayIndex = buffer.readerIndex();
+ for (int i = intCount; i > 0; i--)
+ {
+ hashCode = 31 * hashCode + buffer.getInt(arrayIndex);
+ arrayIndex += 4;
+ }
+
+ for (int i = byteCount; i > 0; i--)
+ {
+ hashCode = 31 * hashCode + buffer.getByte(arrayIndex++);
+ }
+
+ if (hashCode == 0)
+ {
+ hashCode = 1;
+ }
+
+ return hashCode;
+ }
+
+ /**
+ * Returns {@code true} if and only if the two specified buffers are
+ * identical to each other as described in {@code ChannelBuffer#equals(Object)}.
+ * This method is useful when implementing a new buffer type.
+ */
+ public static boolean equals(final HornetQChannelBuffer bufferA, final HornetQChannelBuffer bufferB)
+ {
+ final int aLen = bufferA.readableBytes();
+ if (aLen != bufferB.readableBytes())
+ {
+ return false;
+ }
+
+ final int longCount = aLen >>> 3;
+ final int byteCount = aLen & 7;
+
+ int aIndex = bufferA.readerIndex();
+ int bIndex = bufferB.readerIndex();
+
+ for (int i = longCount; i > 0; i--)
+ {
+ if (bufferA.getLong(aIndex) != bufferB.getLong(bIndex))
+ {
+ return false;
+ }
+ aIndex += 8;
+ bIndex += 8;
+ }
+
+ for (int i = byteCount; i > 0; i--)
+ {
+ if (bufferA.getByte(aIndex) != bufferB.getByte(bIndex))
+ {
+ return false;
+ }
+ aIndex++;
+ bIndex++;
+ }
+
+ return true;
+ }
+
+ /**
+ * Compares the two specified buffers as described in {@link HornetQChannelBuffer#compareTo(HornetQChannelBuffer)}.
+ * This method is useful when implementing a new buffer type.
+ */
+ public static int compare(final HornetQChannelBuffer bufferA, final HornetQChannelBuffer bufferB)
+ {
+ final int aLen = bufferA.readableBytes();
+ final int bLen = bufferB.readableBytes();
+ final int minLength = Math.min(aLen, bLen);
+ final int uintCount = minLength >>> 2;
+ final int byteCount = minLength & 3;
+
+ int aIndex = bufferA.readerIndex();
+ int bIndex = bufferB.readerIndex();
+
+ for (int i = uintCount; i > 0; i--)
+ {
+ long va = bufferA.getUnsignedInt(aIndex);
+ long vb = bufferB.getUnsignedInt(bIndex);
+ if (va > vb)
+ {
+ return 1;
+ }
+ else if (va < vb)
+ {
+ return -1;
+ }
+ aIndex += 4;
+ bIndex += 4;
+ }
+
+ for (int i = byteCount; i > 0; i--)
+ {
+ byte va = bufferA.getByte(aIndex);
+ byte vb = bufferB.getByte(bIndex);
+ if (va > vb)
+ {
+ return 1;
+ }
+ else if (va < vb)
+ {
+ return -1;
+ }
+ aIndex++;
+ bIndex++;
+ }
+
+ return aLen - bLen;
+ }
+//
+// /**
+// * The default implementation of {@link HornetQChannelBuffer#indexOf(int, int, byte)}.
+// * This method is useful when implementing a new buffer type.
+// */
+// public static int indexOf(final HornetQChannelBuffer buffer, final int fromIndex, final int toIndex, final byte value)
+// {
+// if (fromIndex <= toIndex)
+// {
+// return firstIndexOf(buffer, fromIndex, toIndex, value);
+// }
+// else
+// {
+// return lastIndexOf(buffer, fromIndex, toIndex, value);
+// }
+// }
+//
+// /**
+// * Toggles the endianness of the specified 16-bit short integer.
+// */
+// public static short swapShort(final short value)
+// {
+// return (short)(value << 8 | value >>> 8 & 0xff);
+// }
+//
+// /**
+// * Toggles the endianness of the specified 24-bit medium integer.
+// */
+// public static int swapMedium(final int value)
+// {
+// return value << 16 & 0xff0000 | value & 0xff00 | value >>> 16 & 0xff;
+// }
+//
+// /**
+// * Toggles the endianness of the specified 32-bit integer.
+// */
+// public static int swapInt(final int value)
+// {
+// return swapShort((short)value) << 16 | swapShort((short)(value >>> 16)) & 0xffff;
+// }
+//
+// /**
+// * Toggles the endianness of the specified 64-bit long integer.
+// */
+// public static long swapLong(final long value)
+// {
+// return (long)swapInt((int)value) << 32 | swapInt((int)(value >>> 32)) & 0xffffffffL;
+// }
+//
+// private static int firstIndexOf(final HornetQChannelBuffer buffer, int fromIndex, final int toIndex, final byte value)
+// {
+// fromIndex = Math.max(fromIndex, 0);
+// if (fromIndex >= toIndex || buffer.capacity() == 0)
+// {
+// return -1;
+// }
+//
+// for (int i = fromIndex; i < toIndex; i++)
+// {
+// if (buffer.getByte(i) == value)
+// {
+// return i;
+// }
+// }
+//
+// return -1;
+// }
+//
+// private static int lastIndexOf(final HornetQChannelBuffer buffer, int fromIndex, final int toIndex, final byte value)
+// {
+// fromIndex = Math.min(fromIndex, buffer.capacity());
+// if (fromIndex < 0 || buffer.capacity() == 0)
+// {
+// return -1;
+// }
+//
+// for (int i = fromIndex - 1; i >= toIndex; i--)
+// {
+// if (buffer.getByte(i) == value)
+// {
+// return i;
+// }
+// }
+//
+// return -1;
+// }
+
+ private HornetQChannelBuffers()
+ {
+ // Unused
+ }
+}
Copied: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQDynamicChannelBuffer.java (from rev 8288, branches/20-optimisation/src/main/org/hornetq/core/buffers/DynamicChannelBuffer.java)
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQDynamicChannelBuffer.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQDynamicChannelBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -0,0 +1,282 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.core.buffers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.GatheringByteChannel;
+import java.nio.channels.ScatteringByteChannel;
+
+import org.hornetq.core.remoting.spi.HornetQBuffer;
+
+/**
+ * A dynamic capacity buffer which increases its capacity as needed. It is
+ * recommended to use {@link HornetQChannelBuffers#dynamicBuffer(int)} instead of
+ * calling the constructor explicitly.
+ *
+ * @author The Netty Project (netty-dev(a)lists.jboss.org)
+ * @author Trustin Lee (tlee(a)redhat.com)
+ *
+ * @version $Rev: 237 $, $Date: 2008-09-04 20:53:44 +0900 (Thu, 04 Sep 2008) $
+ *
+ */
+public class HornetQDynamicChannelBuffer extends HornetQAbstractChannelBuffer
+{
+ private final int initialCapacity;
+
+ private HornetQChannelBuffer buffer = HornetQChannelBuffers.EMPTY_BUFFER;
+
+ HornetQDynamicChannelBuffer(final int estimatedLength)
+ {
+ if (estimatedLength < 0)
+ {
+ throw new IllegalArgumentException("estimatedLength: " + estimatedLength);
+ }
+ initialCapacity = estimatedLength;
+ }
+
+ HornetQDynamicChannelBuffer(final byte[] initialBuffer)
+ {
+ initialCapacity = initialBuffer.length;
+
+ buffer = new HornetQHeapChannelBuffer(initialBuffer);
+
+ writerIndex(initialBuffer.length);
+ }
+
+ public int capacity()
+ {
+ return buffer.capacity();
+ }
+
+ public byte getByte(final int index)
+ {
+ return buffer.getByte(index);
+ }
+
+ public short getShort(final int index)
+ {
+ return buffer.getShort(index);
+ }
+
+ public int getUnsignedMedium(final int index)
+ {
+ return buffer.getUnsignedMedium(index);
+ }
+
+ public int getInt(final int index)
+ {
+ return buffer.getInt(index);
+ }
+
+ public long getLong(final int index)
+ {
+ return buffer.getLong(index);
+ }
+
+ public void getBytes(final int index, final byte[] dst, final int dstIndex, final int length)
+ {
+ buffer.getBytes(index, dst, dstIndex, length);
+ }
+
+ public void getBytes(final int index, final HornetQChannelBuffer dst, final int dstIndex, final int length)
+ {
+ buffer.getBytes(index, dst, dstIndex, length);
+ }
+
+ public void getBytes(final int index, final ByteBuffer dst)
+ {
+ buffer.getBytes(index, dst);
+ }
+
+ public int getBytes(final int index, final GatheringByteChannel out, final int length) throws IOException
+ {
+ return buffer.getBytes(index, out, length);
+ }
+
+ public void getBytes(final int index, final OutputStream out, final int length) throws IOException
+ {
+ buffer.getBytes(index, out, length);
+ }
+
+ public void setByte(final int index, final byte value)
+ {
+ buffer.setByte(index, value);
+ }
+
+ public void setShort(final int index, final short value)
+ {
+ buffer.setShort(index, value);
+ }
+
+ public void setMedium(final int index, final int value)
+ {
+ buffer.setMedium(index, value);
+ }
+
+ public void setInt(final int index, final int value)
+ {
+ buffer.setInt(index, value);
+ }
+
+ public void setLong(final int index, final long value)
+ {
+ buffer.setLong(index, value);
+ }
+
+ public void setBytes(final int index, final byte[] src, final int srcIndex, final int length)
+ {
+ buffer.setBytes(index, src, srcIndex, length);
+ }
+
+ public void setBytes(final int index, final HornetQChannelBuffer src, final int srcIndex, final int length)
+ {
+ buffer.setBytes(index, src, srcIndex, length);
+ }
+
+ public void setBytes(final int index, final ByteBuffer src)
+ {
+ buffer.setBytes(index, src);
+ }
+
+ public int setBytes(final int index, final InputStream in, final int length) throws IOException
+ {
+ return buffer.setBytes(index, in, length);
+ }
+
+ public int setBytes(final int index, final ScatteringByteChannel in, final int length) throws IOException
+ {
+ return buffer.setBytes(index, in, length);
+ }
+
+ @Override
+ public void writeByte(final byte value)
+ {
+ ensureWritableBytes(1);
+ super.writeByte(value);
+ }
+
+ @Override
+ public void writeShort(final short value)
+ {
+ ensureWritableBytes(2);
+ super.writeShort(value);
+ }
+
+ @Override
+ public void writeMedium(final int value)
+ {
+ ensureWritableBytes(3);
+ super.writeMedium(value);
+ }
+
+ @Override
+ public void writeInt(final int value)
+ {
+ ensureWritableBytes(4);
+ super.writeInt(value);
+ }
+
+ @Override
+ public void writeLong(final long value)
+ {
+ ensureWritableBytes(8);
+ super.writeLong(value);
+ }
+
+ @Override
+ public void writeBytes(final byte[] src, final int srcIndex, final int length)
+ {
+ ensureWritableBytes(length);
+ super.writeBytes(src, srcIndex, length);
+ }
+
+ @Override
+ public void writeBytes(final HornetQChannelBuffer src, final int srcIndex, final int length)
+ {
+ ensureWritableBytes(length);
+ super.writeBytes(src, srcIndex, length);
+ }
+
+ @Override
+ public void writeBytes(final ByteBuffer src)
+ {
+ ensureWritableBytes(src.remaining());
+ super.writeBytes(src);
+ }
+
+ @Override
+ public void writeZero(final int length)
+ {
+ ensureWritableBytes(length);
+ super.writeZero(length);
+ }
+
+ public ByteBuffer toByteBuffer(final int index, final int length)
+ {
+ return buffer.toByteBuffer(index, length);
+ }
+
+ public String toString(final int index, final int length, final String charsetName)
+ {
+ return buffer.toString(index, length, charsetName);
+ }
+
+ private void ensureWritableBytes(final int requestedBytes)
+ {
+ if (requestedBytes <= writableBytes())
+ {
+ return;
+ }
+
+ int newCapacity;
+ if (capacity() == 0)
+ {
+ newCapacity = initialCapacity;
+ if (newCapacity == 0)
+ {
+ newCapacity = 1;
+ }
+ }
+ else
+ {
+ newCapacity = capacity();
+ }
+ int minNewCapacity = writerIndex() + requestedBytes;
+ while (newCapacity < minNewCapacity)
+ {
+ newCapacity <<= 1;
+ }
+
+ HornetQChannelBuffer newBuffer = HornetQChannelBuffers.buffer(newCapacity);
+ newBuffer.writeBytes(buffer, 0, writerIndex());
+ buffer = newBuffer;
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.buffers.AbstractChannelBuffer#array()
+ */
+ public byte[] array()
+ {
+ return buffer.array();
+ }
+
+ public HornetQBuffer copy()
+ {
+ return new HornetQDynamicChannelBuffer(buffer.copy().array());
+ }
+
+}
Copied: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQHeapChannelBuffer.java (from rev 8288, branches/20-optimisation/src/main/org/hornetq/core/buffers/HeapChannelBuffer.java)
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQHeapChannelBuffer.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQHeapChannelBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -0,0 +1,317 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.core.buffers;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.GatheringByteChannel;
+import java.nio.channels.ScatteringByteChannel;
+import java.nio.charset.UnsupportedCharsetException;
+
+import org.hornetq.core.remoting.spi.HornetQBuffer;
+
+/**
+ * A skeletal implementation for Java heap buffers.
+ *
+ * @author The Netty Project (netty-dev(a)lists.jboss.org)
+ * @author Trustin Lee (tlee(a)redhat.com)
+ *
+ * @version $Rev: 486 $, $Date: 2008-11-16 22:52:47 +0900 (Sun, 16 Nov 2008) $
+ */
+public class HornetQHeapChannelBuffer extends HornetQAbstractChannelBuffer
+{
+
+ /**
+ * The underlying heap byte array that this buffer is wrapping.
+ */
+ protected final byte[] array;
+
+ /**
+ * Creates a new heap buffer with a newly allocated byte array.
+ *
+ * @param length the length of the new byte array
+ */
+ HornetQHeapChannelBuffer(final int length)
+ {
+ this(new byte[length], 0, 0);
+ }
+
+ /**
+ * Creates a new heap buffer with an existing byte array.
+ *
+ * @param array the byte array to wrap
+ */
+ HornetQHeapChannelBuffer(final byte[] array)
+ {
+ this(array, 0, array.length);
+ }
+
+ /**
+ * Creates a new heap buffer with an existing byte array.
+ *
+ * @param array the byte array to wrap
+ * @param readerIndex the initial reader index of this buffer
+ * @param writerIndex the initial writer index of this buffer
+ */
+ protected HornetQHeapChannelBuffer(final byte[] array, final int readerIndex, final int writerIndex)
+ {
+ if (array == null)
+ {
+ throw new NullPointerException("array");
+ }
+ this.array = array;
+ setIndex(readerIndex, writerIndex);
+ }
+
+ public int capacity()
+ {
+ return array.length;
+ }
+
+ public byte getByte(final int index)
+ {
+ return array[index];
+ }
+
+ public void getBytes(final int index, final HornetQChannelBuffer dst, final int dstIndex, final int length)
+ {
+ if (dst instanceof HornetQHeapChannelBuffer)
+ {
+ getBytes(index, ((HornetQHeapChannelBuffer)dst).array, dstIndex, length);
+ }
+ else
+ {
+ dst.setBytes(dstIndex, array, index, length);
+ }
+ }
+
+ public void getBytes(final int index, final byte[] dst, final int dstIndex, final int length)
+ {
+ System.arraycopy(array, index, dst, dstIndex, length);
+ }
+
+ public void getBytes(final int index, final ByteBuffer dst)
+ {
+ dst.put(array, index, Math.min(capacity() - index, dst.remaining()));
+ }
+
+ public void getBytes(final int index, final OutputStream out, final int length) throws IOException
+ {
+ out.write(array, index, length);
+ }
+
+ public int getBytes(final int index, final GatheringByteChannel out, final int length) throws IOException
+ {
+ return out.write(ByteBuffer.wrap(array, index, length));
+ }
+
+ public void setByte(final int index, final byte value)
+ {
+ array[index] = value;
+ }
+
+ public void setBytes(final int index, final HornetQChannelBuffer src, final int srcIndex, final int length)
+ {
+ if (src instanceof HornetQHeapChannelBuffer)
+ {
+ setBytes(index, ((HornetQHeapChannelBuffer)src).array, srcIndex, length);
+ }
+ else
+ {
+ src.getBytes(srcIndex, array, index, length);
+ }
+ }
+
+ public void setBytes(final int index, final byte[] src, final int srcIndex, final int length)
+ {
+ System.arraycopy(src, srcIndex, array, index, length);
+ }
+
+ public void setBytes(final int index, final ByteBuffer src)
+ {
+ src.get(array, index, src.remaining());
+ }
+
+ public int setBytes(int index, final InputStream in, int length) throws IOException
+ {
+ int readBytes = 0;
+ do
+ {
+ int localReadBytes = in.read(array, index, length);
+ if (localReadBytes < 0)
+ {
+ if (readBytes == 0)
+ {
+ return -1;
+ }
+ else
+ {
+ break;
+ }
+ }
+ readBytes += localReadBytes;
+ index += localReadBytes;
+ length -= localReadBytes;
+ }
+ while (length > 0);
+
+ return readBytes;
+ }
+
+ public int setBytes(final int index, final ScatteringByteChannel in, final int length) throws IOException
+ {
+ ByteBuffer buf = ByteBuffer.wrap(array, index, length);
+ int readBytes = 0;
+
+ do
+ {
+ int localReadBytes;
+ try
+ {
+ localReadBytes = in.read(buf);
+ }
+ catch (ClosedChannelException e)
+ {
+ localReadBytes = -1;
+ }
+ if (localReadBytes < 0)
+ {
+ if (readBytes == 0)
+ {
+ return -1;
+ }
+ else
+ {
+ break;
+ }
+ }
+ else if (localReadBytes == 0)
+ {
+ break;
+ }
+ readBytes += localReadBytes;
+ }
+ while (readBytes < length);
+
+ return readBytes;
+ }
+
+ public short getShort(final int index)
+ {
+ return (short)(array[index] << 8 | array[index + 1] & 0xFF);
+ }
+
+ public int getUnsignedMedium(final int index)
+ {
+ return (array[index] & 0xff) << 16 | (array[index + 1] & 0xff) << 8 | (array[index + 2] & 0xff) << 0;
+ }
+
+ public int getInt(final int index)
+ {
+ return (array[index] & 0xff) << 24 | (array[index + 1] & 0xff) << 16 |
+ (array[index + 2] & 0xff) << 8 |
+ (array[index + 3] & 0xff) << 0;
+ }
+
+ public long getLong(final int index)
+ {
+ return ((long)array[index] & 0xff) << 56 | ((long)array[index + 1] & 0xff) << 48 |
+ ((long)array[index + 2] & 0xff) << 40 |
+ ((long)array[index + 3] & 0xff) << 32 |
+ ((long)array[index + 4] & 0xff) << 24 |
+ ((long)array[index + 5] & 0xff) << 16 |
+ ((long)array[index + 6] & 0xff) << 8 |
+ ((long)array[index + 7] & 0xff) << 0;
+ }
+
+ public void setShort(final int index, final short value)
+ {
+ array[index] = (byte)(value >>> 8);
+ array[index + 1] = (byte)(value >>> 0);
+ }
+
+ public void setMedium(final int index, final int value)
+ {
+ array[index] = (byte)(value >>> 16);
+ array[index + 1] = (byte)(value >>> 8);
+ array[index + 2] = (byte)(value >>> 0);
+ }
+
+ public void setInt(final int index, final int value)
+ {
+ array[index] = (byte)(value >>> 24);
+ array[index + 1] = (byte)(value >>> 16);
+ array[index + 2] = (byte)(value >>> 8);
+ array[index + 3] = (byte)(value >>> 0);
+ }
+
+ public void setLong(final int index, final long value)
+ {
+ array[index] = (byte)(value >>> 56);
+ array[index + 1] = (byte)(value >>> 48);
+ array[index + 2] = (byte)(value >>> 40);
+ array[index + 3] = (byte)(value >>> 32);
+ array[index + 4] = (byte)(value >>> 24);
+ array[index + 5] = (byte)(value >>> 16);
+ array[index + 6] = (byte)(value >>> 8);
+ array[index + 7] = (byte)(value >>> 0);
+ }
+
+ public HornetQChannelBuffer copy(final int index, final int length)
+ {
+ if (index < 0 || length < 0 || index + length > array.length)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+
+ byte[] copiedArray = new byte[length];
+ System.arraycopy(array, index, copiedArray, 0, length);
+ return new HornetQHeapChannelBuffer(copiedArray);
+ }
+
+ public ByteBuffer toByteBuffer(final int index, final int length)
+ {
+ return ByteBuffer.wrap(array, index, length);
+ }
+
+ public String toString(final int index, final int length, final String charsetName)
+ {
+ try
+ {
+ return new String(array, index, length, charsetName);
+ }
+ catch (UnsupportedEncodingException e)
+ {
+ throw new UnsupportedCharsetException(charsetName);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.remoting.spi.HornetQBuffer#array()
+ */
+ public byte[] array()
+ {
+ return array;
+ }
+
+ public HornetQBuffer copy()
+ {
+ return new HornetQHeapChannelBuffer(array.clone());
+ }
+
+}
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/ClientMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/ClientMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/ClientMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -36,12 +36,10 @@
void acknowledge() throws HornetQException;
- void encodeToBuffer();
-
void decode(HornetQBuffer buffer);
-
-
+ void resetBuffer();
+
//FIXME - the following are only used for large messages - they should be put somewhere else:
/** Sets the OutputStream that will receive the content of a message received in a non blocking way
@@ -61,5 +59,5 @@
void decodeHeadersAndProperties(HornetQBuffer buffer);
- void setBodyInputStream(InputStream bodyInputStream);
+ void setBodyInputStream(InputStream bodyInputStream);
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/ClientSessionFactory.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/ClientSessionFactory.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/ClientSessionFactory.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -170,6 +170,10 @@
void setDiscoveryRefreshTimeout(long discoveryRefreshTimeout);
+ int getInitialMessagePacketSize();
+
+ void setInitialMessagePacketSize(int size);
+
void addInterceptor(Interceptor interceptor);
boolean removeInterceptor(Interceptor interceptor);
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientConsumerImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -17,7 +17,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicLong;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.MessageHandler;
import org.hornetq.core.exception.HornetQException;
@@ -483,13 +483,15 @@
// Flow control for the first packet, we will have others
- flowControl(packet.getRequiredBufferSize(), false);
+ flowControl(packet.getPacketSize(), false);
ClientMessageInternal currentChunkMessage = new ClientMessageImpl();
currentChunkMessage.setDeliveryCount(packet.getDeliveryCount());
- currentChunkMessage.decodeHeadersAndProperties(ChannelBuffers.wrappedBuffer(packet.getLargeMessageHeader()));
+ //FIXME - this is really inefficient - decoding from a buffer to a byte[] then from the byte[] to another buffer
+ //which is then decoded to form the message! Clebert, what were you thinking?
+ currentChunkMessage.decodeHeadersAndProperties(HornetQChannelBuffers.wrappedBuffer(packet.getLargeMessageHeader()));
currentChunkMessage.setLargeMessage(true);
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientMessageImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientMessageImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientMessageImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -23,8 +23,10 @@
import org.hornetq.core.message.impl.MessageImpl;
import org.hornetq.core.remoting.impl.wireformat.PacketImpl;
import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.integration.transports.netty.ChannelBufferWrapper;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.SimpleString;
+import org.jboss.netty.buffer.ChannelBuffer;
/**
*
@@ -67,9 +69,11 @@
final long expiration,
final long timestamp,
final byte priority,
- final HornetQBuffer body)
+ final HornetQBuffer buffer)
{
- super(type, durable, expiration, timestamp, priority, body);
+ super(type, durable, expiration, timestamp, priority, buffer);
+
+ this.resetBuffer();
}
public void onReceipt(final ClientConsumerInternal consumer)
@@ -94,14 +98,6 @@
consumer.acknowledge(this);
}
}
-
-// @Override
-// public void decode(final HornetQBuffer buffer)
-// {
-// decodeHeadersAndProperties(buffer);
-//
-// this.buffer = buffer;
-// }
public int getFlowControlSize()
{
@@ -133,18 +129,33 @@
this.largeMessage = largeMessage;
}
- public void encodeToBuffer()
- {
- //We need to set a byte to work around a Netty bug with Dynamic buffers - this line can be removed
- //when it's fixed in Netty
- buffer.writeByte((byte)0);
-
- //And we leave an extra byte where we store the body length (to be filled in later)
- buffer.setIndex(0, PacketImpl.PACKET_HEADERS_SIZE + DataConstants.SIZE_INT);
+ @Override
+ public void afterSend()
+ {
+ //temp hack
- encodeHeadersAndProperties(buffer);
+// ChannelBuffer cb = (ChannelBuffer)buffer.getUnderlyingBuffer();
+//
+// ChannelBuffer cbCopy = cb.copy(0, cb.capacity());
+//
+// this.buffer = new ChannelBufferWrapper(cbCopy);
+
+ // resetBuffer();
+
+
}
+ public void resetBuffer()
+ {
+ //There is a bug in Netty which requires us to initially write a byte
+ if (buffer.capacity() == 0)
+ {
+ buffer.writeByte((byte)0);
+ }
+
+ buffer.setIndex(0, PacketImpl.PACKET_HEADERS_SIZE + DataConstants.SIZE_INT);
+ }
+
@Override
public String toString()
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientMessageInternal.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientMessageInternal.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientMessageInternal.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -42,6 +42,5 @@
*/
void discardLargeBody();
-
void setBuffer(HornetQBuffer buffer);
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientProducerCreditsImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientProducerCreditsImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientProducerCreditsImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -65,7 +65,7 @@
// credits += offset;
checkCredits(credits);
-
+
semaphore.acquire(credits);
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientProducerImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientProducerImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientProducerImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -18,7 +18,7 @@
import java.io.IOException;
import java.io.InputStream;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.BodyEncoder;
@@ -32,6 +32,7 @@
import org.hornetq.utils.SimpleString;
import org.hornetq.utils.TokenBucketLimiter;
import org.hornetq.utils.UUIDGenerator;
+import org.jboss.netty.buffer.ChannelBuffers;
/**
* The client-side Producer connectionFactory class.
@@ -238,9 +239,7 @@
boolean isLarge;
- int encodeSize = msg.getEncodeSize();
-
- if (msg.getBodyInputStream() != null || encodeSize >= minLargeMessageSize || msg.isLargeMessage())
+ if (msg.getBodyInputStream() != null || msg.isLargeMessage())
{
isLarge = true;
}
@@ -271,8 +270,8 @@
// data in *memory* and continuations go straight to the disk
if (!isLarge)
- {
- theCredits.acquireCredits(encodeSize);
+ {
+ theCredits.acquireCredits(msg.getEncodeSize());
}
}
catch (InterruptedException e)
@@ -310,7 +309,8 @@
msg.getBuffer().readerIndex(0);
}
- HornetQBuffer headerBuffer = ChannelBuffers.buffer(headerSize);
+ HornetQBuffer headerBuffer = HornetQChannelBuffers.buffer(headerSize);
+
msg.encodeHeadersAndProperties(headerBuffer);
SessionSendLargeMessage initialChunk = new SessionSendLargeMessage(headerBuffer.array());
@@ -360,7 +360,7 @@
final int chunkLength = Math.min((int)(bodySize - pos), minLargeMessageSize);
- final HornetQBuffer bodyBuffer = ChannelBuffers.buffer(chunkLength);
+ final HornetQBuffer bodyBuffer = HornetQChannelBuffers.buffer(chunkLength);
context.encode(bodyBuffer, chunkLength);
@@ -384,7 +384,7 @@
try
{
- credits.acquireCredits(chunk.getRequiredBufferSize());
+ credits.acquireCredits(chunk.getPacketSize());
}
catch (InterruptedException e)
{
@@ -470,7 +470,7 @@
try
{
- credits.acquireCredits(chunk.getRequiredBufferSize());
+ credits.acquireCredits(chunk.getPacketSize());
}
catch (InterruptedException e)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientSessionFactoryImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -115,6 +115,8 @@
public static final int DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE = 5;
public static final boolean DEFAULT_CACHE_LARGE_MESSAGE_CLIENT = false;
+
+ public static final int DEFAULT_INITIAL_MESSAGE_PACKET_SIZE = 1500;
// Attributes
// -----------------------------------------------------------------------------------
@@ -194,6 +196,8 @@
private long maxRetryInterval;
private int reconnectAttempts;
+
+ private int initialMessagePacketSize;
private volatile boolean closed;
@@ -375,6 +379,8 @@
failoverOnServerShutdown = other.isFailoverOnServerShutdown();
cacheLargeMessagesClient = other.isCacheLargeMessagesClient();
+
+ initialMessagePacketSize = other.getInitialMessagePacketSize();
}
public ClientSessionFactoryImpl()
@@ -432,6 +438,8 @@
failoverOnServerShutdown = DEFAULT_FAILOVER_ON_SERVER_SHUTDOWN;
cacheLargeMessagesClient = DEFAULT_CACHE_LARGE_MESSAGE_CLIENT;
+
+ initialMessagePacketSize = DEFAULT_INITIAL_MESSAGE_PACKET_SIZE;
}
public ClientSessionFactoryImpl(final String discoveryAddress, final int discoveryPort)
@@ -807,6 +815,17 @@
checkWrite();
this.discoveryRefreshTimeout = discoveryRefreshTimeout;
}
+
+ public synchronized int getInitialMessagePacketSize()
+ {
+ return initialMessagePacketSize;
+ }
+
+ public synchronized void setInitialMessagePacketSize(final int size)
+ {
+ checkWrite();
+ this.initialMessagePacketSize = size;
+ }
public ClientSession createSession(final String username,
final String password,
@@ -1105,7 +1124,8 @@
producerMaxRate,
consumerMaxRate,
blockOnNonPersistentSend,
- blockOnPersistentSend);
+ blockOnPersistentSend,
+ initialMessagePacketSize);
return session;
}
@@ -1139,4 +1159,6 @@
failoverManagerMap.values().toArray(failoverManagerArray);
}
+
+
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -105,8 +105,6 @@
private final boolean trace = log.isTraceEnabled();
- public static final int INITIAL_MESSAGE_BUFFER_SIZE = 1500;
-
// Attributes ----------------------------------------------------------------------------
private final FailoverManager failoverManager;
@@ -150,13 +148,13 @@
private final int producerMaxRate;
- private final int producerWindowSize;
-
private final boolean blockOnNonPersistentSend;
private final boolean blockOnPersistentSend;
private final int minLargeMessageSize;
+
+ private final int initialMessagePacketSize;
private final boolean cacheLargeMessageClient;
@@ -201,6 +199,7 @@
final boolean blockOnPersistentSend,
final boolean cacheLargeMessageClient,
final int minLargeMessageSize,
+ final int initialMessagePacketSize,
final RemotingConnection remotingConnection,
final int version,
final Channel channel,
@@ -242,8 +241,6 @@
this.confirmationWindowSize = confirmationWindowSize;
- this.producerWindowSize = producerWindowSize;
-
this.producerMaxRate = producerMaxRate;
this.blockOnNonPersistentSend = blockOnNonPersistentSend;
@@ -253,6 +250,8 @@
this.cacheLargeMessageClient = cacheLargeMessageClient;
this.minLargeMessageSize = minLargeMessageSize;
+
+ this.initialMessagePacketSize = initialMessagePacketSize;
producerCreditManager = new ClientProducerCreditManagerImpl(this, producerWindowSize);
}
@@ -519,7 +518,7 @@
final long timestamp,
final byte priority)
{
- HornetQBuffer body = remotingConnection.createBuffer(INITIAL_MESSAGE_BUFFER_SIZE);
+ HornetQBuffer body = remotingConnection.createBuffer(initialMessagePacketSize);
return new ClientMessageImpl(type, durable, expiration, timestamp, priority, body);
}
@@ -695,10 +694,10 @@
if (trace)
{
- log.trace("Setting up flowControlSize to " + message.getRequiredBufferSize() + " on message = " + clMessage);
+ log.trace("Setting up flowControlSize to " + message.getPacketSize() + " on message = " + clMessage);
}
- clMessage.setFlowControlSize(message.getRequiredBufferSize());
+ clMessage.setFlowControlSize(message.getPacketSize());
consumer.handleMessage(message.getClientMessage());
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/FailoverManager.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/FailoverManager.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/FailoverManager.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -46,7 +46,8 @@
final int producerMaxRate,
final int consumerMaxRate,
final boolean blockOnNonPersistentSend,
- final boolean blockOnPersistentSend) throws HornetQException;
+ final boolean blockOnPersistentSend,
+ final int initialMessagePacketSize) throws HornetQException;
void removeSession(final ClientSessionInternal session);
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -246,7 +246,8 @@
final int producerMaxRate,
final int consumerMaxRate,
final boolean blockOnNonPersistentSend,
- final boolean blockOnPersistentSend) throws HornetQException
+ final boolean blockOnPersistentSend,
+ final int initialMessagePacketSize) throws HornetQException
{
synchronized (createSessionLock)
{
@@ -357,6 +358,7 @@
blockOnPersistentSend,
cacheLargeMessageClient,
minLargeMessageSize,
+ initialMessagePacketSize,
theConnection,
response.getServerVersion(),
sessionChannel,
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/LargeMessageBufferImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/LargeMessageBufferImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/LargeMessageBufferImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -26,7 +26,8 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-import org.hornetq.core.buffers.ChannelBuffer;
+import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQDynamicChannelBuffer;
import org.hornetq.core.client.LargeMessageBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
@@ -44,7 +45,7 @@
*
*
*/
-public class LargeMessageBufferImpl implements ChannelBuffer, LargeMessageBuffer
+public class LargeMessageBufferImpl implements HornetQChannelBuffer, LargeMessageBuffer
{
// Constants -----------------------------------------------------
@@ -162,7 +163,8 @@
outStream.write(packet.getBody());
- flowControlCredit = packet.getRequiredBufferSize();
+ flowControlCredit = packet.getPacketSize();
+
continues = packet.isContinues();
notifyAll();
@@ -248,7 +250,8 @@
{
break;
}
- totalFlowControl += packet.getRequiredBufferSize();
+ totalFlowControl += packet.getPacketSize();
+
continues = packet.isContinues();
sendPacketToOutput(output, packet);
}
@@ -357,7 +360,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.buffers.ChannelBuffer#getBytes(int, org.hornetq.core.buffers.ChannelBuffer, int, int)
*/
- public void getBytes(final int index, final ChannelBuffer dst, final int dstIndex, final int length)
+ public void getBytes(final int index, final HornetQChannelBuffer dst, final int dstIndex, final int length)
{
byte[] destBytes = new byte[length];
getBytes(index, destBytes);
@@ -367,7 +370,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.buffers.ChannelBuffer#getBytes(int, org.hornetq.core.buffers.ChannelBuffer, int, int)
*/
- public void getBytes(final long index, final ChannelBuffer dst, final int dstIndex, final int length)
+ public void getBytes(final long index, final HornetQChannelBuffer dst, final int dstIndex, final int length)
{
byte[] destBytes = new byte[length];
getBytes(index, destBytes);
@@ -518,7 +521,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.buffers.ChannelBuffer#setBytes(int, org.hornetq.core.buffers.ChannelBuffer, int, int)
*/
- public void setBytes(final int index, final ChannelBuffer src, final int srcIndex, final int length)
+ public void setBytes(final int index, final HornetQChannelBuffer src, final int srcIndex, final int length)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
@@ -760,12 +763,12 @@
}
}
- public void getBytes(final int index, final ChannelBuffer dst)
+ public void getBytes(final int index, final HornetQChannelBuffer dst)
{
getBytes(index, dst, dst.writableBytes());
}
- public void getBytes(final int index, final ChannelBuffer dst, final int length)
+ public void getBytes(final int index, final HornetQChannelBuffer dst, final int length)
{
if (length > dst.writableBytes())
{
@@ -780,12 +783,12 @@
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void setBytes(final int index, final ChannelBuffer src)
+ public void setBytes(final int index, final HornetQChannelBuffer src)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void setBytes(final int index, final ChannelBuffer src, final int length)
+ public void setBytes(final int index, final HornetQChannelBuffer src, final int length)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
@@ -865,12 +868,12 @@
readBytes(dst, 0, dst.length);
}
- public void readBytes(final ChannelBuffer dst)
+ public void readBytes(final HornetQChannelBuffer dst)
{
readBytes(dst, dst.writableBytes());
}
- public void readBytes(final ChannelBuffer dst, final int length)
+ public void readBytes(final HornetQChannelBuffer dst, final int length)
{
if (length > dst.writableBytes())
{
@@ -880,7 +883,7 @@
dst.writerIndex(dst.writerIndex() + length);
}
- public void readBytes(final ChannelBuffer dst, final int dstIndex, final int length)
+ public void readBytes(final HornetQChannelBuffer dst, final int dstIndex, final int length)
{
getBytes(readerIndex, dst, dstIndex, length);
readerIndex += length;
@@ -949,12 +952,12 @@
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void writeBytes(final ChannelBuffer src)
+ public void writeBytes(final HornetQChannelBuffer src)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void writeBytes(final ChannelBuffer src, final int length)
+ public void writeBytes(final HornetQChannelBuffer src, final int length)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
@@ -964,7 +967,7 @@
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void writeBytes(final ChannelBuffer src, final int srcIndex, final int length)
+ public void writeBytes(final HornetQChannelBuffer src, final int srcIndex, final int length)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
@@ -1188,10 +1191,15 @@
/* (non-Javadoc)
* @see org.hornetq.core.buffers.ChannelBuffer#compareTo(org.hornetq.core.buffers.ChannelBuffer)
*/
- public int compareTo(final ChannelBuffer buffer)
+ public int compareTo(final HornetQChannelBuffer buffer)
{
return -1;
}
+
+ public HornetQBuffer copy()
+ {
+ throw new UnsupportedOperationException();
+ }
// Package protected ---------------------------------------------
@@ -1245,7 +1253,7 @@
throw new IndexOutOfBoundsException();
}
- consumerInternal.flowControl(currentPacket.getRequiredBufferSize(), !currentPacket.isContinues());
+ consumerInternal.flowControl(currentPacket.getPacketSize(), !currentPacket.isContinues());
packetPosition += sizeToAdd;
Modified: branches/20-optimisation/src/main/org/hornetq/core/cluster/impl/DiscoveryGroupImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/cluster/impl/DiscoveryGroupImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/cluster/impl/DiscoveryGroupImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -23,7 +23,7 @@
import java.util.List;
import java.util.Map;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.cluster.DiscoveryEntry;
import org.hornetq.core.cluster.DiscoveryGroup;
import org.hornetq.core.cluster.DiscoveryListener;
@@ -328,7 +328,7 @@
}
}
- HornetQBuffer buffer = ChannelBuffers.wrappedBuffer(data);
+ HornetQBuffer buffer = HornetQChannelBuffers.wrappedBuffer(data);
String originatingNodeID = buffer.readString();
Modified: branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AbstractJournalUpdateTask.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AbstractJournalUpdateTask.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AbstractJournalUpdateTask.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -18,8 +18,8 @@
import java.util.List;
import java.util.Set;
-import org.hornetq.core.buffers.ChannelBuffer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.logging.Logger;
@@ -57,7 +57,7 @@
protected int nextOrderingID;
- private ChannelBuffer writingChannel;
+ private HornetQChannelBuffer writingChannel;
private final Set<Long> recordsSnapshot = new ConcurrentHashSet<Long>();
@@ -98,12 +98,12 @@
{
controlFile.open(1);
- ChannelBuffer renameBuffer = ChannelBuffers.dynamicBuffer(1);
+ HornetQChannelBuffer renameBuffer = HornetQChannelBuffers.dynamicBuffer(1);
renameBuffer.writeInt(-1);
renameBuffer.writeInt(-1);
- HornetQBuffer filesToRename = ChannelBuffers.dynamicBuffer(1);
+ HornetQBuffer filesToRename = HornetQChannelBuffers.dynamicBuffer(1);
// DataFiles first
@@ -206,7 +206,7 @@
flush();
ByteBuffer bufferWrite = fileFactory.newBuffer(journal.getFileSize());
- writingChannel = ChannelBuffers.wrappedBuffer(bufferWrite);
+ writingChannel = HornetQChannelBuffers.wrappedBuffer(bufferWrite);
currentFile = journal.getFile(false, false, false, true);
sequentialFile = currentFile.getFile();
@@ -226,7 +226,7 @@
/**
* @return the writingChannel
*/
- protected ChannelBuffer getWritingChannel()
+ protected HornetQChannelBuffer getWritingChannel()
{
return writingChannel;
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalCompactor.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalCompactor.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalCompactor.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -21,8 +21,8 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import org.hornetq.core.buffers.ChannelBuffer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.RecordInfo;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
@@ -83,7 +83,7 @@
}
else
{
- ChannelBuffer input = ChannelBuffers.wrappedBuffer(records.get(0).data);
+ HornetQChannelBuffer input = HornetQChannelBuffers.wrappedBuffer(records.get(0).data);
int numberDataFiles = input.readInt();
Modified: branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -41,8 +41,8 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.hornetq.core.buffers.ChannelBuffer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.EncodingSupport;
import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.journal.JournalLoadInformation;
@@ -322,7 +322,7 @@
final EncodingSupport transactionData,
final int size,
final int numberOfRecords,
- final ChannelBuffer bb) throws Exception
+ final HornetQChannelBuffer bb) throws Exception
{
bb.writeByte(recordType);
bb.writeInt(fileID); // skip ID part
@@ -356,7 +356,7 @@
final byte recordType,
final EncodingSupport record,
final int size,
- final ChannelBuffer bb)
+ final HornetQChannelBuffer bb)
{
bb.writeByte(UPDATE_RECORD_TX);
bb.writeInt(fileID);
@@ -372,7 +372,7 @@
* @param txID
* @param bb
*/
- public static void writeRollback(final int fileID, final long txID, ChannelBuffer bb)
+ public static void writeRollback(final int fileID, final long txID, HornetQChannelBuffer bb)
{
bb.writeByte(ROLLBACK_RECORD);
bb.writeInt(fileID);
@@ -392,7 +392,7 @@
final byte recordType,
final EncodingSupport record,
final int size,
- final ChannelBuffer bb)
+ final HornetQChannelBuffer bb)
{
bb.writeByte(UPDATE_RECORD);
bb.writeInt(fileId);
@@ -415,7 +415,7 @@
final byte recordType,
final EncodingSupport record,
final int size,
- final ChannelBuffer bb)
+ final HornetQChannelBuffer bb)
{
bb.writeByte(ADD_RECORD);
bb.writeInt(fileId);
@@ -431,7 +431,7 @@
* @param size
* @param bb
*/
- public static void writeDeleteRecord(final int fileId, final long id, int size, ChannelBuffer bb)
+ public static void writeDeleteRecord(final int fileId, final long id, int size, HornetQChannelBuffer bb)
{
bb.writeByte(DELETE_RECORD);
bb.writeInt(fileId);
@@ -451,7 +451,7 @@
final long id,
final EncodingSupport record,
final int size,
- final ChannelBuffer bb)
+ final HornetQChannelBuffer bb)
{
bb.writeByte(DELETE_RECORD_TX);
bb.writeInt(fileID);
@@ -480,7 +480,7 @@
final byte recordType,
final EncodingSupport record,
final int size,
- final ChannelBuffer bb)
+ final HornetQChannelBuffer bb)
{
bb.writeByte(ADD_RECORD_TX);
bb.writeInt(fileID);
@@ -860,7 +860,7 @@
{
int size = SIZE_ADD_RECORD + record.getEncodeSize();
- ChannelBuffer bb = newBuffer(size);
+ HornetQChannelBuffer bb = newBuffer(size);
writeAddRecord(-1, id, recordType, record, size, bb); // fileID will be filled later
@@ -920,7 +920,7 @@
int size = SIZE_UPDATE_RECORD + record.getEncodeSize();
- ChannelBuffer bb = newBuffer(size);
+ HornetQChannelBuffer bb = newBuffer(size);
writeUpdateRecord(-1, id, recordType, record, size, bb);
@@ -984,7 +984,7 @@
int size = SIZE_DELETE_RECORD;
- ChannelBuffer bb = newBuffer(size);
+ HornetQChannelBuffer bb = newBuffer(size);
writeDeleteRecord(-1, id, size, bb);
@@ -1046,7 +1046,7 @@
int size = SIZE_ADD_RECORD_TX + record.getEncodeSize();
- ChannelBuffer bb = newBuffer(size);
+ HornetQChannelBuffer bb = newBuffer(size);
writeAddRecordTX(-1, txID, id, recordType, record, size, bb);
@@ -1095,7 +1095,7 @@
int size = SIZE_UPDATE_RECORD_TX + record.getEncodeSize();
- ChannelBuffer bb = newBuffer(size);
+ HornetQChannelBuffer bb = newBuffer(size);
writeUpdateRecordTX(-1, txID, id, recordType, record, size, bb);
@@ -1137,7 +1137,7 @@
{
int size = SIZE_DELETE_RECORD_TX + record.getEncodeSize();
- ChannelBuffer bb = newBuffer(size);
+ HornetQChannelBuffer bb = newBuffer(size);
writeDeleteRecordTransactional(-1, txID, id, record, size, bb);
@@ -1207,7 +1207,7 @@
{
int size = SIZE_COMPLETE_TRANSACTION_RECORD + transactionData.getEncodeSize() + DataConstants.SIZE_INT;
- ChannelBuffer bb = newBuffer(size);
+ HornetQChannelBuffer bb = newBuffer(size);
writeTransaction(-1, PREPARE_RECORD, txID, transactionData, size, -1, bb);
@@ -1269,7 +1269,7 @@
throw new IllegalStateException("Cannot find tx with id " + txID);
}
- ChannelBuffer bb = newBuffer(SIZE_COMPLETE_TRANSACTION_RECORD);
+ HornetQChannelBuffer bb = newBuffer(SIZE_COMPLETE_TRANSACTION_RECORD);
writeTransaction(-1,
COMMIT_RECORD,
@@ -1324,7 +1324,7 @@
throw new IllegalStateException("Cannot find tx with id " + txID);
}
- ChannelBuffer bb = newBuffer(SIZE_ROLLBACK_RECORD);
+ HornetQChannelBuffer bb = newBuffer(SIZE_ROLLBACK_RECORD);
writeRollback(-1, txID, bb);
@@ -3333,9 +3333,9 @@
}
}
- private ChannelBuffer newBuffer(final int size)
+ private HornetQChannelBuffer newBuffer(final int size)
{
- return ChannelBuffers.buffer(size);
+ return HornetQChannelBuffers.buffer(size);
}
// Inner classes
Modified: branches/20-optimisation/src/main/org/hornetq/core/journal/impl/TimedBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/journal/impl/TimedBuffer.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/TimedBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -21,7 +21,7 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.spi.HornetQBuffer;
@@ -104,7 +104,7 @@
}
// Setting the interval for nano-sleeps
- buffer = ChannelBuffers.buffer(bufferSize);
+ buffer = HornetQChannelBuffers.buffer(bufferSize);
buffer.clear();
bufferLimit = 0;
Modified: branches/20-optimisation/src/main/org/hornetq/core/management/impl/ManagementServiceImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/management/impl/ManagementServiceImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/management/impl/ManagementServiceImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -28,7 +28,7 @@
import javax.management.ObjectName;
import javax.management.StandardMBean;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.management.impl.ManagementHelper;
import org.hornetq.core.cluster.DiscoveryGroup;
import org.hornetq.core.config.Configuration;
@@ -411,7 +411,7 @@
public ServerMessage handleMessage(final ServerMessage message) throws Exception
{
// a reply message is sent with the result stored in the message body.
- ServerMessage reply = new ServerMessageImpl(storageManager.generateUniqueID(), ChannelBuffers.dynamicBuffer(1500));
+ ServerMessage reply = new ServerMessageImpl(storageManager.generateUniqueID(), HornetQChannelBuffers.dynamicBuffer(1500));
String resourceName = message.getStringProperty(ManagementHelper.HDR_RESOURCE_NAME);
if (log.isDebugEnabled())
@@ -700,7 +700,7 @@
}
ServerMessage notificationMessage = new ServerMessageImpl(storageManager.generateUniqueID(),
- ChannelBuffers.EMPTY_BUFFER);
+ HornetQChannelBuffers.EMPTY_BUFFER);
// Notification messages are always durable so the user can choose whether to add a durable queue to
// consume
Modified: branches/20-optimisation/src/main/org/hornetq/core/message/Message.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/message/Message.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/message/Message.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -175,6 +175,8 @@
HornetQBuffer getBuffer();
+ void setBuffer(HornetQBuffer buffer);
+
void encodeHeadersAndProperties(HornetQBuffer buffer);
long getLargeBodySize();
@@ -184,5 +186,11 @@
/** Get the InputStream used on a message that will be sent over a producer */
InputStream getBodyInputStream();
+
+ // Sending stuff
+
+ void afterSend();
+
+ boolean isBufferWritten();
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/message/impl/MessageImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/message/impl/MessageImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/message/impl/MessageImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -23,7 +23,7 @@
import java.util.Map;
import java.util.Set;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.BodyEncoder;
@@ -92,8 +92,6 @@
protected HornetQBuffer buffer;
- //private int encodeSize = -1;
-
// Constructors --------------------------------------------------
protected MessageImpl()
@@ -134,18 +132,20 @@
// Message implementation ----------------------------------------
-// public void encode(final HornetQBuffer buffer)
-// {
-// encodeHeadersAndProperties(buffer);
-// buffer.writeInt(getBodySize());
-// encodeBody(buffer);
-// }
-
+ public void afterSend()
+ {
+ }
+
+ public boolean isBufferWritten()
+ {
+ return false;
+ }
+
+ private int encodeSize;
+
public int getEncodeSize()
{
-// return getHeadersAndPropertiesEncodeSize() + SIZE_INT + getBodySize();
-
- return buffer.writerIndex() - PACKET_HEADERS_SIZE;
+ return encodeSize;
}
public int getBodySize()
@@ -155,14 +155,18 @@
public void encodeHeadersAndProperties(final HornetQBuffer buffer)
{
- buffer.writeLong(messageID);
+ //log.info("starting encode message at " + buffer.writerIndex());
+ buffer.writeLong(messageID);
+ // log.info("encoded id " + messageID + " at index " + buffer.writerIndex());
buffer.writeSimpleString(destination);
+ //log.info("encoded destination " + destination + " at index " + buffer.writerIndex());
buffer.writeByte(type);
buffer.writeBoolean(durable);
buffer.writeLong(expiration);
buffer.writeLong(timestamp);
buffer.writeByte(priority);
properties.encode(buffer);
+ encodeSize = buffer.writerIndex();
}
public void decode(final HornetQBuffer buffer)
@@ -174,14 +178,18 @@
public void decodeHeadersAndProperties(final HornetQBuffer buffer)
{
- messageID = buffer.readLong();
- destination = buffer.readSimpleString();
+ // log.info("starting decode at " + buffer.readerIndex());
+ messageID = buffer.readLong();
+ // log.info("decoded message id " + messageID + " at index " + buffer.readerIndex());
+ destination = buffer.readSimpleString();
+ // log.info("decoded destination " + destination + " at index " + buffer.readerIndex());
type = buffer.readByte();
durable = buffer.readBoolean();
expiration = buffer.readLong();
timestamp = buffer.readLong();
priority = buffer.readByte();
properties.decode(buffer);
+ encodeSize = buffer.readerIndex();
}
public long getMessageID()
@@ -576,6 +584,11 @@
{
return buffer;
}
+
+ public void setBuffer(HornetQBuffer buffer)
+ {
+ this.buffer = buffer;
+ }
public BodyEncoder getBodyEncoder()
{
@@ -591,9 +604,8 @@
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
-
- class DecodingContext implements BodyEncoder
+ private class DecodingContext implements BodyEncoder
{
private int lastPos = 0;
@@ -611,7 +623,7 @@
public int encode(ByteBuffer bufferRead) throws HornetQException
{
- HornetQBuffer buffer = ChannelBuffers.wrappedBuffer(bufferRead);
+ HornetQBuffer buffer = HornetQChannelBuffers.wrappedBuffer(bufferRead);
return encode(buffer, bufferRead.capacity());
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PageImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PageImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PageImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -21,8 +21,8 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-import org.hornetq.core.buffers.ChannelBuffer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.logging.Logger;
@@ -98,7 +98,7 @@
buffer2.rewind();
- ChannelBuffer fileBuffer = ChannelBuffers.wrappedBuffer(buffer2);
+ HornetQChannelBuffer fileBuffer = HornetQChannelBuffers.wrappedBuffer(buffer2);
fileBuffer.writerIndex(fileBuffer.capacity());
while (fileBuffer.readable())
@@ -148,7 +148,7 @@
{
ByteBuffer buffer = fileFactory.newBuffer(message.getEncodeSize() + SIZE_RECORD);
- ChannelBuffer wrap = ChannelBuffers.wrappedBuffer(buffer);
+ HornetQChannelBuffer wrap = HornetQChannelBuffers.wrappedBuffer(buffer);
wrap.writeByte(START_BYTE);
wrap.writeInt(message.getEncodeSize());
Modified: branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PagedMessageImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PagedMessageImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PagedMessageImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -17,7 +17,7 @@
import static org.hornetq.utils.DataConstants.SIZE_INT;
import static org.hornetq.utils.DataConstants.SIZE_LONG;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.paging.PagedMessage;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.remoting.spi.HornetQBuffer;
@@ -73,7 +73,7 @@
if (largeMessageLazyData != null)
{
message = storage.createLargeMessage();
- HornetQBuffer buffer = ChannelBuffers.dynamicBuffer(largeMessageLazyData);
+ HornetQBuffer buffer = HornetQChannelBuffers.dynamicBuffer(largeMessageLazyData);
message.decode(buffer);
largeMessageLazyData = null;
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/JournalStorageManager.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/JournalStorageManager.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/JournalStorageManager.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -32,7 +32,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.filter.Filter;
@@ -432,7 +432,7 @@
FileLargeServerMessage largeMessage = (FileLargeServerMessage)createLargeMessage();
- HornetQBuffer headerBuffer = ChannelBuffers.wrappedBuffer(header);
+ HornetQBuffer headerBuffer = HornetQChannelBuffers.wrappedBuffer(header);
largeMessage.decodeHeadersAndProperties(headerBuffer);
@@ -680,7 +680,7 @@
{
byte[] data = record.data;
- HornetQBuffer buff = ChannelBuffers.wrappedBuffer(data);
+ HornetQBuffer buff = HornetQChannelBuffers.wrappedBuffer(data);
try
{
@@ -721,7 +721,7 @@
{
byte[] data = record.data;
- HornetQBuffer buff = ChannelBuffers.wrappedBuffer(data);
+ HornetQBuffer buff = HornetQChannelBuffers.wrappedBuffer(data);
byte recordType = record.getUserRecordType();
@@ -1008,7 +1008,7 @@
{
byte[] data = record.data;
- HornetQBuffer buff = ChannelBuffers.wrappedBuffer(data);
+ HornetQBuffer buff = HornetQChannelBuffers.wrappedBuffer(data);
byte recordType = record.getUserRecordType();
@@ -1140,7 +1140,7 @@
{
byte[] data = record.data;
- HornetQBuffer buff = ChannelBuffers.wrappedBuffer(data);
+ HornetQBuffer buff = HornetQChannelBuffers.wrappedBuffer(data);
long messageID = record.id;
@@ -1224,7 +1224,7 @@
{
long id = record.id;
- HornetQBuffer buffer = ChannelBuffers.wrappedBuffer(record.data);
+ HornetQBuffer buffer = HornetQChannelBuffers.wrappedBuffer(record.data);
byte rec = record.getUserRecordType();
@@ -1441,7 +1441,7 @@
XidEncoding(final byte[] data)
{
- xid = XidCodecSupport.decodeXid(ChannelBuffers.wrappedBuffer(data));
+ xid = XidCodecSupport.decodeXid(HornetQChannelBuffers.wrappedBuffer(data));
}
public void decode(final HornetQBuffer buffer)
Modified: branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -13,7 +13,7 @@
package org.hornetq.core.persistence.impl.nullpm;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.LargeServerMessage;
import org.hornetq.core.server.impl.ServerMessageImpl;
Modified: branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageManager.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageManager.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageManager.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -19,7 +19,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.paging.PageTransactionInfo;
import org.hornetq.core.paging.PagedMessage;
@@ -196,7 +196,7 @@
{
NullStorageLargeServerMessage largeMessage = new NullStorageLargeServerMessage();
- HornetQBuffer headerBuffer = ChannelBuffers.wrappedBuffer(header);
+ HornetQBuffer headerBuffer = HornetQChannelBuffers.wrappedBuffer(header);
largeMessage.decodeHeadersAndProperties(headerBuffer);
Modified: branches/20-optimisation/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -25,7 +25,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.management.impl.ManagementHelper;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.filter.Filter;
@@ -780,7 +780,7 @@
{
// First send a reset message
- ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID(), ChannelBuffers.EMPTY_BUFFER);
+ ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID(), HornetQChannelBuffers.EMPTY_BUFFER);
// message.setDurable(true);
message.setDestination(queueName);
@@ -1000,7 +1000,7 @@
private ServerMessage createQueueInfoMessage(final NotificationType type, final SimpleString queueName)
{
- ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID(), ChannelBuffers.EMPTY_BUFFER);
+ ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID(), HornetQChannelBuffers.EMPTY_BUFFER);
message.setDestination(queueName);
// message.setDurable(true);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/Packet.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/Packet.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/Packet.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -32,16 +32,16 @@
byte getType();
- //int encode(HornetQBuffer buffer);
-
HornetQBuffer encode(RemotingConnection connection);
void decode(HornetQBuffer buffer);
+ /**
+ *
+ * @return The size of the entire packet including headers, and extra data
+ */
int getPacketSize();
- int getRequiredBufferSize();
-
boolean isRequiresConfirmations();
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/invm/InVMConnection.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/invm/InVMConnection.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/invm/InVMConnection.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -15,7 +15,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.spi.BufferHandler;
@@ -97,7 +97,7 @@
public HornetQBuffer createBuffer(final int size)
{
- return ChannelBuffers.buffer(size);
+ return HornetQChannelBuffers.buffer(size);
}
public Object getID()
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateQueueMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateQueueMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateQueueMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -140,18 +140,6 @@
r.temporary == this.temporary;
}
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.Packet#getRequiredBufferSize()
- */
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + address.sizeof() +
- queueName.sizeof() +
- SimpleString.sizeofNullableString(filterString) +
- DataConstants.SIZE_BOOLEAN +
- DataConstants.SIZE_BOOLEAN;
- }
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateReplicationSessionMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateReplicationSessionMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateReplicationSessionMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -48,16 +48,7 @@
}
// Public --------------------------------------------------------
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE +
- // buffer.writeLong(sessionChannelID);
- DataConstants.SIZE_LONG +
- // buffer.writeInt(windowSize);
- DataConstants.SIZE_INT;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateSessionMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateSessionMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateSessionMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -147,32 +147,7 @@
{
return windowSize;
}
-
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + stringEncodeSize(name) + // buffer.writeString(name);
- DataConstants.SIZE_LONG +
- // buffer.writeLong(sessionChannelID);
- DataConstants.SIZE_INT +
- // buffer.writeInt(version);
- nullableStringEncodeSize(username) +
- // buffer.writeNullableString(username);
- nullableStringEncodeSize(password) +
- // buffer.writeNullableString(password);
- DataConstants.SIZE_INT +
- // buffer.writeInt(minLargeMessageSize);
- DataConstants.SIZE_BOOLEAN +
- // buffer.writeBoolean(xa);
- DataConstants.SIZE_BOOLEAN +
- // buffer.writeBoolean(autoCommitSends);
- DataConstants.SIZE_BOOLEAN +
- // buffer.writeBoolean(autoCommitAcks);
- DataConstants.SIZE_INT +
- // buffer.writeInt(windowSize);
- DataConstants.SIZE_BOOLEAN; // buffer.writeBoolean(preAcknowledge);
-
- }
-
+
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateSessionResponseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateSessionResponseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateSessionResponseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -71,11 +71,6 @@
serverVersion = buffer.readInt();
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_INT;
- }
-
@Override
public boolean equals(final Object other)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/HornetQExceptionMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/HornetQExceptionMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/HornetQExceptionMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -64,12 +64,6 @@
return exception;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_INT + nullableStringEncodeSize(exception.getMessage());
- }
-
-
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeInt(exception.getCode());
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/NullResponseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/NullResponseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/NullResponseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -41,16 +41,6 @@
return true;
}
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.Packet#getRequiredBufferSize()
- */
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE;
- }
-
-
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/PacketImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/PacketImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/PacketImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -40,7 +40,7 @@
protected final byte type;
- protected int size;
+ protected int size = -1;
// The packet types
// -----------------------------------------------------------------------------------
@@ -237,14 +237,14 @@
public final int getPacketSize()
{
+ if (size == -1)
+ {
+ throw new IllegalStateException("Packet hasn't been encoded/decoded yet");
+ }
+
return size;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE;
- }
-
public boolean isResponse()
{
return false;
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/PacketsConfirmedMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/PacketsConfirmedMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/PacketsConfirmedMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -54,11 +54,6 @@
return this.commandID;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_INT;
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeInt(commandID);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/Ping.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/Ping.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/Ping.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -54,11 +54,6 @@
return connectionTTL;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_LONG;
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeLong(connectionTTL);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReattachSessionMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReattachSessionMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReattachSessionMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -63,12 +63,6 @@
return lastReceivedCommandID;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + stringEncodeSize(name) + DataConstants.SIZE_INT;
- }
-
-
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeString(name);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReattachSessionResponseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReattachSessionResponseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReattachSessionResponseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -63,11 +63,6 @@
return reattached;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_INT + DataConstants.SIZE_BOOLEAN;
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeInt(lastReceivedCommandID);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationAddMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationAddMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationAddMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -70,18 +70,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_BYTE +
- DataConstants.SIZE_BOOLEAN +
- DataConstants.SIZE_LONG +
- DataConstants.SIZE_BYTE +
- DataConstants.SIZE_INT +
- (encodingData != null ? encodingData.getEncodeSize() : recordData.length);
-
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeByte(journalID);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationAddTXMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationAddTXMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationAddTXMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -74,19 +74,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_BYTE +
- DataConstants.SIZE_BOOLEAN +
- DataConstants.SIZE_LONG +
- DataConstants.SIZE_LONG +
- DataConstants.SIZE_BYTE +
- DataConstants.SIZE_INT +
- (encodingData != null ? encodingData.getEncodeSize() : recordData.length);
-
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeByte(journalID);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationCommitMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationCommitMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationCommitMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -57,12 +57,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_BYTE + DataConstants.SIZE_BOOLEAN + DataConstants.SIZE_LONG;
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeByte(journalID);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationCompareDataMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationCompareDataMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationCompareDataMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -48,14 +48,7 @@
}
// Public --------------------------------------------------------
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE +
- DataConstants.SIZE_INT + (journalInformation.length * (DataConstants.SIZE_INT + DataConstants.SIZE_LONG)) +
- DataConstants.SIZE_INT;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationDeleteMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationDeleteMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationDeleteMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -54,13 +54,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_BYTE + DataConstants.SIZE_LONG;
-
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeByte(journalID);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationDeleteTXMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationDeleteTXMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationDeleteTXMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -66,17 +66,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_BYTE +
- DataConstants.SIZE_LONG +
- DataConstants.SIZE_LONG +
- DataConstants.SIZE_INT +
- (encodingData != null ? encodingData.getEncodeSize() : recordData.length);
-
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeByte(journalID);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargeMessageBeingMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargeMessageBeingMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargeMessageBeingMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -50,12 +50,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_LONG;
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeLong(messageId);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargeMessageWriteMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargeMessageWriteMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargeMessageWriteMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -55,11 +55,6 @@
}
// Public --------------------------------------------------------
- @Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_LONG + DataConstants.SIZE_INT + body.length;
- }
@Override
public void encodeRest(final HornetQBuffer buffer)
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargemessageEndMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargemessageEndMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargemessageEndMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -49,12 +49,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_LONG;
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeLong(messageId);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPageEventMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPageEventMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPageEventMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -60,13 +60,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_INT + storeName.sizeof() + DataConstants.SIZE_BOOLEAN;
-
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeSimpleString(storeName);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPageWriteMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPageWriteMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPageWriteMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -55,13 +55,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_INT + pagedMessage.getEncodeSize();
-
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeInt(pageNumber);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPrepareMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPrepareMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPrepareMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -60,16 +60,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_BYTE +
- DataConstants.SIZE_LONG +
- DataConstants.SIZE_INT +
- (encodingData != null ? encodingData.getEncodeSize() : recordData.length);
-
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeByte(journalID);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationResponseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationResponseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationResponseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -34,15 +34,6 @@
// Public --------------------------------------------------------
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.Packet#getRequiredBufferSize()
- */
- @Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE;
- }
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationSyncContextMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationSyncContextMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationSyncContextMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -42,13 +42,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE;
-
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/RollbackMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/RollbackMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/RollbackMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -65,11 +65,6 @@
considerLastMessageAsDelivered = isLastMessageAsDelived;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_BOOLEAN;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionAcknowledgeMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionAcknowledgeMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionAcknowledgeMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -69,11 +69,6 @@
return requiresResponse;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_LONG + DataConstants.SIZE_LONG + DataConstants.SIZE_BOOLEAN;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionBindingQueryMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionBindingQueryMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionBindingQueryMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -44,11 +44,6 @@
return address;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + address.sizeof();
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionBindingQueryResponseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionBindingQueryResponseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionBindingQueryResponseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -86,16 +86,6 @@
}
}
- public int getRequiredBufferSize()
- {
- int size = PACKET_HEADERS_SIZE + DataConstants.SIZE_BOOLEAN + DataConstants.SIZE_INT;
- for (SimpleString queueName : queueNames)
- {
- size += queueName.sizeof();
- }
- return size;
- }
-
@Override
public boolean equals(final Object other)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionCloseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionCloseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionCloseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -34,11 +34,6 @@
// Public --------------------------------------------------------
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE;
- }
-
@Override
public boolean equals(final Object other)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionConsumerCloseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionConsumerCloseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionConsumerCloseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -52,11 +52,6 @@
return consumerID;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_LONG;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionConsumerFlowCreditMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionConsumerFlowCreditMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionConsumerFlowCreditMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -62,11 +62,6 @@
return credits;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_LONG + DataConstants.SIZE_INT;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionContinuationMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionContinuationMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionContinuationMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -74,12 +74,6 @@
}
@Override
- public int getRequiredBufferSize()
- {
- return SESSION_CONTINUATION_BASE_SIZE + body.length;
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeInt(body.length);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionCreateConsumerMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionCreateConsumerMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionCreateConsumerMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -99,13 +99,6 @@
return requiresResponse;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_LONG + queueName.sizeof() +
- SimpleString.sizeofNullableString(filterString) +
- 2 * DataConstants.SIZE_BOOLEAN ;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionDeleteQueueMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionDeleteQueueMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionDeleteQueueMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -61,11 +61,6 @@
return queueName;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + queueName.sizeof();
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeSimpleString(queueName);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionExpiredMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionExpiredMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionExpiredMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -60,11 +60,6 @@
return messageID;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_LONG + DataConstants.SIZE_LONG;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionForceConsumerDelivery.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionForceConsumerDelivery.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionForceConsumerDelivery.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -61,11 +61,6 @@
return sequence;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_LONG + DataConstants.SIZE_LONG;
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeLong(consumerID);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionProducerCreditsMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionProducerCreditsMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionProducerCreditsMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -86,15 +86,7 @@
offset = buffer.readInt();
}
- public int getRequiredBufferSize()
- {
- int size = PACKET_HEADERS_SIZE + DataConstants.SIZE_INT +
- SimpleString.sizeofString(address) +
- DataConstants.SIZE_INT;
- return size;
- }
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionQueueQueryMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionQueueQueryMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionQueueQueryMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -45,12 +45,6 @@
return queueName;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + queueName.sizeof();
- }
-
-
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeSimpleString(queueName);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionQueueQueryResponseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionQueueQueryResponseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionQueueQueryResponseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -109,18 +109,6 @@
return address;
}
-
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE +
- DataConstants.SIZE_BOOLEAN + // buffer.writeBoolean(exists);
- DataConstants.SIZE_BOOLEAN + // buffer.writeBoolean(durable);
- DataConstants.SIZE_INT + // buffer.writeInt(consumerCount);
- DataConstants.SIZE_INT + // buffer.writeInt(messageCount);
- SimpleString.sizeofNullableString(filterString) + // buffer.writeNullableSimpleString(filterString);
- SimpleString.sizeofNullableString(address); // buffer.writeNullableSimpleString(address);
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeBoolean(exists);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveContinuationMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveContinuationMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveContinuationMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -74,12 +74,6 @@
// Public --------------------------------------------------------
@Override
- public int getRequiredBufferSize()
- {
- return SESSION_RECEIVE_CONTINUATION_BASE_SIZE + body.length;
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
super.encodeRest(buffer);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -84,33 +84,21 @@
return deliveryCount;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE +
- // consumerID
- DataConstants.SIZE_LONG +
- // deliveryCount
- DataConstants.SIZE_INT +
- // isLargeMessage
- DataConstants.SIZE_BOOLEAN +
- // message.encoding
- (serverMessage != null ? serverMessage.getEncodeSize() : clientMessage.getEncodeSize());
-
- }
-
@Override
public HornetQBuffer encode(final RemotingConnection connection)
{
+ //We re-use the same packet buffer - but we need to change the extra data
HornetQBuffer buffer = serverMessage.getBuffer();
buffer.writeLong(consumerID);
buffer.writeInt(deliveryCount);
+ // Calculate the new packet size
size = buffer.writerIndex();
buffer.setIndex(0, 0);
- // The standard header fields
+ // Fill in the standard header fields
int len = size - DataConstants.SIZE_INT;
buffer.writeInt(len);
@@ -130,29 +118,22 @@
{
clientMessage = new ClientMessageImpl();
- //fast forward past the size byte
- int size = buffer.readInt();
+ // We read the position of the end of the body - this is where the message headers and properties are stored
+ int afterBody = buffer.readInt();
+ // We now read message headers/properties
+
+ buffer.setIndex(afterBody, buffer.writerIndex());
+
clientMessage.decode(buffer);
- int bodyBeginning = buffer.readerIndex();
-
- clientMessage.setBuffer(buffer);
-
- //Now we need to fast forward past the body part
-
- //int size = buffer.readInt(PacketImpl.PACKET_HEADERS_SIZE);
-
- buffer.setIndex(size, buffer.writerIndex());
-
consumerID = buffer.readLong();
deliveryCount = buffer.readInt();
clientMessage.setDeliveryCount(deliveryCount);
- //Reset buffer to beginning of body
- buffer.setIndex(bodyBeginning, buffer.writerIndex());
+ buffer.resetReaderIndex();
clientMessage.setBuffer(buffer);
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionRequestProducerCreditsMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionRequestProducerCreditsMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionRequestProducerCreditsMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -80,13 +80,6 @@
address = buffer.readSimpleString();
}
- public int getRequiredBufferSize()
- {
- int size = PACKET_HEADERS_SIZE + DataConstants.SIZE_INT + SimpleString.sizeofString(address);
-
- return size;
- }
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendContinuationMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendContinuationMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendContinuationMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -73,12 +73,6 @@
}
@Override
- public int getRequiredBufferSize()
- {
- return super.getRequiredBufferSize() + DataConstants.SIZE_BOOLEAN;
- }
-
- @Override
public void encodeRest(final HornetQBuffer buffer)
{
super.encodeRest(buffer);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendLargeMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendLargeMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendLargeMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -94,15 +94,6 @@
largeMessageId = buffer.readLong();
}
- public int getRequiredBufferSize()
- {
- int size = PACKET_HEADERS_SIZE + DataConstants.SIZE_INT +
- largeMessageHeader.length +
- DataConstants.SIZE_LONG;
-
- return size;
- }
-
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -19,7 +19,9 @@
import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.ServerMessage;
import org.hornetq.core.server.impl.ServerMessageImpl;
+import org.hornetq.integration.transports.netty.ChannelBufferWrapper;
import org.hornetq.utils.DataConstants;
+import org.jboss.netty.buffer.ChannelBuffer;
/**
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
@@ -33,7 +35,7 @@
// Constants -----------------------------------------------------
private static final Logger log = Logger.getLogger(SessionSendMessage.class);
-
+
// Attributes ----------------------------------------------------
private Message sentMessage;
@@ -80,28 +82,77 @@
@Override
public HornetQBuffer encode(final RemotingConnection connection)
{
+ /*
+ * We write the message to the buffer in the following structure:
+ *
+ * First the standard packet headers - all packets have these
+ *
+ * length:int
+ * packet type:byte
+ * channelID:long
+ *
+ * Then the message body:
+ *
+ * bodySize:int
+ * body:byte[]
+ *
+ * {Note we store the message body before the message headers/properties since this allows the user to
+ * construct a message, add stuff to the body buffer, and send it without us having to copy the body into a new
+ * buffer before sending it, this minmises buffer copying}
+ *
+ * Then followed by the message headers and properties:
+ *
+ * messageID:long
+ * destination:SimpleString
+ * message type: byte
+ * durable: boolean
+ * expiration: long
+ * timestamp: long
+ * priority: byte
+ *
+ * properties: byte[]
+ *
+ *
+ */
HornetQBuffer buffer = sentMessage.getBuffer();
-
+
+ // The body will already be written (if any) at this point, so we take note of the position of the end of the
+ // body
int afterBody = buffer.writerIndex();
-
+
+ // We now write the message headers and properties
+ sentMessage.encodeHeadersAndProperties(buffer);
+
+ // We now write the extra data for the packet
buffer.writeBoolean(requiresResponse);
- // At this point, the rest of the message has already been encoded into the buffer
+ // We take note of the overall size of the packet
size = buffer.writerIndex();
-
- buffer.setIndex(0, 0);
+
+ // We now set the standard packet headers at the beginning of the buffer
- // The standard header fields
-
+ buffer.writerIndex(0);
+
int len = size - DataConstants.SIZE_INT;
buffer.writeInt(len);
buffer.writeByte(type);
buffer.writeLong(channelID);
-
- //This last byte we write marks the position of the end of the message body where we store extra data for the packet
+
+ // This last byte we write marks the position of the end of the message body
buffer.writeInt(afterBody);
+
+ // And we set the indexes back for reading and writing
+ buffer.setIndex(0, size);
+
+ //We must make a copy of the buffer, since the message might get sent again, and the body might get read or written
+ //this might occur while the same send is in operatio since netty send is asynch
+ //this could cause incorrect data to be send and/or reader/writer positions to become corrupted
- buffer.setIndex(0, size);
+ HornetQBuffer newBuffer = buffer.copy();
+
+ newBuffer.setIndex(0, afterBody);
+
+ this.sentMessage.setBuffer(newBuffer);
return buffer;
}
@@ -112,25 +163,28 @@
receivedMessage = new ServerMessageImpl();
sentMessage = receivedMessage;
-
- //Read the position of after the body where extra data is stored
+
+ // At this point, the standard packet headers will already have been read
+
+ // We read the position of the end of the body - this is where the message headers and properties are stored
int afterBody = buffer.readInt();
- receivedMessage.decode(buffer);
-
+ // We now read message headers/properties
+
buffer.setIndex(afterBody, buffer.writerIndex());
-
- requiresResponse = buffer.readBoolean();
-
- receivedMessage.getBuffer().resetReaderIndex();
-
- }
- public int getRequiredBufferSize()
- {
- int size = PACKET_HEADERS_SIZE + sentMessage.getEncodeSize() + DataConstants.SIZE_BOOLEAN;
+ receivedMessage.decode(buffer);
- return size;
+ // And we read extra data in the packet
+
+ requiresResponse = buffer.readBoolean();
+
+ // We set reader index back to the beginning of the buffer so it can be easily read if then delivered
+ // to a client, and we set writer index to just after where the headers/properties were encoded so that it can
+ // be fileld in with extra data required when delivering the packet to the client (e.g. delivery count, consumer
+ // id)
+
+ buffer.setIndex(0, buffer.writerIndex() - DataConstants.SIZE_BOOLEAN);
}
// Package protected ---------------------------------------------
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXACommitMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXACommitMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXACommitMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -62,11 +62,6 @@
return onePhase;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + XidCodecSupport.getXidEncodeLength(xid) + DataConstants.SIZE_BOOLEAN;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAEndMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAEndMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAEndMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -64,11 +64,6 @@
return xid;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + XidCodecSupport.getXidEncodeLength(xid) + DataConstants.SIZE_BOOLEAN;
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
XidCodecSupport.encodeXid(xid, buffer);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAForgetMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAForgetMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAForgetMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -54,11 +54,6 @@
return xid;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + XidCodecSupport.getXidEncodeLength(xid);
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
XidCodecSupport.encodeXid(xid, buffer);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAGetInDoubtXidsResponseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAGetInDoubtXidsResponseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAGetInDoubtXidsResponseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -63,16 +63,6 @@
return xids;
}
- public int getRequiredBufferSize()
- {
- int size = PACKET_HEADERS_SIZE + DataConstants.SIZE_INT;
- for (Xid xid : xids)
- {
- size += XidCodecSupport.getXidEncodeLength(xid);
- }
- return size;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAGetTimeoutResponseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAGetTimeoutResponseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAGetTimeoutResponseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -57,11 +57,6 @@
return this.timeoutSeconds;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_INT;
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
buffer.writeInt(timeoutSeconds);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAJoinMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAJoinMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAJoinMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -54,11 +54,6 @@
return xid;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + XidCodecSupport.getXidEncodeLength(xid);
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
XidCodecSupport.encodeXid(xid, buffer);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAPrepareMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAPrepareMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAPrepareMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -53,11 +53,6 @@
return xid;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + XidCodecSupport.getXidEncodeLength(xid);
- }
-
public void encodeRest(final HornetQBuffer buffer)
{
XidCodecSupport.encodeXid(xid, buffer);
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAResponseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAResponseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAResponseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -55,13 +55,6 @@
// Public --------------------------------------------------------
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_BOOLEAN +
- DataConstants.SIZE_INT +
- nullableStringEncodeSize(message);
- }
-
@Override
public boolean isResponse()
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAResumeMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAResumeMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAResumeMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -53,11 +53,6 @@
return xid;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + XidCodecSupport.getXidEncodeLength(xid);
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXARollbackMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXARollbackMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXARollbackMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -53,11 +53,6 @@
return xid;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + XidCodecSupport.getXidEncodeLength(xid);
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXASetTimeoutMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXASetTimeoutMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXASetTimeoutMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -52,11 +52,6 @@
return timeoutSeconds;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_INT;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXASetTimeoutResponseMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXASetTimeoutResponseMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXASetTimeoutResponseMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -58,11 +58,6 @@
return ok;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + DataConstants.SIZE_BOOLEAN;
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAStartMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAStartMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAStartMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -53,11 +53,6 @@
return xid;
}
- public int getRequiredBufferSize()
- {
- return PACKET_HEADERS_SIZE + XidCodecSupport.getXidEncodeLength(xid);
- }
-
@Override
public void encodeRest(final HornetQBuffer buffer)
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/HornetQBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/HornetQBuffer.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/HornetQBuffer.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -13,6 +13,8 @@
package org.hornetq.core.remoting.spi;
+import java.nio.ByteBuffer;
+
import org.hornetq.utils.SimpleString;
/**
@@ -29,7 +31,7 @@
void writeBytes(byte[] bytes);
void writeBytes(byte[] bytes, int offset, int length);
-
+
void writeBytes(HornetQBuffer src, int srcIndex, int length);
void writeInt(int val);
@@ -67,7 +69,7 @@
void readBytes(byte[] bytes, int offset, int length);
int readInt();
-
+
int readInt(int pos);
long readLong();
@@ -94,8 +96,6 @@
String readUTF() throws Exception;
- byte[] array();
-
int capacity();
int readerIndex();
@@ -123,4 +123,8 @@
void resetWriterIndex();
Object getUnderlyingBuffer();
+
+ byte[] array();
+
+ HornetQBuffer copy();
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/server/cluster/impl/BroadcastGroupImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/server/cluster/impl/BroadcastGroupImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/cluster/impl/BroadcastGroupImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -20,7 +20,7 @@
import java.util.List;
import java.util.concurrent.ScheduledFuture;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.config.TransportConfiguration;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.management.Notification;
@@ -203,7 +203,7 @@
return;
}
- HornetQBuffer buff = ChannelBuffers.dynamicBuffer(4096);
+ HornetQBuffer buff = HornetQChannelBuffers.dynamicBuffer(4096);
buff.writeString(nodeID);
Modified: branches/20-optimisation/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -31,7 +31,7 @@
import javax.management.MBeanServer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientSessionFactory;
import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
import org.hornetq.core.client.impl.FailoverManager;
@@ -1504,7 +1504,7 @@
for (int i = 0; i < numMessages; i++)
{
- ServerMessage msg = new ServerMessageImpl(storageManager.generateUniqueID(), ChannelBuffers.wrappedBuffer(body));
+ ServerMessage msg = new ServerMessageImpl(storageManager.generateUniqueID(), HornetQChannelBuffers.wrappedBuffer(body));
msg.setDestination(address);
Modified: branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerConsumerImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerConsumerImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerConsumerImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -21,7 +21,7 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.impl.ClientConsumerImpl;
import org.hornetq.core.client.management.impl.ManagementHelper;
import org.hornetq.core.exception.HornetQException;
@@ -189,7 +189,7 @@
{
return HandleStatus.BUSY;
}
-
+
lock.lock();
try
@@ -347,7 +347,7 @@
promptDelivery(false);
ServerMessage forcedDeliveryMessage = new ServerMessageImpl(storageManager.generateUniqueID(),
- ChannelBuffers.EMPTY_BUFFER);
+ HornetQChannelBuffers.EMPTY_BUFFER);
forcedDeliveryMessage.putLongProperty(ClientConsumerImpl.FORCED_DELIVERY_MESSAGE, sequence);
forcedDeliveryMessage.setDestination(messageQueue.getName());
@@ -578,13 +578,14 @@
private void deliverStandardMessage(final MessageReference ref, final ServerMessage message)
{
final SessionReceiveMessage packet = new SessionReceiveMessage(id, message, ref.getDeliveryCount());
-
+
+ channel.send(packet);
+
if (availableCredits != null)
{
- availableCredits.addAndGet(-packet.getRequiredBufferSize());
+ availableCredits.addAndGet(-packet.getPacketSize());
}
- channel.send(packet);
}
// Inner classes
@@ -667,7 +668,7 @@
if (!sentInitialPacket)
{
- HornetQBuffer headerBuffer = ChannelBuffers.buffer(largeMessage.getHeadersAndPropertiesEncodeSize());
+ HornetQBuffer headerBuffer = HornetQChannelBuffers.buffer(largeMessage.getHeadersAndPropertiesEncodeSize());
largeMessage.encodeHeadersAndProperties(headerBuffer);
@@ -679,16 +680,16 @@
context = largeMessage.getBodyEncoder();
context.open();
+
+ sentInitialPacket = true;
+ channel.send(initialPacket);
+
if (availableCredits != null)
{
- availableCredits.addAndGet(-initialPacket.getRequiredBufferSize());
+ availableCredits.addAndGet(-initialPacket.getPacketSize());
}
- sentInitialPacket = true;
-
- channel.send(initialPacket);
-
// Execute the rest of the large message on a different thread so as not to tie up the delivery thread
// for too long
@@ -711,21 +712,21 @@
SessionReceiveContinuationMessage chunk = createChunkSend(context);
int chunkLen = chunk.getBody().length;
-
- if (availableCredits != null)
- {
- availableCredits.addAndGet(-chunk.getRequiredBufferSize());
- }
-
+
+ channel.send(chunk);
+
if (trace)
{
- trace("deliverLargeMessage: Sending " + chunk.getRequiredBufferSize() +
+ trace("deliverLargeMessage: Sending " + chunk.getPacketSize() +
" availableCredits now is " +
availableCredits);
}
+
+ if (availableCredits != null)
+ {
+ availableCredits.addAndGet(-chunk.getPacketSize());
+ }
- channel.send(chunk);
-
positionPendingLargeMessage += chunkLen;
if (positionPendingLargeMessage < sizePendingLargeMessage)
@@ -795,7 +796,7 @@
localChunkLen = (int)Math.min(sizePendingLargeMessage - positionPendingLargeMessage, minLargeMessageSize);
- HornetQBuffer bodyBuffer = ChannelBuffers.buffer(localChunkLen);
+ HornetQBuffer bodyBuffer = HornetQChannelBuffers.buffer(localChunkLen);
context.encode(bodyBuffer, localChunkLen);
Modified: branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerMessageImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerMessageImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerMessageImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -309,23 +309,11 @@
// Used when storing to/from journal
- //TODO - this can be further optimised, so when writing into the journal, we just write the message's already existing
- //buffer directly into the timed buffer, the journal specific headers can be added in the timed buffer when the smaller
- //buffer is copied into the timed buffer's larger buffer
-
public void encode(HornetQBuffer buffer)
{
- //FIXME - this won't work
- buffer.writeBytes(buffer, PacketImpl.PACKET_HEADERS_SIZE, 0);
+
}
-// public void decode(HornetQBuffer buffer)
-// {
-// this.decodeHeadersAndProperties(buffer);
-//
-// this.buffer = buffer;
-// }
-
@Override
public String toString()
{
Modified: branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -28,7 +28,7 @@
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.impl.ClientMessageImpl;
import org.hornetq.core.client.management.impl.ManagementHelper;
import org.hornetq.core.exception.HornetQException;
@@ -113,30 +113,30 @@
private static final Logger log = Logger.getLogger(ServerSessionImpl.class);
// Static -------------------------------------------------------------------------------
-
- //TODO not actually used currently
-// private static int offset;
-//
-// static
-// {
-// try
-// {
-// ServerMessage msg = new ServerMessageImpl(1, ChannelBuffers.EMPTY_BUFFER);
-//
-// msg.setDestination(new SimpleString("foobar"));
-//
-// int es = msg.getEncodeSize();
-//
-// int me = msg.getMemoryEstimate();
-//
-// offset = MessageReferenceImpl.getMemoryEstimate() + me - es;
-// }
-// catch (Exception e)
-// {
-// log.error("Failed to initialise mult and offset", e);
-// }
-// }
+ // TODO not actually used currently
+ // private static int offset;
+ //
+ // static
+ // {
+ // try
+ // {
+ // ServerMessage msg = new ServerMessageImpl(1, ChannelBuffers.EMPTY_BUFFER);
+ //
+ // msg.setDestination(new SimpleString("foobar"));
+ //
+ // int es = msg.getEncodeSize();
+ //
+ // int me = msg.getMemoryEstimate();
+ //
+ // offset = MessageReferenceImpl.getMemoryEstimate() + me - es;
+ // }
+ // catch (Exception e)
+ // {
+ // log.error("Failed to initialise mult and offset", e);
+ // }
+ // }
+
// Attributes ----------------------------------------------------------------------------
private final long id;
@@ -1458,15 +1458,13 @@
Packet response = null;
ServerMessage message = packet.getServerMessage();
-
- //log.info("Got msg on server");
-
+
try
{
long id = storageManager.generateUniqueID();
message.setMessageID(id);
-
+
if (message.getDestination().equals(managementAddress))
{
// It's a management message
@@ -1477,10 +1475,7 @@
{
send(message);
}
-
- //log.info("requires response "+ packet.isRequiresResponse());
-
-
+
if (packet.isRequiresResponse())
{
response = new NullResponseMessage();
@@ -1531,7 +1526,7 @@
// Immediately release the credits for the continuations- these don't contrinute to the in-memory size
// of the message
- releaseOutStanding(currentLargeMessage, packet.getRequiredBufferSize());
+ releaseOutStanding(currentLargeMessage, packet.getPacketSize());
currentLargeMessage.addBytes(packet.getBody());
@@ -1545,7 +1540,7 @@
currentLargeMessage = null;
}
-
+
if (packet.isRequiresResponse())
{
response = new NullResponseMessage();
@@ -1732,7 +1727,7 @@
}
});
-
+
storageManager.completeReplication();
}
else
@@ -1755,7 +1750,7 @@
if (confirmPacket != null)
{
channel.confirm(confirmPacket);
-
+
if (flush)
{
channel.flushConfirmations();
@@ -1944,14 +1939,14 @@
}
private void sendProducerCredits(final CreditManagerHolder holder, final int credits, final SimpleString address)
- {
+ {
holder.outstandingCredits += credits;
Packet packet = new SessionProducerCreditsMessage(credits, address, -1);
channel.send(packet);
}
-
+
private void send(final ServerMessage msg) throws Exception
{
// Look up the paging store
@@ -1971,7 +1966,7 @@
}
if (tx == null || autoCommitSends)
- {
+ {
postOffice.route(msg);
}
else
Modified: branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/ChannelBufferWrapper.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/ChannelBufferWrapper.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/ChannelBufferWrapper.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -401,5 +401,10 @@
{
return buffer;
}
+
+ public HornetQBuffer copy()
+ {
+ return new ChannelBufferWrapper(buffer.copy(0, buffer.capacity()));
+ }
}
Modified: branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQBytesMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQBytesMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQBytesMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -47,8 +47,6 @@
// Attributes ----------------------------------------------------
- private HornetQBuffer buffer;
-
// Constructor ---------------------------------------------------
/*
@@ -92,7 +90,7 @@
checkRead();
try
{
- return buffer.readBoolean();
+ return getBuffer().readBoolean();
}
catch (IndexOutOfBoundsException e)
{
@@ -105,7 +103,7 @@
checkRead();
try
{
- return buffer.readByte();
+ return getBuffer().readByte();
}
catch (IndexOutOfBoundsException e)
{
@@ -118,7 +116,7 @@
checkRead();
try
{
- return buffer.readUnsignedByte();
+ return getBuffer().readUnsignedByte();
}
catch (IndexOutOfBoundsException e)
{
@@ -131,7 +129,7 @@
checkRead();
try
{
- return buffer.readShort();
+ return getBuffer().readShort();
}
catch (IndexOutOfBoundsException e)
{
@@ -144,7 +142,7 @@
checkRead();
try
{
- return buffer.readUnsignedShort();
+ return getBuffer().readUnsignedShort();
}
catch (IndexOutOfBoundsException e)
{
@@ -157,7 +155,7 @@
checkRead();
try
{
- return buffer.readChar();
+ return getBuffer().readChar();
}
catch (IndexOutOfBoundsException e)
{
@@ -170,7 +168,7 @@
checkRead();
try
{
- return buffer.readInt();
+ return getBuffer().readInt();
}
catch (IndexOutOfBoundsException e)
{
@@ -183,7 +181,7 @@
checkRead();
try
{
- return buffer.readLong();
+ return getBuffer().readLong();
}
catch (IndexOutOfBoundsException e)
{
@@ -196,7 +194,7 @@
checkRead();
try
{
- return buffer.readFloat();
+ return getBuffer().readFloat();
}
catch (IndexOutOfBoundsException e)
{
@@ -209,7 +207,7 @@
checkRead();
try
{
- return buffer.readDouble();
+ return getBuffer().readDouble();
}
catch (IndexOutOfBoundsException e)
{
@@ -222,7 +220,7 @@
checkRead();
try
{
- return buffer.readUTF();
+ return getBuffer().readUTF();
}
catch (IndexOutOfBoundsException e)
{
@@ -246,13 +244,13 @@
{
checkRead();
- if (!buffer.readable()) { return -1; }
+ if (!getBuffer().readable()) { return -1; }
- int read = Math.min(length, buffer.readableBytes());
+ int read = Math.min(length, getBuffer().readableBytes());
if (read != 0)
{
- buffer.readBytes(value, 0, read);
+ getBuffer().readBytes(value, 0, read);
}
return read;
@@ -261,49 +259,49 @@
public void writeBoolean(final boolean value) throws JMSException
{
checkWrite();
- buffer.writeBoolean(value);
+ getBuffer().writeBoolean(value);
}
public void writeByte(final byte value) throws JMSException
{
checkWrite();
- buffer.writeByte(value);
+ getBuffer().writeByte(value);
}
public void writeShort(final short value) throws JMSException
{
checkWrite();
- buffer.writeShort(value);
+ getBuffer().writeShort(value);
}
public void writeChar(final char value) throws JMSException
{
checkWrite();
- buffer.writeChar(value);
+ getBuffer().writeChar(value);
}
public void writeInt(final int value) throws JMSException
{
checkWrite();
- buffer.writeInt(value);
+ getBuffer().writeInt(value);
}
public void writeLong(final long value) throws JMSException
{
checkWrite();
- buffer.writeLong(value);
+ getBuffer().writeLong(value);
}
public void writeFloat(final float value) throws JMSException
{
checkWrite();
- buffer.writeFloat(value);
+ getBuffer().writeFloat(value);
}
public void writeDouble(final double value) throws JMSException
{
checkWrite();
- buffer.writeDouble(value);
+ getBuffer().writeDouble(value);
}
public void writeUTF(final String value) throws JMSException
@@ -311,7 +309,7 @@
checkWrite();
try
{
- buffer.writeUTF(value);
+ getBuffer().writeUTF(value);
}
catch (Exception e)
{
@@ -324,14 +322,14 @@
public void writeBytes(final byte[] value) throws JMSException
{
checkWrite();
- buffer.writeBytes(value);
+ getBuffer().writeBytes(value);
}
public void writeBytes(final byte[] value, final int offset, final int length)
throws JMSException
{
checkWrite();
- buffer.writeBytes(value, offset, length);
+ getBuffer().writeBytes(value, offset, length);
}
public void writeObject(final Object value) throws JMSException
@@ -390,11 +388,11 @@
{
readOnly = true;
- buffer.resetReaderIndex();
+ getBuffer().resetReaderIndex();
}
else
{
- buffer.resetReaderIndex();
+ getBuffer().resetReaderIndex();
}
}
@@ -404,7 +402,7 @@
{
super.clearBody();
- buffer.clear();
+ getBuffer().clear();
}
public long getBodyLength() throws JMSException
@@ -417,10 +415,6 @@
public void doBeforeSend() throws Exception
{
reset();
-
- message.encodeToBuffer();
-
- message.getBuffer().writeBytes(buffer, 0, buffer.writerIndex());
}
// Public --------------------------------------------------------
@@ -435,6 +429,11 @@
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
-
+
+ private HornetQBuffer getBuffer()
+ {
+ return message.getBuffer();
+ }
+
// Inner classes -------------------------------------------------
}
Modified: branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQConnectionFactory.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -540,7 +540,18 @@
checkWrite();
sessionFactory.setThreadPoolMaxSize(threadPoolMaxSize);
}
+
+ public synchronized int getInitialMessagePacketSize()
+ {
+ return sessionFactory.getInitialMessagePacketSize();
+ }
+ public synchronized void setInitialMessagePacketSize(int size)
+ {
+ checkWrite();
+ sessionFactory.setInitialMessagePacketSize(size);
+ }
+
public ClientSessionFactory getCoreFactory()
{
return sessionFactory;
Modified: branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQMapMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQMapMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQMapMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -366,8 +366,6 @@
public void doBeforeSend() throws Exception
{
- message.encodeToBuffer();
-
map.encode(message.getBuffer());
super.doBeforeSend();
Modified: branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -33,7 +33,7 @@
import javax.jms.MessageNotReadableException;
import javax.jms.MessageNotWriteableException;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientSession;
import org.hornetq.core.client.impl.ClientMessageImpl;
Modified: branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQObjectMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQObjectMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQObjectMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -11,14 +11,13 @@
* permissions and limitations under the License.
*/
-
package org.hornetq.jms.client;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.io.OutputStream;
import java.io.Serializable;
import javax.jms.JMSException;
@@ -26,6 +25,7 @@
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientSession;
+import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
@@ -47,22 +47,23 @@
{
// Constants -----------------------------------------------------
+ public static final Logger log = Logger.getLogger(HornetQObjectMessage.class);
+
public static final byte TYPE = 2;
// Attributes ----------------------------------------------------
-
+
private Serializable object;
-
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
-
- public HornetQObjectMessage( final ClientSession session)
+ public HornetQObjectMessage(final ClientSession session)
{
super(HornetQObjectMessage.TYPE, session);
}
-
+
public HornetQObjectMessage(final ClientMessage message, ClientSession session)
{
super(message, session);
@@ -75,7 +76,7 @@
{
super(foreign, HornetQObjectMessage.TYPE, session);
- setObject(foreign.getObject());
+ setObject(foreign.getObject());
}
// Public --------------------------------------------------------
@@ -84,34 +85,66 @@
{
return HornetQObjectMessage.TYPE;
}
-
+
public void doBeforeSend() throws Exception
- {
+ {
super.doBeforeSend();
-
- ObjectOutputStream oos = new ObjectOutputStream(new BufferOutputStream(message.getBuffer()));
-
- oos.writeObject(object);
-
- oos.flush();
}
-
+
public void doBeforeReceive() throws Exception
{
super.doBeforeReceive();
- ObjectInputStream ois = new ObjectInputStream(new BufferInputStream(message.getBuffer()));
+ HornetQBuffer buffer = message.getBuffer();
- object = (Serializable)ois.readObject();
+ byte[] bytes = new byte[buffer.writerIndex() - buffer.readerIndex()];
+
+ buffer.readBytes(bytes);
+
+ ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
+
+ object = (Serializable)ois.readObject();
}
-
+
// ObjectMessage implementation ----------------------------------
public void setObject(Serializable object) throws JMSException
- {
+ {
checkWrite();
this.object = object;
+
+// This is actually slower than serializing into a byte[] first
+// try
+// {
+// ObjectOutputStream oos = new ObjectOutputStream(new BufferOutputStream(message.getBuffer()));
+//
+// oos.writeObject(object);
+//
+// oos.flush();
+// }
+// catch (IOException e)
+// {
+// log.error("Failed to serialise object", e);
+// }
+
+ //It's actually faster to serialize into a ByteArrayOutputStream than direct into the buffer
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
+
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+
+ oos.writeObject(object);
+
+ oos.flush();
+
+ message.getBuffer().writeBytes(baos.toByteArray());
+ }
+ catch (IOException e)
+ {
+ log.error("Failed to serialise object", e);
+ }
}
// lazy deserialize the Object the first time the client requests it
@@ -123,47 +156,47 @@
public void clearBody() throws JMSException
{
super.clearBody();
-
+
object = null;
}
-
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
-
+
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
-
- private static class BufferOutputStream extends OutputStream
- {
- private HornetQBuffer buffer;
-
- BufferOutputStream(final HornetQBuffer buffer)
- {
- this.buffer = buffer;
- }
- @Override
- public void write(final int b) throws IOException
- {
- buffer.writeByte((byte)b);
- }
- }
-
- private static class BufferInputStream extends InputStream
- {
- private HornetQBuffer buffer;
-
- BufferInputStream(final HornetQBuffer buffer)
- {
- this.buffer = buffer;
- }
-
- @Override
- public int read() throws IOException
- {
- return buffer.readByte();
- }
- }
+// private static class BufferOutputStream extends OutputStream
+// {
+// private HornetQBuffer buffer;
+//
+// BufferOutputStream(final HornetQBuffer buffer)
+// {
+// this.buffer = buffer;
+// }
+//
+// @Override
+// public void write(final int b) throws IOException
+// {
+// buffer.writeByte((byte)b);
+// }
+// }
+//
+// private static class BufferInputStream extends InputStream
+// {
+// private HornetQBuffer buffer;
+//
+// BufferInputStream(final HornetQBuffer buffer)
+// {
+// this.buffer = buffer;
+// }
+//
+// @Override
+// public int read() throws IOException
+// {
+// return buffer.readByte();
+// }
+// }
}
Modified: branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQStreamMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQStreamMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQStreamMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -51,8 +51,6 @@
// Attributes ----------------------------------------------------
- private HornetQBuffer buffer;
-
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -102,14 +100,14 @@
checkRead();
try
{
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
switch (type)
{
case DataConstants.BOOLEAN:
- return buffer.readBoolean();
+ return getBuffer().readBoolean();
case DataConstants.STRING:
- String s = buffer.readNullableString();
+ String s = getBuffer().readNullableString();
return Boolean.valueOf(s);
default:
throw new MessageFormatException("Invalid conversion");
@@ -126,13 +124,13 @@
checkRead();
try
{
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
switch (type)
{
case DataConstants.BYTE:
- return buffer.readByte();
+ return getBuffer().readByte();
case DataConstants.STRING:
- String s = buffer.readNullableString();
+ String s = getBuffer().readNullableString();
return Byte.parseByte(s);
default:
throw new MessageFormatException("Invalid conversion");
@@ -149,15 +147,15 @@
checkRead();
try
{
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
switch (type)
{
case DataConstants.BYTE:
- return buffer.readByte();
+ return getBuffer().readByte();
case DataConstants.SHORT:
- return buffer.readShort();
+ return getBuffer().readShort();
case DataConstants.STRING:
- String s = buffer.readNullableString();
+ String s = getBuffer().readNullableString();
return Short.parseShort(s);
default:
throw new MessageFormatException("Invalid conversion");
@@ -174,11 +172,11 @@
checkRead();
try
{
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
switch (type)
{
case DataConstants.CHAR:
- return buffer.readChar();
+ return getBuffer().readChar();
default:
throw new MessageFormatException("Invalid conversion");
}
@@ -194,17 +192,17 @@
checkRead();
try
{
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
switch (type)
{
case DataConstants.BYTE:
- return buffer.readByte();
+ return getBuffer().readByte();
case DataConstants.SHORT:
- return buffer.readShort();
+ return getBuffer().readShort();
case DataConstants.INT:
- return buffer.readInt();
+ return getBuffer().readInt();
case DataConstants.STRING:
- String s = buffer.readNullableString();
+ String s = getBuffer().readNullableString();
return Integer.parseInt(s);
default:
throw new MessageFormatException("Invalid conversion");
@@ -221,19 +219,19 @@
checkRead();
try
{
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
switch (type)
{
case DataConstants.BYTE:
- return buffer.readByte();
+ return getBuffer().readByte();
case DataConstants.SHORT:
- return buffer.readShort();
+ return getBuffer().readShort();
case DataConstants.INT:
- return buffer.readInt();
+ return getBuffer().readInt();
case DataConstants.LONG:
- return buffer.readLong();
+ return getBuffer().readLong();
case DataConstants.STRING:
- String s = buffer.readNullableString();
+ String s = getBuffer().readNullableString();
return Long.parseLong(s);
default:
throw new MessageFormatException("Invalid conversion");
@@ -250,13 +248,13 @@
checkRead();
try
{
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
switch (type)
{
case DataConstants.FLOAT:
- return buffer.readFloat();
+ return getBuffer().readFloat();
case DataConstants.STRING:
- String s = buffer.readNullableString();
+ String s = getBuffer().readNullableString();
return Float.parseFloat(s);
default:
throw new MessageFormatException("Invalid conversion");
@@ -273,15 +271,15 @@
checkRead();
try
{
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
switch (type)
{
case DataConstants.FLOAT:
- return buffer.readFloat();
+ return getBuffer().readFloat();
case DataConstants.DOUBLE:
- return buffer.readDouble();
+ return getBuffer().readDouble();
case DataConstants.STRING:
- String s = buffer.readNullableString();
+ String s = getBuffer().readNullableString();
return Double.parseDouble(s);
default:
throw new MessageFormatException("Invalid conversion: " + type);
@@ -298,27 +296,27 @@
checkRead();
try
{
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
switch (type)
{
case DataConstants.BOOLEAN:
- return String.valueOf(buffer.readBoolean());
+ return String.valueOf(getBuffer().readBoolean());
case DataConstants.BYTE:
- return String.valueOf(buffer.readByte());
+ return String.valueOf(getBuffer().readByte());
case DataConstants.SHORT:
- return String.valueOf(buffer.readShort());
+ return String.valueOf(getBuffer().readShort());
case DataConstants.CHAR:
- return String.valueOf(buffer.readChar());
+ return String.valueOf(getBuffer().readChar());
case DataConstants.INT:
- return String.valueOf(buffer.readInt());
+ return String.valueOf(getBuffer().readInt());
case DataConstants.LONG:
- return String.valueOf(buffer.readLong());
+ return String.valueOf(getBuffer().readLong());
case DataConstants.FLOAT:
- return String.valueOf(buffer.readFloat());
+ return String.valueOf(getBuffer().readFloat());
case DataConstants.DOUBLE:
- return String.valueOf(buffer.readDouble());
+ return String.valueOf(getBuffer().readDouble());
case DataConstants.STRING:
- return buffer.readNullableString();
+ return getBuffer().readNullableString();
default:
throw new MessageFormatException("Invalid conversion");
}
@@ -343,15 +341,15 @@
}
else if (len == 0)
{
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
if (type != DataConstants.BYTES)
{
throw new MessageFormatException("Invalid conversion");
}
- len = buffer.readInt();
+ len = getBuffer().readInt();
}
int read = Math.min(value.length, len);
- buffer.readBytes(value, 0, read);
+ getBuffer().readBytes(value, 0, read);
len -= read;
if (len == 0)
{
@@ -368,31 +366,31 @@
public Object readObject() throws JMSException
{
checkRead();
- byte type = buffer.readByte();
+ byte type = getBuffer().readByte();
switch (type)
{
case DataConstants.BOOLEAN:
- return buffer.readBoolean();
+ return getBuffer().readBoolean();
case DataConstants.BYTE:
- return buffer.readByte();
+ return getBuffer().readByte();
case DataConstants.SHORT:
- return buffer.readShort();
+ return getBuffer().readShort();
case DataConstants.CHAR:
- return buffer.readChar();
+ return getBuffer().readChar();
case DataConstants.INT:
- return buffer.readInt();
+ return getBuffer().readInt();
case DataConstants.LONG:
- return buffer.readLong();
+ return getBuffer().readLong();
case DataConstants.FLOAT:
- return buffer.readFloat();
+ return getBuffer().readFloat();
case DataConstants.DOUBLE:
- return buffer.readDouble();
+ return getBuffer().readDouble();
case DataConstants.STRING:
- return buffer.readNullableString();
+ return getBuffer().readNullableString();
case DataConstants.BYTES:
- int len = buffer.readInt();
+ int len = getBuffer().readInt();
byte[] bytes = new byte[len];
- buffer.readBytes(bytes);
+ getBuffer().readBytes(bytes);
return bytes;
default:
throw new MessageFormatException("Invalid conversion");
@@ -402,80 +400,80 @@
public void writeBoolean(final boolean value) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.BOOLEAN);
- buffer.writeBoolean(value);
+ getBuffer().writeByte(DataConstants.BOOLEAN);
+ getBuffer().writeBoolean(value);
}
public void writeByte(final byte value) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.BYTE);
- buffer.writeByte(value);
+ getBuffer().writeByte(DataConstants.BYTE);
+ getBuffer().writeByte(value);
}
public void writeShort(final short value) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.SHORT);
- buffer.writeShort(value);
+ getBuffer().writeByte(DataConstants.SHORT);
+ getBuffer().writeShort(value);
}
public void writeChar(final char value) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.CHAR);
- buffer.writeChar(value);
+ getBuffer().writeByte(DataConstants.CHAR);
+ getBuffer().writeChar(value);
}
public void writeInt(final int value) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.INT);
- buffer.writeInt(value);
+ getBuffer().writeByte(DataConstants.INT);
+ getBuffer().writeInt(value);
}
public void writeLong(final long value) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.LONG);
- buffer.writeLong(value);
+ getBuffer().writeByte(DataConstants.LONG);
+ getBuffer().writeLong(value);
}
public void writeFloat(final float value) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.FLOAT);
- buffer.writeFloat(value);
+ getBuffer().writeByte(DataConstants.FLOAT);
+ getBuffer().writeFloat(value);
}
public void writeDouble(final double value) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.DOUBLE);
- buffer.writeDouble(value);
+ getBuffer().writeByte(DataConstants.DOUBLE);
+ getBuffer().writeDouble(value);
}
public void writeString(final String value) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.STRING);
- buffer.writeNullableString(value);
+ getBuffer().writeByte(DataConstants.STRING);
+ getBuffer().writeNullableString(value);
}
public void writeBytes(final byte[] value) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.BYTES);
- buffer.writeInt(value.length);
- buffer.writeBytes(value);
+ getBuffer().writeByte(DataConstants.BYTES);
+ getBuffer().writeInt(value.length);
+ getBuffer().writeBytes(value);
}
public void writeBytes(final byte[] value, final int offset, final int length) throws JMSException
{
checkWrite();
- buffer.writeByte(DataConstants.BYTES);
- buffer.writeInt(length);
- buffer.writeBytes(value, offset, length);
+ getBuffer().writeByte(DataConstants.BYTES);
+ getBuffer().writeInt(length);
+ getBuffer().writeBytes(value, offset, length);
}
public void writeObject(final Object value) throws JMSException
@@ -536,7 +534,7 @@
{
readOnly = true;
}
- buffer.resetReaderIndex();
+ getBuffer().resetReaderIndex();
}
// HornetQRAMessage overrides ----------------------------------------
@@ -546,18 +544,13 @@
{
super.clearBody();
- buffer.clear();
-
+ getBuffer().clear();
}
@Override
public void doBeforeSend() throws Exception
{
reset();
-
- message.encodeToBuffer();
-
- message.getBuffer().writeBytes(buffer, 0, buffer.writerIndex());
}
// Package protected ---------------------------------------------
@@ -565,6 +558,11 @@
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
+
+ private HornetQBuffer getBuffer()
+ {
+ return message.getBuffer();
+ }
// Inner classes -------------------------------------------------
}
Modified: branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQTextMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQTextMessage.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQTextMessage.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -21,6 +21,7 @@
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientSession;
import org.hornetq.core.logging.Logger;
+import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.SimpleString;
/**
@@ -89,11 +90,23 @@
checkWrite();
this.text = new SimpleString(text);
+
+ //Reset buffer to just after standard headers space
+ message.resetBuffer();
+
+ message.getBuffer().writeNullableSimpleString(this.text);
}
public String getText() throws JMSException
{
- return text.toString();
+ if (text != null)
+ {
+ return text.toString();
+ }
+ else
+ {
+ return null;
+ }
}
public void clearBody() throws JMSException
@@ -105,19 +118,6 @@
// HornetQRAMessage override -----------------------------------------
- private SimpleString dest = new SimpleString("jms.queue.test_queue");
-
- public void doBeforeSend() throws Exception
- {
- message.setDestination(dest);
-
- message.encodeToBuffer();
-
- message.getBuffer().writeNullableSimpleString(text);
-
- super.doBeforeSend();
- }
-
public void doBeforeReceive() throws Exception
{
super.doBeforeReceive();
Modified: branches/20-optimisation/tests/jms-tests/src/org/hornetq/jms/tests/message/MessageHeaderTest.java
===================================================================
--- branches/20-optimisation/tests/jms-tests/src/org/hornetq/jms/tests/message/MessageHeaderTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/jms-tests/src/org/hornetq/jms/tests/message/MessageHeaderTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -33,7 +33,7 @@
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -672,7 +672,7 @@
public void testCopyOnJBossMessage() throws JMSException
{
- HornetQBuffer body = ChannelBuffers.buffer(1024);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
ClientSession session = new FakeSession(clientMessage);
HornetQMessage jbossMessage = new HornetQMessage();
@@ -687,7 +687,7 @@
public void testCopyOnForeignMessage() throws JMSException
{
- HornetQBuffer body = ChannelBuffers.buffer(1024);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
ClientSession session = new FakeSession(clientMessage);
@@ -701,7 +701,7 @@
public void testCopyOnForeignBytesMessage() throws JMSException
{
- HornetQBuffer body = ChannelBuffers.buffer(1024);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
ClientSession session = new FakeSession(clientMessage);
@@ -721,7 +721,7 @@
public void testCopyOnForeignMapMessage() throws JMSException
{
- HornetQBuffer body = ChannelBuffers.buffer(1024);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
ClientSession session = new FakeSession(clientMessage);
MapMessage foreignMapMessage = new SimpleJMSMapMessage();
@@ -736,7 +736,7 @@
public void testCopyOnForeignObjectMessage() throws JMSException
{
- HornetQBuffer body = ChannelBuffers.buffer(1024);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
ClientSession session = new FakeSession(clientMessage);
@@ -750,7 +750,7 @@
public void testCopyOnForeignStreamMessage() throws JMSException
{
- HornetQBuffer body = ChannelBuffers.buffer(1024);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
ClientSession session = new FakeSession(clientMessage);
@@ -767,7 +767,7 @@
public void testCopyOnForeignTextMessage() throws JMSException
{
- HornetQBuffer body = ChannelBuffers.buffer(1024);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
ClientSession session = new FakeSession(clientMessage);
TextMessage foreignTextMessage = new SimpleJMSTextMessage();
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/EncodeSizeTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/EncodeSizeTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/EncodeSizeTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -13,7 +13,7 @@
package org.hornetq.tests.integration;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.impl.ClientMessageImpl;
import org.hornetq.core.logging.Logger;
@@ -58,13 +58,13 @@
byte[] bytes = RandomUtil.randomBytes(1000);
- HornetQBuffer body = ChannelBuffers.dynamicBuffer(bytes);
+ HornetQBuffer body = HornetQChannelBuffers.dynamicBuffer(bytes);
clientMessage.setBuffer(body);
int clientEncodeSize = clientMessage.getEncodeSize();
- HornetQBuffer buffer = ChannelBuffers.dynamicBuffer(clientEncodeSize);
+ HornetQBuffer buffer = HornetQChannelBuffers.dynamicBuffer(clientEncodeSize);
clientMessage.encode(buffer);
@@ -102,7 +102,7 @@
byte[] bytes = RandomUtil.randomBytes(1000);
- HornetQBuffer body = ChannelBuffers.dynamicBuffer(bytes);
+ HornetQBuffer body = HornetQChannelBuffers.dynamicBuffer(bytes);
clientMessage.setBuffer(body);
@@ -110,7 +110,7 @@
SessionSendMessage packet = new SessionSendMessage(clientMessage, false);
- HornetQBuffer buffer = ChannelBuffers.dynamicBuffer(packet.getRequiredBufferSize());
+ HornetQBuffer buffer = HornetQChannelBuffers.dynamicBuffer(packet.getRequiredBufferSize());
packet.encode(buffer);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/AckBatchSizeTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/AckBatchSizeTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/AckBatchSizeTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -17,6 +17,7 @@
import org.hornetq.core.client.ClientProducer;
import org.hornetq.core.client.ClientSession;
import org.hornetq.core.client.ClientSessionFactory;
+import org.hornetq.core.logging.Logger;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.Queue;
import org.hornetq.tests.util.ServiceTestBase;
@@ -27,6 +28,8 @@
*/
public class AckBatchSizeTest extends ServiceTestBase
{
+ private static final Logger log = Logger.getLogger(AckBatchSizeTest.class);
+
public final SimpleString addressA = new SimpleString("addressA");
public final SimpleString queueA = new SimpleString("queueA");
@@ -40,7 +43,7 @@
/*
* tests that wed don't acknowledge until the correct ackBatchSize is reached
* */
-
+
private int getMessageEncodeSize(final SimpleString address) throws Exception
{
ClientSessionFactory cf = createInVMFactory();
@@ -51,7 +54,7 @@
int encodeSize = message.getEncodeSize();
session.close();
cf.close();
- return encodeSize;
+ return encodeSize;
}
public void testAckBatchSize() throws Exception
@@ -62,11 +65,11 @@
{
server.start();
ClientSessionFactory cf = createInVMFactory();
- int numMessages = 100;
+ int numMessages = 100;
cf.setAckBatchSize(numMessages * getMessageEncodeSize(addressA));
cf.setBlockOnAcknowledge(true);
ClientSession sendSession = cf.createSession(false, true, true);
-
+
ClientSession session = cf.createSession(false, true, true);
session.createQueue(addressA, queueA, false);
ClientProducer cp = sendSession.createProducer(addressA);
@@ -75,16 +78,20 @@
cp.send(sendSession.createClientMessage(false));
}
+ log.info("sent messages");
+
ClientConsumer consumer = session.createConsumer(queueA);
session.start();
for (int i = 0; i < numMessages - 1; i++)
{
ClientMessage m = consumer.receive(5000);
+
+ log.info("got message " + i);
m.acknowledge();
}
ClientMessage m = consumer.receive(5000);
- Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
+ Queue q = (Queue)server.getPostOffice().getBinding(queueA).getBindable();
assertEquals(numMessages, q.getDeliveringCount());
m.acknowledge();
assertEquals(0, q.getDeliveringCount());
@@ -115,7 +122,7 @@
cf.setBlockOnAcknowledge(true);
ClientSession sendSession = cf.createSession(false, true, true);
int numMessages = 100;
-
+
ClientSession session = cf.createSession(false, true, true);
session.createQueue(addressA, queueA, false);
ClientProducer cp = sendSession.createProducer(addressA);
@@ -126,7 +133,7 @@
ClientConsumer consumer = session.createConsumer(queueA);
session.start();
- Queue q = (Queue) server.getPostOffice().getBinding(queueA).getBindable();
+ Queue q = (Queue)server.getPostOffice().getBinding(queueA).getBindable();
ClientMessage[] messages = new ClientMessage[numMessages];
for (int i = 0; i < numMessages; i++)
{
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/CoreClientTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/CoreClientTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/CoreClientTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -109,12 +109,24 @@
*
* message.setDestination("foo");
*
- * message.encodeToBuffer();
+ * message.writeBody();
*
* message.getBuffer().writeString("testINVMCoreClient");
*
* message.send();
*
+ *
+ * ORRR
+ *
+ * we don't write the headers and properties until *AFTER* the body
+ *
+ * giving this format:
+ * body length
+ * body
+ * headers + properties
+ *
+ * this means we don't need an encodeToBuffer() method!!
+ *
*/
ClientMessage message = session.createClientMessage(HornetQTextMessage.TYPE,
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/LargeMessageTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/LargeMessageTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/LargeMessageTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -20,7 +20,7 @@
import junit.framework.AssertionFailedError;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -2210,7 +2210,7 @@
for (int i = 0; i < 100; i++)
{
- HornetQBuffer bodyLocal = ChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfBytes);
+ HornetQBuffer bodyLocal = HornetQChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfBytes);
for (int j = 1; j <= numberOfBytes; j++)
{
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/PagingTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/PagingTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/PagingTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -18,7 +18,7 @@
import junit.framework.AssertionFailedError;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -234,7 +234,7 @@
ClientProducer producer = session.createProducer(ADDRESS);
- HornetQBuffer bodyLocal = ChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfIntegers);
+ HornetQBuffer bodyLocal = HornetQChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfIntegers);
ClientMessage message = null;
@@ -387,7 +387,7 @@
{
message = session.createClientMessage(true);
- message.setBuffer(ChannelBuffers.wrappedBuffer(body));
+ message.setBuffer(HornetQChannelBuffers.wrappedBuffer(body));
message.putIntProperty(new SimpleString("id"), i);
TestSupportPageStore store = (TestSupportPageStore)server.getPostOffice()
@@ -669,7 +669,7 @@
for (int i = 0; i < numberOfMessages; i++)
{
- HornetQBuffer bodyLocal = ChannelBuffers.wrappedBuffer(new byte[1024]);
+ HornetQBuffer bodyLocal = HornetQChannelBuffers.wrappedBuffer(new byte[1024]);
message = session.createClientMessage(true);
message.setBuffer(bodyLocal);
@@ -697,7 +697,7 @@
for (int i = 0; i < numberOfMessages; i++)
{
- HornetQBuffer bodyLocal = ChannelBuffers.wrappedBuffer(new byte[1024]);
+ HornetQBuffer bodyLocal = HornetQChannelBuffers.wrappedBuffer(new byte[1024]);
message = session.createClientMessage(true);
message.setBuffer(bodyLocal);
@@ -724,7 +724,7 @@
for (int i = 0; i < numberOfMessages; i++)
{
- HornetQBuffer bodyLocal = ChannelBuffers.wrappedBuffer(new byte[1024]);
+ HornetQBuffer bodyLocal = HornetQChannelBuffers.wrappedBuffer(new byte[1024]);
message = session.createClientMessage(true);
message.setBuffer(bodyLocal);
@@ -801,7 +801,7 @@
ClientMessage message = null;
- HornetQBuffer bodyLocal = ChannelBuffers.wrappedBuffer(new byte[1024]);
+ HornetQBuffer bodyLocal = HornetQChannelBuffers.wrappedBuffer(new byte[1024]);
message = session.createClientMessage(true);
message.setBuffer(bodyLocal);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/bridge/BridgeTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/bridge/BridgeTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/bridge/BridgeTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -20,7 +20,7 @@
import java.util.List;
import java.util.Map;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -666,7 +666,7 @@
{
ClientMessage message = session0.createClientMessage(false);
- message.setBuffer(ChannelBuffers.wrappedBuffer(new byte[1024]));
+ message.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
message.putIntProperty(propKey, i);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/PagingFailoverTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/PagingFailoverTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/PagingFailoverTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -17,7 +17,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -114,7 +114,7 @@
session.commit();
}
ClientMessage msg = session.createClientMessage(true);
- msg.setBuffer(ChannelBuffers.buffer(1024));
+ msg.setBuffer(HornetQChannelBuffers.buffer(1024));
msg.putIntProperty(new SimpleString("key"), i);
prod.send(msg);
}
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/ReplicatedDistributionTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/ReplicatedDistributionTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/ReplicatedDistributionTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -16,7 +16,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -78,7 +78,7 @@
{
ClientMessage msg = sessionOne.createClientMessage(true);
- msg.setBuffer(ChannelBuffers.wrappedBuffer(new byte[1024]));
+ msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
msg.putIntProperty(new SimpleString("key"), i);
@@ -182,7 +182,7 @@
for (int i = 0; i < 100; i++)
{
ClientMessage msg = sessionOne.createClientMessage(true);
- msg.setBuffer(ChannelBuffers.wrappedBuffer(new byte[1024]));
+ msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
msg.putIntProperty(new SimpleString("key"), i);
producer.send(msg);
}
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -24,7 +24,7 @@
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -591,7 +591,7 @@
protected HornetQBuffer createLargeBuffer(final int numberOfIntegers)
{
- HornetQBuffer body = ChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfIntegers);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfIntegers);
for (int i = 0; i < numberOfIntegers; i++)
{
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/management/ManagementHelperTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/management/ManagementHelperTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/management/ManagementHelperTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -24,7 +24,7 @@
import junit.framework.TestCase;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.impl.ClientMessageImpl;
import org.hornetq.core.client.management.impl.ManagementHelper;
import org.hornetq.core.logging.Logger;
@@ -58,7 +58,7 @@
String operationName = randomString();
String param = randomString();
String[] params = new String[] { randomString(), randomString(), randomString() };
- Message msg = new ClientMessageImpl(false, ChannelBuffers.dynamicBuffer(1024));
+ Message msg = new ClientMessageImpl(false, HornetQChannelBuffers.dynamicBuffer(1024));
ManagementHelper.putOperationInvocation(msg, resource, operationName, param, params);
Object[] parameters = ManagementHelper.retrieveOperationParameters(msg);
@@ -146,7 +146,7 @@
Object[] params = new Object[] { i, s, d, b, l, map, strArray, maps };
- Message msg = new ClientMessageImpl(false, ChannelBuffers.dynamicBuffer(1024));
+ Message msg = new ClientMessageImpl(false, HornetQChannelBuffers.dynamicBuffer(1024));
ManagementHelper.putOperationInvocation(msg, resource, operationName, params);
Object[] parameters = ManagementHelper.retrieveOperationParameters(msg);
@@ -212,7 +212,7 @@
Object[] params = new Object[] { "hello", map };
- Message msg = new ClientMessageImpl(false, ChannelBuffers.dynamicBuffer(1024));
+ Message msg = new ClientMessageImpl(false, HornetQChannelBuffers.dynamicBuffer(1024));
ManagementHelper.putOperationInvocation(msg, resource, operationName, params);
Object[] parameters = ManagementHelper.retrieveOperationParameters(msg);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/management/ManagementServiceImplTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/management/ManagementServiceImplTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/management/ManagementServiceImplTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -16,7 +16,7 @@
import static org.hornetq.tests.util.RandomUtil.randomSimpleString;
import static org.hornetq.tests.util.RandomUtil.randomString;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.management.impl.ManagementHelper;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
@@ -68,7 +68,7 @@
// invoke attribute and operation on the server
ServerMessage message = new ServerMessageImpl();
- HornetQBuffer body = ChannelBuffers.buffer(2048);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(2048);
message.setBuffer(body);
ManagementHelper.putOperationInvocation(message,
ResourceNames.CORE_SERVER,
@@ -93,7 +93,7 @@
// invoke attribute and operation on the server
ServerMessage message = new ServerMessageImpl();
- HornetQBuffer body = ChannelBuffers.buffer(2048);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(2048);
message.setBuffer(body);
ManagementHelper.putOperationInvocation(message,
ResourceNames.CORE_SERVER,
@@ -117,7 +117,7 @@
// invoke attribute and operation on the server
ServerMessage message = new ServerMessageImpl();
- HornetQBuffer body = ChannelBuffers.buffer(2048);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(2048);
message.setBuffer(body);
ManagementHelper.putOperationInvocation(message,
"Resouce.Does.Not.Exist",
@@ -141,7 +141,7 @@
// invoke attribute and operation on the server
ServerMessage message = new ServerMessageImpl();
- HornetQBuffer body = ChannelBuffers.buffer(2048);
+ HornetQBuffer body = HornetQChannelBuffers.buffer(2048);
message.setBuffer(body);
ManagementHelper.putAttribute(message, ResourceNames.CORE_SERVER, "attribute.Does.Not.Exist");
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -27,7 +27,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientSessionFactory;
import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
import org.hornetq.core.client.impl.FailoverManager;
@@ -292,7 +292,7 @@
SimpleString dummy = new SimpleString("dummy");
msg.setDestination(dummy);
- msg.setBuffer(ChannelBuffers.wrappedBuffer(new byte[10]));
+ msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[10]));
replicatedJournal.appendAddRecordTransactional(23, 24, (byte)1, new FakeData());
@@ -327,7 +327,7 @@
serverMsg.setMessageID(500);
serverMsg.setDestination(new SimpleString("tttt"));
- HornetQBuffer buffer = ChannelBuffers.dynamicBuffer(100);
+ HornetQBuffer buffer = HornetQChannelBuffers.dynamicBuffer(100);
serverMsg.encodeHeadersAndProperties(buffer);
manager.largeMessageBegin(500);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/performance/persistence/StorageManagerTimingTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/performance/persistence/StorageManagerTimingTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/performance/persistence/StorageManagerTimingTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -19,7 +19,7 @@
import java.util.concurrent.atomic.AtomicLong;
import org.hornetq.core.asyncio.impl.AsynchronousFileImpl;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.config.impl.FileConfiguration;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.persistence.impl.journal.JournalStorageManager;
@@ -171,12 +171,12 @@
true, /* expiration */
0,
/* timestamp */0, /* priority */
- (byte)0, ChannelBuffers.wrappedBuffer(new byte[1024]));
+ (byte)0, HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
implMsg.putStringProperty(new SimpleString("Key"), new SimpleString("This String is worthless!"));
implMsg.setMessageID(i);
- implMsg.setBuffer(ChannelBuffers.wrappedBuffer(bytes));
+ implMsg.setBuffer(HornetQChannelBuffers.wrappedBuffer(bytes));
implMsg.setDestination(address);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/CompactingStressTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/CompactingStressTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/CompactingStressTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -17,7 +17,7 @@
import java.util.concurrent.atomic.AtomicInteger;
import org.hornetq.core.asyncio.impl.AsynchronousFileImpl;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -186,7 +186,7 @@
byte[] buffer = new byte[10 * 1024];
ClientMessage msg = session.createClientMessage(true);
- msg.setBuffer(ChannelBuffers.wrappedBuffer(buffer));
+ msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(buffer));
for (int i = 0; i < TOT_AD3; i++)
{
producer.send(msg);
@@ -246,7 +246,7 @@
slowProd.send(session.createClientMessage(true));
}
ClientMessage msg = session.createClientMessage(true);
- msg.setBuffer(ChannelBuffers.wrappedBuffer(new byte[1024]));
+ msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
prod.send(msg);
}
sessionSlow.commit();
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/LargeJournalStressTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/LargeJournalStressTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/LargeJournalStressTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -16,7 +16,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -117,7 +117,7 @@
slowProd.send(session.createClientMessage(true));
}
ClientMessage msg = session.createClientMessage(true);
- msg.setBuffer(ChannelBuffers.wrappedBuffer(new byte[1024]));
+ msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
prod.send(msg);
}
sessionSlow.commit();
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/MultiThreadConsumerStressTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/MultiThreadConsumerStressTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/MultiThreadConsumerStressTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -16,7 +16,7 @@
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.*;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
@@ -249,7 +249,7 @@
System.out.println(Thread.currentThread().getName() + "::received #" + i);
}
ClientMessage msg = session.createClientMessage(true);
- msg.setBuffer(ChannelBuffers.wrappedBuffer(new byte[1024]));
+ msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
prod.send(msg);
}
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/NIOMultiThreadCompactorStressTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/NIOMultiThreadCompactorStressTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/NIOMultiThreadCompactorStressTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -22,7 +22,7 @@
import javax.transaction.xa.Xid;
import org.hornetq.core.asyncio.impl.AsynchronousFileImpl;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -455,7 +455,7 @@
// System.out.println(Thread.currentThread().getName() + "::sent #" + i);
}
ClientMessage msg = session.createClientMessage(true);
- msg.setBuffer(ChannelBuffers.wrappedBuffer(new byte[1024]));
+ msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
prod.send(msg);
}
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/timing/util/UTF8Test.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/timing/util/UTF8Test.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/timing/util/UTF8Test.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -13,7 +13,7 @@
package org.hornetq.tests.timing.util;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.tests.util.UnitTestCase;
import org.hornetq.utils.UTF8Util;
@@ -47,7 +47,7 @@
public void testWriteUTF() throws Exception
{
- HornetQBuffer buffer = ChannelBuffers.buffer(10 * 1024);
+ HornetQBuffer buffer = HornetQChannelBuffers.buffer(10 * 1024);
long start = System.currentTimeMillis();
@@ -72,7 +72,7 @@
public void testReadUTF() throws Exception
{
- HornetQBuffer buffer = ChannelBuffers.buffer(10 * 1024);
+ HornetQBuffer buffer = HornetQChannelBuffers.buffer(10 * 1024);
buffer.writeUTF(str);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/ByteBufferBackedHeapChannelBufferTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/ByteBufferBackedHeapChannelBufferTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/ByteBufferBackedHeapChannelBufferTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -14,8 +14,8 @@
import java.nio.ByteBuffer;
-import org.hornetq.core.buffers.ChannelBuffer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
/**
@@ -28,15 +28,15 @@
public class ByteBufferBackedHeapChannelBufferTest extends ChannelBuffersTestBase {
@Override
- protected ChannelBuffer newBuffer(int length) {
- ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(ByteBuffer.allocate(length));
+ protected HornetQChannelBuffer newBuffer(int length) {
+ HornetQChannelBuffer buffer = HornetQChannelBuffers.wrappedBuffer(ByteBuffer.allocate(length));
return buffer;
}
public void testShouldNotAllowNullInConstructor() {
try
{
- ChannelBuffers.wrappedBuffer((ByteBuffer)null);
+ HornetQChannelBuffers.wrappedBuffer((ByteBuffer)null);
fail("NullPointerException");
}
catch (NullPointerException e)
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/ChannelBuffersTestBase.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/ChannelBuffersTestBase.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/ChannelBuffersTestBase.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -12,7 +12,7 @@
*/
package org.hornetq.tests.unit.core.buffers;
-import static org.hornetq.core.buffers.ChannelBuffers.wrappedBuffer;
+import static org.hornetq.core.buffers.HornetQChannelBuffers.wrappedBuffer;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -20,7 +20,7 @@
import java.util.Arrays;
import java.util.Random;
-import org.hornetq.core.buffers.ChannelBuffer;
+import org.hornetq.core.buffers.HornetQChannelBuffer;
import org.hornetq.tests.util.UnitTestCase;
/**
@@ -43,9 +43,9 @@
private Random random;
- private ChannelBuffer buffer;
+ private HornetQChannelBuffer buffer;
- protected abstract ChannelBuffer newBuffer(int capacity);
+ protected abstract HornetQChannelBuffer newBuffer(int capacity);
@Override
public void setUp()
@@ -957,7 +957,7 @@
random.setSeed(seed);
byte[] expectedValueContent = new byte[BLOCK_SIZE];
- ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
+ HornetQChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
random.nextBytes(expectedValueContent);
@@ -980,7 +980,7 @@
random.setSeed(seed);
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
+ HornetQChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
random.nextBytes(expectedValueContent);
@@ -996,7 +996,7 @@
public void testRandomHeapBufferTransfer1()
{
byte[] valueContent = new byte[BLOCK_SIZE];
- ChannelBuffer value = wrappedBuffer(valueContent);
+ HornetQChannelBuffer value = wrappedBuffer(valueContent);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
random.nextBytes(valueContent);
@@ -1008,7 +1008,7 @@
random.setSeed(seed);
byte[] expectedValueContent = new byte[BLOCK_SIZE];
- ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
+ HornetQChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
random.nextBytes(expectedValueContent);
@@ -1026,7 +1026,7 @@
public void testRandomHeapBufferTransfer2()
{
byte[] valueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer value = wrappedBuffer(valueContent);
+ HornetQChannelBuffer value = wrappedBuffer(valueContent);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
random.nextBytes(valueContent);
@@ -1035,7 +1035,7 @@
random.setSeed(seed);
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
+ HornetQChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
random.nextBytes(expectedValueContent);
@@ -1134,7 +1134,7 @@
public void testSequentialHeapBufferTransfer1()
{
byte[] valueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer value = wrappedBuffer(valueContent);
+ HornetQChannelBuffer value = wrappedBuffer(valueContent);
buffer.writerIndex(0);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
@@ -1148,7 +1148,7 @@
random.setSeed(seed);
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
+ HornetQChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
random.nextBytes(expectedValueContent);
@@ -1168,7 +1168,7 @@
public void testSequentialHeapBufferTransfer2()
{
byte[] valueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer value = wrappedBuffer(valueContent);
+ HornetQChannelBuffer value = wrappedBuffer(valueContent);
buffer.writerIndex(0);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
@@ -1185,7 +1185,7 @@
random.setSeed(seed);
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
+ HornetQChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
random.nextBytes(expectedValueContent);
@@ -1207,7 +1207,7 @@
public void testSequentialByteBufferBackedHeapBufferTransfer1()
{
byte[] valueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
+ HornetQChannelBuffer value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
value.writerIndex(0);
buffer.writerIndex(0);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
@@ -1223,7 +1223,7 @@
random.setSeed(seed);
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
+ HornetQChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
random.nextBytes(expectedValueContent);
@@ -1244,7 +1244,7 @@
public void testSequentialByteBufferBackedHeapBufferTransfer2()
{
byte[] valueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
+ HornetQChannelBuffer value = wrappedBuffer(ByteBuffer.allocate(BLOCK_SIZE * 2));
value.writerIndex(0);
buffer.writerIndex(0);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
@@ -1264,7 +1264,7 @@
random.setSeed(seed);
byte[] expectedValueContent = new byte[BLOCK_SIZE * 2];
- ChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
+ HornetQChannelBuffer expectedValue = wrappedBuffer(expectedValueContent);
for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE)
{
random.nextBytes(expectedValueContent);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/DynamicChannelBufferTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/DynamicChannelBufferTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/DynamicChannelBufferTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -13,8 +13,8 @@
package org.hornetq.tests.unit.core.buffers;
-import org.hornetq.core.buffers.ChannelBuffer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.jboss.netty.buffer.DynamicChannelBuffer;
/**
@@ -33,9 +33,9 @@
* @see org.hornetq.tests.unit.core.buffers.AbstractChannelBufferTest#newBuffer(int)
*/
@Override
- protected ChannelBuffer newBuffer(final int length)
+ protected HornetQChannelBuffer newBuffer(final int length)
{
- ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(length);
+ HornetQChannelBuffer buffer = HornetQChannelBuffers.dynamicBuffer(length);
// A dynamic buffer does lazy initialization.
assertEquals(0, buffer.capacity());
@@ -65,7 +65,7 @@
public void testExpanding()
{
- ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(10);
+ HornetQChannelBuffer buffer = HornetQChannelBuffers.dynamicBuffer(10);
for (byte b = 0; b < (byte)20; b++)
{
@@ -92,7 +92,7 @@
}
- ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(bytes);
+ HornetQChannelBuffer buffer = HornetQChannelBuffers.dynamicBuffer(bytes);
buffer.clear();
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/HeapChannelBufferTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/HeapChannelBufferTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/HeapChannelBufferTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -12,8 +12,8 @@
*/
package org.hornetq.tests.unit.core.buffers;
-import org.hornetq.core.buffers.ChannelBuffer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
/**
*
@@ -27,9 +27,9 @@
{
@Override
- protected ChannelBuffer newBuffer(final int length)
+ protected HornetQChannelBuffer newBuffer(final int length)
{
- ChannelBuffer buffer = ChannelBuffers.buffer(length);
+ HornetQChannelBuffer buffer = HornetQChannelBuffers.buffer(length);
assertEquals(0, buffer.writerIndex());
return buffer;
}
@@ -38,7 +38,7 @@
{
try
{
- ChannelBuffers.wrappedBuffer((byte[])null);
+ HornetQChannelBuffers.wrappedBuffer((byte[])null);
fail("Exception expected");
}
catch (NullPointerException e)
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/client/impl/LargeMessageBufferTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/client/impl/LargeMessageBufferTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/client/impl/LargeMessageBufferTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -25,8 +25,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import org.hornetq.core.buffers.ChannelBuffer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.MessageHandler;
import org.hornetq.core.client.impl.ClientConsumerInternal;
@@ -114,7 +114,7 @@
{
LargeMessageBufferImpl buffer = create15BytesSample();
- ChannelBuffer dstBuffer = ChannelBuffers.buffer(20);
+ HornetQChannelBuffer dstBuffer = HornetQChannelBuffers.buffer(20);
dstBuffer.setIndex(0, 5);
@@ -168,7 +168,7 @@
public void testReadData() throws Exception
{
- ChannelBuffer dynamic = ChannelBuffers.dynamicBuffer(1);
+ HornetQChannelBuffer dynamic = HornetQChannelBuffers.dynamicBuffer(1);
String str1 = RandomUtil.randomString();
String str2 = RandomUtil.randomString();
@@ -197,7 +197,7 @@
{
clearData();
- ChannelBuffer dynamic = ChannelBuffers.dynamicBuffer(1);
+ HornetQChannelBuffer dynamic = HornetQChannelBuffers.dynamicBuffer(1);
String str1 = RandomUtil.randomString();
String str2 = RandomUtil.randomString();
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/filter/impl/FilterTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/filter/impl/FilterTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/filter/impl/FilterTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -13,7 +13,7 @@
package org.hornetq.tests.unit.core.filter.impl;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.filter.Filter;
import org.hornetq.core.filter.impl.FilterImpl;
@@ -102,7 +102,7 @@
public void testHQSize() throws Exception
{
message.setDestination(RandomUtil.randomSimpleString());
- message.setBuffer(ChannelBuffers.wrappedBuffer(RandomUtil.randomBytes(1)));
+ message.setBuffer(HornetQChannelBuffers.wrappedBuffer(RandomUtil.randomBytes(1)));
assertTrue(message.getEncodeSize() < 1024);
Filter moreThan128 = FilterImpl.createFilter(new SimpleString("HQSize > 128"));
@@ -111,7 +111,7 @@
assertFalse(moreThan128.match(message));
assertTrue(lessThan1024.match(message));
- message.setBuffer(ChannelBuffers.wrappedBuffer(RandomUtil.randomBytes(1024)));
+ message.setBuffer(HornetQChannelBuffers.wrappedBuffer(RandomUtil.randomBytes(1024)));
assertTrue(moreThan128.match(message));
assertFalse(lessThan1024.match(message));
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/message/impl/MessageImplTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/message/impl/MessageImplTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/message/impl/MessageImplTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -25,7 +25,7 @@
import java.util.Set;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.impl.ClientMessageImpl;
import org.hornetq.core.journal.EncodingSupport;
import org.hornetq.core.logging.Logger;
@@ -53,14 +53,14 @@
{
bytes[i] = randomByte();
}
- HornetQBuffer body = ChannelBuffers.wrappedBuffer(bytes);
+ HornetQBuffer body = HornetQChannelBuffers.wrappedBuffer(bytes);
Message message1 = new ClientMessageImpl(randomByte(), randomBoolean(), randomLong(), randomLong(), randomByte(), body);
Message message = message1;
message.setDestination(new SimpleString("oasoas"));
message.putStringProperty(new SimpleString("prop1"), new SimpleString("blah1"));
message.putStringProperty(new SimpleString("prop2"), new SimpleString("blah2"));
- HornetQBuffer buffer = ChannelBuffers.buffer(message.getEncodeSize());
+ HornetQBuffer buffer = HornetQChannelBuffers.buffer(message.getEncodeSize());
message.encode(buffer);
Message message2 = new ClientMessageImpl(false);
message2.decode(buffer);
@@ -77,7 +77,7 @@
{
bytes[i] = randomByte();
}
- HornetQBuffer body = ChannelBuffers.wrappedBuffer(bytes);
+ HornetQBuffer body = HornetQChannelBuffers.wrappedBuffer(bytes);
final byte type = randomByte();
final boolean durable = randomBoolean();
@@ -149,7 +149,7 @@
Message msg = new ClientMessageImpl(false);
byte[] bytes = new byte[]{(byte)1, (byte)2, (byte)3};
- msg.setBuffer(ChannelBuffers.wrappedBuffer(bytes));
+ msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(bytes));
msg.setDestination(address);
msg.putStringProperty(new SimpleString("Key"), new SimpleString("This String is worthless!"));
@@ -324,7 +324,7 @@
private void checkSizes(final Message obj, final EncodingSupport newObject)
{
- HornetQBuffer buffer = ChannelBuffers.buffer(1024);
+ HornetQBuffer buffer = HornetQChannelBuffers.buffer(1024);
obj.encode(buffer);
assertEquals (buffer.writerIndex(), obj.getEncodeSize());
int originalSize = buffer.writerIndex();
@@ -333,7 +333,7 @@
newObject.decode(buffer);
- HornetQBuffer newBuffer = ChannelBuffers.buffer(1024);
+ HornetQBuffer newBuffer = HornetQChannelBuffers.buffer(1024);
newObject.encode(newBuffer);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PageImplTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PageImplTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PageImplTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -17,7 +17,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.journal.impl.NIOSequentialFileFactory;
@@ -208,7 +208,7 @@
for (int i = 0; i < numberOfElements; i++)
{
- HornetQBuffer buffer = ChannelBuffers.buffer(10);
+ HornetQBuffer buffer = HornetQChannelBuffers.buffer(10);
for (int j = 0; j < buffer.capacity(); j++)
{
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingManagerImplTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingManagerImplTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingManagerImplTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -18,7 +18,7 @@
import java.util.List;
import java.util.concurrent.Executors;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.paging.Page;
import org.hornetq.core.paging.PagedMessage;
import org.hornetq.core.paging.impl.PagedMessageImpl;
@@ -117,7 +117,7 @@
0,
System.currentTimeMillis(),
(byte)0,
- ChannelBuffers.wrappedBuffer(new byte[1024]));
+ HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
msg.setMessageID(messageId);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingStoreImplTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingStoreImplTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingStoreImplTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -28,7 +28,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
@@ -107,7 +107,7 @@
assertEquals(nr1, trans.getNumberOfMessages());
- HornetQBuffer buffer = ChannelBuffers.buffer(trans.getEncodeSize());
+ HornetQBuffer buffer = HornetQChannelBuffers.buffer(trans.getEncodeSize());
trans.encode(buffer);
@@ -717,7 +717,7 @@
private HornetQBuffer createRandomBuffer(final long id, final int size)
{
- HornetQBuffer buffer = ChannelBuffers.buffer(size + 8);
+ HornetQBuffer buffer = HornetQChannelBuffers.buffer(size + 8);
buffer.writeLong(id);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/persistence/impl/BatchIDGeneratorUnitTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/persistence/impl/BatchIDGeneratorUnitTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/persistence/impl/BatchIDGeneratorUnitTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -16,7 +16,7 @@
import java.io.File;
import java.util.ArrayList;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.Journal;
import org.hornetq.core.journal.PreparedTransactionInfo;
import org.hornetq.core.journal.RecordInfo;
@@ -145,7 +145,7 @@
{
if (record.userRecordType == JournalStorageManager.ID_COUNTER_RECORD)
{
- HornetQBuffer buffer = ChannelBuffers.wrappedBuffer(record.data);
+ HornetQBuffer buffer = HornetQChannelBuffers.wrappedBuffer(record.data);
batch.loadState(record.id, buffer);
}
}
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/ByteBufferWrapperTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/ByteBufferWrapperTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/ByteBufferWrapperTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -15,7 +15,7 @@
import java.nio.ByteBuffer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.tests.unit.core.remoting.HornetQBufferTestBase;
@@ -43,7 +43,7 @@
@Override
protected HornetQBuffer createBuffer()
{
- return ChannelBuffers.wrappedBuffer(ByteBuffer.allocate(512));
+ return HornetQChannelBuffers.wrappedBuffer(ByteBuffer.allocate(512));
}
// Package protected ---------------------------------------------
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/ChannelBufferWrapper2Test.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/ChannelBufferWrapper2Test.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/ChannelBufferWrapper2Test.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -13,7 +13,7 @@
package org.hornetq.tests.unit.core.remoting.impl.netty;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.tests.unit.core.remoting.HornetQBufferTestBase;
@@ -43,7 +43,7 @@
@Override
protected HornetQBuffer createBuffer()
{
- return ChannelBuffers.dynamicBuffer(512);
+ return HornetQChannelBuffers.dynamicBuffer(512);
}
// Package protected ---------------------------------------------
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -19,7 +19,7 @@
import java.util.LinkedList;
import java.util.List;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.remoting.spi.Connection;
import org.hornetq.core.remoting.spi.ConnectionLifeCycleListener;
@@ -52,7 +52,7 @@
public void testWrite() throws Exception
{
- HornetQBuffer buff = ChannelBuffers.wrappedBuffer(ByteBuffer.allocate(128));
+ HornetQBuffer buff = HornetQChannelBuffers.wrappedBuffer(ByteBuffer.allocate(128));
SimpleChannel channel = new SimpleChannel(randomInt());
assertEquals(0, channel.getWritten().size());
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/util/TypedPropertiesTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/util/TypedPropertiesTest.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/util/TypedPropertiesTest.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -26,7 +26,7 @@
import java.util.Iterator;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.tests.util.UnitTestCase;
import org.hornetq.utils.SimpleString;
@@ -210,7 +210,7 @@
SimpleString keyToRemove = randomSimpleString();
props.putSimpleStringProperty(keyToRemove, randomSimpleString());
- HornetQBuffer buffer = ChannelBuffers.dynamicBuffer(1024);
+ HornetQBuffer buffer = HornetQChannelBuffers.dynamicBuffer(1024);
props.encode(buffer);
assertEquals(props.getEncodeSize(), buffer.writerIndex());
@@ -234,7 +234,7 @@
{
TypedProperties emptyProps = new TypedProperties();
- HornetQBuffer buffer = ChannelBuffers.dynamicBuffer(1024);
+ HornetQBuffer buffer = HornetQChannelBuffers.dynamicBuffer(1024);
emptyProps.encode(buffer);
assertEquals(props.getEncodeSize(), buffer.writerIndex());
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/util/UTF8Test.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/util/UTF8Test.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/util/UTF8Test.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -19,7 +19,7 @@
import java.io.DataOutputStream;
import java.nio.ByteBuffer;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.tests.util.RandomUtil;
import org.hornetq.tests.util.UnitTestCase;
@@ -41,7 +41,7 @@
public void testValidateUTF() throws Exception
{
- HornetQBuffer buffer = ChannelBuffers.buffer(60 * 1024);
+ HornetQBuffer buffer = HornetQChannelBuffers.buffer(60 * 1024);
byte[] bytes = new byte[20000];
@@ -71,11 +71,11 @@
String str = new String(bytes);
// The maximum size the encoded UTF string would reach is str.length * 3 (look at the UTF8 implementation)
- testValidateUTFOnDataInputStream(str, ChannelBuffers.wrappedBuffer(ByteBuffer.allocate(str.length() * 3 + DataConstants.SIZE_SHORT)));
+ testValidateUTFOnDataInputStream(str, HornetQChannelBuffers.wrappedBuffer(ByteBuffer.allocate(str.length() * 3 + DataConstants.SIZE_SHORT)));
- testValidateUTFOnDataInputStream(str, ChannelBuffers.dynamicBuffer(100));
+ testValidateUTFOnDataInputStream(str, HornetQChannelBuffers.dynamicBuffer(100));
- testValidateUTFOnDataInputStream(str, ChannelBuffers.buffer(100 * 1024));
+ testValidateUTFOnDataInputStream(str, HornetQChannelBuffers.buffer(100 * 1024));
}
}
@@ -94,7 +94,7 @@
outData.writeUTF(str);
- HornetQBuffer buffer = ChannelBuffers.wrappedBuffer(byteOut.toByteArray());
+ HornetQBuffer buffer = HornetQChannelBuffers.wrappedBuffer(byteOut.toByteArray());
newStr = UTF8Util.readUTF(buffer);
@@ -113,7 +113,7 @@
String str = new String(chars);
- HornetQBuffer buffer = ChannelBuffers.buffer(0xffff + 4);
+ HornetQBuffer buffer = HornetQChannelBuffers.buffer(0xffff + 4);
try
{
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/util/UnitTestCase.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/util/UnitTestCase.java 2009-11-20 05:20:11 UTC (rev 8333)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/util/UnitTestCase.java 2009-11-20 10:04:40 UTC (rev 8334)
@@ -44,7 +44,7 @@
import junit.framework.TestSuite;
import org.hornetq.core.asyncio.impl.AsynchronousFileImpl;
-import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientSession;
import org.hornetq.core.exception.HornetQException;
@@ -838,7 +838,7 @@
0,
System.currentTimeMillis(),
(byte)4,
- ChannelBuffers.dynamicBuffer(1024));
+ HornetQChannelBuffers.dynamicBuffer(1024));
message.setMessageID(id);
15 years, 1 month
JBoss hornetq SVN: r8333 - in branches/ClebertTemporary: src/main/org/hornetq/core/journal/impl and 6 other directories.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2009-11-20 00:20:11 -0500 (Fri, 20 Nov 2009)
New Revision: 8333
Modified:
branches/ClebertTemporary/src/main/org/hornetq/core/journal/IOCompletion.java
branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/DummyCallback.java
branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/JournalImpl.java
branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/SimpleWaitIOCallback.java
branches/ClebertTemporary/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java
branches/ClebertTemporary/src/main/org/hornetq/core/persistence/OperationContext.java
branches/ClebertTemporary/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java
branches/ClebertTemporary/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java
branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/client/PagingTest.java
branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java
Log:
Fixing tests & ordering on clustering
Modified: branches/ClebertTemporary/src/main/org/hornetq/core/journal/IOCompletion.java
===================================================================
--- branches/ClebertTemporary/src/main/org/hornetq/core/journal/IOCompletion.java 2009-11-20 04:00:56 UTC (rev 8332)
+++ branches/ClebertTemporary/src/main/org/hornetq/core/journal/IOCompletion.java 2009-11-20 05:20:11 UTC (rev 8333)
@@ -22,5 +22,5 @@
*/
public interface IOCompletion extends IOAsyncTask
{
- void linedUp();
+ void lineUp();
}
Modified: branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/DummyCallback.java
===================================================================
--- branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/DummyCallback.java 2009-11-20 04:00:56 UTC (rev 8332)
+++ branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/DummyCallback.java 2009-11-20 05:20:11 UTC (rev 8333)
@@ -50,7 +50,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.journal.IOCompletion#linedUp()
*/
- public void linedUp()
+ public void lineUp()
{
}
}
Modified: branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/JournalImpl.java
===================================================================
--- branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-11-20 04:00:56 UTC (rev 8332)
+++ branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
@@ -878,7 +878,7 @@
if (callback != null)
{
- callback.linedUp();
+ callback.lineUp();
}
compactingLock.readLock().lock();
@@ -945,7 +945,7 @@
if (callback != null)
{
- callback.linedUp();
+ callback.lineUp();
}
compactingLock.readLock().lock();
@@ -1023,7 +1023,7 @@
if (callback != null)
{
- callback.linedUp();
+ callback.lineUp();
}
compactingLock.readLock().lock();
@@ -1284,7 +1284,7 @@
if (callback != null)
{
- callback.linedUp();
+ callback.lineUp();
}
compactingLock.readLock().lock();
@@ -1361,7 +1361,7 @@
if (callback != null)
{
- callback.linedUp();
+ callback.lineUp();
}
compactingLock.readLock().lock();
@@ -1431,7 +1431,7 @@
if (callback != null)
{
- callback.linedUp();
+ callback.lineUp();
}
compactingLock.readLock().lock();
Modified: branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/SimpleWaitIOCallback.java
===================================================================
--- branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/SimpleWaitIOCallback.java 2009-11-20 04:00:56 UTC (rev 8332)
+++ branches/ClebertTemporary/src/main/org/hornetq/core/journal/impl/SimpleWaitIOCallback.java 2009-11-20 05:20:11 UTC (rev 8333)
@@ -71,7 +71,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.journal.IOCompletion#linedUp()
*/
- public void linedUp()
+ public void lineUp()
{
}
}
Modified: branches/ClebertTemporary/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java
===================================================================
--- branches/ClebertTemporary/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java 2009-11-20 04:00:56 UTC (rev 8332)
+++ branches/ClebertTemporary/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
@@ -919,8 +919,6 @@
for (PagedMessage pagedMessage : pagedMessages)
{
ServerMessage message = pagedMessage.getMessage(storageManager);
-
- System.out.println("Depaged id = " + message.getIntProperty("id"));
if (message.isLargeMessage())
{
Modified: branches/ClebertTemporary/src/main/org/hornetq/core/persistence/OperationContext.java
===================================================================
--- branches/ClebertTemporary/src/main/org/hornetq/core/persistence/OperationContext.java 2009-11-20 04:00:56 UTC (rev 8332)
+++ branches/ClebertTemporary/src/main/org/hornetq/core/persistence/OperationContext.java 2009-11-20 05:20:11 UTC (rev 8333)
@@ -28,16 +28,17 @@
public interface OperationContext extends IOCompletion
{
- boolean hasData();
+ boolean hasReplication();
void executeOnCompletion(IOAsyncTask runnable);
+ void replicationLineUp();
+
+ void replicationDone();
+
/** To be called when there are no more operations pending */
void complete();
- /** Flush all pending callbacks on the Context */
- void flush();
-
/** Replication may need some extra controls to guarantee ordering
* when nothing is persisted through the contexts
* @return The context is empty
Modified: branches/ClebertTemporary/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java
===================================================================
--- branches/ClebertTemporary/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java 2009-11-20 04:00:56 UTC (rev 8332)
+++ branches/ClebertTemporary/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
@@ -23,9 +23,6 @@
* A ReplicationToken
*
* @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
- *
- * TODO: Maybe I should move this to persistence.journal. I need to check a few dependencies first.
- *
*/
public class OperationContextImpl implements OperationContext
{
@@ -42,16 +39,22 @@
return token;
}
- private List<IOAsyncTask> tasks;
-
- private int storeLinedUp = 0;
+ private List<TaskHolder> tasks;
+ private volatile int storeLineUp = 0;
+
+ private volatile int replicationLineUp = 0;
+
+ private int minimalStore = Integer.MAX_VALUE;
+
+ private int minimalReplicated = Integer.MAX_VALUE;
+
private int stored = 0;
+ private int replicated = 0;
+
private boolean empty = false;
- private volatile boolean complete = false;
-
/**
* @param executor
*/
@@ -61,69 +64,77 @@
}
/** To be called by the replication manager, when new replication is added to the queue */
- public void linedUp()
+ public void lineUp()
{
- storeLinedUp++;
+ storeLineUp++;
}
- public boolean hasData()
+ public void replicationLineUp()
{
- return storeLinedUp > 0;
+ replicationLineUp++;
}
+ public synchronized void replicationDone()
+ {
+ replicated++;
+ checkTasks();
+ }
+
+ public boolean hasReplication()
+ {
+ return replicationLineUp > 0;
+ }
+
/** You may have several actions to be done after a replication operation is completed. */
- public void executeOnCompletion(IOAsyncTask completion)
+ public synchronized void executeOnCompletion(IOAsyncTask completion)
{
- if (complete)
+ if (tasks == null)
{
- // Sanity check, this shouldn't happen
- throw new IllegalStateException("The Replication Context is complete, and no more tasks are accepted");
+ tasks = new LinkedList<TaskHolder>();
+ minimalReplicated = replicationLineUp;
+ minimalStore = storeLineUp;
}
- if (tasks == null)
+ if (replicationLineUp == replicated && storeLineUp == stored)
{
- // No need to use Concurrent, we only add from a single thread.
- // We don't add any more Runnables after it is complete
- tasks = new LinkedList<IOAsyncTask>();
+ completion.done();
}
-
- tasks.add(completion);
+ else
+ {
+ tasks.add(new TaskHolder(completion));
+ }
}
/** To be called by the storage manager, when data is confirmed on the channel */
public synchronized void done()
{
- if (++stored == storeLinedUp && complete)
+ stored++;
+ checkTasks();
+ }
+
+ private void checkTasks()
+ {
+ if (stored >= minimalStore && replicated >= minimalReplicated)
{
- flush();
+ for (TaskHolder holder : tasks)
+ {
+ if (!holder.executed && stored >= holder.storeLined && replicated >= holder.replicationLined)
+ {
+ holder.executed = true;
+ holder.task.done();
+ }
+ }
}
}
/* (non-Javadoc)
* @see org.hornetq.core.replication.ReplicationToken#complete()
*/
- public synchronized void complete()
+ public void complete()
{
tlContext.set(null);
- complete = true;
- if (stored == storeLinedUp && complete)
- {
- flush();
- }
}
- public synchronized void flush()
- {
- if (tasks != null)
- {
- for (IOAsyncTask run : tasks)
- {
- run.done();
- }
- tasks.clear();
- }
- }
-
/* (non-Javadoc)
* @see org.hornetq.core.replication.ReplicationContext#isRoundtrip()
*/
@@ -137,7 +148,6 @@
this.empty = sync;
}
-
/* (non-Javadoc)
* @see org.hornetq.core.asyncio.AIOCallback#onError(int, java.lang.String)
*/
@@ -145,11 +155,29 @@
{
if (tasks != null)
{
- for (IOAsyncTask run : tasks)
+ for (TaskHolder run : tasks)
{
- run.onError(errorCode, errorMessage);
+ run.task.onError(errorCode, errorMessage);
}
}
}
+ class TaskHolder
+ {
+ int storeLined;
+
+ int replicationLined;
+
+ boolean executed;
+
+ IOAsyncTask task;
+
+ TaskHolder(IOAsyncTask task)
+ {
+ this.storeLined = storeLineUp;
+ this.replicationLined = replicationLineUp;
+ this.task = task;
+ }
+ }
+
}
Modified: branches/ClebertTemporary/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java
===================================================================
--- branches/ClebertTemporary/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java 2009-11-20 04:00:56 UTC (rev 8332)
+++ branches/ClebertTemporary/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java 2009-11-20 05:20:11 UTC (rev 8333)
@@ -359,22 +359,14 @@
{
enabled = false;
- LinkedHashSet<OperationContext> activeContexts = new LinkedHashSet<OperationContext>();
-
// The same context will be replicated on the pending tokens...
// as the multiple operations will be replicated on the same context
while (!pendingTokens.isEmpty())
{
OperationContext ctx = pendingTokens.poll();
- activeContexts.add(ctx);
+ ctx.replicationDone();
}
- for (OperationContext ctx : activeContexts)
- {
- ctx.complete();
- ctx.flush();
- }
-
if (replicatingChannel != null)
{
replicatingChannel.close();
@@ -402,7 +394,7 @@
if (token != null)
{
// Remove from pending tokens as soon as this is complete
- if (!token.hasData())
+ if (!token.hasReplication())
{
sync(token);
}
@@ -436,7 +428,7 @@
boolean runItNow = false;
OperationContext repliToken = getContext();
- repliToken.linedUp();
+ repliToken.replicationLineUp();
synchronized (replicationLock)
{
@@ -476,7 +468,7 @@
for (OperationContext ctx : tokensToExecute)
{
- ctx.done();
+ ctx.replicationDone();
}
}
@@ -491,7 +483,7 @@
boolean executeNow = false;
synchronized (replicationLock)
{
- context.linedUp();
+ context.lineUp();
context.setEmpty(true);
if (pendingTokens.isEmpty())
{
Modified: branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/client/PagingTest.java
===================================================================
--- branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/client/PagingTest.java 2009-11-20 04:00:56 UTC (rev 8332)
+++ branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/client/PagingTest.java 2009-11-20 05:20:11 UTC (rev 8333)
@@ -971,9 +971,6 @@
assertNull(consumerPaged.receiveImmediate());
- assertFalse(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS).isPaging());
- assertFalse(server.getPostOffice().getPagingManager().getPageStore(NON_PAGED_ADDRESS).isPaging());
-
session.close();
}
Modified: branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java
===================================================================
--- branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java 2009-11-20 04:00:56 UTC (rev 8332)
+++ branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java 2009-11-20 05:20:11 UTC (rev 8333)
@@ -494,7 +494,7 @@
}
}
- public void testOrderOnNonPersistency() throws Exception
+ public void disabledForNowtestOrderOnNonPersistency() throws Exception
{
Configuration config = createDefaultConfig(false);
15 years, 1 month
JBoss hornetq SVN: r8332 - in branches/ClebertTemporary: src/main/org/hornetq/core/persistence/impl/journal and 1 other directories.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2009-11-19 23:00:56 -0500 (Thu, 19 Nov 2009)
New Revision: 8332
Modified:
branches/ClebertTemporary/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java
branches/ClebertTemporary/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java
branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/client/PagingTest.java
Log:
Fixing ordering on paging
Modified: branches/ClebertTemporary/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java
===================================================================
--- branches/ClebertTemporary/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java 2009-11-20 03:01:51 UTC (rev 8331)
+++ branches/ClebertTemporary/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java 2009-11-20 04:00:56 UTC (rev 8332)
@@ -919,6 +919,8 @@
for (PagedMessage pagedMessage : pagedMessages)
{
ServerMessage message = pagedMessage.getMessage(storageManager);
+
+ System.out.println("Depaged id = " + message.getIntProperty("id"));
if (message.isLargeMessage())
{
@@ -1008,9 +1010,10 @@
}
depageTransaction.commit();
+
+ // TODO: If we implement ordering on AIO, we won't need to block here
+ storageManager.waitOnOperations();
- storageManager.completeOperations();
-
if (isTrace)
{
trace("Depage committed, running = " + running);
Modified: branches/ClebertTemporary/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java
===================================================================
--- branches/ClebertTemporary/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java 2009-11-20 03:01:51 UTC (rev 8331)
+++ branches/ClebertTemporary/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java 2009-11-20 04:00:56 UTC (rev 8332)
@@ -44,9 +44,9 @@
private List<IOAsyncTask> tasks;
- private int linedup = 0;
+ private int storeLinedUp = 0;
- private int replicated = 0;
+ private int stored = 0;
private boolean empty = false;
@@ -63,12 +63,12 @@
/** To be called by the replication manager, when new replication is added to the queue */
public void linedUp()
{
- linedup++;
+ storeLinedUp++;
}
public boolean hasData()
{
- return linedup > 0;
+ return storeLinedUp > 0;
}
/** You may have several actions to be done after a replication operation is completed. */
@@ -90,10 +90,10 @@
tasks.add(completion);
}
- /** To be called by the replication manager, when data is confirmed on the channel */
+ /** To be called by the storage manager, when data is confirmed on the channel */
public synchronized void done()
{
- if (++replicated == linedup && complete)
+ if (++stored == storeLinedUp && complete)
{
flush();
}
@@ -106,7 +106,7 @@
{
tlContext.set(null);
complete = true;
- if (replicated == linedup && complete)
+ if (stored == storeLinedUp && complete)
{
flush();
}
Modified: branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/client/PagingTest.java
===================================================================
--- branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/client/PagingTest.java 2009-11-20 03:01:51 UTC (rev 8331)
+++ branches/ClebertTemporary/tests/src/org/hornetq/tests/integration/client/PagingTest.java 2009-11-20 04:00:56 UTC (rev 8332)
@@ -163,8 +163,7 @@
assertNotNull(message2);
- // TODO: AIO doesn't support ordering ATM
-// assertEquals(i, ((Integer)message2.getObjectProperty(new SimpleString("id"))).intValue());
+ assertEquals(i, message2.getIntProperty("id").intValue());
message2.acknowledge();
15 years, 1 month