JBoss hornetq SVN: r8391 - in trunk/src/main/org/hornetq/core: replication/impl and 1 other directory.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2009-11-23 22:50:27 -0500 (Mon, 23 Nov 2009)
New Revision: 8391
Modified:
trunk/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java
trunk/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java
Log:
Tweaks
Modified: trunk/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java 2009-11-24 03:26:19 UTC (rev 8390)
+++ trunk/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java 2009-11-24 03:50:27 UTC (rev 8391)
@@ -25,9 +25,15 @@
/**
*
- * This class will hold operations when there are IO operations...
- * and it will
+ * Each instance of OperationContextImpl is associated with an executor (usually an ordered Executor).
*
+ * Tasks are hold until the operations are complete and executed in the natural order as soon as the operations are returned
+ * from replication and storage.
+ *
+ * If there are no pending IO operations, the tasks are just executed at the callers thread without any context switch.
+ *
+ * So, if you are doing operations that are not dependent on IO (e.g NonPersistentMessages) you wouldn't have any context switch.
+ *
* @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
*/
public class OperationContextImpl implements OperationContext
Modified: trunk/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java 2009-11-24 03:26:19 UTC (rev 8390)
+++ trunk/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java 2009-11-24 03:50:27 UTC (rev 8391)
@@ -26,7 +26,6 @@
import org.hornetq.core.logging.Logger;
import org.hornetq.core.paging.PagedMessage;
import org.hornetq.core.persistence.OperationContext;
-import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.persistence.impl.journal.OperationContextImpl;
import org.hornetq.core.remoting.Channel;
import org.hornetq.core.remoting.ChannelHandler;
15 years, 1 month
JBoss hornetq SVN: r8390 - trunk/native/bin.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2009-11-23 22:26:19 -0500 (Mon, 23 Nov 2009)
New Revision: 8390
Modified:
trunk/native/bin/libHornetQAIO32.so
Log:
32 bits compilation
Modified: trunk/native/bin/libHornetQAIO32.so
===================================================================
(Binary files differ)
15 years, 1 month
JBoss hornetq SVN: r8389 - in trunk: native/src and 42 other directories.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2009-11-23 21:53:23 -0500 (Mon, 23 Nov 2009)
New Revision: 8389
Added:
trunk/src/main/org/hornetq/core/journal/IOAsyncTask.java
trunk/src/main/org/hornetq/core/journal/impl/SyncIOCompletion.java
trunk/src/main/org/hornetq/core/persistence/OperationContext.java
trunk/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java
trunk/tests/src/org/hornetq/tests/integration/client/OrderTest.java
Removed:
trunk/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationSyncContextMessage.java
trunk/src/main/org/hornetq/core/replication/ReplicationContext.java
trunk/src/main/org/hornetq/core/replication/impl/ReplicationContextImpl.java
trunk/tests/src/org/hornetq/tests/performance/persistence/StorageManagerTimingTest.java
Modified:
trunk/native/bin/libHornetQAIO64.so
trunk/native/src/AIOException.h
trunk/native/src/JNICallbackAdapter.cpp
trunk/native/src/JNICallbackAdapter.h
trunk/native/src/JNI_AsynchronousFileImpl.cpp
trunk/native/src/Version.h
trunk/src/main/org/hornetq/core/asyncio/impl/AsynchronousFileImpl.java
trunk/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java
trunk/src/main/org/hornetq/core/exception/HornetQException.java
trunk/src/main/org/hornetq/core/journal/IOCompletion.java
trunk/src/main/org/hornetq/core/journal/Journal.java
trunk/src/main/org/hornetq/core/journal/SequentialFile.java
trunk/src/main/org/hornetq/core/journal/impl/AIOSequentialFile.java
trunk/src/main/org/hornetq/core/journal/impl/AIOSequentialFileFactory.java
trunk/src/main/org/hornetq/core/journal/impl/AbstractSequentialFactory.java
trunk/src/main/org/hornetq/core/journal/impl/AbstractSequentialFile.java
trunk/src/main/org/hornetq/core/journal/impl/DummyCallback.java
trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java
trunk/src/main/org/hornetq/core/journal/impl/NIOSequentialFile.java
trunk/src/main/org/hornetq/core/journal/impl/NIOSequentialFileFactory.java
trunk/src/main/org/hornetq/core/journal/impl/SimpleWaitIOCallback.java
trunk/src/main/org/hornetq/core/journal/impl/TimedBuffer.java
trunk/src/main/org/hornetq/core/journal/impl/TimedBufferObserver.java
trunk/src/main/org/hornetq/core/journal/impl/TransactionCallback.java
trunk/src/main/org/hornetq/core/management/ManagementService.java
trunk/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java
trunk/src/main/org/hornetq/core/management/impl/ManagementServiceImpl.java
trunk/src/main/org/hornetq/core/paging/PagingStore.java
trunk/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java
trunk/src/main/org/hornetq/core/persistence/StorageManager.java
trunk/src/main/org/hornetq/core/persistence/impl/journal/FileLargeServerMessage.java
trunk/src/main/org/hornetq/core/persistence/impl/journal/JournalStorageManager.java
trunk/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java
trunk/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageManager.java
trunk/src/main/org/hornetq/core/postoffice/impl/DuplicateIDCacheImpl.java
trunk/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java
trunk/src/main/org/hornetq/core/remoting/impl/PacketDecoder.java
trunk/src/main/org/hornetq/core/remoting/impl/RemotingConnectionImpl.java
trunk/src/main/org/hornetq/core/remoting/impl/wireformat/PacketImpl.java
trunk/src/main/org/hornetq/core/replication/ReplicationManager.java
trunk/src/main/org/hornetq/core/replication/impl/ReplicatedJournal.java
trunk/src/main/org/hornetq/core/replication/impl/ReplicationEndpointImpl.java
trunk/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java
trunk/src/main/org/hornetq/core/server/LargeServerMessage.java
trunk/src/main/org/hornetq/core/server/ServerMessage.java
trunk/src/main/org/hornetq/core/server/cluster/impl/Redistributor.java
trunk/src/main/org/hornetq/core/server/group/impl/LocalGroupingHandler.java
trunk/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
trunk/src/main/org/hornetq/core/server/impl/LastValueQueue.java
trunk/src/main/org/hornetq/core/server/impl/QueueFactoryImpl.java
trunk/src/main/org/hornetq/core/server/impl/QueueImpl.java
trunk/src/main/org/hornetq/core/server/impl/ServerMessageImpl.java
trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java
trunk/src/main/org/hornetq/core/server/impl/ServerSessionPacketHandler.java
trunk/src/main/org/hornetq/core/transaction/TransactionOperation.java
trunk/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java
trunk/tests/src/org/hornetq/tests/concurrent/server/impl/QueueTest.java
trunk/tests/src/org/hornetq/tests/integration/client/DeadLetterAddressTest.java
trunk/tests/src/org/hornetq/tests/integration/client/MessageGroupingTest.java
trunk/tests/src/org/hornetq/tests/integration/client/NettyConsumerWindowSizeTest.java
trunk/tests/src/org/hornetq/tests/integration/client/PagingTest.java
trunk/tests/src/org/hornetq/tests/integration/cluster/failover/FailoverTest.java
trunk/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java
trunk/tests/src/org/hornetq/tests/integration/largemessage/ServerLargeMessageTest.java
trunk/tests/src/org/hornetq/tests/integration/persistence/RestartSMTest.java
trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationOrderTest.java
trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java
trunk/tests/src/org/hornetq/tests/integration/scheduling/ScheduledMessageTest.java
trunk/tests/src/org/hornetq/tests/integration/server/LVQRecoveryTest.java
trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaRecoveryTest.java
trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java
trunk/tests/src/org/hornetq/tests/integration/xa/XaTimeoutTest.java
trunk/tests/src/org/hornetq/tests/timing/core/server/impl/QueueImplTest.java
trunk/tests/src/org/hornetq/tests/unit/core/asyncio/AIOTestBase.java
trunk/tests/src/org/hornetq/tests/unit/core/asyncio/AsynchronousFileTest.java
trunk/tests/src/org/hornetq/tests/unit/core/asyncio/MultiThreadAsynchronousFileTest.java
trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/JournalAsyncTest.java
trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java
trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/TimedBufferTest.java
trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
trunk/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingStoreImplTest.java
trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java
trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/DuplicateDetectionUnitTest.java
trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/FakeQueue.java
trunk/tests/src/org/hornetq/tests/unit/core/server/impl/QueueImplTest.java
trunk/tests/src/org/hornetq/tests/unit/core/server/impl/fakes/FakeQueueFactory.java
trunk/tests/src/org/hornetq/tests/util/UnitTestCase.java
Log:
https://jira.jboss.org/jira/browse/HORNETQ-225 - Asynchronous responses on the journal
Modified: trunk/native/bin/libHornetQAIO64.so
===================================================================
(Binary files differ)
Modified: trunk/native/src/AIOException.h
===================================================================
--- trunk/native/src/AIOException.h 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/native/src/AIOException.h 2009-11-24 02:53:23 UTC (rev 8389)
@@ -29,7 +29,7 @@
#define NATIVE_ERROR_CANT_ALLOCATE_QUEUE 206
#define NATIVE_ERROR_PREALLOCATE_FILE 208
#define NATIVE_ERROR_ALLOCATE_MEMORY 209
-#define NATIVE_ERROR_IO 210
+#define NATIVE_ERROR_IO 006
#define NATIVE_ERROR_AIO_FULL 211
Modified: trunk/native/src/JNICallbackAdapter.cpp
===================================================================
--- trunk/native/src/JNICallbackAdapter.cpp 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/native/src/JNICallbackAdapter.cpp 2009-11-24 02:53:23 UTC (rev 8389)
@@ -18,13 +18,20 @@
jobject nullObj = NULL;
-JNICallbackAdapter::JNICallbackAdapter(AIOController * _controller, jobject _callback, jobject _fileController, jobject _bufferReference, short _isRead) : CallbackAdapter()
+JNICallbackAdapter::JNICallbackAdapter(AIOController * _controller, jlong _sequence, jobject _callback, jobject _fileController, jobject _bufferReference, short _isRead) : CallbackAdapter()
{
controller = _controller;
+
+ sequence = _sequence;
+
callback = _callback;
+
fileController = _fileController;
+
bufferReference = _bufferReference;
+
isRead = _isRead;
+
}
JNICallbackAdapter::~JNICallbackAdapter()
@@ -33,15 +40,19 @@
void JNICallbackAdapter::done(THREAD_CONTEXT threadContext)
{
- JNI_ENV(threadContext)->CallVoidMethod(fileController, controller->done, callback, isRead ? nullObj : bufferReference);
+ JNI_ENV(threadContext)->CallVoidMethod(fileController, controller->done, callback, sequence, isRead ? nullObj : bufferReference);
+
release(threadContext);
}
void JNICallbackAdapter::onError(THREAD_CONTEXT threadContext, long errorCode, std::string error)
{
controller->log(threadContext, 0, "Libaio event generated errors, callback object was informed about it");
+
jstring strError = JNI_ENV(threadContext)->NewStringUTF(error.data());
- JNI_ENV(threadContext)->CallVoidMethod(fileController, controller->error, callback, isRead ? nullObj : bufferReference, (jint)errorCode, strError);
+
+ JNI_ENV(threadContext)->CallVoidMethod(fileController, controller->error, callback, sequence, isRead ? nullObj : bufferReference, (jint)errorCode, strError);
+
release(threadContext);
}
Modified: trunk/native/src/JNICallbackAdapter.h
===================================================================
--- trunk/native/src/JNICallbackAdapter.h 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/native/src/JNICallbackAdapter.h 2009-11-24 02:53:23 UTC (rev 8389)
@@ -24,10 +24,17 @@
class JNICallbackAdapter : public CallbackAdapter
{
private:
+
AIOController * controller;
+
jobject callback;
+
jobject fileController;
+
jobject bufferReference;
+
+ jlong sequence;
+
// Is this a read operation
short isRead;
@@ -43,7 +50,7 @@
public:
// _ob must be a global Reference (use createGloblReferente before calling the constructor)
- JNICallbackAdapter(AIOController * _controller, jobject _callback, jobject _fileController, jobject _bufferReference, short _isRead);
+ JNICallbackAdapter(AIOController * _controller, jlong sequence, jobject _callback, jobject _fileController, jobject _bufferReference, short _isRead);
virtual ~JNICallbackAdapter();
void done(THREAD_CONTEXT threadContext);
Modified: trunk/native/src/JNI_AsynchronousFileImpl.cpp
===================================================================
--- trunk/native/src/JNI_AsynchronousFileImpl.cpp 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/native/src/JNI_AsynchronousFileImpl.cpp 2009-11-24 02:53:23 UTC (rev 8389)
@@ -48,10 +48,10 @@
std::string fileName = convertJavaString(env, jstrFileName);
controller = new AIOController(fileName, (int) maxIO);
- controller->done = env->GetMethodID(clazz,"callbackDone","(Lorg/hornetq/core/asyncio/AIOCallback;Ljava/nio/ByteBuffer;)V");
+ controller->done = env->GetMethodID(clazz,"callbackDone","(Lorg/hornetq/core/asyncio/AIOCallback;JLjava/nio/ByteBuffer;)V");
if (!controller->done) return 0;
- controller->error = env->GetMethodID(clazz, "callbackError", "(Lorg/hornetq/core/asyncio/AIOCallback;Ljava/nio/ByteBuffer;ILjava/lang/String;)V");
+ controller->error = env->GetMethodID(clazz, "callbackError", "(Lorg/hornetq/core/asyncio/AIOCallback;JLjava/nio/ByteBuffer;ILjava/lang/String;)V");
if (!controller->error) return 0;
jclass loggerClass = env->GetObjectClass(logger);
@@ -97,7 +97,7 @@
return;
}
- CallbackAdapter * adapter = new JNICallbackAdapter(controller, env->NewGlobalRef(callback), env->NewGlobalRef(objThis), env->NewGlobalRef(jbuffer), true);
+ CallbackAdapter * adapter = new JNICallbackAdapter(controller, -1, env->NewGlobalRef(callback), env->NewGlobalRef(objThis), env->NewGlobalRef(jbuffer), true);
controller->fileOutput.read(env, position, (size_t)size, buffer, adapter);
}
@@ -166,7 +166,7 @@
}
JNIEXPORT void JNICALL Java_org_hornetq_core_asyncio_impl_AsynchronousFileImpl_write
- (JNIEnv *env, jobject objThis, jlong controllerAddress, jlong position, jlong size, jobject jbuffer, jobject callback)
+ (JNIEnv *env, jobject objThis, jlong controllerAddress, jlong sequence, jlong position, jlong size, jobject jbuffer, jobject callback)
{
try
{
@@ -180,7 +180,7 @@
}
- CallbackAdapter * adapter = new JNICallbackAdapter(controller, env->NewGlobalRef(callback), env->NewGlobalRef(objThis), env->NewGlobalRef(jbuffer), false);
+ CallbackAdapter * adapter = new JNICallbackAdapter(controller, sequence, env->NewGlobalRef(callback), env->NewGlobalRef(objThis), env->NewGlobalRef(jbuffer), false);
controller->fileOutput.write(env, position, (size_t)size, buffer, adapter);
}
Modified: trunk/native/src/Version.h
===================================================================
--- trunk/native/src/Version.h 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/native/src/Version.h 2009-11-24 02:53:23 UTC (rev 8389)
@@ -1,5 +1,5 @@
#ifndef _VERSION_NATIVE_AIO
-#define _VERSION_NATIVE_AIO 25
+#define _VERSION_NATIVE_AIO 27
#endif
Modified: trunk/src/main/org/hornetq/core/asyncio/impl/AsynchronousFileImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/asyncio/impl/AsynchronousFileImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/asyncio/impl/AsynchronousFileImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -14,11 +14,14 @@
package org.hornetq.core.asyncio.impl;
import java.nio.ByteBuffer;
+import java.util.PriorityQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.hornetq.core.asyncio.AIOCallback;
@@ -46,8 +49,21 @@
private static boolean loaded = false;
- private static int EXPECTED_NATIVE_VERSION = 25;
+ private static int EXPECTED_NATIVE_VERSION = 27;
+ /** Used to determine the next writing sequence */
+ private AtomicLong nextWritingSequence = new AtomicLong(0);
+
+ /** Used to determine the next writing sequence.
+ * This is accessed from a single thread (the Poller Thread) */
+ private long nextReadSequence = 0;
+
+ /**
+ * AIO can't guarantee ordering over callbacks.
+ * We use thie PriorityQueue to hold values until they are in order
+ */
+ private PriorityQueue<CallbackHolder> pendingCallbacks = new PriorityQueue<CallbackHolder>();
+
public static void addMax(final int io)
{
totalMaxIO.addAndGet(io);
@@ -124,6 +140,10 @@
private String fileName;
+ /** Used while inside the callbackDone and callbackError
+ **/
+ private final Lock callbackLock = new ReentrantLock();
+
private final VariableLatch pollerLatch = new VariableLatch();
private volatile Runnable poller;
@@ -131,10 +151,10 @@
private int maxIO;
private final Lock writeLock = new ReentrantReadWriteLock().writeLock();
-
+
private final VariableLatch pendingWrites = new VariableLatch();
- private Semaphore writeSemaphore;
+ private Semaphore maxIOSemaphore;
private BufferCallback bufferCallback;
@@ -175,7 +195,7 @@
}
this.maxIO = maxIO;
- writeSemaphore = new Semaphore(this.maxIO);
+ maxIOSemaphore = new Semaphore(this.maxIO);
this.fileName = fileName;
@@ -189,10 +209,10 @@
if (e.getCode() == HornetQException.NATIVE_ERROR_CANT_INITIALIZE_AIO)
{
ex = new HornetQException(e.getCode(),
- "Can't initialize AIO. Currently AIO in use = " + totalMaxIO.get() +
- ", trying to allocate more " +
- maxIO,
- e);
+ "Can't initialize AIO. Currently AIO in use = " + totalMaxIO.get() +
+ ", trying to allocate more " +
+ maxIO,
+ e);
}
else
{
@@ -202,6 +222,8 @@
}
opened = true;
addMax(this.maxIO);
+ nextWritingSequence.set(0);
+ nextReadSequence = 0;
}
finally
{
@@ -222,13 +244,13 @@
{
log.warn("Couldn't get lock after 60 seconds on closing AsynchronousFileImpl::" + this.fileName);
}
-
- while (!writeSemaphore.tryAcquire(maxIO, 60, TimeUnit.SECONDS))
+
+ while (!maxIOSemaphore.tryAcquire(maxIO, 60, TimeUnit.SECONDS))
{
log.warn("Couldn't get lock after 60 seconds on closing AsynchronousFileImpl::" + this.fileName);
}
- writeSemaphore = null;
+ maxIOSemaphore = null;
if (poller != null)
{
stopPoller();
@@ -263,7 +285,7 @@
{
startPoller();
}
-
+
pendingWrites.up();
if (writeExecutor != null)
@@ -272,38 +294,46 @@
{
public void run()
{
- writeSemaphore.acquireUninterruptibly();
+ maxIOSemaphore.acquireUninterruptibly();
+ long sequence = nextWritingSequence.getAndIncrement();
+
try
{
- write(handler, position, size, directByteBuffer, aioCallback);
+ write(handler, sequence, position, size, directByteBuffer, aioCallback);
}
catch (HornetQException e)
{
- callbackError(aioCallback, directByteBuffer, e.getCode(), e.getMessage());
+ callbackError(aioCallback, sequence, directByteBuffer, e.getCode(), e.getMessage());
}
catch (RuntimeException e)
{
- callbackError(aioCallback, directByteBuffer, HornetQException.INTERNAL_ERROR, e.getMessage());
+ callbackError(aioCallback,
+ sequence,
+ directByteBuffer,
+ HornetQException.INTERNAL_ERROR,
+ e.getMessage());
}
}
});
}
else
{
- writeSemaphore.acquireUninterruptibly();
+ maxIOSemaphore.acquireUninterruptibly();
+ long sequence = nextWritingSequence.getAndIncrement();
+
try
{
- write(handler, position, size, directByteBuffer, aioCallback);
+ write(handler, sequence, position, size, directByteBuffer, aioCallback);
}
catch (HornetQException e)
{
- callbackError(aioCallback, directByteBuffer, e.getCode(), e.getMessage());
+ callbackError(aioCallback, sequence, directByteBuffer, e.getCode(), e.getMessage());
}
catch (RuntimeException e)
{
- callbackError(aioCallback, directByteBuffer, HornetQException.INTERNAL_ERROR, e.getMessage());
+ callbackError(aioCallback, sequence, directByteBuffer, HornetQException.INTERNAL_ERROR, e.getMessage());
}
}
@@ -320,7 +350,7 @@
startPoller();
}
pendingWrites.up();
- writeSemaphore.acquireUninterruptibly();
+ maxIOSemaphore.acquireUninterruptibly();
try
{
read(handler, position, size, directByteBuffer, aioPackage);
@@ -328,14 +358,14 @@
catch (HornetQException e)
{
// Release only if an exception happened
- writeSemaphore.release();
+ maxIOSemaphore.release();
pendingWrites.down();
throw e;
}
catch (RuntimeException e)
{
// Release only if an exception happened
- writeSemaphore.release();
+ maxIOSemaphore.release();
pendingWrites.down();
throw e;
}
@@ -397,9 +427,9 @@
resetBuffer(buffer, buffer.limit());
buffer.position(0);
}
-
+
// Protected -------------------------------------------------------------------------
-
+
protected void finalize()
{
if (opened)
@@ -410,32 +440,108 @@
// Private ---------------------------------------------------------------------------
- /** The JNI layer will call this method, so we could use it to unlock readWriteLocks held in the java layer */
+ /** */
@SuppressWarnings("unused")
- // Called by the JNI layer.. just ignore the
- // warning
- private void callbackDone(final AIOCallback callback, final ByteBuffer buffer)
+ private void callbackDone(final AIOCallback callback, final long sequence, final ByteBuffer buffer)
{
- writeSemaphore.release();
+ maxIOSemaphore.release();
+
pendingWrites.down();
- callback.done();
-
- // The buffer is not sent on callback for read operations
- if (bufferCallback != null && buffer != null)
+
+ callbackLock.lock();
+
+ try
{
- bufferCallback.bufferDone(buffer);
+
+ if (sequence == -1)
+ {
+ callback.done();
+ }
+ else
+ {
+ if (sequence == nextReadSequence)
+ {
+ nextReadSequence++;
+ callback.done();
+ flushCallbacks();
+ }
+ else
+ {
+ pendingCallbacks.add(new CallbackHolder(sequence, callback));
+ }
+ }
+
+ // The buffer is not sent on callback for read operations
+ if (bufferCallback != null && buffer != null)
+ {
+ bufferCallback.bufferDone(buffer);
+ }
}
+ finally
+ {
+ callbackLock.unlock();
+ }
}
+ private void flushCallbacks()
+ {
+ while (!pendingCallbacks.isEmpty() && pendingCallbacks.peek().sequence == nextReadSequence)
+ {
+ CallbackHolder holder = pendingCallbacks.poll();
+ if (holder.isError())
+ {
+ ErrorCallback error = (ErrorCallback) holder;
+ holder.callback.onError(error.errorCode, error.message);
+ }
+ else
+ {
+ holder.callback.done();
+ }
+ nextReadSequence++;
+ }
+ }
+
// Called by the JNI layer.. just ignore the
// warning
- private void callbackError(final AIOCallback callback, final ByteBuffer buffer, final int errorCode, final String errorMessage)
+ private void callbackError(final AIOCallback callback,
+ final long sequence,
+ final ByteBuffer buffer,
+ final int errorCode,
+ final String errorMessage)
{
log.warn("CallbackError: " + errorMessage);
- writeSemaphore.release();
+
+ maxIOSemaphore.release();
+
pendingWrites.down();
- callback.onError(errorCode, errorMessage);
+ callbackLock.lock();
+
+ try
+ {
+ if (sequence == -1)
+ {
+ callback.onError(errorCode, errorMessage);
+ }
+ else
+ {
+ if (sequence == nextReadSequence)
+ {
+ nextReadSequence++;
+ callback.onError(errorCode, errorMessage);
+ flushCallbacks();
+ }
+ else
+ {
+ pendingCallbacks.add(new ErrorCallback(sequence, callback, errorCode, errorMessage));
+ }
+ }
+ }
+ finally
+ {
+ callbackLock.unlock();
+ }
+
// The buffer is not sent on callback for read operations
if (bufferCallback != null && buffer != null)
{
@@ -504,10 +610,10 @@
private static native void resetBuffer(ByteBuffer directByteBuffer, int size);
public static native void destroyBuffer(ByteBuffer buffer);
-
+
/** Instead of passing the nanoSeconds through the stack call every time, we set it statically inside the native method */
public static native void setNanoSleepInterval(int nanoseconds);
-
+
public static native void nanoSleep();
private static native ByteBuffer newNativeBuffer(long size);
@@ -516,7 +622,12 @@
private native long size0(long handle) throws HornetQException;
- private native void write(long handle, long position, long size, ByteBuffer buffer, AIOCallback aioPackage) throws HornetQException;
+ private native void write(long handle,
+ long sequence,
+ long position,
+ long size,
+ ByteBuffer buffer,
+ AIOCallback aioPackage) throws HornetQException;
private native void read(long handle, long position, long size, ByteBuffer buffer, AIOCallback aioPackage) throws HornetQException;
@@ -529,11 +640,63 @@
/** A native method that does nothing, and just validate if the ELF dependencies are loaded and on the correct platform as this binary format */
private static native int getNativeVersion();
- /** Poll asynchrounous events from internal queues */
+ /** Poll asynchronous events from internal queues */
private static native void internalPollEvents(long handler);
// Inner classes ---------------------------------------------------------------------
+ private static class CallbackHolder implements Comparable<CallbackHolder>
+ {
+ final long sequence;
+
+ final AIOCallback callback;
+
+ public boolean isError()
+ {
+ return false;
+ }
+
+ public CallbackHolder(final long sequence, final AIOCallback callback)
+ {
+ this.sequence = sequence;
+ this.callback = callback;
+ }
+
+ public int compareTo(CallbackHolder o)
+ {
+ // It shouldn't be equals in any case
+ if (sequence <= o.sequence)
+ {
+ return -1;
+ }
+ else
+ {
+ return 1;
+ }
+ }
+ }
+
+ private static class ErrorCallback extends CallbackHolder
+ {
+ final int errorCode;
+
+ final String message;
+
+ public boolean isError()
+ {
+ return true;
+ }
+
+ public ErrorCallback(final long sequence, final AIOCallback callback, int errorCode, String message)
+ {
+ super(sequence, callback);
+
+ this.errorCode = errorCode;
+
+ this.message = message;
+ }
+ }
+
private class PollerRunnable implements Runnable
{
PollerRunnable()
Modified: trunk/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -1024,6 +1024,7 @@
}
catch (HornetQException e)
{
+ log.warn(e.getMessage(), e);
// This should never occur
throw new XAException(XAException.XAER_RMERR);
}
Modified: trunk/src/main/org/hornetq/core/exception/HornetQException.java
===================================================================
--- trunk/src/main/org/hornetq/core/exception/HornetQException.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/exception/HornetQException.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -38,6 +38,9 @@
public static final int UNBLOCKED = 005;
+ public static final int IO_ERROR = 006;
+
+
public static final int QUEUE_DOES_NOT_EXIST = 100;
public static final int QUEUE_EXISTS = 101;
@@ -85,8 +88,6 @@
public static final int NATIVE_ERROR_ALLOCATE_MEMORY = 209;
- public static final int NATIVE_ERROR_IO = 210;
-
public static final int NATIVE_ERROR_AIO_FULL = 211;
Added: trunk/src/main/org/hornetq/core/journal/IOAsyncTask.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/IOAsyncTask.java (rev 0)
+++ trunk/src/main/org/hornetq/core/journal/IOAsyncTask.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -0,0 +1,28 @@
+/*
+ * 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.journal;
+
+import org.hornetq.core.asyncio.AIOCallback;
+
+/**
+ *
+ * This class is just a direct extension of AIOCallback.
+ * Just to avoid the direct dependency of org.hornetq.core.asynciio.AIOCallback from the journal.
+ *
+ * @author <a href="mailto:clebert.suconic@jboss.com">Clebert Suconic</a>
+ *
+ */
+public interface IOAsyncTask extends AIOCallback
+{
+}
Modified: trunk/src/main/org/hornetq/core/journal/IOCompletion.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/IOCompletion.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/IOCompletion.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -13,17 +13,14 @@
package org.hornetq.core.journal;
-import org.hornetq.core.asyncio.AIOCallback;
-
/**
- *
- * This class is just a direct extension of AIOCallback.
- * Just to avoid the direct dependency of org.hornetq.core.asynciio.AIOCallback from the journal.
- *
- * @author <a href="mailto:clebert.suconic@jboss.com">Clebert Suconic</a>
+ * A IOCompletion
*
+ * @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
+ *
+ *
*/
-public interface IOCompletion extends AIOCallback
+public interface IOCompletion extends IOAsyncTask
{
- void waitCompletion() throws Exception;
+ void lineUp();
}
Modified: trunk/src/main/org/hornetq/core/journal/Journal.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/Journal.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/Journal.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -19,8 +19,10 @@
/**
*
- * A Journal
+ * Most methods on the journal provide a blocking version where you select the sync mode and a non blocking mode where you pass a completion callback as a parameter.
*
+ * Notice also that even on the callback methods it's possible to pass the sync mode. That will only make sense on the NIO operations.
+ *
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
* @author <a href="mailto:clebert.suconic@jboss.com">Clebert Suconic</a>
*
@@ -31,14 +33,24 @@
void appendAddRecord(long id, byte recordType, byte[] record, boolean sync) throws Exception;
+ void appendAddRecord(long id, byte recordType, byte[] record, boolean sync, IOCompletion completionCallback) throws Exception;
+
void appendAddRecord(long id, byte recordType, EncodingSupport record, boolean sync) throws Exception;
+ void appendAddRecord(long id, byte recordType, EncodingSupport record, boolean sync, IOCompletion completionCallback) throws Exception;
+
void appendUpdateRecord(long id, byte recordType, byte[] record, boolean sync) throws Exception;
+ void appendUpdateRecord(long id, byte recordType, byte[] record, boolean sync, IOCompletion completionCallback) throws Exception;
+
void appendUpdateRecord(long id, byte recordType, EncodingSupport record, boolean sync) throws Exception;
+ void appendUpdateRecord(long id, byte recordType, EncodingSupport record, boolean sync, IOCompletion completionCallback) throws Exception;
+
void appendDeleteRecord(long id, boolean sync) throws Exception;
+ void appendDeleteRecord(long id, boolean sync, IOCompletion completionCallback) throws Exception;
+
// Transactional operations
void appendAddRecordTransactional(long txID, long id, byte recordType, byte[] record) throws Exception;
@@ -57,6 +69,8 @@
void appendCommitRecord(long txID, boolean sync) throws Exception;
+ void appendCommitRecord(long txID, boolean sync, IOCompletion callback) throws Exception;
+
/**
*
* <p>If the system crashed after a prepare was called, it should store information that is required to bring the transaction
@@ -70,10 +84,16 @@
*/
void appendPrepareRecord(long txID, EncodingSupport transactionData, boolean sync) throws Exception;
+ void appendPrepareRecord(long txID, EncodingSupport transactionData, boolean sync, IOCompletion callback) throws Exception;
+
void appendPrepareRecord(long txID, byte[] transactionData, boolean sync) throws Exception;
+ void appendPrepareRecord(long txID, byte[] transactionData, boolean sync, IOCompletion callback) throws Exception;
+
void appendRollbackRecord(long txID, boolean sync) throws Exception;
+ void appendRollbackRecord(long txID, boolean sync, IOCompletion callback) throws Exception;
+
// Load
JournalLoadInformation load(LoaderCallback reloadManager) throws Exception;
Modified: trunk/src/main/org/hornetq/core/journal/SequentialFile.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/SequentialFile.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/SequentialFile.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -38,7 +38,7 @@
boolean exists();
/**
- * For certain operations (like loading) we don't need open the file with full maxIO
+ * The maximum number of simultaneous writes accepted
* @param maxIO
* @throws Exception
*/
@@ -56,17 +56,17 @@
void delete() throws Exception;
- void write(HornetQBuffer bytes, boolean sync, IOCompletion callback) throws Exception;
+ void write(HornetQBuffer bytes, boolean sync, IOAsyncTask callback) throws Exception;
void write(HornetQBuffer bytes, boolean sync) throws Exception;
/** Write directly to the file without using any buffer */
- void writeDirect(ByteBuffer bytes, boolean sync, IOCompletion callback);
+ void writeDirect(ByteBuffer bytes, boolean sync, IOAsyncTask callback);
/** Write directly to the file without using any buffer */
void writeDirect(ByteBuffer bytes, boolean sync) throws Exception;
- int read(ByteBuffer bytes, IOCompletion callback) throws Exception;
+ int read(ByteBuffer bytes, IOAsyncTask callback) throws Exception;
int read(ByteBuffer bytes) throws Exception;
Modified: trunk/src/main/org/hornetq/core/journal/impl/AIOSequentialFile.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/AIOSequentialFile.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/AIOSequentialFile.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -15,21 +15,15 @@
import java.io.File;
import java.nio.ByteBuffer;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-import org.hornetq.core.asyncio.AIOCallback;
import org.hornetq.core.asyncio.AsynchronousFile;
import org.hornetq.core.asyncio.BufferCallback;
import org.hornetq.core.asyncio.impl.AsynchronousFileImpl;
-import org.hornetq.core.journal.IOCompletion;
-import org.hornetq.core.journal.SequentialFileFactory;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.journal.SequentialFile;
+import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
*
@@ -50,14 +44,9 @@
private final BufferCallback bufferCallback;
- /** A context switch on AIO would make it to synchronize the disk before
- switching to the new thread, what would cause
- serious performance problems. Because of that we make all the writes on
- AIO using a single thread. */
- private final Executor executor;
-
/** The pool for Thread pollers */
private final Executor pollerExecutor;
+
public AIOSequentialFile(final SequentialFileFactory factory,
final int bufferSize,
@@ -66,13 +55,12 @@
final String fileName,
final int maxIO,
final BufferCallback bufferCallback,
- final Executor executor,
+ final Executor writerExecutor,
final Executor pollerExecutor)
{
- super(directory, new File(directory + "/" + fileName), factory);
+ super(directory, new File(directory + "/" + fileName), factory, writerExecutor);
this.maxIO = maxIO;
this.bufferCallback = bufferCallback;
- this.executor = executor;
this.pollerExecutor = pollerExecutor;
}
@@ -99,7 +87,7 @@
public SequentialFile copy()
{
- return new AIOSequentialFile(factory, -1, -1, getFile().getParent(), getFileName(), maxIO, bufferCallback, executor, pollerExecutor);
+ return new AIOSequentialFile(factory, -1, -1, getFile().getParent(), getFileName(), maxIO, bufferCallback, writerExecutor, pollerExecutor);
}
public synchronized void close() throws Exception
@@ -108,27 +96,13 @@
{
return;
}
+
+ super.close();
+
opened = false;
timedBuffer = null;
- final CountDownLatch donelatch = new CountDownLatch(1);
-
- executor.execute(new Runnable()
- {
- public void run()
- {
- donelatch.countDown();
- }
- });
-
- while (!donelatch.await(60, TimeUnit.SECONDS))
- {
- log.warn("Executor on file " + getFile().getName() + " couldn't complete its tasks in 60 seconds.",
- new Exception("Warning: Executor on file " + getFile().getName() +
- " couldn't complete its tasks in 60 seconds."));
- }
-
aioFile.close();
aioFile = null;
@@ -199,13 +173,18 @@
open(maxIO);
}
- public synchronized void open(final int currentMaxIO) throws Exception
+ public synchronized void open(final int maxIO) throws Exception
{
opened = true;
- aioFile = newFile();
- aioFile.open(getFile().getAbsolutePath(), currentMaxIO);
+
+ aioFile = new AsynchronousFileImpl(writerExecutor, pollerExecutor);
+
+ aioFile.open(getFile().getAbsolutePath(), maxIO);
+
position.set(0);
+
aioFile.setBufferCallback(bufferCallback);
+
this.fileSize = aioFile.size();
}
@@ -214,7 +193,7 @@
aioFile.setBufferCallback(callback);
}
- public int read(final ByteBuffer bytes, final IOCompletion callback) throws Exception
+ public int read(final ByteBuffer bytes, final IOAsyncTask callback) throws Exception
{
int bytesToRead = bytes.limit();
@@ -229,7 +208,7 @@
public int read(final ByteBuffer bytes) throws Exception
{
- IOCompletion waitCompletion = SimpleWaitIOCallback.getInstance();
+ SimpleWaitIOCallback waitCompletion = new SimpleWaitIOCallback();
int bytesRead = read(bytes, waitCompletion);
@@ -268,20 +247,12 @@
// Protected methods
// -----------------------------------------------------------------------------------------------------
- /**
- * An extension point for tests
- */
- protected AsynchronousFile newFile()
- {
- return new AsynchronousFileImpl(executor, pollerExecutor);
- }
-
public void writeDirect(final ByteBuffer bytes, final boolean sync) throws Exception
{
if (sync)
{
- IOCompletion completion = SimpleWaitIOCallback.getInstance();
+ SimpleWaitIOCallback completion = new SimpleWaitIOCallback();
writeDirect(bytes, true, completion);
@@ -298,7 +269,7 @@
*
* @param sync Not used on AIO
* */
- public void writeDirect(final ByteBuffer bytes, final boolean sync, IOCompletion callback)
+ public void writeDirect(final ByteBuffer bytes, final boolean sync, IOAsyncTask callback)
{
final int bytesToWrite = factory.calculateBlockSize(bytes.limit());
Modified: trunk/src/main/org/hornetq/core/journal/impl/AIOSequentialFileFactory.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/AIOSequentialFileFactory.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/AIOSequentialFileFactory.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -36,15 +36,14 @@
public class AIOSequentialFileFactory extends AbstractSequentialFactory
{
- // Timeout used to wait executors to shutdown
- private static final int EXECUTOR_TIMEOUT = 60;
-
private static final Logger log = Logger.getLogger(AIOSequentialFileFactory.class);
private static final boolean trace = log.isTraceEnabled();
private final ReuseBuffersController buffersControl = new ReuseBuffersController();
+ private ExecutorService pollerExecutor;
+
// This method exists just to make debug easier.
// I could replace log.trace by log.info temporarily while I was debugging
// Journal
@@ -53,13 +52,6 @@
log.trace(message);
}
- /** A single AIO write executor for every AIO File.
- * This is used only for AIO & instant operations. We only need one executor-thread for the entire journal as we always have only one active file.
- * And even if we had multiple files at a given moment, this should still be ok, as we control max-io in a semaphore, guaranteeing AIO calls don't block on disk calls */
- private ExecutorService writeExecutor;
-
- private ExecutorService pollerExecutor;
-
public AIOSequentialFileFactory(final String journalDir)
{
this(journalDir,
@@ -152,9 +144,6 @@
{
super.start();
- writeExecutor = Executors.newSingleThreadExecutor(new HornetQThreadFactory("HornetQ-AIO-writer-pool" + System.identityHashCode(this),
- true));
-
pollerExecutor = Executors.newCachedThreadPool(new HornetQThreadFactory("HornetQ-AIO-poller-pool" + System.identityHashCode(this),
true));
@@ -163,23 +152,8 @@
@Override
public void stop()
{
- super.stop();
-
buffersControl.stop();
- writeExecutor.shutdown();
-
- try
- {
- if (!writeExecutor.awaitTermination(EXECUTOR_TIMEOUT, TimeUnit.SECONDS))
- {
- log.warn("Timed out on AIO writer shutdown", new Exception("Timed out on AIO writer shutdown"));
- }
- }
- catch (InterruptedException e)
- {
- }
-
pollerExecutor.shutdown();
try
@@ -192,6 +166,8 @@
catch (InterruptedException e)
{
}
+
+ super.stop();
}
@Override
Modified: trunk/src/main/org/hornetq/core/journal/impl/AbstractSequentialFactory.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/AbstractSequentialFactory.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/AbstractSequentialFactory.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -19,10 +19,14 @@
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.HornetQThreadFactory;
/**
*
@@ -34,16 +38,28 @@
*/
public abstract class AbstractSequentialFactory implements SequentialFileFactory
{
+
+ // Timeout used to wait executors to shutdown
+ protected static final int EXECUTOR_TIMEOUT = 60;
+
private static final Logger log = Logger.getLogger(AbstractSequentialFactory.class);
protected final String journalDir;
protected final TimedBuffer timedBuffer;
-
+
protected final int bufferSize;
protected final long bufferTimeout;
+
+ /**
+ * Asynchronous writes need to be done at another executor.
+ * This needs to be done at NIO, or else we would have the callers thread blocking for the return.
+ * At AIO this is necessary as context switches on writes would fire flushes at the kernel.
+ * */
+ protected ExecutorService writeExecutor;
+
public AbstractSequentialFactory(final String journalDir,
final boolean buffered,
@@ -71,6 +87,24 @@
{
timedBuffer.stop();
}
+
+ if (isSupportsCallbacks())
+ {
+ writeExecutor.shutdown();
+
+ try
+ {
+ if (!writeExecutor.awaitTermination(EXECUTOR_TIMEOUT, TimeUnit.SECONDS))
+ {
+ log.warn("Timed out on AIO writer shutdown", new Exception("Timed out on AIO writer shutdown"));
+ }
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+
+
}
public void start()
@@ -79,6 +113,14 @@
{
timedBuffer.start();
}
+
+ if (isSupportsCallbacks())
+ {
+ writeExecutor = Executors.newSingleThreadExecutor(new HornetQThreadFactory("HornetQ-Asynchronous-Persistent-Writes" + System.identityHashCode(this),
+ true));
+ }
+
+
}
/* (non-Javadoc)
@@ -99,7 +141,7 @@
}
}
}
-
+
public void flush()
{
if (timedBuffer != null)
@@ -117,7 +159,6 @@
}
}
-
public void releaseBuffer(ByteBuffer buffer)
{
}
Modified: trunk/src/main/org/hornetq/core/journal/impl/AbstractSequentialFile.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/AbstractSequentialFile.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/AbstractSequentialFile.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -16,9 +16,12 @@
import java.io.File;
import java.nio.ByteBuffer;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executor;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
-import org.hornetq.core.journal.IOCompletion;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.logging.Logger;
@@ -55,6 +58,9 @@
* This is the class returned to the factory when the file is being activated. */
protected final TimedBufferObserver timedBufferObserver = new LocalBufferObserver();
+ /** Used for asynchronous writes */
+ protected final Executor writerExecutor;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -63,12 +69,16 @@
* @param file
* @param directory
*/
- public AbstractSequentialFile(final String directory, final File file, final SequentialFileFactory factory)
+ public AbstractSequentialFile(final String directory,
+ final File file,
+ final SequentialFileFactory factory,
+ final Executor writerExecutor)
{
super();
this.file = file;
this.directory = directory;
this.factory = factory;
+ this.writerExecutor = writerExecutor;
}
// Public --------------------------------------------------------
@@ -115,6 +125,29 @@
}
}
+ public synchronized void close() throws Exception
+ {
+ final CountDownLatch donelatch = new CountDownLatch(1);
+
+ if (writerExecutor != null)
+ {
+ writerExecutor.execute(new Runnable()
+ {
+ public void run()
+ {
+ donelatch.countDown();
+ }
+ });
+
+ while (!donelatch.await(60, TimeUnit.SECONDS))
+ {
+ log.warn("Executor on file " + getFile().getName() + " couldn't complete its tasks in 60 seconds.",
+ new Exception("Warning: Executor on file " + getFile().getName() +
+ " couldn't complete its tasks in 60 seconds."));
+ }
+ }
+ }
+
public final boolean fits(final int size)
{
if (timedBuffer == null)
@@ -159,7 +192,7 @@
}
- public void write(final HornetQBuffer bytes, final boolean sync, final IOCompletion callback) throws Exception
+ public void write(final HornetQBuffer bytes, final boolean sync, final IOAsyncTask callback) throws Exception
{
if (timedBuffer != null)
{
@@ -178,7 +211,7 @@
{
if (sync)
{
- IOCompletion completion = SimpleWaitIOCallback.getInstance();
+ SimpleWaitIOCallback completion = new SimpleWaitIOCallback();
write(bytes, true, completion);
@@ -203,18 +236,18 @@
// Inner classes -------------------------------------------------
- protected static class DelegateCallback implements IOCompletion
+ protected static class DelegateCallback implements IOAsyncTask
{
- final List<IOCompletion> delegates;
+ final List<IOAsyncTask> delegates;
- DelegateCallback(final List<IOCompletion> delegates)
+ DelegateCallback(final List<IOAsyncTask> delegates)
{
this.delegates = delegates;
}
public void done()
{
- for (IOCompletion callback : delegates)
+ for (IOAsyncTask callback : delegates)
{
try
{
@@ -229,7 +262,7 @@
public void onError(final int errorCode, final String errorMessage)
{
- for (IOCompletion callback : delegates)
+ for (IOAsyncTask callback : delegates)
{
try
{
@@ -249,7 +282,7 @@
protected class LocalBufferObserver implements TimedBufferObserver
{
- public void flushBuffer(final ByteBuffer buffer, final boolean requestedSync, final List<IOCompletion> callbacks)
+ public void flushBuffer(final ByteBuffer buffer, final boolean requestedSync, final List<IOAsyncTask> callbacks)
{
buffer.flip();
Modified: trunk/src/main/org/hornetq/core/journal/impl/DummyCallback.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/DummyCallback.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/DummyCallback.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -14,7 +14,6 @@
package org.hornetq.core.journal.impl;
-import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.logging.Logger;
/**
@@ -24,13 +23,13 @@
*
*
*/
-public class DummyCallback implements IOCompletion
+class DummyCallback extends SyncIOCompletion
{
private static DummyCallback instance = new DummyCallback();
private static final Logger log = Logger.getLogger(SimpleWaitIOCallback.class);
- public static IOCompletion getInstance()
+ public static DummyCallback getInstance()
{
return instance;
}
@@ -47,5 +46,12 @@
public void waitCompletion() throws Exception
{
}
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.IOCompletion#linedUp()
+ */
+ public void lineUp()
+ {
+ }
}
Modified: trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -44,6 +44,7 @@
import org.hornetq.core.buffers.ChannelBuffer;
import org.hornetq.core.buffers.ChannelBuffers;
import org.hornetq.core.journal.EncodingSupport;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.journal.LoaderCallback;
@@ -84,7 +85,7 @@
private static final Logger log = Logger.getLogger(JournalImpl.class);
- private static final boolean trace = false;
+ private static final boolean trace = log.isTraceEnabled();
/** This is to be set to true at DEBUG & development only */
private static final boolean LOAD_TRACE = false;
@@ -95,6 +96,7 @@
private static final void trace(final String message)
{
log.trace(message);
+ //System.out.println("JournalImpl::" + message);
}
// The sizes of primitive types
@@ -845,15 +847,35 @@
appendAddRecord(id, recordType, new ByteArrayEncoding(record), sync);
}
+ public void appendAddRecord(final long id, final byte recordType, final byte[] record, final boolean sync, final IOCompletion callback) throws Exception
+ {
+ appendAddRecord(id, recordType, new ByteArrayEncoding(record), sync, callback);
+ }
+
public void appendAddRecord(final long id, final byte recordType, final EncodingSupport record, final boolean sync) throws Exception
{
+ SyncIOCompletion callback = getSyncCallback(sync);
+
+ appendAddRecord(id, recordType, record, sync, callback);
+
+ // We only wait on explicit callbacks
+ if (callback != null)
+ {
+ callback.waitCompletion();
+ }
+ }
+
+ public void appendAddRecord(final long id, final byte recordType, final EncodingSupport record, final boolean sync, final IOCompletion callback) throws Exception
+ {
+ if (LOAD_TRACE)
+ {
+ trace("appendAddRecord id = " + id + ", recordType = " + recordType);
+ }
if (state != STATE_LOADED)
{
throw new IllegalStateException("Journal must be loaded first");
}
-
- IOCompletion callback = null;
-
+
compactingLock.readLock().lock();
try
@@ -864,7 +886,10 @@
writeAddRecord(-1, id, recordType, record, size, bb); // fileID will be filled later
- callback = getSyncCallback(sync);
+ if (callback != null)
+ {
+ callback.lineUp();
+ }
lockAppend.lock();
try
@@ -882,11 +907,6 @@
{
compactingLock.readLock().unlock();
}
-
- if (callback != null)
- {
- callback.waitCompletion();
- }
}
public void appendUpdateRecord(final long id, final byte recordType, final byte[] record, final boolean sync) throws Exception
@@ -894,15 +914,35 @@
appendUpdateRecord(id, recordType, new ByteArrayEncoding(record), sync);
}
+ public void appendUpdateRecord(final long id, final byte recordType, final byte[] record, final boolean sync, final IOCompletion callback) throws Exception
+ {
+ appendUpdateRecord(id, recordType, new ByteArrayEncoding(record), sync, callback);
+ }
+
public void appendUpdateRecord(final long id, final byte recordType, final EncodingSupport record, final boolean sync) throws Exception
{
+ SyncIOCompletion callback = getSyncCallback(sync);
+
+ appendUpdateRecord(id, recordType, record, sync, callback);
+
+ // We only wait on explicit callbacks
+ if (callback != null)
+ {
+ callback.waitCompletion();
+ }
+ }
+
+ public void appendUpdateRecord(final long id, final byte recordType, final EncodingSupport record, final boolean sync, final IOCompletion callback) throws Exception
+ {
+ if (LOAD_TRACE)
+ {
+ trace("appendUpdateRecord id = " + id + ", recordType = " + recordType);
+ }
if (state != STATE_LOADED)
{
throw new IllegalStateException("Journal must be loaded first");
}
-
- IOCompletion callback = null;
-
+
compactingLock.readLock().lock();
try
@@ -924,7 +964,10 @@
writeUpdateRecord(-1, id, recordType, record, size, bb);
- callback = getSyncCallback(sync);
+ if (callback != null)
+ {
+ callback.lineUp();
+ }
lockAppend.lock();
try
@@ -951,24 +994,35 @@
{
compactingLock.readLock().unlock();
}
+ }
+
+ public void appendDeleteRecord(final long id, final boolean sync) throws Exception
+ {
+ SyncIOCompletion callback = getSyncCallback(sync);
+
+ appendDeleteRecord(id, sync, callback);
+
+ // We only wait on explicit callbacks
if (callback != null)
{
callback.waitCompletion();
}
}
-
- public void appendDeleteRecord(final long id, final boolean sync) throws Exception
+
+ public void appendDeleteRecord(final long id, final boolean sync, final IOCompletion callback) throws Exception
{
+ if (LOAD_TRACE)
+ {
+ trace("appendDeleteRecord id = " + id);
+ }
if (state != STATE_LOADED)
{
throw new IllegalStateException("Journal must be loaded first");
}
-
+
compactingLock.readLock().lock();
- IOCompletion callback = null;
-
try
{
@@ -981,14 +1035,17 @@
throw new IllegalStateException("Cannot find add info " + id);
}
}
-
+
int size = SIZE_DELETE_RECORD;
ChannelBuffer bb = newBuffer(size);
writeDeleteRecord(-1, id, size, bb);
- callback = getSyncCallback(sync);
+ if (callback != null)
+ {
+ callback.lineUp();
+ }
lockAppend.lock();
try
@@ -1016,11 +1073,6 @@
{
compactingLock.readLock().unlock();
}
-
- if (callback != null)
- {
- callback.waitCompletion();
- }
}
public void appendAddRecordTransactional(final long txID, final long id, final byte recordType, final byte[] record) throws Exception
@@ -1034,6 +1086,10 @@
final byte recordType,
final EncodingSupport record) throws Exception
{
+ if (LOAD_TRACE)
+ {
+ trace("appendAddRecordTransactional txID " + txID + ", id = " + id + ", recordType = " + recordType);
+ }
if (state != STATE_LOADED)
{
throw new IllegalStateException("Journal must be loaded first");
@@ -1083,6 +1139,10 @@
final byte recordType,
final EncodingSupport record) throws Exception
{
+ if (LOAD_TRACE)
+ {
+ trace("appendUpdateRecordTransactional txID " + txID + ", id = " + id + ", recordType = " + recordType);
+ }
if (state != STATE_LOADED)
{
throw new IllegalStateException("Journal must be loaded first");
@@ -1126,6 +1186,11 @@
public void appendDeleteRecordTransactional(final long txID, final long id, final EncodingSupport record) throws Exception
{
+ if (LOAD_TRACE)
+ {
+ trace("appendDeleteRecordTransactional txID " + txID + ", id = " + id);
+ }
+
if (state != STATE_LOADED)
{
throw new IllegalStateException("Journal must be loaded first");
@@ -1165,6 +1230,12 @@
{
appendDeleteRecordTransactional(txID, id, NullEncoding.instance);
}
+
+
+ public void appendPrepareRecord(long txID, byte[] transactionData, boolean sync, IOCompletion completion) throws Exception
+ {
+ appendPrepareRecord(txID, new ByteArrayEncoding(transactionData), sync, completion);
+ }
/* (non-Javadoc)
* @see org.hornetq.core.journal.Journal#appendPrepareRecord(long, byte[], boolean)
@@ -1174,6 +1245,18 @@
appendPrepareRecord(txID, new ByteArrayEncoding(transactionData), sync);
}
+ public void appendPrepareRecord(final long txID, final EncodingSupport transactionData, final boolean sync) throws Exception
+ {
+ SyncIOCompletion syncCompletion = getSyncCallback(sync);
+
+ appendPrepareRecord(txID, transactionData, sync, syncCompletion);
+
+ if (syncCompletion != null)
+ {
+ syncCompletion.waitCompletion();
+ }
+ }
+
/**
*
* <p>If the system crashed after a prepare was called, it should store information that is required to bring the transaction
@@ -1187,8 +1270,13 @@
* @param transactionData - extra user data for the prepare
* @throws Exception
*/
- public void appendPrepareRecord(final long txID, final EncodingSupport transactionData, final boolean sync) throws Exception
+ public void appendPrepareRecord(final long txID, final EncodingSupport transactionData, final boolean sync, IOCompletion callback) throws Exception
{
+ if (LOAD_TRACE)
+ {
+ trace("appendPrepareRecord txID " + txID);
+ }
+
if (state != STATE_LOADED)
{
throw new IllegalStateException("Journal must be loaded first");
@@ -1198,11 +1286,6 @@
JournalTransaction tx = getTransactionInfo(txID);
- if (sync)
- {
- tx.syncPreviousFiles(fileFactory.isSupportsCallbacks(), currentFile);
- }
-
try
{
@@ -1211,10 +1294,15 @@
writeTransaction(-1, PREPARE_RECORD, txID, transactionData, size, -1, bb);
+ if (callback != null)
+ {
+ callback.lineUp();
+ }
+
lockAppend.lock();
try
{
- JournalFile usedFile = appendRecord(bb, true, sync, tx, null);
+ JournalFile usedFile = appendRecord(bb, true, sync, tx, callback);
tx.prepare(usedFile);
}
@@ -1228,11 +1316,23 @@
{
compactingLock.readLock().unlock();
}
-
- // We should wait this outside of the lock, to increase throughput
- tx.waitCompletion();
}
+
+
+
+ public void appendCommitRecord(final long txID, final boolean sync) throws Exception
+ {
+ SyncIOCompletion syncCompletion = getSyncCallback(sync);
+
+ appendCommitRecord(txID, sync, syncCompletion);
+
+ if (syncCompletion != null)
+ {
+ syncCompletion.waitCompletion();
+ }
+ }
+
/**
* <p>A transaction record (Commit or Prepare), will hold the number of elements the transaction has on each file.</p>
* <p>For example, a transaction was spread along 3 journal files with 10 pendingTransactions on each file.
@@ -1250,7 +1350,9 @@
*
* @see JournalImpl#writeTransaction(byte, long, org.hornetq.core.journal.impl.JournalImpl.JournalTransaction, EncodingSupport)
*/
- public void appendCommitRecord(final long txID, final boolean sync) throws Exception
+
+
+ public void appendCommitRecord(final long txID, final boolean sync, final IOCompletion callback) throws Exception
{
if (state != STATE_LOADED)
{
@@ -1264,6 +1366,7 @@
try
{
+
if (tx == null)
{
throw new IllegalStateException("Cannot find tx with id " + txID);
@@ -1279,10 +1382,15 @@
-1 /* number of records on this transaction will be filled later inside append record */,
bb);
+ if (callback != null)
+ {
+ callback.lineUp();
+ }
+
lockAppend.lock();
try
{
- JournalFile usedFile = appendRecord(bb, true, sync, tx, null);
+ JournalFile usedFile = appendRecord(bb, true, sync, tx, callback);
tx.commit(usedFile);
}
@@ -1296,15 +1404,23 @@
{
compactingLock.readLock().unlock();
}
+ }
- if (sync)
+
+ public void appendRollbackRecord(final long txID, final boolean sync) throws Exception
+ {
+ SyncIOCompletion syncCompletion = getSyncCallback(sync);
+
+ appendRollbackRecord(txID, sync, syncCompletion);
+
+ if (syncCompletion != null)
{
- // We should wait this outside of the lock, to increase throuput
- tx.waitCompletion();
+ syncCompletion.waitCompletion();
}
+
}
-
- public void appendRollbackRecord(final long txID, final boolean sync) throws Exception
+
+ public void appendRollbackRecord(final long txID, final boolean sync, final IOCompletion callback) throws Exception
{
if (state != STATE_LOADED)
{
@@ -1323,15 +1439,20 @@
{
throw new IllegalStateException("Cannot find tx with id " + txID);
}
-
+
ChannelBuffer bb = newBuffer(SIZE_ROLLBACK_RECORD);
writeRollback(-1, txID, bb);
+ if (callback != null)
+ {
+ callback.lineUp();
+ }
+
lockAppend.lock();
try
{
- JournalFile usedFile = appendRecord(bb, false, sync, tx, null);
+ JournalFile usedFile = appendRecord(bb, false, sync, tx, callback);
tx.rollback(usedFile);
}
@@ -1345,14 +1466,6 @@
{
compactingLock.readLock().unlock();
}
-
- // We should wait this outside of the lock, to increase throuput
-
- if (sync)
- {
- tx.waitCompletion();
- }
-
}
public int getAlignment() throws Exception
@@ -2833,7 +2946,7 @@
final boolean completeTransaction,
final boolean sync,
final JournalTransaction tx,
- IOCompletion callback) throws Exception
+ final IOAsyncTask parameterCallback) throws Exception
{
try
{
@@ -2841,6 +2954,8 @@
{
throw new IllegalStateException("The journal is not loaded " + state);
}
+
+ final IOAsyncTask callback;
int size = bb.capacity();
@@ -2874,25 +2989,29 @@
if (tx != null)
{
- if (callback != null)
- {
- // sanity check, it should not happen.
- throw new IllegalArgumentException("Invalid callback parameter. Use of tx is mutually exclusive with the callback");
- }
-
// The callback of a transaction has to be taken inside the lock,
// when we guarantee the currentFile will not be changed,
// since we individualize the callback per file
if (fileFactory.isSupportsCallbacks())
{
- callback = tx.getCallback(currentFile);
+ // Set the delegated callback as a parameter
+ TransactionCallback txcallback = tx.getCallback(currentFile);
+ if (parameterCallback != null)
+ {
+ txcallback.setDelegateCompletion(parameterCallback);
+ }
+ callback = txcallback;
}
+ else
+ {
+ callback = null;
+ }
if (sync)
{
- // 99 % of the times this will be already synced, as previous files should be closed already.
- // This is to have 100% guarantee the transaction will be persisted and no loss of information would
- // happen
+ // In an edge case the transaction could still have pending data from previous files.
+ // This shouldn't cause any blocking issues, as this is here to guarantee we cover all possibilities
+ // on guaranteeing the data is on the disk
tx.syncPreviousFiles(fileFactory.isSupportsCallbacks(), currentFile);
}
@@ -2903,6 +3022,10 @@
tx.fillNumberOfRecords(currentFile, bb);
}
}
+ else
+ {
+ callback = parameterCallback;
+ }
// Adding fileID
bb.writerIndex(DataConstants.SIZE_BYTE);
@@ -3233,13 +3356,13 @@
return tx;
}
- private IOCompletion getSyncCallback(final boolean sync)
+ private SyncIOCompletion getSyncCallback(final boolean sync)
{
if (fileFactory.isSupportsCallbacks())
{
if (sync)
{
- return SimpleWaitIOCallback.getInstance();
+ return new SimpleWaitIOCallback();
}
else
{
Modified: trunk/src/main/org/hornetq/core/journal/impl/NIOSequentialFile.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/NIOSequentialFile.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/NIOSequentialFile.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -18,8 +18,12 @@
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
-import org.hornetq.core.journal.IOCompletion;
+import org.hornetq.core.exception.HornetQException;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.logging.Logger;
@@ -40,14 +44,23 @@
private RandomAccessFile rfile;
- public NIOSequentialFile(final SequentialFileFactory factory, final String directory, final String fileName)
+ /** The write semaphore here is only used when writing asynchronously */
+ private Semaphore maxIOSemaphore;
+
+ private final int defaultMaxIO;
+
+ private int maxIO;
+
+ public NIOSequentialFile(final SequentialFileFactory factory, final String directory, final String fileName, final int maxIO, final Executor writerExecutor)
{
- super(directory, new File(directory + "/" + fileName), factory);
+ super(directory, new File(directory + "/" + fileName), factory, writerExecutor);
+ this.defaultMaxIO = maxIO;
}
- public NIOSequentialFile(final SequentialFileFactory factory, final File file)
+ public NIOSequentialFile(final SequentialFileFactory factory, final File file, final int maxIO, final Executor writerExecutor)
{
- super(file.getParent(), new File(file.getPath()), factory);
+ super(file.getParent(), new File(file.getPath()), factory, writerExecutor);
+ this.defaultMaxIO = maxIO;
}
public int getAlignment()
@@ -65,20 +78,28 @@
return channel != null;
}
+ /** this.maxIO represents the default maxIO.
+ * Some operations while initializing files on the journal may require a different maxIO */
public synchronized void open() throws Exception
{
+ open(this.defaultMaxIO);
+ }
+
+ public void open(final int maxIO) throws Exception
+ {
rfile = new RandomAccessFile(getFile(), "rw");
channel = rfile.getChannel();
fileSize = channel.size();
+
+ if (writerExecutor != null)
+ {
+ this.maxIOSemaphore = new Semaphore(maxIO);
+ this.maxIO = maxIO;
+ }
}
- public void open(final int currentMaxIO) throws Exception
- {
- open();
- }
-
public void fill(final int position, final int size, final byte fillCharacter) throws Exception
{
ByteBuffer bb = ByteBuffer.allocateDirect(size);
@@ -111,6 +132,8 @@
public synchronized void close() throws Exception
{
+ super.close();
+
if (channel != null)
{
channel.close();
@@ -125,6 +148,16 @@
rfile = null;
+ if (maxIOSemaphore != null)
+ {
+ while (!maxIOSemaphore.tryAcquire(maxIO, 60, TimeUnit.SECONDS))
+ {
+ log.warn("Couldn't get lock after 60 seconds on closing AsynchronousFileImpl::" + this.getFileName());
+ }
+ }
+
+ maxIOSemaphore = null;
+
notifyAll();
}
@@ -133,7 +166,7 @@
return read(bytes, null);
}
- public int read(final ByteBuffer bytes, final IOCompletion callback) throws Exception
+ public int read(final ByteBuffer bytes, final IOAsyncTask callback) throws Exception
{
try
{
@@ -152,7 +185,7 @@
{
if (callback != null)
{
- callback.onError(-1, e.getLocalizedMessage());
+ callback.onError(HornetQException.IO_ERROR, e.getLocalizedMessage());
}
throw e;
@@ -194,10 +227,10 @@
public SequentialFile copy()
{
- return new NIOSequentialFile(factory, getFile());
+ return new NIOSequentialFile(factory, getFile(), maxIO, writerExecutor);
}
- public void writeDirect(final ByteBuffer bytes, final boolean sync, final IOCompletion callback)
+ public void writeDirect(final ByteBuffer bytes, final boolean sync, final IOAsyncTask callback)
{
if (callback == null)
{
@@ -219,6 +252,55 @@
internalWrite(bytes, sync, null);
}
+ private void internalWrite(final ByteBuffer bytes, final boolean sync, final IOAsyncTask callback) throws Exception
+ {
+ if (!isOpen())
+ {
+ if (callback != null)
+ {
+ callback.onError(HornetQException.IO_ERROR, "File not opened");
+ }
+ else
+ {
+ throw new HornetQException(HornetQException.IO_ERROR, "File not opened");
+ }
+ return;
+ }
+
+ if (writerExecutor == null)
+ {
+ doInternalWrite(bytes, sync, callback);
+ }
+ else
+ {
+ // This is a flow control on writing, just like maxAIO on libaio
+ maxIOSemaphore.acquire();
+
+ writerExecutor.execute(new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
+ try
+ {
+ doInternalWrite(bytes, sync, callback);
+ }
+ catch (Throwable e)
+ {
+ log.warn("Exception on submitting write", e);
+ callback.onError(HornetQException.IO_ERROR, e.getMessage());
+ }
+ }
+ finally
+ {
+ maxIOSemaphore.release();
+ }
+ }
+ });
+ }
+ }
+
/**
* @param bytes
* @param sync
@@ -226,8 +308,9 @@
* @throws IOException
* @throws Exception
*/
- private void internalWrite(final ByteBuffer bytes, final boolean sync, final IOCompletion callback) throws Exception
+ private void doInternalWrite(final ByteBuffer bytes, final boolean sync, final IOAsyncTask callback) throws Exception
{
+
position.addAndGet(bytes.limit());
channel.write(bytes);
Modified: trunk/src/main/org/hornetq/core/journal/impl/NIOSequentialFileFactory.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/NIOSequentialFileFactory.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/NIOSequentialFileFactory.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -64,9 +64,15 @@
}
// maxIO is ignored on NIO
- public SequentialFile createSequentialFile(final String fileName, final int maxIO)
+ public SequentialFile createSequentialFile(final String fileName, int maxIO)
{
- return new NIOSequentialFile(this, journalDir, fileName);
+ if (maxIO < 0)
+ {
+ // A single threaded IO
+ maxIO = 1;
+ }
+
+ return new NIOSequentialFile(this, journalDir, fileName, maxIO, writeExecutor);
}
public boolean isSupportsCallbacks()
Modified: trunk/src/main/org/hornetq/core/journal/impl/SimpleWaitIOCallback.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/SimpleWaitIOCallback.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/SimpleWaitIOCallback.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -14,9 +14,9 @@
package org.hornetq.core.journal.impl;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import org.hornetq.core.exception.HornetQException;
-import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.logging.Logger;
/**
@@ -26,7 +26,7 @@
*
*
*/
-public class SimpleWaitIOCallback implements IOCompletion
+public class SimpleWaitIOCallback extends SyncIOCompletion
{
private static final Logger log = Logger.getLogger(SimpleWaitIOCallback.class);
@@ -37,12 +37,6 @@
private volatile int errorCode = 0;
- public static IOCompletion getInstance()
- {
- return new SimpleWaitIOCallback();
- }
-
-
public void done()
{
latch.countDown();
@@ -68,4 +62,16 @@
}
return;
}
+
+ public boolean waitCompletion(final long timeout) throws Exception
+ {
+ return latch.await(timeout, TimeUnit.MILLISECONDS);
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.IOCompletion#linedUp()
+ */
+ public void lineUp()
+ {
+ }
}
Added: trunk/src/main/org/hornetq/core/journal/impl/SyncIOCompletion.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/SyncIOCompletion.java (rev 0)
+++ trunk/src/main/org/hornetq/core/journal/impl/SyncIOCompletion.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -0,0 +1,48 @@
+/*
+ * 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.journal.impl;
+
+import org.hornetq.core.journal.IOCompletion;
+
+/**
+ * Internal class used to manage explicit syncs on the Journal through callbacks.
+ *
+ * @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public abstract class SyncIOCompletion implements IOCompletion
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public abstract void waitCompletion() throws Exception;
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Modified: trunk/src/main/org/hornetq/core/journal/impl/TimedBuffer.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/TimedBuffer.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/TimedBuffer.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -15,6 +15,7 @@
import java.nio.ByteBuffer;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
@@ -22,7 +23,7 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.hornetq.core.buffers.ChannelBuffers;
-import org.hornetq.core.journal.IOCompletion;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.VariableLatch;
@@ -56,7 +57,7 @@
private int bufferLimit = 0;
- private List<IOCompletion> callbacks;
+ private List<IOAsyncTask> callbacks;
private final Lock lock = new ReentrantReadWriteLock().writeLock();
@@ -106,7 +107,7 @@
buffer.clear();
bufferLimit = 0;
- callbacks = new ArrayList<IOCompletion>();
+ callbacks = new ArrayList<IOAsyncTask>();
this.flushOnSync = flushOnSync;
latchTimer.up();
this.timeout = timeout;
@@ -225,7 +226,7 @@
}
}
- public synchronized void addBytes(final byte[] bytes, final boolean sync, final IOCompletion callback)
+ public synchronized void addBytes(final byte[] bytes, final boolean sync, final IOAsyncTask callback)
{
if (buffer.writerIndex() == 0)
{
@@ -258,36 +259,55 @@
}
}
- public synchronized void flush()
+ public void flush()
{
- if (buffer.writerIndex() > 0)
+ ByteBuffer bufferToFlush = null;
+
+ boolean useSync = false;
+
+ List<IOAsyncTask> callbacksToCall = null;
+
+ synchronized (this)
{
- latchTimer.up();
+ if (buffer.writerIndex() > 0)
+ {
+ latchTimer.up();
+
+ int pos = buffer.writerIndex();
+
+ if (logRates)
+ {
+ bytesFlushed += pos;
+ }
+
+ bufferToFlush = bufferObserver.newBuffer(bufferSize, pos);
+
+ // Putting a byteArray on a native buffer is much faster, since it will do in a single native call.
+ // Using bufferToFlush.put(buffer) would make several append calls for each byte
+
+ bufferToFlush.put(buffer.array(), 0, pos);
- int pos = buffer.writerIndex();
-
- if (logRates)
- {
- bytesFlushed += pos;
+ callbacksToCall = callbacks;
+
+ callbacks = new LinkedList<IOAsyncTask>();
+
+ useSync = pendingSync;
+
+ active = false;
+ pendingSync = false;
+
+ buffer.clear();
+ bufferLimit = 0;
}
+ }
+
+ // Execute the flush outside of the lock
+ // This is important for NIO performance while we are using NIO Callbacks
+ if (bufferToFlush != null)
+ {
+ bufferObserver.flushBuffer(bufferToFlush, useSync, callbacksToCall);
+ }
- ByteBuffer directBuffer = bufferObserver.newBuffer(bufferSize, pos);
-
- // Putting a byteArray on a native buffer is much faster, since it will do in a single native call.
- // Using directBuffer.put(buffer) would make several append calls for each byte
-
- directBuffer.put(buffer.array(), 0, pos);
-
- bufferObserver.flushBuffer(directBuffer, pendingSync, callbacks);
-
- callbacks = new ArrayList<IOCompletion>();
-
- active = false;
- pendingSync = false;
-
- buffer.clear();
- bufferLimit = 0;
- }
}
// Package protected ---------------------------------------------
Modified: trunk/src/main/org/hornetq/core/journal/impl/TimedBufferObserver.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/TimedBufferObserver.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/TimedBufferObserver.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -17,7 +17,7 @@
import java.nio.ByteBuffer;
import java.util.List;
-import org.hornetq.core.journal.IOCompletion;
+import org.hornetq.core.journal.IOAsyncTask;
/**
* A TimedBufferObserver
@@ -39,7 +39,7 @@
// Public --------------------------------------------------------
- public void flushBuffer(ByteBuffer buffer, boolean syncRequested, List<IOCompletion> callbacks);
+ public void flushBuffer(ByteBuffer buffer, boolean syncRequested, List<IOAsyncTask> callbacks);
/** Return the number of remaining bytes that still fit on the observer (file) */
Modified: trunk/src/main/org/hornetq/core/journal/impl/TransactionCallback.java
===================================================================
--- trunk/src/main/org/hornetq/core/journal/impl/TransactionCallback.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/journal/impl/TransactionCallback.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -14,7 +14,7 @@
package org.hornetq.core.journal.impl;
-import org.hornetq.core.journal.IOCompletion;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.utils.VariableLatch;
/**
@@ -24,22 +24,34 @@
*
*
*/
-public class TransactionCallback implements IOCompletion
+public class TransactionCallback implements IOAsyncTask
{
private final VariableLatch countLatch = new VariableLatch();
private volatile String errorMessage = null;
private volatile int errorCode = 0;
+
+ private volatile int up = 0;
+
+ private volatile int done = 0;
+
+ private volatile IOAsyncTask delegateCompletion;
public void countUp()
{
+ up++;
countLatch.up();
}
public void done()
{
countLatch.down();
+ if (++done == up && delegateCompletion != null)
+ {
+ delegateCompletion.done();
+ delegateCompletion = null;
+ }
}
public void waitCompletion() throws InterruptedException
@@ -59,9 +71,30 @@
this.errorCode = errorCode;
countLatch.down();
+
+ if (delegateCompletion != null)
+ {
+ delegateCompletion.onError(errorCode, errorMessage);
+ }
}
/**
+ * @return the delegateCompletion
+ */
+ public IOAsyncTask getDelegateCompletion()
+ {
+ return delegateCompletion;
+ }
+
+ /**
+ * @param delegateCompletion the delegateCompletion to set
+ */
+ public void setDelegateCompletion(IOAsyncTask delegateCompletion)
+ {
+ this.delegateCompletion = delegateCompletion;
+ }
+
+ /**
* @return the errorMessage
*/
public String getErrorMessage()
Modified: trunk/src/main/org/hornetq/core/management/ManagementService.java
===================================================================
--- trunk/src/main/org/hornetq/core/management/ManagementService.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/management/ManagementService.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -71,6 +71,8 @@
ObjectNameBuilder getObjectNameBuilder();
// Resource Registration
+
+ void setStorageManager(StorageManager storageManager);
HornetQServerControlImpl registerServer(PostOffice postOffice,
StorageManager storageManager,
Modified: trunk/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -437,7 +437,8 @@
if (XidImpl.toBase64String(xid).equals(transactionAsBase64))
{
Transaction transaction = resourceManager.removeTransaction(xid);
- transaction.commit();
+ transaction.commit(false);
+ server.getStorageManager().waitOnOperations(-1);
long recordID = server.getStorageManager().storeHeuristicCompletion(xid, true);
resourceManager.putHeuristicCompletion(recordID, xid, true);
return true;
@@ -456,6 +457,7 @@
{
Transaction transaction = resourceManager.removeTransaction(xid);
transaction.rollback();
+ server.getStorageManager().completeOperations();
long recordID = server.getStorageManager().storeHeuristicCompletion(xid, false);
resourceManager.putHeuristicCompletion(recordID, xid, false);
return true;
Modified: trunk/src/main/org/hornetq/core/management/impl/ManagementServiceImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/management/impl/ManagementServiceImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/management/impl/ManagementServiceImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -21,7 +21,9 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import javax.management.MBeanServer;
import javax.management.NotificationBroadcasterSupport;
@@ -39,6 +41,7 @@
import org.hornetq.core.config.cluster.DiscoveryGroupConfiguration;
import org.hornetq.core.config.cluster.DivertConfiguration;
import org.hornetq.core.config.impl.ConfigurationImpl;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.management.AcceptorControl;
import org.hornetq.core.management.BridgeControl;
@@ -177,6 +180,11 @@
{
return messageCounterManager;
}
+
+ public void setStorageManager(StorageManager storageManager)
+ {
+ this.storageManager = storageManager;
+ }
public HornetQServerControlImpl registerServer(final PostOffice postOffice,
final StorageManager storageManager,
@@ -736,6 +744,12 @@
}
}
}
+
+ if (storageManager != null)
+ {
+ storageManager.waitOnOperations(managementRequestTimeout);
+ storageManager.clearContext();
+ }
}
public void enableNotifications(boolean enabled)
Modified: trunk/src/main/org/hornetq/core/paging/PagingStore.java
===================================================================
--- trunk/src/main/org/hornetq/core/paging/PagingStore.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/paging/PagingStore.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -67,14 +67,14 @@
* @param message
* @throws Exception
*/
- void addSize(ServerMessage message, boolean add) throws Exception;
+ void addSize(ServerMessage message, boolean add);
/**
*
* @param reference
* @throws Exception
*/
- void addSize(MessageReference reference, boolean add) throws Exception;
+ void addSize(MessageReference reference, boolean add);
/**
*
Modified: trunk/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -279,7 +279,7 @@
checkReleaseProducerFlowControlCredits(-credits);
}
- public void addSize(final ServerMessage message, final boolean add) throws Exception
+ public void addSize(final ServerMessage message, final boolean add)
{
long size = message.getMemoryEstimate();
@@ -297,7 +297,7 @@
}
}
- public void addSize(final MessageReference reference, final boolean add) throws Exception
+ public void addSize(final MessageReference reference, final boolean add)
{
long size = MessageReferenceImpl.getMemoryEstimate();
@@ -477,7 +477,7 @@
}
}
- public boolean startPaging() throws Exception
+ public boolean startPaging()
{
if (!running)
{
@@ -508,7 +508,17 @@
{
if (currentPage == null)
{
- openNewPage();
+ try
+ {
+ openNewPage();
+ }
+ catch (Exception e)
+ {
+ // If not possible to starting page due to an IO error, we will just consider it non paging.
+ // This shouldn't happen anyway
+ log.warn("IO Error, impossible to start paging", e);
+ return false;
+ }
return true;
}
@@ -699,7 +709,7 @@
}
}
- private void addSize(final long size) throws Exception
+ private void addSize(final long size)
{
if (addressFullMessagePolicy != AddressFullMessagePolicy.PAGE)
{
@@ -996,10 +1006,9 @@
}
depageTransaction.commit();
+
+ storageManager.waitOnOperations();
- // StorageManager does the check: if (replicated) -> do the proper cleanup already
- storageManager.completeReplication();
-
if (isTrace)
{
trace("Depage committed, running = " + running);
Added: trunk/src/main/org/hornetq/core/persistence/OperationContext.java
===================================================================
--- trunk/src/main/org/hornetq/core/persistence/OperationContext.java (rev 0)
+++ trunk/src/main/org/hornetq/core/persistence/OperationContext.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -0,0 +1,48 @@
+/*
+ * 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.persistence;
+
+import java.util.concurrent.Executor;
+
+import org.hornetq.core.journal.IOAsyncTask;
+import org.hornetq.core.journal.IOCompletion;
+
+
+/**
+ * This represents a set of operations done as part of replication.
+ * When the entire set is done a group of Runnables can be executed.
+ *
+ * @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public interface OperationContext extends IOCompletion
+{
+
+ /** The executor used on responses.
+ * If this is not set, it will use the current thread. */
+ void setExecutor(Executor executor);
+
+ /** Execute the task when all IO operations are complete,
+ * Or execute it immediately if nothing is pending. */
+ void executeOnCompletion(IOAsyncTask runnable);
+
+ void replicationLineUp();
+
+ void replicationDone();
+
+ /** To be called when there are no more operations pending */
+ void complete();
+
+}
Modified: trunk/src/main/org/hornetq/core/persistence/StorageManager.java
===================================================================
--- trunk/src/main/org/hornetq/core/persistence/StorageManager.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/persistence/StorageManager.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -15,9 +15,11 @@
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Executor;
import javax.transaction.xa.Xid;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.paging.PageTransactionInfo;
import org.hornetq.core.paging.PagedMessage;
@@ -46,6 +48,16 @@
*/
public interface StorageManager extends HornetQComponent
{
+
+ /** Get the context associated with the thread for later reuse */
+ OperationContext getContext();
+
+ /** It just creates an OperationContext without associating it */
+ OperationContext newContext(Executor executor);
+
+ /** Set the context back to the thread */
+ void setContext(OperationContext context);
+
// Message related operations
void pageClosed(SimpleString storeName, int pageNumber);
@@ -56,14 +68,21 @@
boolean isReplicated();
- void afterReplicated(Runnable run);
+ void afterCompleteOperations(IOAsyncTask run);
- /** Block until the replication is done.
+ /** Block until the operations are done.
* @throws Exception */
- void waitOnReplication(long timeout) throws Exception;
+ void waitOnOperations(long timeout) throws Exception;
- void completeReplication();
+ /** Block until the operations are done.
+ * @throws Exception */
+ void waitOnOperations() throws Exception;
+ /** To close the OperationsContext */
+ void completeOperations();
+
+ void clearContext();
+
UUID getPersistentID();
void setPersistentID(UUID id) throws Exception;
@@ -147,6 +166,4 @@
void deleteGrouping(GroupBinding groupBinding) throws Exception;
-
- void sync();
}
Modified: trunk/src/main/org/hornetq/core/persistence/impl/journal/FileLargeServerMessage.java
===================================================================
--- trunk/src/main/org/hornetq/core/persistence/impl/journal/FileLargeServerMessage.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/persistence/impl/journal/FileLargeServerMessage.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -176,7 +176,7 @@
this.delayDeletionCount.incrementAndGet();
}
- public synchronized void decrementDelayDeletionCount() throws Exception
+ public synchronized void decrementDelayDeletionCount()
{
int count = this.delayDeletionCount.decrementAndGet();
@@ -191,7 +191,7 @@
return new DecodingContext();
}
- private void checkDelete() throws Exception
+ private void checkDelete()
{
if (getRefCount() <= 0)
{
@@ -220,7 +220,7 @@
}
@Override
- public synchronized int decrementRefCount(MessageReference reference) throws Exception
+ public synchronized int decrementRefCount(MessageReference reference)
{
int currentRefCount = super.decrementRefCount(reference);
Modified: trunk/src/main/org/hornetq/core/persistence/impl/journal/JournalStorageManager.java
===================================================================
--- trunk/src/main/org/hornetq/core/persistence/impl/journal/JournalStorageManager.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/persistence/impl/journal/JournalStorageManager.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -26,9 +26,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
-import java.util.concurrent.TimeUnit;
import javax.transaction.xa.Xid;
@@ -37,6 +35,8 @@
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.filter.Filter;
import org.hornetq.core.journal.EncodingSupport;
+import org.hornetq.core.journal.IOAsyncTask;
+import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.journal.Journal;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.journal.PreparedTransactionInfo;
@@ -47,6 +47,7 @@
import org.hornetq.core.journal.impl.AIOSequentialFileFactory;
import org.hornetq.core.journal.impl.JournalImpl;
import org.hornetq.core.journal.impl.NIOSequentialFileFactory;
+import org.hornetq.core.journal.impl.SimpleWaitIOCallback;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.impl.MessageImpl;
import org.hornetq.core.paging.PageTransactionInfo;
@@ -54,6 +55,7 @@
import org.hornetq.core.paging.PagingManager;
import org.hornetq.core.paging.impl.PageTransactionInfoImpl;
import org.hornetq.core.persistence.GroupingInfo;
+import org.hornetq.core.persistence.OperationContext;
import org.hornetq.core.persistence.QueueBindingInfo;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.postoffice.Binding;
@@ -76,6 +78,7 @@
import org.hornetq.core.transaction.Transaction.State;
import org.hornetq.core.transaction.impl.TransactionImpl;
import org.hornetq.utils.DataConstants;
+import org.hornetq.utils.ExecutorFactory;
import org.hornetq.utils.Pair;
import org.hornetq.utils.SimpleString;
import org.hornetq.utils.UUID;
@@ -91,6 +94,7 @@
*/
public class JournalStorageManager implements StorageManager
{
+
private static final Logger log = Logger.getLogger(JournalStorageManager.class);
private static final long CHECKPOINT_BATCH_SIZE = Integer.MAX_VALUE;
@@ -142,6 +146,9 @@
private final SequentialFileFactory largeMessagesFactory;
private volatile boolean started;
+
+ /** Used to create Operation Contexts */
+ private final ExecutorFactory executorFactory;
private final Executor executor;
@@ -161,15 +168,17 @@
private final String largeMessagesDirectory;
- public JournalStorageManager(final Configuration config, final Executor executor)
+ public JournalStorageManager(final Configuration config, final ExecutorFactory executorFactory)
{
- this(config, executor, null);
+ this(config, executorFactory, null);
}
- public JournalStorageManager(final Configuration config, final Executor executor, final ReplicationManager replicator)
+ public JournalStorageManager(final Configuration config, final ExecutorFactory executorFactory, final ReplicationManager replicator)
{
- this.executor = executor;
+ this.executorFactory = executorFactory;
+ this.executor = executorFactory.getExecutor();
+
this.replicator = replicator;
if (config.getJournalType() != JournalType.NIO && config.getJournalType() != JournalType.ASYNCIO)
@@ -291,34 +300,41 @@
/* (non-Javadoc)
* @see org.hornetq.core.persistence.StorageManager#completeReplication()
*/
- public void completeReplication()
+ public void completeOperations()
{
- if (replicator != null)
- {
- replicator.closeContext();
- }
+ getContext().complete();
}
+
+ public void clearContext()
+ {
+ OperationContextImpl.clearContext();
+ }
public boolean isReplicated()
{
return replicator != null;
}
+
+ public void waitOnOperations() throws Exception
+ {
+ waitOnOperations(-1);
+ }
+
/* (non-Javadoc)
* @see org.hornetq.core.persistence.StorageManager#blockOnReplication()
*/
- public void waitOnReplication(final long timeout) throws Exception
+ public void waitOnOperations(final long timeout) throws Exception
{
- final CountDownLatch latch = new CountDownLatch(1);
- afterReplicated(new Runnable()
+ SimpleWaitIOCallback waitCallback = new SimpleWaitIOCallback();
+ afterCompleteOperations(waitCallback);
+ completeOperations();
+ if (timeout <= 0)
{
- public void run()
- {
- latch.countDown();
- }
- });
- completeReplication();
- if (!latch.await(timeout, TimeUnit.MILLISECONDS))
+ waitCallback.waitCompletion();
+ }
+ else
+ if (!waitCallback.waitCompletion(timeout))
{
throw new IllegalStateException("no response received from replication");
}
@@ -363,15 +379,33 @@
// TODO: shouldn't those page methods be on the PageManager? ^^^^
- public void afterReplicated(Runnable run)
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#getContext()
+ */
+ public OperationContext getContext()
{
- if (replicator == null)
- {
- throw new IllegalStateException("StorageManager is not replicated");
- }
- replicator.afterReplicated(run);
+ return OperationContextImpl.getContext(executorFactory);
}
+
+ public void setContext(OperationContext context)
+ {
+ OperationContextImpl.setContext(context);
+ }
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#newContext()
+ */
+ public OperationContext newContext(Executor executor)
+ {
+ return new OperationContextImpl(executor);
+ }
+
+ public void afterCompleteOperations(IOAsyncTask run)
+ {
+ getContext().executeOnCompletion(run);
+ }
+
public UUID getPersistentID()
{
return persistentID;
@@ -452,27 +486,27 @@
messageJournal.appendAddRecord(message.getMessageID(),
ADD_LARGE_MESSAGE,
new LargeMessageEncoding((LargeServerMessage)message),
- false);
+ false, getContext());
}
else
{
- messageJournal.appendAddRecord(message.getMessageID(), ADD_MESSAGE, message, false);
+ messageJournal.appendAddRecord(message.getMessageID(), ADD_MESSAGE, message, false, getContext());
}
}
public void storeReference(final long queueID, final long messageID) throws Exception
{
- messageJournal.appendUpdateRecord(messageID, ADD_REF, new RefEncoding(queueID), syncNonTransactional);
+ messageJournal.appendUpdateRecord(messageID, ADD_REF, new RefEncoding(queueID), syncNonTransactional, getContext());
}
public void storeAcknowledge(final long queueID, final long messageID) throws Exception
{
- messageJournal.appendUpdateRecord(messageID, ACKNOWLEDGE_REF, new RefEncoding(queueID), syncNonTransactional);
+ messageJournal.appendUpdateRecord(messageID, ACKNOWLEDGE_REF, new RefEncoding(queueID), syncNonTransactional, getContext());
}
public void deleteMessage(final long messageID) throws Exception
{
- messageJournal.appendDeleteRecord(messageID, syncNonTransactional);
+ messageJournal.appendDeleteRecord(messageID, syncNonTransactional, getContext());
}
public void updateScheduledDeliveryTime(final MessageReference ref) throws Exception
@@ -483,29 +517,21 @@
messageJournal.appendUpdateRecord(ref.getMessage().getMessageID(),
SET_SCHEDULED_DELIVERY_TIME,
encoding,
- syncNonTransactional);
+ syncNonTransactional, getContext());
}
public void storeDuplicateID(final SimpleString address, final byte[] duplID, final long recordID) throws Exception
{
DuplicateIDEncoding encoding = new DuplicateIDEncoding(address, duplID);
- messageJournal.appendAddRecord(recordID, DUPLICATE_ID, encoding, syncNonTransactional);
+ messageJournal.appendAddRecord(recordID, DUPLICATE_ID, encoding, syncNonTransactional, getContext());
}
public void deleteDuplicateID(long recordID) throws Exception
{
- messageJournal.appendDeleteRecord(recordID, syncNonTransactional);
+ messageJournal.appendDeleteRecord(recordID, syncNonTransactional, getContext());
}
- public void sync()
- {
- if (replicator != null)
- {
- replicator.sync();
- }
- }
-
// Transactional operations
public void storeMessageTransactional(final long txID, final ServerMessage message) throws Exception
@@ -559,13 +585,13 @@
public long storeHeuristicCompletion(Xid xid, boolean isCommit) throws Exception
{
long id = generateUniqueID();
- messageJournal.appendAddRecord(id, HEURISTIC_COMPLETION, new HeuristicCompletionEncoding(xid, isCommit), true);
+ messageJournal.appendAddRecord(id, HEURISTIC_COMPLETION, new HeuristicCompletionEncoding(xid, isCommit), true, getContext());
return id;
}
public void deleteHeuristicCompletion(long id) throws Exception
{
- messageJournal.appendDeleteRecord(id, true);
+ messageJournal.appendDeleteRecord(id, true, getContext());
}
public void deletePageTransactional(final long txID, final long recordID) throws Exception
@@ -591,17 +617,17 @@
public void prepare(final long txID, final Xid xid) throws Exception
{
- messageJournal.appendPrepareRecord(txID, new XidEncoding(xid), syncTransactional);
+ messageJournal.appendPrepareRecord(txID, new XidEncoding(xid), syncTransactional, getContext());
}
public void commit(final long txID) throws Exception
{
- messageJournal.appendCommitRecord(txID, syncTransactional);
+ messageJournal.appendCommitRecord(txID, syncTransactional, getContext());
}
public void rollback(final long txID) throws Exception
{
- messageJournal.appendRollbackRecord(txID, syncTransactional);
+ messageJournal.appendRollbackRecord(txID, syncTransactional, getContext());
}
public void storeDuplicateIDTransactional(final long txID,
@@ -639,7 +665,7 @@
messageJournal.appendUpdateRecord(ref.getMessage().getMessageID(),
UPDATE_DELIVERY_COUNT,
updateInfo,
- syncNonTransactional);
+ syncNonTransactional, getContext());
}
private static final class AddMessageRecord
@@ -1323,7 +1349,7 @@
return info;
}
-
+
// Public -----------------------------------------------------------------------------------
public Journal getMessageJournal()
@@ -1384,7 +1410,7 @@
}
// Private ----------------------------------------------------------------------------------
-
+
private void checkAndCreateDir(final String dir, final boolean create)
{
File f = new File(dir);
@@ -1874,11 +1900,11 @@
}
}
- public void afterPrepare(final Transaction tx) throws Exception
+ public void afterPrepare(final Transaction tx)
{
}
- public void afterRollback(final Transaction tx) throws Exception
+ public void afterRollback(final Transaction tx)
{
PageTransactionInfo pageTransaction = (PageTransactionInfo)tx.getProperty(TransactionPropertyIndexes.PAGE_TRANSACTION);
@@ -1909,7 +1935,6 @@
}
}
-
}
Added: trunk/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java (rev 0)
+++ trunk/src/main/org/hornetq/core/persistence/impl/journal/OperationContextImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -0,0 +1,272 @@
+/*
+ * 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.persistence.impl.journal;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.hornetq.core.journal.IOAsyncTask;
+import org.hornetq.core.persistence.OperationContext;
+import org.hornetq.utils.ExecutorFactory;
+
+/**
+ *
+ * This class will hold operations when there are IO operations...
+ * and it will
+ *
+ * @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
+ */
+public class OperationContextImpl implements OperationContext
+{
+
+ private static final ThreadLocal<OperationContext> threadLocalContext = new ThreadLocal<OperationContext>();
+
+ public static void clearContext()
+ {
+ threadLocalContext.set(null);
+ }
+
+ public static OperationContext getContext(final ExecutorFactory executorFactory)
+ {
+ OperationContext token = threadLocalContext.get();
+ if (token == null)
+ {
+ token = new OperationContextImpl(executorFactory.getExecutor());
+ threadLocalContext.set(token);
+ }
+ return token;
+ }
+
+ public static void setContext(OperationContext context)
+ {
+ threadLocalContext.set(context);
+ }
+
+
+ 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 int errorCode = -1;
+
+ private String errorMessage = null;
+
+ private Executor executor;
+
+ private final AtomicInteger executorsPending = new AtomicInteger(0);
+
+ public OperationContextImpl(final Executor executor)
+ {
+ super();
+ this.executor = executor;
+ }
+
+ /** To be called by the replication manager, when new replication is added to the queue */
+ public void lineUp()
+ {
+ storeLineUp++;
+ }
+
+ public void replicationLineUp()
+ {
+ replicationLineUp++;
+ }
+
+ /** this method needs to be called before the executor became operational */
+ public void setExecutor(Executor executor)
+ {
+ this.executor = executor;
+ }
+
+ public synchronized void replicationDone()
+ {
+ replicated++;
+ checkTasks();
+ }
+
+ /** You may have several actions to be done after a replication operation is completed. */
+ public void executeOnCompletion(final IOAsyncTask completion)
+ {
+ if (errorCode != -1)
+ {
+ completion.onError(errorCode, errorMessage);
+ return;
+ }
+
+ boolean executeNow = false;
+
+ synchronized (this)
+ {
+ if (tasks == null)
+ {
+ tasks = new LinkedList<TaskHolder>();
+ minimalReplicated = replicationLineUp;
+ minimalStore = storeLineUp;
+ }
+
+ // On this case, we can just execute the context directly
+ if (replicationLineUp == replicated && storeLineUp == stored)
+ {
+ if (executor != null)
+ {
+ // We want to avoid the executor if everything is complete...
+ // However, we can't execute the context if there are executions pending
+ // We need to use the executor on this case
+ if (executorsPending.get() == 0)
+ {
+ // No need to use an executor here or a context switch
+ // there are no actions pending.. hence we can just execute the task directly on the same thread
+ executeNow = true;
+ }
+ else
+ {
+ execute(completion);
+ }
+ }
+ else
+ {
+ executeNow = true;
+ }
+ }
+ else
+ {
+ tasks.add(new TaskHolder(completion));
+ }
+ }
+
+ if (executeNow)
+ {
+ // Executing outside of any locks
+ completion.done();
+ }
+
+ }
+
+ /** To be called by the storage manager, when data is confirmed on the channel */
+ public synchronized void done()
+ {
+ stored++;
+ checkTasks();
+ }
+
+ private void checkTasks()
+ {
+ if (stored >= minimalStore && replicated >= minimalReplicated)
+ {
+ Iterator<TaskHolder> iter = tasks.iterator();
+ while (iter.hasNext())
+ {
+ TaskHolder holder = iter.next();
+ if (stored >= holder.storeLined && replicated >= holder.replicationLined)
+ {
+ if (executor != null)
+ {
+ // If set, we use an executor to avoid the server being single threaded
+ execute(holder.task);
+ }
+ else
+ {
+ holder.task.done();
+ }
+
+ iter.remove();
+ }
+ else
+ {
+ // The actions need to be done in order...
+ // so it must achieve both conditions before we can proceed to more tasks
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * @param holder
+ */
+ private void execute(final IOAsyncTask task)
+ {
+ executorsPending.incrementAndGet();
+ executor.execute(new Runnable()
+ {
+ public void run()
+ {
+ // If any IO is done inside the callback, it needs to be done on a new context
+ clearContext();
+ task.done();
+ executorsPending.decrementAndGet();
+ }
+ });
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.replication.ReplicationToken#complete()
+ */
+ public void complete()
+ {
+ // We hold errors until the complete is set, or the callbacks will never get informed
+ errorCode = -1;
+ errorMessage = null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.asyncio.AIOCallback#onError(int, java.lang.String)
+ */
+ public synchronized void onError(int errorCode, String errorMessage)
+ {
+ this.errorCode = errorCode;
+ this.errorMessage = errorMessage;
+
+ if (tasks != null)
+ {
+ Iterator<TaskHolder> iter = tasks.iterator();
+ while (iter.hasNext())
+ {
+ TaskHolder holder = iter.next();
+ holder.task.onError(errorCode, errorMessage);
+ iter.remove();
+ }
+ }
+ }
+
+ class TaskHolder
+ {
+ int storeLined;
+
+ int replicationLined;
+
+ IOAsyncTask task;
+
+ TaskHolder(IOAsyncTask task)
+ {
+ this.storeLined = storeLineUp;
+ this.replicationLined = replicationLineUp;
+ this.task = task;
+ }
+ }
+
+}
Modified: trunk/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java
===================================================================
--- trunk/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -138,7 +138,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.server.LargeServerMessage#decrementDelayDeletionCount()
*/
- public void decrementDelayDeletionCount() throws Exception
+ public void decrementDelayDeletionCount()
{
}
Modified: trunk/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageManager.java
===================================================================
--- trunk/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageManager.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageManager.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -15,16 +15,19 @@
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicLong;
import javax.transaction.xa.Xid;
import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.paging.PageTransactionInfo;
import org.hornetq.core.paging.PagedMessage;
import org.hornetq.core.paging.PagingManager;
import org.hornetq.core.persistence.GroupingInfo;
+import org.hornetq.core.persistence.OperationContext;
import org.hornetq.core.persistence.QueueBindingInfo;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.postoffice.Binding;
@@ -282,14 +285,6 @@
}
/* (non-Javadoc)
- * @see org.hornetq.core.persistence.StorageManager#afterReplicated(java.lang.Runnable)
- */
- public void afterReplicated(Runnable run)
- {
- run.run();
- }
-
- /* (non-Javadoc)
* @see org.hornetq.core.persistence.StorageManager#isReplicated()
*/
public boolean isReplicated()
@@ -300,7 +295,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.persistence.StorageManager#completeReplication()
*/
- public void completeReplication()
+ public void completeOperations()
{
}
@@ -336,7 +331,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.persistence.StorageManager#blockOnReplication(long)
*/
- public void waitOnReplication(long timeout) throws Exception
+ public void waitOnOperations(long timeout) throws Exception
{
}
@@ -348,4 +343,49 @@
throw new IllegalStateException("Null Persistence should never be used as replicated");
}
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#afterCompleteOperations(org.hornetq.core.journal.IOCompletion)
+ */
+ public void afterCompleteOperations(IOAsyncTask run)
+ {
+ run.done();
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#waitOnOperations()
+ */
+ public void waitOnOperations() throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#getContext()
+ */
+ public OperationContext getContext()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#newContext()
+ */
+ public OperationContext newContext(Executor executor)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#setContext(org.hornetq.core.persistence.OperationContext)
+ */
+ public void setContext(OperationContext context)
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#clearContext()
+ */
+ public void clearContext()
+ {
+ }
+
}
Modified: trunk/src/main/org/hornetq/core/postoffice/impl/DuplicateIDCacheImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/postoffice/impl/DuplicateIDCacheImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/postoffice/impl/DuplicateIDCacheImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -155,7 +155,7 @@
}
}
- private synchronized void addToCacheInMemory(final byte[] duplID, final long recordID) throws Exception
+ private synchronized void addToCacheInMemory(final byte[] duplID, final long recordID)
{
cache.add(new ByteArrayHolder(duplID));
@@ -173,7 +173,14 @@
// reclaimed
id.a = new ByteArrayHolder(duplID);
- storageManager.deleteDuplicateID(id.b);
+ try
+ {
+ storageManager.deleteDuplicateID(id.b);
+ }
+ catch (Exception e)
+ {
+ log.warn("Error on deleting duplicate cache", e);
+ }
id.b = recordID;
}
@@ -205,7 +212,7 @@
this.recordID = recordID;
}
- private void process() throws Exception
+ private void process()
{
if (!done)
{
@@ -227,17 +234,17 @@
{
}
- public void afterCommit(final Transaction tx) throws Exception
+ public void afterCommit(final Transaction tx)
{
process();
}
- public void afterPrepare(final Transaction tx) throws Exception
+ public void afterPrepare(final Transaction tx)
{
process();
}
- public void afterRollback(final Transaction tx) throws Exception
+ public void afterRollback(final Transaction tx)
{
}
Modified: trunk/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -28,6 +28,7 @@
import org.hornetq.core.client.management.impl.ManagementHelper;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.filter.Filter;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.management.ManagementService;
import org.hornetq.core.management.Notification;
@@ -914,13 +915,6 @@
}
}
}
- else
- {
- if (storageManager.isReplicated())
- {
- storageManager.sync();
- }
- }
message.incrementRefCount(reference);
}
@@ -931,20 +925,20 @@
}
else
{
- if (storageManager.isReplicated())
+ // This will use the same thread if there are no pending operations
+ // avoiding a context switch on this case
+ storageManager.afterCompleteOperations(new IOAsyncTask()
{
- storageManager.afterReplicated(new Runnable()
+ public void onError(int errorCode, String errorMessage)
{
- public void run()
- {
- addReferences(refs);
- }
- });
- }
- else
- {
- addReferences(refs);
- }
+ log.warn("It wasn't possible to add references due to an IO error code " + errorCode + " message = " + errorMessage);
+ }
+
+ public void done()
+ {
+ addReferences(refs);
+ }
+ });
}
}
@@ -1120,11 +1114,11 @@
}
}
- public void afterPrepare(final Transaction tx) throws Exception
+ public void afterPrepare(final Transaction tx)
{
}
- public void afterRollback(final Transaction tx) throws Exception
+ public void afterRollback(final Transaction tx)
{
PageTransactionInfo pageTransaction = (PageTransactionInfo)tx.getProperty(TransactionPropertyIndexes.PAGE_TRANSACTION);
@@ -1231,11 +1225,11 @@
}
}
- public void afterPrepare(Transaction tx) throws Exception
+ public void afterPrepare(Transaction tx)
{
}
- public void afterRollback(Transaction tx) throws Exception
+ public void afterRollback(Transaction tx)
{
}
Modified: trunk/src/main/org/hornetq/core/remoting/impl/PacketDecoder.java
===================================================================
--- trunk/src/main/org/hornetq/core/remoting/impl/PacketDecoder.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/remoting/impl/PacketDecoder.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -29,7 +29,6 @@
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_APPEND_TX;
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_COMMIT_ROLLBACK;
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_COMPARE_DATA;
-import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_SYNC;
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_DELETE;
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_DELETE_TX;
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_LARGE_MESSAGE_BEGIN;
@@ -94,7 +93,6 @@
import org.hornetq.core.remoting.impl.wireformat.ReplicationAddTXMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationCommitMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationCompareDataMessage;
-import org.hornetq.core.remoting.impl.wireformat.ReplicationSyncContextMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationDeleteMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationDeleteTXMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationLargeMessageBeingMessage;
@@ -416,11 +414,6 @@
packet = new ReplicationDeleteMessage();
break;
}
- case REPLICATION_SYNC:
- {
- packet = new ReplicationSyncContextMessage();
- break;
- }
case REPLICATION_DELETE_TX:
{
packet = new ReplicationDeleteTXMessage();
Modified: trunk/src/main/org/hornetq/core/remoting/impl/RemotingConnectionImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/remoting/impl/RemotingConnectionImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/remoting/impl/RemotingConnectionImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -243,6 +243,8 @@
log.warn("Connection failure has been detected: " + me.getMessage() + " [code=" + me.getCode() + "]");
+ System.out.println("Fail on RemotingConnectio");
+
// Then call the listeners
callFailureListeners(me);
@@ -399,6 +401,7 @@
for (final FailureListener listener : listenersClone)
{
+ System.out.println("Calling failure listener: " + listener.getClass().getName());
try
{
listener.connectionFailed(me);
Modified: trunk/src/main/org/hornetq/core/remoting/impl/wireformat/PacketImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/remoting/impl/wireformat/PacketImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/remoting/impl/wireformat/PacketImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -172,8 +172,6 @@
public static final byte REPLICATION_LARGE_MESSAGE_WRITE = 91;
public static final byte REPLICATION_COMPARE_DATA = 92;
-
- public static final byte REPLICATION_SYNC = 93;
// Static --------------------------------------------------------
public PacketImpl(final byte type)
Deleted: trunk/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationSyncContextMessage.java
===================================================================
--- trunk/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationSyncContextMessage.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationSyncContextMessage.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -1,80 +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.remoting.impl.wireformat;
-
-import org.hornetq.core.remoting.spi.HornetQBuffer;
-
-/**
- * Message sent when a Replication Context is complete without any persistence replicated.
- * On that case we need to go over the cluster to make sure we get the data sent at the right order.
- *
- * @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
- *
- *
- */
-public class ReplicationSyncContextMessage extends PacketImpl
-{
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- public ReplicationSyncContextMessage()
- {
- super(REPLICATION_SYNC);
- }
-
- // Public --------------------------------------------------------
-
- @Override
- public int getRequiredBufferSize()
- {
- return BASIC_PACKET_SIZE;
-
- }
-
- @Override
- public void encodeBody(final HornetQBuffer buffer)
- {
- }
-
- @Override
- public void decodeBody(final HornetQBuffer buffer)
- {
- }
-
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
- // Public --------------------------------------------------------
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-
-}
Deleted: trunk/src/main/org/hornetq/core/replication/ReplicationContext.java
===================================================================
--- trunk/src/main/org/hornetq/core/replication/ReplicationContext.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/replication/ReplicationContext.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -1,41 +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.replication;
-
-
-/**
- * This represents a set of operations done as part of replication.
- * When the entire set is done a group of Runnables can be executed.
- *
- * @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
- *
- *
- */
-public interface ReplicationContext
-{
- /** To be called by the replication manager, when new replication is added to the queue */
- void linedUp();
-
- /** To be called by the replication manager, when data is confirmed on the channel */
- void replicated();
-
- void addReplicationAction(Runnable runnable);
-
- /** To be called when there are no more operations pending */
- void complete();
-
- /** Flush all pending callbacks on the Context */
- void flush();
-
-}
Modified: trunk/src/main/org/hornetq/core/replication/ReplicationManager.java
===================================================================
--- trunk/src/main/org/hornetq/core/replication/ReplicationManager.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/replication/ReplicationManager.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -19,6 +19,7 @@
import org.hornetq.core.journal.EncodingSupport;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.paging.PagedMessage;
+import org.hornetq.core.persistence.OperationContext;
import org.hornetq.core.server.HornetQComponent;
import org.hornetq.utils.SimpleString;
@@ -49,13 +50,8 @@
void appendRollbackRecord(byte journalID, long txID) throws Exception;
- /** Add an action to be executed after the pending replications */
- void afterReplicated(Runnable runnable);
-
- void closeContext();
-
/** A list of tokens that are still waiting for replications to be completed */
- Set<ReplicationContext> getActiveTokens();
+ Set<OperationContext> getActiveTokens();
/**
* @param storeName
@@ -87,7 +83,5 @@
* @throws HornetQException
*/
void compareJournals(JournalLoadInformation[] journalInfo) throws HornetQException;
-
- void sync();
-
+
}
Modified: trunk/src/main/org/hornetq/core/replication/impl/ReplicatedJournal.java
===================================================================
--- trunk/src/main/org/hornetq/core/replication/impl/ReplicatedJournal.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/replication/impl/ReplicatedJournal.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -16,6 +16,7 @@
import java.util.List;
import org.hornetq.core.journal.EncodingSupport;
+import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.journal.Journal;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.journal.LoaderCallback;
@@ -27,7 +28,6 @@
import org.hornetq.core.persistence.impl.journal.JournalStorageManager;
import org.hornetq.core.replication.ReplicationManager;
-
/**
* Used by the {@link JournalStorageManager} to replicate journal calls.
*
@@ -46,7 +46,7 @@
// Attributes ----------------------------------------------------
private static final boolean trace = false;
-
+
private static void trace(String message)
{
System.out.println("ReplicatedJournal::" + message);
@@ -58,9 +58,7 @@
private final byte journalID;
- public ReplicatedJournal(final byte journaID,
- final Journal localJournal,
- final ReplicationManager replicationManager)
+ public ReplicatedJournal(final byte journaID, final Journal localJournal, final ReplicationManager replicationManager)
{
super();
journalID = journaID;
@@ -69,11 +67,11 @@
}
// Static --------------------------------------------------------
-
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+
/**
* @param id
* @param recordType
@@ -87,6 +85,21 @@
this.appendAddRecord(id, recordType, new ByteArrayEncoding(record), sync);
}
+ public void appendAddRecord(long id, byte recordType, EncodingSupport record, boolean sync) throws Exception
+ {
+ if (trace)
+ {
+ trace("Append record id = " + id + " recordType = " + recordType);
+ }
+ replicationManager.appendAddRecord(journalID, id, recordType, record);
+ localJournal.appendAddRecord(id, recordType, record, sync);
+ }
+
+ public void appendAddRecord(long id, byte recordType, byte[] record, boolean sync, IOCompletion completionCallback) throws Exception
+ {
+ this.appendAddRecord(id, recordType, new ByteArrayEncoding(record), sync, completionCallback);
+ }
+
/**
* @param id
* @param recordType
@@ -95,14 +108,18 @@
* @throws Exception
* @see org.hornetq.core.journal.Journal#appendAddRecord(long, byte, org.hornetq.core.journal.EncodingSupport, boolean)
*/
- public void appendAddRecord(final long id, final byte recordType, final EncodingSupport record, final boolean sync) throws Exception
+ public void appendAddRecord(final long id,
+ final byte recordType,
+ final EncodingSupport record,
+ final boolean sync,
+ IOCompletion completionCallback) throws Exception
{
if (trace)
{
trace("Append record id = " + id + " recordType = " + recordType);
}
replicationManager.appendAddRecord(journalID, id, recordType, record);
- localJournal.appendAddRecord(id, recordType, record, sync);
+ localJournal.appendAddRecord(id, recordType, record, sync, completionCallback);
}
/**
@@ -155,6 +172,19 @@
localJournal.appendCommitRecord(txID, sync);
}
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendCommitRecord(long, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendCommitRecord(long txID, boolean sync, IOCompletion callback) throws Exception
+ {
+ if (trace)
+ {
+ trace("AppendCommit " + txID);
+ }
+ replicationManager.appendCommitRecord(journalID, txID);
+ localJournal.appendCommitRecord(txID, sync, callback);
+ }
+
/**
* @param id
* @param sync
@@ -171,6 +201,19 @@
localJournal.appendDeleteRecord(id, sync);
}
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendDeleteRecord(long, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendDeleteRecord(long id, boolean sync, IOCompletion completionCallback) throws Exception
+ {
+ if (trace)
+ {
+ trace("AppendDelete " + id);
+ }
+ replicationManager.appendDeleteRecord(journalID, id);
+ localJournal.appendDeleteRecord(id, sync, completionCallback);
+ }
+
/**
* @param txID
* @param id
@@ -245,6 +288,27 @@
localJournal.appendPrepareRecord(txID, transactionData, sync);
}
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendPrepareRecord(long, org.hornetq.core.journal.EncodingSupport, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendPrepareRecord(long txID, EncodingSupport transactionData, boolean sync, IOCompletion callback) throws Exception
+ {
+ if (trace)
+ {
+ trace("AppendPrepare txID=" + txID);
+ }
+ replicationManager.appendPrepareRecord(journalID, txID, transactionData);
+ localJournal.appendPrepareRecord(txID, transactionData, sync, callback);
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendPrepareRecord(long, byte[], boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendPrepareRecord(long txID, byte[] transactionData, boolean sync, IOCompletion callback) throws Exception
+ {
+ this.appendPrepareRecord(txID, new ByteArrayEncoding(transactionData), sync, callback);
+ }
+
/**
* @param txID
* @param sync
@@ -261,6 +325,19 @@
localJournal.appendRollbackRecord(txID, sync);
}
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendRollbackRecord(long, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendRollbackRecord(long txID, boolean sync, IOCompletion callback) throws Exception
+ {
+ if (trace)
+ {
+ trace("AppendRollback " + txID);
+ }
+ replicationManager.appendRollbackRecord(journalID, txID);
+ localJournal.appendRollbackRecord(txID, sync, callback);
+ }
+
/**
* @param id
* @param recordType
@@ -291,7 +368,34 @@
replicationManager.appendUpdateRecord(journalID, id, recordType, record);
localJournal.appendUpdateRecord(id, recordType, record, sync);
}
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendUpdateRecord(long, byte, byte[], boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendUpdateRecord(long id, byte recordType, byte[] record, boolean sync, IOCompletion completionCallback) throws Exception
+ {
+ this.appendUpdateRecord(id, recordType, new ByteArrayEncoding(record), sync, completionCallback);
+ }
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendUpdateRecord(long, byte, org.hornetq.core.journal.EncodingSupport, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendUpdateRecord(long id,
+ byte recordType,
+ EncodingSupport record,
+ boolean sync,
+ IOCompletion completionCallback) throws Exception
+ {
+ if (trace)
+ {
+ trace("AppendUpdateRecord id = " + id + " , recordType = " + recordType);
+ }
+ replicationManager.appendUpdateRecord(journalID, id, recordType, record);
+ localJournal.appendUpdateRecord(id, recordType, record, sync, completionCallback);
+ }
+
+
+
/**
* @param txID
* @param id
@@ -338,8 +442,8 @@
* @see org.hornetq.core.journal.Journal#load(java.util.List, java.util.List, org.hornetq.core.journal.TransactionFailureCallback)
*/
public JournalLoadInformation load(final List<RecordInfo> committedRecords,
- final List<PreparedTransactionInfo> preparedTransactions,
- final TransactionFailureCallback transactionFailure) throws Exception
+ final List<PreparedTransactionInfo> preparedTransactions,
+ final TransactionFailureCallback transactionFailure) throws Exception
{
return localJournal.load(committedRecords, preparedTransactions, transactionFailure);
}
Deleted: trunk/src/main/org/hornetq/core/replication/impl/ReplicationContextImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/replication/impl/ReplicationContextImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/replication/impl/ReplicationContextImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -1,105 +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.replication.impl;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.hornetq.core.replication.ReplicationContext;
-
-/**
- * A ReplicationToken
- *
- * @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
- *
- *
- */
-public class ReplicationContextImpl implements ReplicationContext
-{
- private List<Runnable> tasks;
-
- private AtomicInteger pendings = new AtomicInteger(0);
-
- private volatile boolean complete = false;
-
- /**
- * @param executor
- */
- public ReplicationContextImpl()
- {
- super();
- }
-
- /** To be called by the replication manager, when new replication is added to the queue */
- public void linedUp()
- {
- pendings.incrementAndGet();
- }
-
- /** You may have several actions to be done after a replication operation is completed. */
- public void addReplicationAction(Runnable runnable)
- {
- if (complete)
- {
- // Sanity check, this shouldn't happen
- throw new IllegalStateException("The Replication Context is complete, and no more tasks are accepted");
- }
-
- if (tasks == null)
- {
- // 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 ArrayList<Runnable>();
- }
-
- tasks.add(runnable);
- }
-
- /** To be called by the replication manager, when data is confirmed on the channel */
- public synchronized void replicated()
- {
- if (pendings.decrementAndGet() == 0 && complete)
- {
- flush();
- }
- }
-
-
- /* (non-Javadoc)
- * @see org.hornetq.core.replication.ReplicationToken#complete()
- */
- public synchronized void complete()
- {
- complete = true;
- if (pendings.get() == 0 && complete)
- {
- flush();
- }
- }
-
- public synchronized void flush()
- {
- if (tasks != null)
- {
- for (Runnable run : tasks)
- {
- run.run();
- }
- tasks.clear();
- }
- }
-
-
-}
Modified: trunk/src/main/org/hornetq/core/replication/impl/ReplicationEndpointImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/replication/impl/ReplicationEndpointImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/replication/impl/ReplicationEndpointImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -17,7 +17,6 @@
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_LARGE_MESSAGE_END;
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_LARGE_MESSAGE_WRITE;
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_COMPARE_DATA;
-import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.REPLICATION_SYNC;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -163,11 +162,6 @@
handleCompareDataMessage((ReplicationCompareDataMessage)packet);
response = new NullResponseMessage();
}
- else if (packet.getType() == REPLICATION_SYNC)
- {
- // https://jira.jboss.org/jira/browse/HORNETQ-218
- // Nothing to be done, we just needed a round trip to process events in order
- }
else
{
log.warn("Packet " + packet + " can't be processed by the ReplicationEndpoint");
@@ -196,8 +190,10 @@
{
Configuration config = server.getConfiguration();
- storage = new JournalStorageManager(config, server.getExecutorFactory().getExecutor());
+ storage = new JournalStorageManager(config, server.getExecutorFactory());
storage.start();
+
+ server.getManagementService().setStorageManager(storage);
bindingsJournal = storage.getBindingsJournal();
messagingJournal = storage.getMessageJournal();
Modified: trunk/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -13,6 +13,7 @@
package org.hornetq.core.replication.impl;
+import java.util.LinkedHashSet;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -24,6 +25,9 @@
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.paging.PagedMessage;
+import org.hornetq.core.persistence.OperationContext;
+import org.hornetq.core.persistence.StorageManager;
+import org.hornetq.core.persistence.impl.journal.OperationContextImpl;
import org.hornetq.core.remoting.Channel;
import org.hornetq.core.remoting.ChannelHandler;
import org.hornetq.core.remoting.Packet;
@@ -34,7 +38,6 @@
import org.hornetq.core.remoting.impl.wireformat.ReplicationAddTXMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationCommitMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationCompareDataMessage;
-import org.hornetq.core.remoting.impl.wireformat.ReplicationSyncContextMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationDeleteMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationDeleteTXMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationLargeMessageBeingMessage;
@@ -44,9 +47,8 @@
import org.hornetq.core.remoting.impl.wireformat.ReplicationPageWriteMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationPrepareMessage;
import org.hornetq.core.remoting.spi.HornetQBuffer;
-import org.hornetq.core.replication.ReplicationContext;
import org.hornetq.core.replication.ReplicationManager;
-import org.hornetq.utils.ConcurrentHashSet;
+import org.hornetq.utils.ExecutorFactory;
import org.hornetq.utils.SimpleString;
/**
@@ -80,12 +82,10 @@
private final Object replicationLock = new Object();
- private final ThreadLocal<ReplicationContext> tlReplicationContext = new ThreadLocal<ReplicationContext>();
+ private final Queue<OperationContext> pendingTokens = new ConcurrentLinkedQueue<OperationContext>();
+
+ private final ExecutorFactory executorFactory;
- private final Queue<ReplicationContext> pendingTokens = new ConcurrentLinkedQueue<ReplicationContext>();
-
- private final ConcurrentHashSet<ReplicationContext> activeContexts = new ConcurrentHashSet<ReplicationContext>();
-
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
@@ -93,11 +93,12 @@
/**
* @param replicationConnectionManager
*/
- public ReplicationManagerImpl(final FailoverManager failoverManager, final int backupWindowSize)
+ public ReplicationManagerImpl(final FailoverManager failoverManager, final ExecutorFactory executorFactory, final int backupWindowSize)
{
super();
this.failoverManager = failoverManager;
this.backupWindowSize = backupWindowSize;
+ this.executorFactory = executorFactory;
}
// Public --------------------------------------------------------
@@ -278,14 +279,6 @@
sendReplicatePacket(new ReplicationLargemessageEndMessage(messageId));
}
}
-
- public void sync()
- {
- if (enabled)
- {
- sendReplicatePacket(new ReplicationSyncContextMessage());
- }
- }
/* (non-Javadoc)
* @see org.hornetq.core.replication.ReplicationManager#largeMessageWrite(long, byte[])
@@ -351,9 +344,9 @@
log.warn(e.getMessage(), e);
}
}
-
+
public void beforeReconnect(HornetQException me)
- {
+ {
}
});
@@ -374,14 +367,14 @@
enabled = false;
- for (ReplicationContext ctx : activeContexts)
+ // The same context will be replicated on the pending tokens...
+ // as the multiple operations will be replicated on the same context
+ while (!pendingTokens.isEmpty())
{
- ctx.complete();
- ctx.flush();
+ OperationContext ctx = pendingTokens.poll();
+ ctx.replicationDone();
}
-
- activeContexts.clear();
-
+
if (replicatingChannel != null)
{
replicatingChannel.close();
@@ -401,63 +394,47 @@
started = false;
}
- public ReplicationContext getContext()
- {
- ReplicationContext token = tlReplicationContext.get();
- if (token == null)
- {
- token = new ReplicationContextImpl();
- activeContexts.add(token);
- tlReplicationContext.set(token);
- }
- return token;
- }
- /* (non-Javadoc)
- * @see org.hornetq.core.replication.ReplicationManager#addReplicationAction(java.lang.Runnable)
+ /* method for testcases only
+ * @see org.hornetq.core.replication.ReplicationManager#getPendingTokens()
*/
- public void afterReplicated(final Runnable runnable)
+ public Set<OperationContext> getActiveTokens()
{
- getContext().addReplicationAction(runnable);
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.replication.ReplicationManager#completeToken()
- */
- public void closeContext()
- {
- final ReplicationContext token = tlReplicationContext.get();
- if (token != null)
+ 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
+
+ for (OperationContext ctx : pendingTokens)
{
- // Disassociate thread local
- tlReplicationContext.set(null);
- // Remove from pending tokens as soon as this is complete
- token.addReplicationAction(new Runnable()
- {
- public void run()
- {
- activeContexts.remove(token);
- }
- });
- token.complete();
+ activeContexts.add(ctx);
}
+
+ return activeContexts;
+
}
/* (non-Javadoc)
- * @see org.hornetq.core.replication.ReplicationManager#getPendingTokens()
+ * @see org.hornetq.core.replication.ReplicationManager#compareJournals(org.hornetq.core.journal.JournalLoadInformation[])
*/
- public Set<ReplicationContext> getActiveTokens()
+ public void compareJournals(JournalLoadInformation[] journalInfo) throws HornetQException
{
- return activeContexts;
+ replicatingChannel.sendBlocking(new ReplicationCompareDataMessage(journalInfo));
}
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
private void sendReplicatePacket(final Packet packet)
{
boolean runItNow = false;
- ReplicationContext repliToken = getContext();
- repliToken.linedUp();
+ OperationContext repliToken = OperationContextImpl.getContext(executorFactory);
+ repliToken.replicationLineUp();
synchronized (replicationLock)
{
@@ -479,38 +456,22 @@
if (runItNow)
{
- repliToken.replicated();
+ repliToken.replicationDone();
}
}
-
- /* (non-Javadoc)
- * @see org.hornetq.core.replication.ReplicationManager#compareJournals(org.hornetq.core.journal.JournalLoadInformation[])
- */
- public void compareJournals(JournalLoadInformation[] journalInfo) throws HornetQException
- {
- replicatingChannel.sendBlocking(new ReplicationCompareDataMessage(journalInfo));
- }
-
private void replicated()
{
- ReplicationContext tokenPolled = pendingTokens.poll();
- if (tokenPolled == null)
+ OperationContext ctx = pendingTokens.poll();
+
+ if (ctx == null)
{
throw new IllegalStateException("Missing replication token on the queue.");
}
- else
- {
- tokenPolled.replicated();
- }
+
+ ctx.replicationDone();
}
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
// Inner classes -------------------------------------------------
protected class ResponseHandler implements ChannelHandler
Modified: trunk/src/main/org/hornetq/core/server/LargeServerMessage.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/LargeServerMessage.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/LargeServerMessage.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -42,5 +42,5 @@
void incrementDelayDeletionCount();
- void decrementDelayDeletionCount() throws Exception;
+ void decrementDelayDeletionCount();
}
Modified: trunk/src/main/org/hornetq/core/server/ServerMessage.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/ServerMessage.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/ServerMessage.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -33,7 +33,7 @@
int incrementRefCount(MessageReference reference) throws Exception;
- int decrementRefCount(MessageReference reference) throws Exception;
+ int decrementRefCount(MessageReference reference);
int incrementDurableRefCount();
Modified: trunk/src/main/org/hornetq/core/server/cluster/impl/Redistributor.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/cluster/impl/Redistributor.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/cluster/impl/Redistributor.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -16,6 +16,7 @@
import java.util.concurrent.Executor;
import org.hornetq.core.filter.Filter;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.postoffice.PostOffice;
@@ -144,21 +145,21 @@
tx.commit();
- if (storageManager.isReplicated())
+ storageManager.afterCompleteOperations(new IOAsyncTask()
{
- storageManager.afterReplicated(new Runnable()
+
+ public void onError(int errorCode, String errorMessage)
{
- public void run()
- {
- execPrompter();
- }
- });
- storageManager.completeReplication();
- }
- else
- {
- execPrompter();
- }
+ log.warn("IO Error during redistribution, errorCode = " + errorCode + " message = " + errorMessage);
+ }
+
+ public void done()
+ {
+ execPrompter();
+ }
+ });
+
+ storageManager.completeOperations();
}
private void execPrompter()
Modified: trunk/src/main/org/hornetq/core/server/group/impl/LocalGroupingHandler.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/group/impl/LocalGroupingHandler.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/group/impl/LocalGroupingHandler.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -87,10 +87,7 @@
}
newList.add(groupBinding);
storageManager.addGrouping(groupBinding);
- if (storageManager.isReplicated())
- {
- storageManager.waitOnReplication(timeout);
- }
+ storageManager.waitOnOperations(timeout);
return new Response(groupBinding.getGroupId(), groupBinding.getClusterName());
}
else
Modified: trunk/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -22,6 +22,7 @@
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -61,6 +62,7 @@
import org.hornetq.core.paging.impl.PagingManagerImpl;
import org.hornetq.core.paging.impl.PagingStoreFactoryNIO;
import org.hornetq.core.persistence.GroupingInfo;
+import org.hornetq.core.persistence.OperationContext;
import org.hornetq.core.persistence.QueueBindingInfo;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.persistence.impl.journal.JournalStorageManager;
@@ -414,6 +416,12 @@
{
log.debug("Waiting for " + task);
}
+
+ if (replicationManager != null)
+ {
+ replicationManager.stop();
+ replicationManager = null;
+ }
threadPool.shutdown();
@@ -640,6 +648,10 @@
}
Channel channel = connection.getChannel(channelID, sendWindowSize);
+
+ Executor sessionExecutor = executorFactory.getExecutor();
+
+ storageManager.newContext(sessionExecutor);
final ServerSessionImpl session = new ServerSessionImpl(name,
username,
@@ -655,7 +667,7 @@
postOffice,
resourceManager,
securityStore,
- executorFactory.getExecutor(),
+ sessionExecutor,
channel,
managementService,
// queueFactory,
@@ -664,7 +676,8 @@
sessions.put(name, session);
- ServerSessionPacketHandler handler = new ServerSessionPacketHandler(session);
+ // The executor on the OperationContext here has to be the same as the session, or we would have ordering issues on messages
+ ServerSessionPacketHandler handler = new ServerSessionPacketHandler(session, storageManager.newContext(sessionExecutor), storageManager);
session.setHandler(handler);
@@ -893,7 +906,7 @@
{
if (configuration.isPersistenceEnabled())
{
- return new JournalStorageManager(configuration, threadPool, replicationManager);
+ return new JournalStorageManager(configuration, this.executorFactory, replicationManager);
}
else
{
@@ -922,6 +935,7 @@
replicationFailoverManager = createBackupConnection(backupConnector, threadPool, scheduledPool);
replicationManager = new ReplicationManagerImpl(replicationFailoverManager,
+ executorFactory,
configuration.getBackupWindowSize());
replicationManager.start();
}
@@ -1031,7 +1045,7 @@
configuration.getManagementClusterPassword(),
managementService);
- queueFactory = new QueueFactoryImpl(scheduledPool, addressSettingsRepository, storageManager);
+ queueFactory = new QueueFactoryImpl(executorFactory, scheduledPool, addressSettingsRepository, storageManager);
pagingManager = createPagingManager();
Modified: trunk/src/main/org/hornetq/core/server/impl/LastValueQueue.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/LastValueQueue.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/impl/LastValueQueue.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -14,6 +14,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
import org.hornetq.core.filter.Filter;
Modified: trunk/src/main/org/hornetq/core/server/impl/QueueFactoryImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/QueueFactoryImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/impl/QueueFactoryImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -22,6 +22,7 @@
import org.hornetq.core.server.QueueFactory;
import org.hornetq.core.settings.HierarchicalRepository;
import org.hornetq.core.settings.impl.AddressSettings;
+import org.hornetq.utils.ExecutorFactory;
import org.hornetq.utils.SimpleString;
/**
@@ -42,11 +43,16 @@
private PostOffice postOffice;
private final StorageManager storageManager;
+
+ private final ExecutorFactory executorFactory;
- public QueueFactoryImpl(final ScheduledExecutorService scheduledExecutor,
+ public QueueFactoryImpl(final ExecutorFactory executorFactory,
+ final ScheduledExecutorService scheduledExecutor,
final HierarchicalRepository<AddressSettings> addressSettingsRepository,
final StorageManager storageManager)
{
+ this.executorFactory = executorFactory;
+
this.addressSettingsRepository = addressSettingsRepository;
this.scheduledExecutor = scheduledExecutor;
Modified: trunk/src/main/org/hornetq/core/server/impl/QueueImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/QueueImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/impl/QueueImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -114,7 +114,7 @@
private final HierarchicalRepository<AddressSettings> addressSettingsRepository;
private final ScheduledExecutorService scheduledExecutor;
-
+
private final SimpleString address;
private Redistributor redistributor;
@@ -621,6 +621,8 @@
{
acknowledge(ref);
}
+
+ storageManager.completeOperations();
}
public void setExpiryAddress(final SimpleString expiryAddress)
@@ -643,40 +645,46 @@
return deleteMatchingReferences(null);
}
- public synchronized int deleteMatchingReferences(final Filter filter) throws Exception
+ public int deleteMatchingReferences(final Filter filter) throws Exception
{
int count = 0;
-
- Transaction tx = new TransactionImpl(storageManager);
-
- Iterator<MessageReference> iter = messageReferences.iterator();
-
- while (iter.hasNext())
+
+ synchronized(this)
{
- MessageReference ref = iter.next();
-
- if (filter == null || filter.match(ref.getMessage()))
+
+ Transaction tx = new TransactionImpl(storageManager);
+
+ Iterator<MessageReference> iter = messageReferences.iterator();
+
+ while (iter.hasNext())
{
- deliveringCount.incrementAndGet();
- acknowledge(tx, ref);
- iter.remove();
- count++;
+ MessageReference ref = iter.next();
+
+ if (filter == null || filter.match(ref.getMessage()))
+ {
+ deliveringCount.incrementAndGet();
+ acknowledge(tx, ref);
+ iter.remove();
+ count++;
+ }
}
- }
-
- List<MessageReference> cancelled = scheduledDeliveryHandler.cancel();
- for (MessageReference messageReference : cancelled)
- {
- if (filter == null || filter.match(messageReference.getMessage()))
+
+ List<MessageReference> cancelled = scheduledDeliveryHandler.cancel();
+ for (MessageReference messageReference : cancelled)
{
- deliveringCount.incrementAndGet();
- acknowledge(tx, messageReference);
- count++;
+ if (filter == null || filter.match(messageReference.getMessage()))
+ {
+ deliveringCount.incrementAndGet();
+ acknowledge(tx, messageReference);
+ count++;
+ }
}
+
+ tx.commit();
}
+
+ storageManager.waitOnOperations(-1);
- tx.commit();
-
return count;
}
@@ -930,6 +938,7 @@
if (message.isDurable() && durable)
{
storageManager.updateDeliveryCount(reference);
+ storageManager.waitOnOperations();
}
AddressSettings addressSettings = addressSettingsRepository.getMatch(address.toString());
@@ -939,6 +948,7 @@
if (maxDeliveries > 0 && reference.getDeliveryCount() >= maxDeliveries)
{
sendToDeadLetterAddress(reference);
+ storageManager.waitOnOperations();
return false;
}
@@ -1381,7 +1391,7 @@
return status;
}
- private void removeExpiringReference(final MessageReference ref) throws Exception
+ private void removeExpiringReference(final MessageReference ref)
{
if (ref.getMessage().getExpiration() > 0)
{
@@ -1389,9 +1399,9 @@
}
}
- private void postAcknowledge(final MessageReference ref) throws Exception
+ private void postAcknowledge(final MessageReference ref)
{
- ServerMessage message = ref.getMessage();
+ final ServerMessage message = ref.getMessage();
QueueImpl queue = (QueueImpl)ref.getQueue();
@@ -1431,7 +1441,7 @@
message.decrementRefCount(ref);
}
- void postRollback(final LinkedList<MessageReference> refs) throws Exception
+ void postRollback(final LinkedList<MessageReference> refs)
{
synchronized (this)
{
@@ -1481,29 +1491,36 @@
{
}
- public void afterPrepare(final Transaction tx) throws Exception
+ public void afterPrepare(final Transaction tx)
{
}
- public void afterRollback(final Transaction tx) throws Exception
+ public void afterRollback(final Transaction tx)
{
Map<QueueImpl, LinkedList<MessageReference>> queueMap = new HashMap<QueueImpl, LinkedList<MessageReference>>();
for (MessageReference ref : refsToAck)
{
- if (ref.getQueue().checkDLQ(ref))
+ try
{
- LinkedList<MessageReference> toCancel = queueMap.get(ref.getQueue());
-
- if (toCancel == null)
+ if (ref.getQueue().checkDLQ(ref))
{
- toCancel = new LinkedList<MessageReference>();
-
- queueMap.put((QueueImpl)ref.getQueue(), toCancel);
+ LinkedList<MessageReference> toCancel = queueMap.get(ref.getQueue());
+
+ if (toCancel == null)
+ {
+ toCancel = new LinkedList<MessageReference>();
+
+ queueMap.put((QueueImpl)ref.getQueue(), toCancel);
+ }
+
+ toCancel.addFirst(ref);
}
-
- toCancel.addFirst(ref);
}
+ catch (Exception e)
+ {
+ log.warn("Error on checkDLQ", e);
+ }
}
for (Map.Entry<QueueImpl, LinkedList<MessageReference>> entry : queueMap.entrySet())
@@ -1519,7 +1536,7 @@
}
}
- public void afterCommit(final Transaction tx) throws Exception
+ public void afterCommit(final Transaction tx)
{
for (MessageReference ref : refsToAck)
{
Modified: trunk/src/main/org/hornetq/core/server/impl/ServerMessageImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/ServerMessageImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/impl/ServerMessageImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -119,7 +119,7 @@
return count;
}
- public int decrementRefCount(final MessageReference reference) throws Exception
+ public int decrementRefCount(final MessageReference reference)
{
int count = refCount.decrementAndGet();
Modified: trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -1,5 +1,5 @@
/*
- * Copyright 2009 Red Hat, Inc.
+x * 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
@@ -34,6 +34,7 @@
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.filter.Filter;
import org.hornetq.core.filter.impl.FilterImpl;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.management.ManagementService;
import org.hornetq.core.management.Notification;
@@ -185,7 +186,7 @@
private final HornetQServer server;
private final SimpleString managementAddress;
-
+
// The current currentLargeMessage being processed
private volatile LargeServerMessage currentLargeMessage;
@@ -240,7 +241,7 @@
this.resourceManager = resourceManager;
this.securityStore = securityStore;
-
+
this.executor = executor;
if (!xa)
@@ -1457,7 +1458,7 @@
public void handleSend(final SessionSendMessage packet)
{
Packet response = null;
-
+
ServerMessage message = packet.getServerMessage();
try
@@ -1718,23 +1719,23 @@
final boolean flush,
final boolean closeChannel)
{
- if (storageManager.isReplicated())
+ storageManager.afterCompleteOperations(new IOAsyncTask()
{
- storageManager.afterReplicated(new Runnable()
+
+ public void onError(int errorCode, String errorMessage)
{
- public void run()
- {
- doSendResponse(confirmPacket, response, flush, closeChannel);
- }
+ log.warn("Error processing IOCallback code = " + errorCode + " message = " + errorMessage);
- });
+ HornetQExceptionMessage exceptionMessage = new HornetQExceptionMessage(new HornetQException(errorCode, errorMessage));
+
+ doSendResponse(confirmPacket, exceptionMessage, flush, closeChannel);
+ }
- storageManager.completeReplication();
- }
- else
- {
- doSendResponse(confirmPacket, response, flush, closeChannel);
- }
+ public void done()
+ {
+ doSendResponse(confirmPacket, response, flush, closeChannel);
+ }
+ });
}
/**
Modified: trunk/src/main/org/hornetq/core/server/impl/ServerSessionPacketHandler.java
===================================================================
--- trunk/src/main/org/hornetq/core/server/impl/ServerSessionPacketHandler.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/server/impl/ServerSessionPacketHandler.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -45,6 +45,8 @@
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.SESS_XA_SUSPEND;
import org.hornetq.core.logging.Logger;
+import org.hornetq.core.persistence.OperationContext;
+import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.remoting.ChannelHandler;
import org.hornetq.core.remoting.Packet;
import org.hornetq.core.remoting.impl.wireformat.CreateQueueMessage;
@@ -80,16 +82,26 @@
* @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
* @author <a href="mailto:andy.taylor@jboss.org>Andy Taylor</a>
+ * @author <a href="mailto:clebert.suconic@jboss.org>Clebert Suconic</a>
*/
public class ServerSessionPacketHandler implements ChannelHandler
{
private static final Logger log = Logger.getLogger(ServerSessionPacketHandler.class);
private final ServerSession session;
+
+ private final OperationContext sessionContext;
+
+ // Storagemanager here is used to set the Context
+ private final StorageManager storageManager;
- public ServerSessionPacketHandler(final ServerSession session)
+ public ServerSessionPacketHandler(final ServerSession session, OperationContext sessionContext, StorageManager storageManager)
{
this.session = session;
+
+ this.storageManager = storageManager;
+
+ this.sessionContext = sessionContext;
}
public long getID()
@@ -101,6 +113,8 @@
{
byte type = packet.getType();
+ storageManager.setContext(sessionContext);
+
try
{
switch (type)
@@ -289,5 +303,10 @@
{
log.error("Caught unexpected exception", t);
}
+ finally
+ {
+ storageManager.completeOperations();
+ storageManager.clearContext();
+ }
}
}
Modified: trunk/src/main/org/hornetq/core/transaction/TransactionOperation.java
===================================================================
--- trunk/src/main/org/hornetq/core/transaction/TransactionOperation.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/transaction/TransactionOperation.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -29,9 +29,9 @@
void beforeRollback(Transaction tx) throws Exception;
- void afterPrepare(Transaction tx) throws Exception;
+ void afterPrepare(Transaction tx);
- void afterCommit(Transaction tx) throws Exception;
+ void afterCommit(Transaction tx);
- void afterRollback(Transaction tx) throws Exception;
+ void afterRollback(Transaction tx);
}
Modified: trunk/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -19,6 +19,7 @@
import javax.transaction.xa.Xid;
import org.hornetq.core.exception.HornetQException;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.postoffice.PostOffice;
@@ -98,7 +99,7 @@
{
this.containsPersistent = true;
}
-
+
public long getID()
{
return id;
@@ -146,14 +147,37 @@
storageManager.prepare(id, xid);
state = State.PREPARED;
+ // We use the Callback even for non persistence
+ // If we are using non-persistence with replication, the replication manager will have
+ // to execute this runnable in the correct order
+ storageManager.afterCompleteOperations(new IOAsyncTask()
+ {
- if (operations != null)
- {
- for (TransactionOperation operation : operations)
+ public void onError(int errorCode, String errorMessage)
{
- operation.afterPrepare(this);
+ log.warn("IO Error completing the transaction, code = " + errorCode + ", message = " + errorMessage);
}
- }
+
+ public void done()
+ {
+ if (operations != null)
+ {
+ for (TransactionOperation operation : operations)
+ {
+ try
+ {
+ operation.afterPrepare(TransactionImpl.this);
+ }
+ catch (Exception e)
+ {
+ // https://jira.jboss.org/jira/browse/HORNETQ-188
+ // After commit shouldn't throw an exception
+ log.warn(e.getMessage(), e);
+ }
+ }
+ }
+ }
+ });
}
}
@@ -181,15 +205,8 @@
if (xid != null)
{
- if (onePhase)
+ if (onePhase && state != State.ACTIVE || !onePhase && state != State.PREPARED)
{
- if (state == State.ACTIVE)
- {
- prepare();
- }
- }
- if (state != State.PREPARED)
- {
throw new IllegalStateException("Transaction is in invalid state " + state);
}
}
@@ -209,13 +226,29 @@
}
}
- Runnable execAfterCommit = null;
+ if (containsPersistent || (xid != null && state == State.PREPARED))
+ {
+ storageManager.commit(id);
- if (operations != null)
+ state = State.COMMITTED;
+ }
+
+ // We use the Callback even for non persistence
+ // If we are using non-persistence with replication, the replication manager will have
+ // to execute this runnable in the correct order
+ // This also will only use a different thread if there are any IO pendings.
+ // If the IO finished early by the time we got here, we won't need an executor
+ storageManager.afterCompleteOperations(new IOAsyncTask()
{
- execAfterCommit = new Runnable()
+
+ public void onError(int errorCode, String errorMessage)
{
- public void run()
+ log.warn("IO Error completing the transaction, code = " + errorCode + ", message = " + errorMessage);
+ }
+
+ public void done()
+ {
+ if (operations != null)
{
for (TransactionOperation operation : operations)
{
@@ -231,31 +264,9 @@
}
}
}
- };
- }
+ }
+ });
- if (containsPersistent || (xid != null && state == State.PREPARED))
- {
- storageManager.commit(id);
-
- state = State.COMMITTED;
-
- if (execAfterCommit != null)
- {
- if (storageManager.isReplicated())
- {
- storageManager.afterReplicated(execAfterCommit);
- }
- else
- {
- execAfterCommit.run();
- }
- }
- }
- else if (execAfterCommit != null)
- {
- execAfterCommit.run();
- }
}
}
@@ -290,13 +301,37 @@
state = State.ROLLEDBACK;
- if (operations != null)
+ // We use the Callback even for non persistence
+ // If we are using non-persistence with replication, the replication manager will have
+ // to execute this runnable in the correct order
+ storageManager.afterCompleteOperations(new IOAsyncTask()
{
- for (TransactionOperation operation : operations)
+
+ public void onError(int errorCode, String errorMessage)
{
- operation.afterRollback(this);
+ log.warn("IO Error completing the transaction, code = " + errorCode + ", message = " + errorMessage);
}
- }
+
+ public void done()
+ {
+ if (operations != null)
+ {
+ for (TransactionOperation operation : operations)
+ {
+ try
+ {
+ operation.afterRollback(TransactionImpl.this);
+ }
+ catch (Exception e)
+ {
+ // https://jira.jboss.org/jira/browse/HORNETQ-188
+ // After commit shouldn't throw an exception
+ log.warn(e.getMessage(), e);
+ }
+ }
+ }
+ }
+ });
}
}
Modified: trunk/tests/src/org/hornetq/tests/concurrent/server/impl/QueueTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/concurrent/server/impl/QueueTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/concurrent/server/impl/QueueTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -40,8 +40,20 @@
{
private static final Logger log = Logger.getLogger(QueueTest.class);
- private QueueFactory queueFactory = new FakeQueueFactory();
+ private FakeQueueFactory queueFactory = new FakeQueueFactory();
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ queueFactory = new FakeQueueFactory();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ queueFactory.stop();
+ super.tearDown();
+ }
+
/*
* Concurrent set consumer not busy, busy then, call deliver while messages are being added and consumed
*/
Modified: trunk/tests/src/org/hornetq/tests/integration/client/DeadLetterAddressTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/client/DeadLetterAddressTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/client/DeadLetterAddressTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -179,6 +179,14 @@
clientSession.rollback();
}
+ long timeout = System.currentTimeMillis() + 5000;
+
+ // DLA transfer is asynchronous fired on the rollback
+ while (System.currentTimeMillis() < timeout && ((Queue)server.getPostOffice().getBinding(qName).getBindable()).getMessageCount() != 0)
+ {
+ Thread.sleep(1);
+ }
+
assertEquals(0, ((Queue)server.getPostOffice().getBinding(qName).getBindable()).getMessageCount());
ClientMessage m = clientConsumer.receiveImmediate();
assertNull(m);
Modified: trunk/tests/src/org/hornetq/tests/integration/client/MessageGroupingTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/client/MessageGroupingTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/client/MessageGroupingTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -433,7 +433,7 @@
assertTrue(latch.await(10, TimeUnit.SECONDS));
clientSession.end(xid, XAResource.TMSUCCESS);
clientSession.prepare(xid);
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
assertEquals(dummyMessageHandler.list.size(), 50);
int i = 0;
for (ClientMessage message : dummyMessageHandler.list)
Modified: trunk/tests/src/org/hornetq/tests/integration/client/NettyConsumerWindowSizeTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/client/NettyConsumerWindowSizeTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/client/NettyConsumerWindowSizeTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -13,6 +13,14 @@
package org.hornetq.tests.integration.client;
+import java.util.HashMap;
+
+import org.hornetq.core.client.ClientSessionFactory;
+import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
+import org.hornetq.core.config.Configuration;
+import org.hornetq.core.config.TransportConfiguration;
+import org.hornetq.integration.transports.netty.TransportConstants;
+
/**
* A NettyConsumerWindowSizeTest
*
@@ -32,7 +40,39 @@
return true;
}
+ protected ClientSessionFactory createNettyFactory()
+ {
+ HashMap<String, Object> parameters = new HashMap<String, Object>();
+
+ parameters.put(TransportConstants.TCP_NODELAY_PROPNAME, true);
+
+ TransportConfiguration config = new TransportConfiguration(NETTY_CONNECTOR_FACTORY, parameters);
+
+ return new ClientSessionFactoryImpl(config);
+
+ //return super.createNettyFactory();
+ }
+ protected Configuration createDefaultConfig(final boolean netty)
+ {
+ if (netty)
+ {
+
+ HashMap<String, Object> parameters = new HashMap<String, Object>();
+
+ parameters.put(TransportConstants.TCP_NODELAY_PROPNAME, true);
+
+ return createDefaultConfig(parameters, INVM_ACCEPTOR_FACTORY, NETTY_ACCEPTOR_FACTORY);
+ }
+ else
+ {
+ new Exception("This test wasn't supposed to use InVM").printStackTrace();
+ return super.createDefaultConfig(false);
+ }
+ }
+
+
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
Added: trunk/tests/src/org/hornetq/tests/integration/client/OrderTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/client/OrderTest.java (rev 0)
+++ trunk/tests/src/org/hornetq/tests/integration/client/OrderTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -0,0 +1,156 @@
+/*
+ * 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.integration.client;
+
+import org.hornetq.core.client.ClientConsumer;
+import org.hornetq.core.client.ClientMessage;
+import org.hornetq.core.client.ClientProducer;
+import org.hornetq.core.client.ClientSession;
+import org.hornetq.core.client.ClientSessionFactory;
+import org.hornetq.core.server.HornetQServer;
+import org.hornetq.tests.util.ServiceTestBase;
+
+/**
+ * A OrderTest
+ *
+ * @author <mailto:clebert.suconic@jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class OrderTest extends ServiceTestBase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ private HornetQServer server;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ server.stop();
+ super.tearDown();
+ }
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testSimpleOrderNoStorage() throws Exception
+ {
+ doTestSimpleOrder(false);
+ }
+
+ public void testSimpleOrderPersistence() throws Exception
+ {
+ doTestSimpleOrder(true);
+ }
+
+ public void doTestSimpleOrder(final boolean persistent) throws Exception
+ {
+ server = createServer(persistent, true);
+ server.start();
+
+ ClientSessionFactory sf = createNettyFactory();
+
+ sf.setBlockOnNonPersistentSend(false);
+ sf.setBlockOnPersistentSend(false);
+ sf.setBlockOnAcknowledge(true);
+
+ ClientSession session = sf.createSession(true, true, 0);
+
+ try
+ {
+ session.createQueue("queue", "queue", true);
+
+ ClientProducer prod = session.createProducer("queue");
+
+ for (int i = 0; i < 100; i++)
+ {
+ ClientMessage msg = session.createClientMessage(i % 2 == 0);
+ msg.setBody(session.createBuffer(new byte[1024]));
+ msg.putIntProperty("id", i);
+ prod.send(msg);
+ }
+
+ session.close();
+
+ boolean started = false;
+
+ for (int start = 0; start < 2; start++)
+ {
+
+ if (persistent && start == 1)
+ {
+ started = true;
+ server.stop();
+ server.start();
+ }
+
+ session = sf.createSession(true, true);
+
+ session.start();
+
+ ClientConsumer cons = session.createConsumer("queue");
+
+ for (int i = 0; i < 100; i++)
+ {
+ if (!started || started && i % 2 == 0)
+ {
+ ClientMessage msg = cons.receive(10000);
+ assertEquals(i, msg.getIntProperty("id").intValue());
+ }
+ }
+
+ cons.close();
+
+ cons = session.createConsumer("queue");
+
+ for (int i = 0; i < 100; i++)
+ {
+ if (!started || started && i % 2 == 0)
+ {
+ ClientMessage msg = cons.receive(10000);
+ assertEquals(i, msg.getIntProperty("id").intValue());
+ }
+ }
+
+ session.close();
+ }
+
+ }
+ finally
+ {
+ sf.close();
+ session.close();
+ }
+
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Modified: trunk/tests/src/org/hornetq/tests/integration/client/PagingTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/client/PagingTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/client/PagingTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -158,15 +158,18 @@
for (int i = 0; i < numberOfMessages; i++)
{
+ System.out.println("Message " + i + " of " + numberOfMessages);
ClientMessage message2 = consumer.receive(RECEIVE_TIMEOUT);
assertNotNull(message2);
- assertEquals(i, ((Integer)message2.getObjectProperty(new SimpleString("id"))).intValue());
+ assertEquals(i, message2.getIntProperty("id").intValue());
message2.acknowledge();
assertNotNull(message2);
+
+ session.commit();
try
{
@@ -968,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: trunk/tests/src/org/hornetq/tests/integration/cluster/failover/FailoverTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/cluster/failover/FailoverTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/cluster/failover/FailoverTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -169,7 +169,6 @@
assertEquals(0, sf.numConnections());
}
-
/** It doesn't fail, but it restart both servers, live and backup, and the data should be received after the restart,
* and the servers should be able to connect without any problems. */
public void testRestartServers() throws Exception
@@ -1670,6 +1669,73 @@
assertEquals(0, sf.numConnections());
}
+ public void testSimpleSendAfterFailover() throws Exception
+ {
+ ClientSessionFactoryInternal sf = getSessionFactory();
+
+ sf.setBlockOnNonPersistentSend(true);
+ sf.setBlockOnPersistentSend(true);
+ sf.setBlockOnAcknowledge(true);
+
+ ClientSession session = sf.createSession(true, true, 0);
+
+ session.createQueue(ADDRESS, ADDRESS, null, true);
+
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ class MyListener extends BaseListener
+ {
+ public void connectionFailed(HornetQException me)
+ {
+ latch.countDown();
+ }
+ }
+
+ session.addFailureListener(new MyListener());
+
+ ClientProducer producer = session.createProducer(ADDRESS);
+
+ final int numMessages = 100;
+
+ ClientConsumer consumer = session.createConsumer(ADDRESS);
+
+ session.start();
+
+ fail(session, latch);
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = session.createClientMessage(i % 2 == 0);
+
+ setBody(i, message);
+
+ System.out.println("Durable = " + message.isDurable());
+
+ message.putIntProperty("counter", i);
+
+ producer.send(message);
+ }
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ ClientMessage message = consumer.receive(1000);
+
+ assertNotNull(message);
+
+ assertMessageBody(i, message);
+
+ assertEquals(i, message.getIntProperty("counter").intValue());
+
+ message.acknowledge();
+ }
+
+ session.close();
+
+ assertEquals(0, sf.numSessions());
+
+ assertEquals(0, sf.numConnections());
+ }
+
public void testForceBlockingReturn() throws Exception
{
ClientSessionFactoryInternal sf = this.getSessionFactory();
Modified: trunk/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -237,7 +237,7 @@
producer = session.createProducer(ADDRESS);
- session.commit(xid, true);
+ session.commit(xid, false);
xid = newXID();
session.start(xid, XAResource.TMNOFLAGS);
}
Modified: trunk/tests/src/org/hornetq/tests/integration/largemessage/ServerLargeMessageTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/largemessage/ServerLargeMessageTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/largemessage/ServerLargeMessageTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -13,6 +13,8 @@
package org.hornetq.tests.integration.largemessage;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.hornetq.core.config.Configuration;
@@ -21,6 +23,8 @@
import org.hornetq.core.server.LargeServerMessage;
import org.hornetq.core.server.ServerMessage;
import org.hornetq.tests.util.ServiceTestBase;
+import org.hornetq.utils.ExecutorFactory;
+import org.hornetq.utils.OrderedExecutorFactory;
/**
* A ServerLargeMessageTest
@@ -36,12 +40,32 @@
// Attributes ----------------------------------------------------
+ ExecutorService executor;
+
+ ExecutorFactory execFactory;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ executor = Executors.newCachedThreadPool();
+
+ execFactory = new OrderedExecutorFactory(executor);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ executor.shutdown();
+
+ super.tearDown();
+ }
+
public void testLargeMessageCopy() throws Exception
{
clearData();
@@ -52,7 +76,7 @@
configuration.setJournalType(JournalType.ASYNCIO);
- final JournalStorageManager journal = new JournalStorageManager(configuration, Executors.newCachedThreadPool());
+ final JournalStorageManager journal = new JournalStorageManager(configuration, execFactory);
journal.start();
LargeServerMessage msg = journal.createLargeMessage();
Modified: trunk/tests/src/org/hornetq/tests/integration/persistence/RestartSMTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/persistence/RestartSMTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/persistence/RestartSMTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -18,6 +18,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.hornetq.core.config.Configuration;
@@ -30,6 +32,8 @@
import org.hornetq.core.server.Queue;
import org.hornetq.tests.unit.core.server.impl.fakes.FakePostOffice;
import org.hornetq.tests.util.ServiceTestBase;
+import org.hornetq.utils.ExecutorFactory;
+import org.hornetq.utils.OrderedExecutorFactory;
/**
* A DeleteMessagesRestartTest
@@ -48,11 +52,32 @@
// Attributes ----------------------------------------------------
+ ExecutorService executor;
+
+ ExecutorFactory execFactory;
+
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ executor = Executors.newCachedThreadPool();
+
+ this.execFactory = new OrderedExecutorFactory(executor);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ executor.shutdown();
+
+ super.tearDown();
+ }
+
public void testRestartStorageManager() throws Exception
{
@@ -67,7 +92,8 @@
PostOffice postOffice = new FakePostOffice();
- final JournalStorageManager journal = new JournalStorageManager(configuration, Executors.newCachedThreadPool());
+ final JournalStorageManager journal = new JournalStorageManager(configuration, execFactory);
+
try
{
Modified: trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationOrderTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationOrderTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationOrderTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -52,17 +52,6 @@
// Public --------------------------------------------------------
- public void _test() throws Exception
- {
- for (int i = 0; i < 100; i++)
- {
- System.out.println("<<<<<< " + i + " >>>>>>>");
- testTxMixedPersistentAndNonPersistentMessagesOrderWithReplicatedBackup();
- tearDown();
- setUp();
- }
- }
-
public void testMixedPersistentAndNonPersistentMessagesOrderWithReplicatedBackup() throws Exception
{
doTestMixedPersistentAndNonPersistentMessagesOrderWithReplicatedBackup(false);
@@ -92,7 +81,7 @@
}
session.createQueue(address, queue, true);
ClientProducer producer = session.createProducer(address);
- boolean durable = true;
+ boolean durable = false;
for (int i = 0; i < NUM; i++)
{
ClientMessage msg = session.createClientMessage(durable);
Modified: trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -26,6 +26,7 @@
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
import org.hornetq.core.buffers.ChannelBuffers;
import org.hornetq.core.client.ClientSessionFactory;
@@ -37,6 +38,8 @@
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.journal.EncodingSupport;
+import org.hornetq.core.journal.IOAsyncTask;
+import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.journal.Journal;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.journal.LoaderCallback;
@@ -49,7 +52,10 @@
import org.hornetq.core.paging.impl.PagedMessageImpl;
import org.hornetq.core.paging.impl.PagingManagerImpl;
import org.hornetq.core.paging.impl.PagingStoreFactoryNIO;
+import org.hornetq.core.persistence.OperationContext;
import org.hornetq.core.persistence.StorageManager;
+import org.hornetq.core.persistence.impl.journal.JournalStorageManager;
+import org.hornetq.core.persistence.impl.journal.OperationContextImpl;
import org.hornetq.core.remoting.Interceptor;
import org.hornetq.core.remoting.Packet;
import org.hornetq.core.remoting.RemotingConnection;
@@ -66,6 +72,7 @@
import org.hornetq.tests.util.ServiceTestBase;
import org.hornetq.utils.ExecutorFactory;
import org.hornetq.utils.HornetQThreadFactory;
+import org.hornetq.utils.OrderedExecutorFactory;
import org.hornetq.utils.SimpleString;
/**
@@ -85,6 +92,8 @@
private ThreadFactory tFactory;
private ExecutorService executor;
+
+ private ExecutorFactory factory;
private ScheduledExecutorService scheduledExecutor;
@@ -110,6 +119,7 @@
try
{
ReplicationManagerImpl manager = new ReplicationManagerImpl(failoverManager,
+ this.factory,
ConfigurationImpl.DEFAULT_BACKUP_WINDOW_SIZE);
manager.start();
manager.stop();
@@ -136,6 +146,7 @@
try
{
ReplicationManagerImpl manager = new ReplicationManagerImpl(failoverManager,
+ this.factory,
ConfigurationImpl.DEFAULT_BACKUP_WINDOW_SIZE);
manager.start();
try
@@ -178,6 +189,7 @@
try
{
ReplicationManagerImpl manager = new ReplicationManagerImpl(failoverManager,
+ this.factory,
ConfigurationImpl.DEFAULT_BACKUP_WINDOW_SIZE);
manager.start();
@@ -185,6 +197,7 @@
try
{
ReplicationManagerImpl manager2 = new ReplicationManagerImpl(failoverManager,
+ this.factory,
ConfigurationImpl.DEFAULT_BACKUP_WINDOW_SIZE);
manager2.start();
@@ -219,6 +232,7 @@
try
{
ReplicationManagerImpl manager = new ReplicationManagerImpl(failoverManager,
+ this.factory,
ConfigurationImpl.DEFAULT_BACKUP_WINDOW_SIZE);
try
@@ -237,7 +251,7 @@
server.stop();
}
}
-
+
public void testSendPackets() throws Exception
{
@@ -253,7 +267,10 @@
try
{
+ StorageManager storage = getStorage();
+
ReplicationManagerImpl manager = new ReplicationManagerImpl(failoverManager,
+ this.factory,
ConfigurationImpl.DEFAULT_BACKUP_WINDOW_SIZE);
manager.start();
@@ -272,20 +289,8 @@
replicatedJournal.appendPrepareRecord(3, new FakeData(), false);
replicatedJournal.appendRollbackRecord(3, false);
- assertEquals(1, manager.getActiveTokens().size());
+ blockOnReplication(storage, manager);
- blockOnReplication(manager);
-
- for (int i = 0; i < 100; i++)
- {
- // This is asynchronous. Have to wait completion
- if (manager.getActiveTokens().size() == 0)
- {
- break;
- }
- Thread.sleep(1);
- }
-
assertEquals(0, manager.getActiveTokens().size());
ServerMessage msg = new ServerMessageImpl();
@@ -302,7 +307,7 @@
manager.pageWrite(pgmsg, 3);
manager.pageWrite(pgmsg, 4);
- blockOnReplication(manager);
+ blockOnReplication(storage, manager);
PagingManager pagingManager = createPageManager(server.getStorageManager(),
server.getConfiguration(),
@@ -321,7 +326,7 @@
manager.pageDeleted(dummy, 5);
manager.pageDeleted(dummy, 6);
- blockOnReplication(manager);
+ blockOnReplication(storage, manager);
ServerMessageImpl serverMsg = new ServerMessageImpl();
serverMsg.setMessageID(500);
@@ -336,7 +341,7 @@
manager.largeMessageDelete(500);
- blockOnReplication(manager);
+ blockOnReplication(storage, manager);
store.start();
@@ -371,13 +376,14 @@
try
{
+ StorageManager storage = getStorage();
ReplicationManagerImpl manager = new ReplicationManagerImpl(failoverManager,
+ this.factory,
ConfigurationImpl.DEFAULT_BACKUP_WINDOW_SIZE);
manager.start();
Journal replicatedJournal = new ReplicatedJournal((byte)1, new FakeJournal(), manager);
- Thread.sleep(100);
TestInterceptor.value.set(false);
for (int i = 0; i < 500; i++)
@@ -386,16 +392,19 @@
}
final CountDownLatch latch = new CountDownLatch(1);
- manager.afterReplicated(new Runnable()
+ storage.afterCompleteOperations(new IOAsyncTask()
{
- public void run()
+
+ public void onError(int errorCode, String errorMessage)
{
+ }
+
+ public void done()
+ {
latch.countDown();
}
});
- manager.closeContext();
-
server.stop();
assertTrue(latch.await(50, TimeUnit.SECONDS));
@@ -405,26 +414,124 @@
server.stop();
}
}
+
+ public void testExceptionSettingActionBefore() throws Exception
+ {
+ OperationContext ctx = OperationContextImpl.getContext(factory);
+
+ ctx.lineUp();
+
+ String msg = "I'm an exception";
+
+ ctx.onError(5, msg);
+
+ final AtomicInteger lastError = new AtomicInteger(0);
+
+ final List<String> msgsResult = new ArrayList<String>();
+
+ final CountDownLatch latch = new CountDownLatch(1);
+
+ ctx.executeOnCompletion(new IOAsyncTask()
+ {
+ public void onError(int errorCode, String errorMessage)
+ {
+ lastError.set(errorCode);
+ msgsResult.add(errorMessage);
+ latch.countDown();
+ }
+
+ public void done()
+ {
+ }
+ });
+
+ assertTrue(latch.await(5, TimeUnit.SECONDS));
+
+ assertEquals(5, lastError.get());
+
+ assertEquals(1, msgsResult.size());
+
+ assertEquals(msg, msgsResult.get(0));
+
+ final CountDownLatch latch2 = new CountDownLatch(1);
+
+ // Adding the Task after the exception should still throw an exception
+ ctx.executeOnCompletion(new IOAsyncTask()
+ {
+ public void onError(int errorCode, String errorMessage)
+ {
+ lastError.set(errorCode);
+ msgsResult.add(errorMessage);
+ latch2.countDown();
+ }
+
+ public void done()
+ {
+ }
+ });
+
+ assertTrue(latch2.await(5, TimeUnit.SECONDS));
+
+ assertEquals(2, msgsResult.size());
+ assertEquals(msg, msgsResult.get(0));
+
+ assertEquals(msg, msgsResult.get(1));
+
+ // Clearing any exception from the Context, so we can use the context again
+ ctx.complete();
+
+
+ final CountDownLatch latch3 = new CountDownLatch(1);
+
+ ctx.executeOnCompletion(new IOAsyncTask()
+ {
+ public void onError(int errorCode, String errorMessage)
+ {
+ }
+
+ public void done()
+ {
+ latch3.countDown();
+ }
+ });
+
+
+ assertTrue(latch2.await(5, TimeUnit.SECONDS));
+
+
+
+
+ }
+
/**
+ * @return
+ */
+ private JournalStorageManager getStorage()
+ {
+ return new JournalStorageManager(createDefaultConfig(), factory);
+ }
+
+ /**
* @param manager
* @return
*/
- private void blockOnReplication(ReplicationManagerImpl manager) throws Exception
+ private void blockOnReplication(StorageManager storage, ReplicationManagerImpl manager) throws Exception
{
final CountDownLatch latch = new CountDownLatch(1);
- manager.afterReplicated(new Runnable()
+ storage.afterCompleteOperations(new IOAsyncTask()
{
- public void run()
+ public void onError(int errorCode, String errorMessage)
{
+ }
+
+ public void done()
+ {
latch.countDown();
}
-
});
- manager.closeContext();
-
assertTrue(latch.await(30, TimeUnit.SECONDS));
}
@@ -435,6 +542,7 @@
try
{
ReplicationManagerImpl manager = new ReplicationManagerImpl(failoverManager,
+ this.factory,
ConfigurationImpl.DEFAULT_BACKUP_WINDOW_SIZE);
manager.start();
fail("Exception expected");
@@ -460,7 +568,9 @@
try
{
+ StorageManager storage = getStorage();
ReplicationManagerImpl manager = new ReplicationManagerImpl(failoverManager,
+ this.factory,
ConfigurationImpl.DEFAULT_BACKUP_WINDOW_SIZE);
manager.start();
@@ -469,32 +579,21 @@
replicatedJournal.appendPrepareRecord(1, new FakeData(), false);
final CountDownLatch latch = new CountDownLatch(1);
- manager.afterReplicated(new Runnable()
+ storage.afterCompleteOperations(new IOAsyncTask()
{
- public void run()
+ public void onError(int errorCode, String errorMessage)
{
+ }
+
+ public void done()
+ {
latch.countDown();
}
-
});
- assertEquals(1, manager.getActiveTokens().size());
-
- manager.closeContext();
-
assertTrue(latch.await(1, TimeUnit.SECONDS));
- for (int i = 0; i < 100; i++)
- {
- // This is asynchronous. Have to wait completion
- if (manager.getActiveTokens().size() == 0)
- {
- break;
- }
- Thread.sleep(1);
- }
-
assertEquals(0, manager.getActiveTokens().size());
manager.stop();
}
@@ -521,63 +620,52 @@
try
{
+ StorageManager storage = getStorage();
ReplicationManagerImpl manager = new ReplicationManagerImpl(failoverManager,
+ this.factory,
ConfigurationImpl.DEFAULT_BACKUP_WINDOW_SIZE);
manager.start();
Journal replicatedJournal = new ReplicatedJournal((byte)1, new FakeJournal(), manager);
int numberOfAdds = 200;
-
+
final CountDownLatch latch = new CountDownLatch(numberOfAdds);
+
+ OperationContext ctx = storage.getContext();
for (int i = 0; i < numberOfAdds; i++)
{
final int nAdd = i;
-
+
if (i % 2 == 0)
{
replicatedJournal.appendPrepareRecord(i, new FakeData(), false);
}
- else
- {
- manager.sync();
- }
-
- manager.afterReplicated(new Runnable()
+ ctx.executeOnCompletion(new IOAsyncTask()
{
- public void run()
+ public void onError(int errorCode, String errorMessage)
{
+ }
+
+ public void done()
+ {
+ System.out.println("Add " + nAdd);
executions.add(nAdd);
latch.countDown();
}
-
});
+ }
- manager.closeContext();
- }
-
assertTrue(latch.await(10, TimeUnit.SECONDS));
-
for (int i = 0; i < numberOfAdds; i++)
{
assertEquals(i, executions.get(i).intValue());
}
-
- for (int i = 0; i < 100; i++)
- {
- // This is asynchronous. Have to wait completion
- if (manager.getActiveTokens().size() == 0)
- {
- break;
- }
- Thread.sleep(1);
- }
-
assertEquals(0, manager.getActiveTokens().size());
manager.stop();
}
@@ -622,9 +710,26 @@
executor = Executors.newCachedThreadPool(tFactory);
scheduledExecutor = new ScheduledThreadPoolExecutor(10, tFactory);
+
+ factory = new OrderedExecutorFactory(executor);
+ }
+ protected void tearDown() throws Exception
+ {
+
+ executor.shutdown();
+
+ scheduledExecutor.shutdown();
+
+ tFactory = null;
+
+ scheduledExecutor = null;
+
+ super.tearDown();
+
}
+
private FailoverManagerImpl createFailoverManager()
{
return createFailoverManager(null);
@@ -651,22 +756,6 @@
scheduledExecutor,
interceptors);
}
-
- protected void tearDown() throws Exception
- {
-
- executor.shutdown();
-
- scheduledExecutor.shutdown();
-
- tFactory = null;
-
- scheduledExecutor = null;
-
- super.tearDown();
-
- }
-
protected PagingManager createPageManager(StorageManager storageManager,
Configuration configuration,
ExecutorFactory executorFactory,
@@ -906,5 +995,87 @@
return 0;
}
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendAddRecord(long, byte, byte[], boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendAddRecord(long id, byte recordType, byte[] record, boolean sync, IOCompletion completionCallback) throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendAddRecord(long, byte, org.hornetq.core.journal.EncodingSupport, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendAddRecord(long id,
+ byte recordType,
+ EncodingSupport record,
+ boolean sync,
+ IOCompletion completionCallback) throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendCommitRecord(long, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendCommitRecord(long txID, boolean sync, IOCompletion callback) throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendDeleteRecord(long, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendDeleteRecord(long id, boolean sync, IOCompletion completionCallback) throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendPrepareRecord(long, org.hornetq.core.journal.EncodingSupport, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendPrepareRecord(long txID, EncodingSupport transactionData, boolean sync, IOCompletion callback) throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendPrepareRecord(long, byte[], boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendPrepareRecord(long txID, byte[] transactionData, boolean sync, IOCompletion callback) throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendRollbackRecord(long, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendRollbackRecord(long txID, boolean sync, IOCompletion callback) throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendUpdateRecord(long, byte, byte[], boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendUpdateRecord(long id,
+ byte recordType,
+ byte[] record,
+ boolean sync,
+ IOCompletion completionCallback) throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#appendUpdateRecord(long, byte, org.hornetq.core.journal.EncodingSupport, boolean, org.hornetq.core.journal.IOCompletion)
+ */
+ public void appendUpdateRecord(long id,
+ byte recordType,
+ EncodingSupport record,
+ boolean sync,
+ IOCompletion completionCallback) throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.journal.Journal#sync(org.hornetq.core.journal.IOCompletion)
+ */
+ public void sync(IOCompletion callback)
+ {
+ }
+
}
}
Modified: trunk/tests/src/org/hornetq/tests/integration/scheduling/ScheduledMessageTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/scheduling/ScheduledMessageTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/scheduling/ScheduledMessageTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -12,8 +12,6 @@
*/
package org.hornetq.tests.integration.scheduling;
-import java.util.Calendar;
-
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
@@ -583,7 +581,7 @@
session = sessionFactory.createSession(true, false, false);
}
- session.commit(xid, true);
+ session.commit(xid, false);
ClientConsumer consumer = session.createConsumer(atestq);
session.start();
@@ -598,7 +596,7 @@
message2.acknowledge();
session.end(xid2, XAResource.TMSUCCESS);
session.prepare(xid2);
- session.commit(xid2, true);
+ session.commit(xid2, false);
consumer.close();
// Make sure no more messages
consumer = session.createConsumer(atestq);
@@ -683,7 +681,7 @@
{
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
- session.commit(xid, true);
+ session.commit(xid, false);
} else
{
session.commit();
@@ -758,7 +756,7 @@
{
session.end(xid, XAResource.TMSUCCESS);
session.prepare(xid);
- session.commit(xid, true);
+ session.commit(xid, false);
}
session.close();
Modified: trunk/tests/src/org/hornetq/tests/integration/server/LVQRecoveryTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/server/LVQRecoveryTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/server/LVQRecoveryTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -76,7 +76,7 @@
clientSessionXa.close();
restartServer();
- clientSessionXa.commit(xid, true);
+ clientSessionXa.commit(xid, false);
ClientConsumer consumer = clientSession.createConsumer(qName1);
clientSession.start();
ClientMessage m = consumer.receive(1000);
Modified: trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaRecoveryTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaRecoveryTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaRecoveryTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -295,7 +295,7 @@
assertEqualsByteArrays(xids[0].getBranchQualifier(), xid.getBranchQualifier());
assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
clientSession.close();
@@ -426,7 +426,7 @@
assertEquals(xids.length, 0);
if (commit)
{
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
}
else
{
@@ -455,7 +455,7 @@
if (i == 2)
{
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
}
recreateClients();
@@ -504,7 +504,7 @@
xids = clientSession.recover(XAResource.TMENDRSCAN);
assertEquals(xids.length, 0);
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
clientSession.start();
ClientMessage m = clientConsumer.receive(1000);
assertNotNull(m);
@@ -607,7 +607,7 @@
assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
xids = clientSession.recover(XAResource.TMENDRSCAN);
assertEquals(xids.length, 0);
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
clientSession.start();
ClientMessage m = clientConsumer.receive(1000);
assertNotNull(m);
@@ -668,8 +668,8 @@
assertEqualXids(xids, xid, xid2);
xids = clientSession.recover(XAResource.TMENDRSCAN);
assertEquals(xids.length, 0);
- clientSession.commit(xid, true);
- clientSession.commit(xid2, true);
+ clientSession.commit(xid, false);
+ clientSession.commit(xid2, false);
clientSession.start();
ClientMessage m = clientConsumer.receive(1000);
assertNotNull(m);
@@ -795,7 +795,7 @@
xids = clientSession.recover(XAResource.TMENDRSCAN);
assertEquals(xids.length, 0);
clientSession.rollback(xid);
- clientSession.commit(xid2, true);
+ clientSession.commit(xid2, false);
clientSession.start();
ClientMessage m = clientConsumer.receive(1000);
assertNotNull(m);
@@ -858,7 +858,7 @@
assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
xids = clientSession.recover(XAResource.TMENDRSCAN);
assertEquals(xids.length, 0);
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
clientSession.start();
ClientMessage m = clientConsumer.receive(1000);
assertNotNull(m);
@@ -938,7 +938,7 @@
assertEqualsByteArrays(xids[0].getGlobalTransactionId(), xid.getGlobalTransactionId());
xids = clientSession.recover(XAResource.TMENDRSCAN);
assertEquals(xids.length, 0);
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
clientSession.start();
m = clientConsumer.receiveImmediate();
assertNull(m);
@@ -1100,7 +1100,7 @@
assertEqualXids(xids, xid, xid2);
xids = clientSession.recover(XAResource.TMENDRSCAN);
assertEquals(xids.length, 0);
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
clientSession.start();
m = clientConsumer.receiveImmediate();
assertNull(m);
Modified: trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/xa/BasicXaTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -158,7 +158,7 @@
clientSession = sessionFactory.createSession(true, false, false);
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
clientSession.start();
ClientConsumer clientConsumer = clientSession.createConsumer(atestq);
ClientMessage m = clientConsumer.receive(1000);
@@ -216,7 +216,7 @@
clientSession = sessionFactory.createSession(true, false, false);
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
clientSession.start();
clientConsumer = clientSession.createConsumer(atestq);
m = clientConsumer.receiveImmediate();
@@ -729,7 +729,7 @@
}
else
{
- session.commit(xid, true);
+ session.commit(xid, false);
}
}
}
Modified: trunk/tests/src/org/hornetq/tests/integration/xa/XaTimeoutTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/integration/xa/XaTimeoutTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/integration/xa/XaTimeoutTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -354,7 +354,7 @@
CountDownLatch latch = new CountDownLatch(1);
messagingService.getResourceManager().getTransaction(xid).addOperation(new RollbackCompleteOperation(latch));
assertFalse(latch.await(2600, TimeUnit.MILLISECONDS));
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
clientSession.setTransactionTimeout(0);
clientConsumer.close();
@@ -434,7 +434,7 @@
messagingService.getResourceManager().getTransaction(xid).addOperation(new RollbackCompleteOperation(latch));
assertFalse(latch.await(2600, TimeUnit.MILLISECONDS));
clientSession.prepare(xid);
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
ClientSession clientSession2 = sessionFactory.createSession(false, true, true);
ClientConsumer consumer = clientSession2.createConsumer(atestq);
clientSession2.start();
@@ -538,15 +538,15 @@
{
}
- public void afterPrepare(Transaction tx) throws Exception
+ public void afterPrepare(Transaction tx)
{
}
- public void afterCommit(Transaction tx) throws Exception
+ public void afterCommit(Transaction tx)
{
}
- public void afterRollback(Transaction tx) throws Exception
+ public void afterRollback(Transaction tx)
{
latch.countDown();
}
Deleted: trunk/tests/src/org/hornetq/tests/performance/persistence/StorageManagerTimingTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/performance/persistence/StorageManagerTimingTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/performance/persistence/StorageManagerTimingTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -1,280 +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.tests.performance.persistence;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.hornetq.core.asyncio.impl.AsynchronousFileImpl;
-import org.hornetq.core.buffers.ChannelBuffers;
-import org.hornetq.core.config.impl.FileConfiguration;
-import org.hornetq.core.logging.Logger;
-import org.hornetq.core.persistence.impl.journal.JournalStorageManager;
-import org.hornetq.core.postoffice.PostOffice;
-import org.hornetq.core.server.JournalType;
-import org.hornetq.core.server.Queue;
-import org.hornetq.core.server.impl.ServerMessageImpl;
-import org.hornetq.tests.unit.core.server.impl.fakes.FakePostOffice;
-import org.hornetq.tests.util.UnitTestCase;
-import org.hornetq.utils.SimpleString;
-
-/**
- *
- * @author <a href="mailto:clebert.suconic@jboss.com">Clebert Suconic</a>
- *
- */
-public class StorageManagerTimingTest extends UnitTestCase
-{
- private static final Logger log = Logger.getLogger(StorageManagerTimingTest.class);
-
- protected void tearDown() throws Exception
- {
- assertEquals(0, AsynchronousFileImpl.getTotalMaxIO());
-
- super.tearDown();
- }
-
- public void testAIO() throws Exception
- {
- // just to do some initial loading.. ignore this rate
- internalTestStorage(JournalType.ASYNCIO, 1000, 1, 1);
-
- double rate = internalTestStorage(JournalType.ASYNCIO, 60000, 1, 1)[0];
- printRates("Rate of AIO, 60000 inserts / commits on every insert", rate);
-
- rate = internalTestStorage(JournalType.ASYNCIO, 30000, -1, 1)[0];
- printRates("Rate of AIO, 30000 inserts / single commit at the end", rate);
-
- rate = internalTestStorage(JournalType.ASYNCIO, 30000, 5, 1)[0];
- printRates("Rate of AIO, 30000 inserts / commit every 5 recodds", rate);
-
- rate = internalTestStorage(JournalType.ASYNCIO, 30000, -1, 1)[0];
- printRates("Rate of AIO, 30000 inserts / single commit at the end (again)", rate);
-
- }
-
- public void testAIOMultiThread() throws Exception
- {
- double[] rates = internalTestStorage(JournalType.ASYNCIO, 10000, -1, 1);
- rates = internalTestStorage(JournalType.ASYNCIO, 30000, -1, 5);
-
- printRates("Rate of AIO, 30000 inserts / single commit at the end", rates);
-
- rates = internalTestStorage(JournalType.ASYNCIO, 5000, 1, 5);
-
- printRates("Rate of AIO, 30000 inserts / commit on every insert", rates);
- }
-
- public void testNIO() throws Exception
- {
- // just to do some initial loading.. ignore this rate
- internalTestStorage(JournalType.NIO, 1000, 1, 1);
- double rate = internalTestStorage(JournalType.NIO, 1000, 1, 1)[0];
- printRates("Rate of NIO, 1000 inserts, 1000 commits", rate);
-
- rate = internalTestStorage(JournalType.NIO, 30000, -1, 1)[0];
- printRates("Rate of NIO, 30000 inserts / single commit at the end", rate);
-
- rate = internalTestStorage(JournalType.NIO, 30000, 5, 1)[0];
- printRates("Rate of NIO, 30000 inserts / commit every 5 records", rate);
- }
-
- public void testNIOMultiThread() throws Exception
- {
-
- double[] rates = internalTestStorage(JournalType.NIO, 5000, -1, 5);
-
- printRates("Rate of NIO, 5000 inserts / single commit at the end", rates);
-
- rates = internalTestStorage(JournalType.NIO, 5000, 1, 5);
-
- printRates("Rate of NIO, 5000 inserts / commit on every insert", rates);
-
- }
-
- public double[] internalTestStorage(final JournalType journalType,
- final long numberOfMessages,
- final int transInterval,
- final int numberOfThreads) throws Exception
- {
- FileConfiguration configuration = new FileConfiguration();
-
- configuration.start();
-
- deleteDirectory(new File(configuration.getBindingsDirectory()));
- deleteDirectory(new File(configuration.getJournalDirectory()));
-
- configuration.setJournalType(journalType);
-
- PostOffice postOffice = new FakePostOffice();
-
- final JournalStorageManager journal = new JournalStorageManager(configuration,
- Executors.newCachedThreadPool());
- journal.start();
-
- HashMap<Long, Queue> queues = new HashMap<Long, Queue>();
-
- journal.loadMessageJournal(postOffice, null, null, queues, null);
-
- final byte[] bytes = new byte[900];
-
- for (int i = 0; i < bytes.length; i++)
- {
- bytes[i] = (byte)('a' + (i % 20));
- }
-
- final AtomicLong transactionGenerator = new AtomicLong(1);
-
- class LocalThread extends Thread
- {
- int id;
-
- int commits = 1;
-
- Exception e;
-
- long totalTime = 0;
-
- public LocalThread(int id)
- {
- super("LocalThread:" + id);
- this.id = id;
- }
-
- public void run()
- {
- try
- {
- long start = System.currentTimeMillis();
-
- long trans = transactionGenerator.incrementAndGet();
- boolean commitPending = false;
- for (long i = 1; i <= numberOfMessages; i++)
- {
-
- final SimpleString address = new SimpleString("Destination " + i);
-
- ServerMessageImpl implMsg = new ServerMessageImpl(/* type */(byte)1, /* durable */
- true, /* expiration */
- 0,
- /* timestamp */0, /* priority */
- (byte)0, ChannelBuffers.wrappedBuffer(new byte[1024]));
-
- implMsg.putStringProperty(new SimpleString("Key"), new SimpleString("This String is worthless!"));
-
- implMsg.setMessageID(i);
- implMsg.setBody(ChannelBuffers.wrappedBuffer(bytes));
-
- implMsg.setDestination(address);
-
- journal.storeMessageTransactional(trans, implMsg);
-
- commitPending = true;
-
- if (transInterval > 0 && i % transInterval == 0)
- {
- journal.commit(trans);
- commits++;
- trans = transactionGenerator.incrementAndGet();
- commitPending = false;
- }
- }
-
- if (commitPending)
- journal.commit(trans);
-
- long end = System.currentTimeMillis();
-
- totalTime = end - start;
- }
- catch (Exception e)
- {
- log.error(e.getMessage(), e);
- this.e = e;
- }
- }
- }
-
- try
- {
- LocalThread[] threads = new LocalThread[numberOfThreads];
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- threads[i] = new LocalThread(i);
- }
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- threads[i].start();
- }
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- threads[i].join();
- }
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- if (threads[i].e != null)
- {
- throw threads[i].e;
- }
- }
-
- double rates[] = new double[numberOfThreads];
-
- for (int i = 0; i < numberOfThreads; i++)
- {
- rates[i] = (numberOfMessages + threads[i].commits) * 1000 / threads[i].totalTime;
- }
-
- return rates;
- }
- finally
- {
- journal.stop();
- }
-
- }
-
- private void printRates(String msg, double rate)
- {
- printRates(msg, new double[] { rate });
- }
-
- private void printRates(String msg, double[] rates)
- {
- double rate = 0;
-
- log.info("*************************************************************************");
- log.info(" " + msg + " ");
-
- double totalRate = 0;
- for (int i = 0; i < rates.length; i++)
- {
- rate = rates[i];
- totalRate += rate;
- if (rates.length > 1)
- {
- log.info(" Thread " + i + ": = " + rate + " inserts/sec (including commits)");
- }
- }
-
- log.info(" Total rate : = " + totalRate + " inserts/sec (including commits)");
- log.info("*************************************************************************");
- }
-}
Modified: trunk/tests/src/org/hornetq/tests/timing/core/server/impl/QueueImplTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/timing/core/server/impl/QueueImplTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/timing/core/server/impl/QueueImplTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -41,6 +41,8 @@
private static final Logger log = Logger.getLogger(QueueImplTest.class);
private ScheduledExecutorService scheduledExecutor;
+
+ //private ExecutorService executor;
public void setUp() throws Exception
{
Modified: trunk/tests/src/org/hornetq/tests/unit/core/asyncio/AIOTestBase.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/asyncio/AIOTestBase.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/asyncio/AIOTestBase.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -15,6 +15,8 @@
import java.io.File;
import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
@@ -84,20 +86,36 @@
protected static class CountDownCallback implements AIOCallback
{
private final CountDownLatch latch;
+
+ private final List<Integer> outputList;
+
+ private final int order;
+
+ private final AtomicInteger errors;
- public CountDownCallback(final CountDownLatch latch)
+ public CountDownCallback(final CountDownLatch latch, final AtomicInteger errors, final List<Integer> outputList, final int order)
{
this.latch = latch;
+
+ this.outputList = outputList;
+
+ this.order = order;
+
+ this.errors = errors;
}
volatile boolean doneCalled = false;
- volatile boolean errorCalled = false;
+ volatile int errorCalled = 0;
final AtomicInteger timesDoneCalled = new AtomicInteger(0);
public void done()
{
+ if (outputList != null)
+ {
+ outputList.add(order);
+ }
doneCalled = true;
timesDoneCalled.incrementAndGet();
if (latch != null)
@@ -108,7 +126,15 @@
public void onError(final int errorCode, final String errorMessage)
{
- errorCalled = true;
+ errorCalled++;
+ if (outputList != null)
+ {
+ outputList.add(order);
+ }
+ if (errors != null)
+ {
+ errors.incrementAndGet();
+ }
if (latch != null)
{
// even thought an error happened, we need to inform the latch,
@@ -116,6 +142,16 @@
latch.countDown();
}
}
+
+ public static void checkResults(final int numberOfElements, final ArrayList<Integer> result)
+ {
+ assertEquals(numberOfElements, result.size());
+ int i = 0;
+ for (Integer resultI : result)
+ {
+ assertEquals(i++, resultI.intValue());
+ }
+ }
}
}
Modified: trunk/tests/src/org/hornetq/tests/unit/core/asyncio/AsynchronousFileTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/asyncio/AsynchronousFileTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/asyncio/AsynchronousFileTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -136,6 +136,11 @@
int numberOfLines = 1000;
int size = 1024;
+
+ ArrayList<Integer> listResult1 = new ArrayList<Integer>();
+ ArrayList<Integer> listResult2 = new ArrayList<Integer>();
+
+ AtomicInteger errors = new AtomicInteger(0);
ByteBuffer buffer = null;
try
@@ -154,41 +159,43 @@
for (int i = 0; i < numberOfLines; i++)
{
- list.add(new CountDownCallback(latchDone));
- list2.add(new CountDownCallback(latchDone2));
+ list.add(new CountDownCallback(latchDone, errors, listResult1, i));
+ list2.add(new CountDownCallback(latchDone2, errors, listResult2, i));
}
- long valueInitial = System.currentTimeMillis();
-
int counter = 0;
+
Iterator<CountDownCallback> iter2 = list2.iterator();
- for (CountDownCallback tmp : list)
+ for (CountDownCallback cb1 : list)
{
- CountDownCallback tmp2 = iter2.next();
+ CountDownCallback cb2 = iter2.next();
- controller.write(counter * size, size, buffer, tmp);
- controller.write(counter * size, size, buffer, tmp2);
+ controller.write(counter * size, size, buffer, cb1);
+ controller2.write(counter * size, size, buffer, cb2);
++counter;
}
latchDone.await();
latchDone2.await();
+
+ CountDownCallback.checkResults(numberOfLines, listResult1);
+ CountDownCallback.checkResults(numberOfLines, listResult2);
for (CountDownCallback callback : list)
{
assertEquals(1, callback.timesDoneCalled.get());
assertTrue(callback.doneCalled);
- assertFalse(callback.errorCalled);
}
for (CountDownCallback callback : list2)
{
assertEquals(1, callback.timesDoneCalled.get());
assertTrue(callback.doneCalled);
- assertFalse(callback.errorCalled);
}
+
+ assertEquals(0, errors.get());
controller.close();
}
@@ -358,7 +365,7 @@
controller.setBufferCallback(bufferCallback);
CountDownLatch latch = new CountDownLatch(NUMBER_LINES);
- CountDownCallback aio = new CountDownCallback(latch);
+ ArrayList<Integer> result = new ArrayList<Integer>();
for (int i = 0; i < NUMBER_LINES; i++)
{
ByteBuffer buffer = AsynchronousFileImpl.newBuffer(SIZE);
@@ -367,6 +374,7 @@
{
buffer.put((byte)(j % Byte.MAX_VALUE));
}
+ CountDownCallback aio = new CountDownCallback(latch, null, result, i);
controller.write(i * SIZE, SIZE, buffer, aio);
}
@@ -379,7 +387,7 @@
controller.close();
closed = true;
- assertEquals(NUMBER_LINES, buffers.size());
+ CountDownCallback.checkResults(NUMBER_LINES, result);
// Make sure all the buffers are unique
ByteBuffer lineOne = null;
@@ -439,7 +447,6 @@
controller.setBufferCallback(bufferCallback);
CountDownLatch latch = new CountDownLatch(NUMBER_LINES);
- CountDownCallback aio = new CountDownCallback(latch);
buffer = AsynchronousFileImpl.newBuffer(SIZE);
buffer.rewind();
@@ -448,8 +455,11 @@
buffer.put((byte)(j % Byte.MAX_VALUE));
}
+ ArrayList<Integer> result = new ArrayList<Integer>();
+
for (int i = 0; i < NUMBER_LINES; i++)
{
+ CountDownCallback aio = new CountDownCallback(latch, null, result, i);
controller.write(i * SIZE, SIZE, buffer, aio);
}
@@ -462,6 +472,8 @@
controller.close();
closed = true;
+ CountDownCallback.checkResults(NUMBER_LINES, result);
+
assertEquals(NUMBER_LINES, buffers.size());
// Make sure all the buffers are unique
@@ -517,7 +529,9 @@
{
CountDownLatch latch = new CountDownLatch(NUMBER_LINES);
- CountDownCallback aio = new CountDownCallback(latch);
+ ArrayList<Integer> result = new ArrayList<Integer>();
+
+ AtomicInteger errors = new AtomicInteger(0);
for (int i = 0; i < NUMBER_LINES; i++)
{
@@ -531,12 +545,15 @@
buffer.put(getSamplebyte(j));
}
+ CountDownCallback aio = new CountDownCallback(latch, errors, result, i);
controller.write(i * SIZE, SIZE, buffer, aio);
}
latch.await();
- assertFalse(aio.errorCalled);
- assertEquals(NUMBER_LINES, aio.timesDoneCalled.get());
+
+ assertEquals(0, errors.get());
+
+ CountDownCallback.checkResults(NUMBER_LINES, result);
}
// If you call close you're supposed to wait events to finish before
@@ -557,12 +574,13 @@
AsynchronousFileImpl.clearBuffer(readBuffer);
CountDownLatch latch = new CountDownLatch(1);
- CountDownCallback aio = new CountDownCallback(latch);
+ AtomicInteger errors = new AtomicInteger(0);
+ CountDownCallback aio = new CountDownCallback(latch, errors, null, 0);
controller.read(i * SIZE, SIZE, readBuffer, aio);
latch.await();
- assertFalse(aio.errorCalled);
+ assertEquals(0, errors.get());
assertTrue(aio.doneCalled);
byte bytesRead[] = new byte[SIZE];
@@ -634,7 +652,7 @@
}
buffer.put((byte)'\n');
- CountDownCallback aio = new CountDownCallback(readLatch);
+ CountDownCallback aio = new CountDownCallback(readLatch, null, null, 0);
controller.write(i * SIZE, SIZE, buffer, aio);
}
@@ -663,10 +681,10 @@
newBuffer.put((byte)'\n');
CountDownLatch latch = new CountDownLatch(1);
- CountDownCallback aio = new CountDownCallback(latch);
+ CountDownCallback aio = new CountDownCallback(latch, null, null, 0);
controller.read(i * SIZE, SIZE, buffer, aio);
latch.await();
- assertFalse(aio.errorCalled);
+ assertEquals(0, aio.errorCalled);
assertTrue(aio.doneCalled);
byte bytesRead[] = new byte[SIZE];
@@ -720,9 +738,11 @@
ArrayList<CountDownCallback> list = new ArrayList<CountDownCallback>();
+ ArrayList<Integer> result = new ArrayList<Integer>();
+
for (int i = 0; i < numberOfLines; i++)
{
- list.add(new CountDownCallback(latchDone));
+ list.add(new CountDownCallback(latchDone, null, result, i));
}
long valueInitial = System.currentTimeMillis();
@@ -743,6 +763,9 @@
latchDone.await();
long timeTotal = System.currentTimeMillis() - valueInitial;
+
+ CountDownCallback.checkResults(numberOfLines, result);
+
debug("After completions time = " + timeTotal +
" for " +
numberOfLines +
@@ -759,7 +782,7 @@
{
assertEquals(1, tmp.timesDoneCalled.get());
assertTrue(tmp.doneCalled);
- assertFalse(tmp.errorCalled);
+ assertEquals(0, tmp.errorCalled);
}
controller.close();
@@ -799,11 +822,11 @@
for (int i = 0; i < NUMBER_LINES; i++)
{
CountDownLatch latchDone = new CountDownLatch(1);
- CountDownCallback aioBlock = new CountDownCallback(latchDone);
+ CountDownCallback aioBlock = new CountDownCallback(latchDone, null, null, 0);
controller.write(i * 512, 512, buffer, aioBlock);
latchDone.await();
assertTrue(aioBlock.doneCalled);
- assertFalse(aioBlock.errorCalled);
+ assertEquals(0, aioBlock.errorCalled);
}
long timeTotal = System.currentTimeMillis() - startTime;
@@ -850,12 +873,12 @@
CountDownLatch latchDone = new CountDownLatch(1);
- CountDownCallback aioBlock = new CountDownCallback(latchDone);
+ CountDownCallback aioBlock = new CountDownCallback(latchDone, null, null, 0);
controller.write(11, 512, buffer, aioBlock);
latchDone.await();
- assertTrue(aioBlock.errorCalled);
+ assertTrue(aioBlock.errorCalled != 0);
assertFalse(aioBlock.doneCalled);
}
Modified: trunk/tests/src/org/hornetq/tests/unit/core/asyncio/MultiThreadAsynchronousFileTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/asyncio/MultiThreadAsynchronousFileTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/asyncio/MultiThreadAsynchronousFileTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -40,7 +40,7 @@
* */
public class MultiThreadAsynchronousFileTest extends AIOTestBase
{
-
+
public static TestSuite suite()
{
return createAIOTestSuite(MultiThreadAsynchronousFileTest.class);
@@ -56,37 +56,33 @@
static final int NUMBER_OF_LINES = 1000;
- // Executor exec
-
ExecutorService executor;
-
+
ExecutorService pollerExecutor;
-
private static void debug(final String msg)
{
log.debug(msg);
}
-
-
protected void setUp() throws Exception
{
super.setUp();
- pollerExecutor = Executors.newCachedThreadPool(new HornetQThreadFactory("HornetQ-AIO-poller-pool" + System.identityHashCode(this), false));
+ pollerExecutor = Executors.newCachedThreadPool(new HornetQThreadFactory("HornetQ-AIO-poller-pool" + System.identityHashCode(this),
+ false));
executor = Executors.newSingleThreadExecutor();
}
-
+
protected void tearDown() throws Exception
{
executor.shutdown();
pollerExecutor.shutdown();
super.tearDown();
}
-
+
public void testMultipleASynchronousWrites() throws Throwable
{
- executeTest(false);
+ executeTest(false);
}
public void testMultipleSynchronousWrites() throws Throwable
@@ -132,15 +128,15 @@
long endTime = System.currentTimeMillis();
debug((sync ? "Sync result:" : "Async result:") + " Records/Second = " +
- NUMBER_OF_THREADS *
- NUMBER_OF_LINES *
- 1000 /
- (endTime - startTime) +
- " total time = " +
- (endTime - startTime) +
- " total number of records = " +
- NUMBER_OF_THREADS *
- NUMBER_OF_LINES);
+ NUMBER_OF_THREADS *
+ NUMBER_OF_LINES *
+ 1000 /
+ (endTime - startTime) +
+ " total time = " +
+ (endTime - startTime) +
+ " total number of records = " +
+ NUMBER_OF_THREADS *
+ NUMBER_OF_LINES);
}
finally
{
@@ -180,9 +176,8 @@
{
super.run();
-
ByteBuffer buffer = null;
-
+
synchronized (MultiThreadAsynchronousFileTest.class)
{
buffer = AsynchronousFileImpl.newBuffer(SIZE);
@@ -222,7 +217,7 @@
{
latchFinishThread = new CountDownLatch(1);
}
- CountDownCallback callback = new CountDownCallback(latchFinishThread);
+ CountDownCallback callback = new CountDownCallback(latchFinishThread, null, null, 0);
if (!sync)
{
list.add(callback);
@@ -232,7 +227,7 @@
{
latchFinishThread.await();
assertTrue(callback.doneCalled);
- assertFalse(callback.errorCalled);
+ assertFalse(callback.errorCalled != 0);
}
}
if (!sync)
@@ -243,13 +238,13 @@
for (CountDownCallback callback : list)
{
assertTrue(callback.doneCalled);
- assertFalse(callback.errorCalled);
+ assertFalse(callback.errorCalled != 0);
}
for (CountDownCallback callback : list)
{
assertTrue(callback.doneCalled);
- assertFalse(callback.errorCalled);
+ assertFalse(callback.errorCalled != 0);
}
}
Modified: trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/JournalAsyncTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/JournalAsyncTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/JournalAsyncTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -13,7 +13,6 @@
package org.hornetq.tests.unit.core.journal.impl;
-import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -57,6 +56,16 @@
public void testAsynchronousCommit() throws Exception
{
+ doAsynchronousTest(true);
+ }
+
+ public void testAsynchronousRollback() throws Exception
+ {
+ doAsynchronousTest(false);
+ }
+
+ public void doAsynchronousTest(final boolean isCommit) throws Exception
+ {
final int JOURNAL_SIZE = 20000;
setupJournal(JOURNAL_SIZE, 100, 5);
@@ -81,7 +90,14 @@
latch.countDown();
factory.setHoldCallbacks(false, null);
- journalImpl.appendCommitRecord(1l, true);
+ if (isCommit)
+ {
+ journalImpl.appendCommitRecord(1l, true);
+ }
+ else
+ {
+ journalImpl.appendRollbackRecord(1l, true);
+ }
}
catch (Exception e)
{
@@ -97,6 +113,8 @@
assertTrue(latch.await(5, TimeUnit.SECONDS));
Thread.yield();
+
+ Thread.sleep(100);
assertTrue(t.isAlive());
@@ -109,145 +127,7 @@
throw t.e;
}
}
-
- public void testAsynchronousRollbackWithError() throws Exception
- {
- final int JOURNAL_SIZE = 20000;
-
- setupJournal(JOURNAL_SIZE, 100, 5);
-
- final CountDownLatch latch = new CountDownLatch(11);
-
- factory.setHoldCallbacks(true, new FakeSequentialFileFactory.ListenerHoldCallback()
- {
-
- public void callbackAdded(final ByteBuffer bytes)
- {
- latch.countDown();
- }
- });
-
- class LocalThread extends Thread
- {
- Exception e;
-
- @Override
- public void run()
- {
- try
- {
- for (int i = 0; i < 10; i++)
- {
- journalImpl.appendAddRecordTransactional(1l, i, (byte)1, new SimpleEncoding(1, (byte)0));
- }
-
- journalImpl.appendRollbackRecord(1l, true);
- }
- catch (Exception e)
- {
- this.e = e;
- }
- }
- };
-
- LocalThread t = new LocalThread();
- t.start();
-
- latch.await();
-
- Thread.yield();
-
- assertTrue(t.isAlive());
-
- factory.setCallbackAsError(0);
-
- factory.flushCallback(0);
-
- Thread.yield();
-
- assertTrue(t.isAlive());
-
- factory.flushAllCallbacks();
-
- t.join();
-
- assertNotNull(t.e);
- }
-
- public void testAsynchronousCommitWithError() throws Exception
- {
- final int JOURNAL_SIZE = 20000;
-
- setupJournal(JOURNAL_SIZE, 100, 5);
-
- final CountDownLatch latch = new CountDownLatch(11);
-
- factory.setHoldCallbacks(true, new FakeSequentialFileFactory.ListenerHoldCallback()
- {
-
- public void callbackAdded(final ByteBuffer bytes)
- {
- latch.countDown();
- }
- });
-
- class LocalThread extends Thread
- {
- Exception e;
-
- @Override
- public void run()
- {
- try
- {
- for (int i = 0; i < 10; i++)
- {
- journalImpl.appendAddRecordTransactional(1l, i, (byte)1, new SimpleEncoding(1, (byte)0));
- }
-
- journalImpl.appendCommitRecord(1l, true);
- }
- catch (Exception e)
- {
- this.e = e;
- }
- }
- };
-
- LocalThread t = new LocalThread();
- t.start();
-
- latch.await();
-
- Thread.yield();
-
- assertTrue(t.isAlive());
-
- factory.setCallbackAsError(0);
-
- factory.flushCallback(0);
-
- Thread.yield();
-
- assertTrue(t.isAlive());
-
- factory.flushAllCallbacks();
-
- t.join();
-
- assertNotNull(t.e);
-
- try
- {
- journalImpl.appendRollbackRecord(1l, false);
- fail("Supposed to throw an exception");
- }
- catch (Exception e)
- {
-
- }
- }
-
+
// If a callback error already arrived, we should just throw the exception
// right away
public void testPreviousError() throws Exception
Modified: trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -19,9 +19,11 @@
import java.util.UUID;
import org.hornetq.core.asyncio.impl.AsynchronousFileImpl;
+import org.hornetq.core.buffers.ChannelBuffers;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.logging.Logger;
+import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.tests.util.UnitTestCase;
/**
@@ -213,30 +215,30 @@
String s1 = "aardvark";
byte[] bytes1 = s1.getBytes("UTF-8");
- ByteBuffer bb1 = factory.wrapBuffer(bytes1);
+ HornetQBuffer bb1 = wrapBuffer(bytes1);
String s2 = "hippopotamus";
byte[] bytes2 = s2.getBytes("UTF-8");
- ByteBuffer bb2 = factory.wrapBuffer(bytes2);
+ HornetQBuffer bb2 = wrapBuffer(bytes2);
String s3 = "echidna";
byte[] bytes3 = s3.getBytes("UTF-8");
- ByteBuffer bb3 = factory.wrapBuffer(bytes3);
+ HornetQBuffer bb3 = wrapBuffer(bytes3);
long initialPos = sf.position();
- sf.writeDirect(bb1, true);
+ sf.write(bb1, true);
long bytesWritten = sf.position() - initialPos;
assertEquals(calculateRecordSize(bytes1.length, sf.getAlignment()), bytesWritten);
initialPos = sf.position();
- sf.writeDirect(bb2, true);
+ sf.write(bb2, true);
bytesWritten = sf.position() - initialPos;
assertEquals(calculateRecordSize(bytes2.length, sf.getAlignment()), bytesWritten);
initialPos = sf.position();
- sf.writeDirect(bb3, true);
+ sf.write(bb3, true);
bytesWritten = sf.position() - initialPos;
assertEquals(calculateRecordSize(bytes3.length, sf.getAlignment()), bytesWritten);
@@ -286,33 +288,30 @@
String s1 = "orange";
byte[] bytes1 = s1.getBytes("UTF-8");
- ByteBuffer bb1 = factory.wrapBuffer(bytes1);
byte[] bytes2 = s1.getBytes("UTF-8");
- ByteBuffer bb2 = factory.wrapBuffer(bytes2);
String s3 = "lemon";
byte[] bytes3 = s3.getBytes("UTF-8");
- ByteBuffer bb3 = factory.wrapBuffer(bytes3);
-
+
long initialPos = sf.position();
- sf.writeDirect(bb1, true);
+ sf.write(wrapBuffer(bytes1), true);
long bytesWritten = sf.position() - initialPos;
- assertEquals(bb1.limit(), bytesWritten);
+ assertEquals(calculateRecordSize(bytes1.length,sf.getAlignment()), bytesWritten);
initialPos = sf.position();
- sf.writeDirect(bb2, true);
+ sf.write(wrapBuffer(bytes2), true);
bytesWritten = sf.position() - initialPos;
- assertEquals(bb2.limit(), bytesWritten);
+ assertEquals(calculateRecordSize(bytes2.length,sf.getAlignment()), bytesWritten);
initialPos = sf.position();
- sf.writeDirect(bb3, true);
+ sf.write(wrapBuffer(bytes3), true);
bytesWritten = sf.position() - initialPos;
- assertEquals(bb3.limit(), bytesWritten);
+ assertEquals(calculateRecordSize(bytes3.length,sf.getAlignment()), bytesWritten);
byte[] rbytes1 = new byte[bytes1.length];
@@ -324,7 +323,7 @@
ByteBuffer rb2 = factory.newBuffer(rbytes2.length);
ByteBuffer rb3 = factory.newBuffer(rbytes3.length);
- sf.position(bb1.limit() + bb2.limit());
+ sf.position(calculateRecordSize(bytes1.length, sf.getAlignment()) + calculateRecordSize(bytes2.length, sf.getAlignment()));
int bytesRead = sf.read(rb3);
assertEquals(rb3.limit(), bytesRead);
@@ -370,39 +369,45 @@
String s1 = "cheesecake";
byte[] bytes1 = s1.getBytes("UTF-8");
- ByteBuffer bb1 = factory.wrapBuffer(bytes1);
long initialPos = sf.position();
- sf.writeDirect(bb1, true);
+ sf.write(wrapBuffer(bytes1), true);
long bytesWritten = sf.position() - initialPos;
- assertEquals(bb1.limit(), bytesWritten);
+ assertEquals(calculateRecordSize(bytes1.length, sf.getAlignment()), bytesWritten);
sf.close();
try
{
- bb1 = factory.wrapBuffer(bytes1);
-
- sf.writeDirect(bb1, true);
+ sf.write(wrapBuffer(bytes1), true);
fail("Should throw exception");
}
catch (Exception e)
{
- // OK
}
sf.open();
- sf.writeDirect(bb1, true);
+ sf.write(wrapBuffer(bytes1), true);
sf.close();
}
// Private ---------------------------------
+
+ private HornetQBuffer wrapBuffer(ByteBuffer buffer)
+ {
+ return ChannelBuffers.wrappedBuffer(buffer);
+ }
+ private HornetQBuffer wrapBuffer(byte[] bytes)
+ {
+ return ChannelBuffers.wrappedBuffer(bytes);
+ }
+
protected void checkFill(final SequentialFile file, final int pos, final int size, final byte fillChar) throws Exception
{
file.fill(pos, size, fillChar);
Modified: trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/TimedBufferTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/TimedBufferTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/TimedBufferTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -18,7 +18,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-import org.hornetq.core.journal.IOCompletion;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.journal.impl.TimedBuffer;
import org.hornetq.core.journal.impl.TimedBufferObserver;
import org.hornetq.tests.util.UnitTestCase;
@@ -42,7 +42,7 @@
// Public --------------------------------------------------------
- IOCompletion dummyCallback = new IOCompletion()
+ IOAsyncTask dummyCallback = new IOAsyncTask()
{
public void done()
@@ -64,7 +64,7 @@
final AtomicInteger flushTimes = new AtomicInteger(0);
class TestObserver implements TimedBufferObserver
{
- public void flushBuffer(final ByteBuffer buffer, final boolean sync, final List<IOCompletion> callbacks)
+ public void flushBuffer(final ByteBuffer buffer, final boolean sync, final List<IOAsyncTask> callbacks)
{
buffers.add(buffer);
flushTimes.incrementAndGet();
Modified: trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -20,7 +20,7 @@
import java.util.concurrent.ConcurrentHashMap;
import org.hornetq.core.asyncio.BufferCallback;
-import org.hornetq.core.journal.IOCompletion;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.journal.impl.TimedBuffer;
@@ -241,11 +241,11 @@
final ByteBuffer bytes;
- final IOCompletion callback;
+ final IOAsyncTask callback;
volatile boolean sendError;
- CallbackRunnable(final FakeSequentialFile file, final ByteBuffer bytes, final IOCompletion callback)
+ CallbackRunnable(final FakeSequentialFile file, final ByteBuffer bytes, final IOAsyncTask callback)
{
this.file = file;
this.bytes = bytes;
@@ -399,7 +399,7 @@
return read(bytes, null);
}
- public int read(final ByteBuffer bytes, final IOCompletion callback) throws Exception
+ public int read(final ByteBuffer bytes, final IOAsyncTask callback) throws Exception
{
if (!open)
{
@@ -439,7 +439,7 @@
return data.position();
}
- public synchronized void writeDirect(final ByteBuffer bytes, final boolean sync, final IOCompletion callback)
+ public synchronized void writeDirect(final ByteBuffer bytes, final boolean sync, final IOAsyncTask callback)
{
if (!open)
{
@@ -605,7 +605,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.journal.SequentialFile#write(org.hornetq.core.remoting.spi.HornetQBuffer, boolean, org.hornetq.core.journal.IOCallback)
*/
- public void write(HornetQBuffer bytes, boolean sync, IOCompletion callback) throws Exception
+ public void write(HornetQBuffer bytes, boolean sync, IOAsyncTask callback) throws Exception
{
writeDirect(ByteBuffer.wrap(bytes.array()), sync, callback);
Modified: trunk/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingStoreImplTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingStoreImplTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingStoreImplTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -29,6 +29,7 @@
import javax.transaction.xa.Xid;
import org.hornetq.core.buffers.ChannelBuffers;
+import org.hornetq.core.journal.IOAsyncTask;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
@@ -43,6 +44,7 @@
import org.hornetq.core.paging.impl.PagingStoreImpl;
import org.hornetq.core.paging.impl.TestSupportPageStore;
import org.hornetq.core.persistence.GroupingInfo;
+import org.hornetq.core.persistence.OperationContext;
import org.hornetq.core.persistence.QueueBindingInfo;
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.postoffice.Binding;
@@ -1155,7 +1157,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.persistence.StorageManager#afterReplicated(java.lang.Runnable)
*/
- public void afterReplicated(Runnable run)
+ public void afterCompleteOperations(Runnable run)
{
}
@@ -1163,7 +1165,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.persistence.StorageManager#completeReplication()
*/
- public void completeReplication()
+ public void completeOperations()
{
}
@@ -1221,7 +1223,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.persistence.StorageManager#blockOnReplication(long)
*/
- public void waitOnReplication(long timeout) throws Exception
+ public void waitOnOperations(long timeout) throws Exception
{
}
@@ -1232,6 +1234,50 @@
{
}
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#afterCompleteOperations(org.hornetq.core.journal.IOCompletion)
+ */
+ public void afterCompleteOperations(IOAsyncTask run)
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#waitOnOperations()
+ */
+ public void waitOnOperations() throws Exception
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#getContext()
+ */
+ public OperationContext getContext()
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#newContext(java.util.concurrent.Executor)
+ */
+ public OperationContext newContext(Executor executor)
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#clearContext()
+ */
+ public void clearContext()
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see org.hornetq.core.persistence.StorageManager#setContext(org.hornetq.core.persistence.OperationContext)
+ */
+ public void setContext(OperationContext context)
+ {
+ }
+
}
class FakeStoreFactory implements PagingStoreFactory
Modified: trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -1131,7 +1131,7 @@
return null;
}
- public int decrementRefCount(MessageReference reference) throws Exception
+ public int decrementRefCount(MessageReference reference)
{
// TODO Auto-generated method stub
return 0;
Modified: trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/DuplicateDetectionUnitTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/DuplicateDetectionUnitTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/DuplicateDetectionUnitTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -17,6 +17,8 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -37,6 +39,8 @@
import org.hornetq.tests.unit.core.server.impl.fakes.FakePostOffice;
import org.hornetq.tests.util.RandomUtil;
import org.hornetq.tests.util.ServiceTestBase;
+import org.hornetq.utils.ExecutorFactory;
+import org.hornetq.utils.OrderedExecutorFactory;
import org.hornetq.utils.Pair;
import org.hornetq.utils.SimpleString;
@@ -57,11 +61,23 @@
// Constructors --------------------------------------------------
+ ExecutorService executor;
+
+ ExecutorFactory factory;
+
@Override
protected void tearDown() throws Exception
{
super.tearDown();
+ executor.shutdown();
}
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ executor = Executors.newSingleThreadExecutor();
+ factory = new OrderedExecutorFactory(executor);
+ }
// Public --------------------------------------------------------
@@ -86,7 +102,7 @@
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(ConfigurationImpl.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE);
- journal = new JournalStorageManager(configuration, Executors.newCachedThreadPool());
+ journal = new JournalStorageManager(configuration, factory);
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>());
@@ -110,7 +126,7 @@
journal.stop();
- journal = new JournalStorageManager(configuration, Executors.newCachedThreadPool());
+ journal = new JournalStorageManager(configuration, factory);
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>());
@@ -138,7 +154,7 @@
mapDups.clear();
- journal = new JournalStorageManager(configuration, Executors.newCachedThreadPool());
+ journal = new JournalStorageManager(configuration, factory);
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>());
Modified: trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/FakeQueue.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/FakeQueue.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/postoffice/impl/FakeQueue.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -493,4 +493,13 @@
return false;
}
+ /* (non-Javadoc)
+ * @see org.hornetq.core.server.Queue#checkDLQ(org.hornetq.core.server.MessageReference, java.util.concurrent.Executor)
+ */
+ public boolean checkDLQ(MessageReference ref, Executor ioExecutor) throws Exception
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
}
\ No newline at end of file
Modified: trunk/tests/src/org/hornetq/tests/unit/core/server/impl/QueueImplTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/server/impl/QueueImplTest.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/server/impl/QueueImplTest.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -43,7 +43,19 @@
{
// The tests ----------------------------------------------------------------
- private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
+ private ScheduledExecutorService scheduledExecutor;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+ scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ scheduledExecutor.shutdown();
+ super.tearDown();
+ }
private static final SimpleString queue1 = new SimpleString("queue1");
Modified: trunk/tests/src/org/hornetq/tests/unit/core/server/impl/fakes/FakeQueueFactory.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/unit/core/server/impl/fakes/FakeQueueFactory.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/unit/core/server/impl/fakes/FakeQueueFactory.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -13,6 +13,7 @@
package org.hornetq.tests.unit.core.server.impl.fakes;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -32,8 +33,8 @@
*/
public class FakeQueueFactory implements QueueFactory
{
- private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
-
+ private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
+
private PostOffice postOffice;
public Queue createQueue(long persistenceID, final SimpleString address, SimpleString name, Filter filter,
@@ -47,5 +48,10 @@
this.postOffice = postOffice;
}
+
+ public void stop() throws Exception
+ {
+ scheduledExecutor.shutdown();
+ }
}
Modified: trunk/tests/src/org/hornetq/tests/util/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/util/UnitTestCase.java 2009-11-23 23:28:33 UTC (rev 8388)
+++ trunk/tests/src/org/hornetq/tests/util/UnitTestCase.java 2009-11-24 02:53:23 UTC (rev 8389)
@@ -50,6 +50,8 @@
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.journal.impl.AIOSequentialFileFactory;
import org.hornetq.core.logging.Logger;
+import org.hornetq.core.persistence.impl.journal.JournalStorageManager;
+import org.hornetq.core.persistence.impl.journal.OperationContextImpl;
import org.hornetq.core.postoffice.Binding;
import org.hornetq.core.postoffice.Bindings;
import org.hornetq.core.postoffice.PostOffice;
@@ -647,6 +649,8 @@
@Override
protected void tearDown() throws Exception
{
+ OperationContextImpl.clearContext();
+
deleteDirectory(new File(getTestDir()));
assertEquals(0, InVMRegistry.instance.size());
15 years, 1 month
JBoss hornetq SVN: r8388 - branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat.
by do-not-reply@jboss.org
Author: timfox
Date: 2009-11-23 18:28:33 -0500 (Mon, 23 Nov 2009)
New Revision: 8388
Added:
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/MessagePacket.java
Log:
optimisation
Added: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/MessagePacket.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/MessagePacket.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/MessagePacket.java 2009-11-23 23:28:33 UTC (rev 8388)
@@ -0,0 +1,81 @@
+/*
+ * 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.buffers.HornetQBuffer;
+import org.hornetq.core.message.Message;
+import org.hornetq.core.remoting.RemotingConnection;
+import org.hornetq.utils.DataConstants;
+
+/**
+ * A MessagePacket
+ *
+ * @author tim
+ *
+ *
+ */
+public abstract class MessagePacket extends PacketImpl
+{
+ protected Message message;
+
+ public MessagePacket(final byte type, final Message message)
+ {
+ super(type);
+
+ this.message = message;
+ }
+
+ public Message getMessage()
+ {
+ return message;
+ }
+
+ @Override
+ public HornetQBuffer encode(final RemotingConnection connection)
+ {
+ HornetQBuffer buffer = message.encodeToBuffer();
+
+ buffer.setIndex(0, message.getEndOfMessagePosition());
+
+ encodeExtraData(buffer);
+
+ size = buffer.writerIndex();
+
+ //Write standard headers
+
+ int len = size - DataConstants.SIZE_INT;
+ buffer.setInt(0, len);
+ buffer.setByte(DataConstants.SIZE_INT, type);
+ buffer.setLong(DataConstants.SIZE_INT + DataConstants.SIZE_BYTE, channelID);
+
+ //Position reader for reading by Netty
+ buffer.readerIndex(0);
+
+ return buffer;
+ }
+
+ @Override
+ public void decodeRest(HornetQBuffer buffer)
+ {
+ //Buffer comes in after having read standard headers and positioned at Beginning of body part
+
+ message.decodeFromBuffer(buffer);
+
+ decodeExtraData(buffer);
+ }
+
+ protected abstract void encodeExtraData(HornetQBuffer buffer);
+
+ protected abstract void decodeExtraData(HornetQBuffer buffer);
+}
15 years, 1 month
JBoss hornetq SVN: r8387 - in branches/20-optimisation: src/main/org/hornetq/core/buffers/impl and 53 other directories.
by do-not-reply@jboss.org
Author: timfox
Date: 2009-11-23 18:27:50 -0500 (Mon, 23 Nov 2009)
New Revision: 8387
Added:
branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/impl/
branches/20-optimisation/src/main/org/hornetq/core/buffers/impl/ChannelBufferWrapper.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/impl/ResetLimitWrappedHornetQBuffer.java
Removed:
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/HornetQDynamicChannelBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQHeapChannelBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/buffers/ResetLimitWrappedHornetQBuffer.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/HornetQBuffer.java
branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/ChannelBufferWrapper.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/buffers/
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/ByteBufferWrapperTest.java
Modified:
branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffers.java
branches/20-optimisation/src/main/org/hornetq/core/client/ClientMessage.java
branches/20-optimisation/src/main/org/hornetq/core/client/ClientSession.java
branches/20-optimisation/src/main/org/hornetq/core/client/LargeMessageBuffer.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/ClientSessionImpl.java
branches/20-optimisation/src/main/org/hornetq/core/client/impl/DelegatingSession.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/config/TransportConfiguration.java
branches/20-optimisation/src/main/org/hornetq/core/journal/EncodingSupport.java
branches/20-optimisation/src/main/org/hornetq/core/journal/SequentialFile.java
branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AIOSequentialFile.java
branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AbstractJournalUpdateTask.java
branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AbstractSequentialFile.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/JournalTransaction.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/BodyEncoder.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/PageTransactionInfoImpl.java
branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PagedMessageImpl.java
branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java
branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/BatchingIDGenerator.java
branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/JournalStorageManager.java
branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/LargeServerMessageImpl.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/BindingsImpl.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/RemotingConnection.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/AbstractBufferHandler.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/ChannelImpl.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/PacketDecoder.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/RemotingConnectionImpl.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/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/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/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/SessionReceiveLargeMessage.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/impl/wireformat/XidCodecSupport.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/BufferHandler.java
branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/Connection.java
branches/20-optimisation/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java
branches/20-optimisation/src/main/org/hornetq/core/server/ServerMessage.java
branches/20-optimisation/src/main/org/hornetq/core/server/cluster/impl/BroadcastGroupImpl.java
branches/20-optimisation/src/main/org/hornetq/core/server/cluster/impl/RemoteQueueBindingImpl.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/HornetQChannelHandler.java
branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder.java
branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/NettyConnection.java
branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQBytesMessage.java
branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQMessage.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/src/main/org/hornetq/utils/TypedProperties.java
branches/20-optimisation/src/main/org/hornetq/utils/UTF8Util.java
branches/20-optimisation/tests/jms-tests/src/org/hornetq/jms/tests/message/MessageHeaderTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/InterceptorTest.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/InVMNonPersistentMessageBufferTest.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/client/SelfExpandingBufferTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/TemporaryQueueTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/clientcrash/DummyInterceptor.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/bridge/BridgeTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/bridge/SimpleTransformer.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/distribution/SymmetricClusterTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/LargeMessageFailoverTest.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/http/NettyHttpTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java
branches/20-optimisation/tests/src/org/hornetq/tests/integration/largemessage/mock/MockConnector.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/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/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/journal/impl/fakes/FakeSequentialFileFactory.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/SimpleEncoding.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/postoffice/impl/BindingsImplTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/HornetQBufferTestBase.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/ChannelBufferWrapperTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyAcceptorFactoryTest.java
branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.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/core/remoting/impl/netty/NettyConnectorTest.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/HornetQAbstractChannelBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQAbstractChannelBuffer.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQAbstractChannelBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -1,804 +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 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)
- {
- if (src instanceof HornetQChannelBuffer)
- {
- writeBytes((HornetQChannelBuffer)src, srcIndex, length);
- }
- else
- {
- //There is a bug in Netty readBytes() which doesn't let us to do this, so we workaround it
-// byte[] bytes = new byte[length];
-//
-// src.readBytes(bytes, srcIndex, length);
-//
-// writeBytes(bytes);
-
- byte[] bytes = src.array();
-
- writeBytes(bytes, 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/HornetQBuffer.java (from rev 8367, branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/HornetQBuffer.java)
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQBuffer.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -0,0 +1,223 @@
+/*
+ * 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;
+
+import org.hornetq.utils.SimpleString;
+import org.jboss.netty.buffer.ChannelBuffer;
+
+/**
+ *
+ * A HornetQBuffer
+ *
+ * Much of it derived from Netty ChannelBuffer by Trustin Lee
+ *
+ * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
+ *
+ */
+public interface HornetQBuffer
+{
+ ChannelBuffer channelBuffer();
+
+ int capacity();
+
+ int readerIndex();
+
+ void readerIndex(int readerIndex);
+
+ int writerIndex();
+
+ void writerIndex(int writerIndex);
+
+ void setIndex(int readerIndex, int writerIndex);
+
+ int readableBytes();
+
+ int writableBytes();
+
+ boolean readable();
+
+ boolean writable();
+
+ void clear();
+
+ void markReaderIndex();
+
+ void resetReaderIndex();
+
+ void markWriterIndex();
+
+ void resetWriterIndex();
+
+ void discardReadBytes();
+
+ byte getByte(int index);
+
+ short getUnsignedByte(int index);
+
+ short getShort(int index);
+
+ int getUnsignedShort(int index);
+
+ int getInt(int index);
+
+ long getUnsignedInt(int index);
+
+ long getLong(int index);
+
+ void getBytes(int index, HornetQBuffer dst);
+
+ void getBytes(int index, HornetQBuffer dst, int length);
+
+ void getBytes(int index, HornetQBuffer dst, int dstIndex, int length);
+
+ void getBytes(int index, byte[] dst);
+
+ void getBytes(int index, byte[] dst, int dstIndex, int length);
+
+ void getBytes(int index, ByteBuffer dst);
+
+ char getChar(int index);
+
+ float getFloat(int index);
+
+ double getDouble(int index);
+
+ void setByte(int index, byte value);
+
+ void setShort(int index, short value);
+
+ void setInt(int index, int value);
+
+ void setLong(int index, long value);
+
+ void setBytes(int index, HornetQBuffer src);
+
+ void setBytes(int index, HornetQBuffer src, int length);
+
+ void setBytes(int index, HornetQBuffer src, int srcIndex, int length);
+
+ void setBytes(int index, byte[] src);
+
+ void setBytes(int index, byte[] src, int srcIndex, int length);
+
+ void setBytes(int index, ByteBuffer src);
+
+ void setChar(int index, char value);
+
+ void setFloat(int index, float value);
+
+ void setDouble(int index, double value);
+
+ byte readByte();
+
+ short readUnsignedByte();
+
+ short readShort();
+
+ int readUnsignedShort();
+
+ int readInt();
+
+ long readUnsignedInt();
+
+ long readLong();
+
+ char readChar();
+
+ float readFloat();
+
+ double readDouble();
+
+ HornetQBuffer readBytes(int length);
+
+ HornetQBuffer readSlice(int length);
+
+ void readBytes(HornetQBuffer dst);
+
+ void readBytes(HornetQBuffer dst, int length);
+
+ void readBytes(HornetQBuffer dst, int dstIndex, int length);
+
+ void readBytes(byte[] dst);
+
+ void readBytes(byte[] dst, int dstIndex, int length);
+
+ void readBytes(ByteBuffer dst);
+
+ void skipBytes(int length);
+
+ void writeByte(byte value);
+
+ void writeShort(short value);
+
+ void writeInt(int value);
+
+ void writeLong(long value);
+
+ void writeChar(char chr);
+
+ void writeFloat(float value);
+
+ void writeDouble(double value);
+
+ void writeBytes(HornetQBuffer src, int length);
+
+ void writeBytes(HornetQBuffer src, int srcIndex, int length);
+
+ void writeBytes(byte[] src);
+
+ void writeBytes(byte[] src, int srcIndex, int length);
+
+ void writeBytes(ByteBuffer src);
+
+ HornetQBuffer copy();
+
+ HornetQBuffer copy(int index, int length);
+
+ HornetQBuffer slice();
+
+ HornetQBuffer slice(int index, int length);
+
+ HornetQBuffer duplicate();
+
+ ByteBuffer toByteBuffer();
+
+ ByteBuffer toByteBuffer(int index, int length);
+
+ boolean readBoolean();
+
+ SimpleString readNullableSimpleString();
+
+ String readNullableString();
+
+ SimpleString readSimpleString();
+
+ String readString();
+
+ String readUTF() throws Exception;
+
+ void writeBoolean(boolean val);
+
+ void writeNullableSimpleString(SimpleString val);
+
+ void writeNullableString(String val);
+
+ void writeSimpleString(SimpleString val);
+
+ void writeString(String val);
+
+ void writeUTF(String utf) throws Exception;
+}
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQByteBufferBackedChannelBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQByteBufferBackedChannelBuffer.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQByteBufferBackedChannelBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -1,400 +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;
-
-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()
- {
- ByteBuffer newBuffer = ByteBuffer.allocate(buffer.remaining());
- newBuffer.put(buffer);
- newBuffer.flip();
- return new HornetQByteBufferBackedChannelBuffer(newBuffer);
- }
-
- public HornetQBuffer slice(int index, int length)
- {
- int currentPos = buffer.position();
- int currentLimit = buffer.limit();
-
- buffer.position(index);
- buffer.limit(length);
-
- ByteBuffer sliced = buffer.slice();
-
- buffer.position(currentPos);
- buffer.limit(currentLimit);
-
- return new HornetQByteBufferBackedChannelBuffer(sliced);
- }
-}
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffer.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -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 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();
-}
Modified: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffers.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffers.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQChannelBuffers.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,455 +15,47 @@
import java.nio.ByteBuffer;
+import org.hornetq.core.buffers.impl.ChannelBufferWrapper;
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+
+
/**
- * Creates a new {@link HornetQChannelBuffer} by allocating new space or by wrapping
- * or copying existing byte arrays, byte buffers and a string.
+ *
+ * A HornetQChannelBuffers
*
- * <h3>Use static import</h3>
- * This classes is intended to be used with Java 5 static import statement:
+ * @author tim
*
- * <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
+ public static HornetQBuffer dynamicBuffer(int estimatedLength)
{
- 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];
- }
+ return new ChannelBufferWrapper(ChannelBuffers.dynamicBuffer(estimatedLength));
}
-
- /**
- * 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)
+
+ public static HornetQBuffer dynamicBuffer(byte[] bytes)
{
- if (capacity == 0)
- {
- return EMPTY_BUFFER;
- }
- else
- {
- return new HornetQHeapChannelBuffer(capacity);
- }
+ ChannelBuffer buff = ChannelBuffers.dynamicBuffer(bytes.length);
+
+ buff.writeBytes(bytes);
+
+ return new ChannelBufferWrapper(buff);
}
- /**
- * 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)
+ public static HornetQBuffer wrappedBuffer(ByteBuffer underlying)
{
- return new HornetQDynamicChannelBuffer(initialBuffer);
+ return new ChannelBufferWrapper(ChannelBuffers.wrappedBuffer(underlying));
}
-
- /**
- * 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)
+
+ public static HornetQBuffer wrappedBuffer(byte[] underlying)
{
- return new HornetQDynamicChannelBuffer(estimatedLength);
+ return new ChannelBufferWrapper(ChannelBuffers.wrappedBuffer(underlying));
}
-
- /**
- * 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)
+ public static HornetQBuffer fixedBuffer(int size)
{
-
- HornetQChannelBuffer newbuffer = new HornetQByteBufferBackedChannelBuffer(buffer);
- newbuffer.clear();
- return newbuffer;
+ return new ChannelBufferWrapper(ChannelBuffers.buffer(size));
}
-
- /**
- * 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
- }
}
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQDynamicChannelBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQDynamicChannelBuffer.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQDynamicChannelBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -1,290 +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;
-
-/**
- * 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 static final Logger log = Logger.getLogger(HornetQDynamicChannelBuffer.class);
-
- 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());
- }
-
- public HornetQBuffer slice(int index, int length)
- {
- return buffer.slice(index, length);
- }
-
-}
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQHeapChannelBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQHeapChannelBuffer.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/HornetQHeapChannelBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -1,331 +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;
-
-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());
- }
-
- public HornetQBuffer slice(int index, int length)
- {
- //FIXME - this is currently very inefficient since we just copy the underlying array
- //We should really get rid of these versions of the Netty classes and just use the real
- //Netty classes, since these don't have all the functionality and fixes.
- //However this will introduce a dependency on Netty on core
-
- byte[] copied = new byte[length];
-
- System.arraycopy(array, index, copied, 0, length);
-
- return new HornetQHeapChannelBuffer(copied);
- }
-
-}
Deleted: branches/20-optimisation/src/main/org/hornetq/core/buffers/ResetLimitWrappedHornetQBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/ResetLimitWrappedHornetQBuffer.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/ResetLimitWrappedHornetQBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -1,327 +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 org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
-import org.hornetq.utils.SimpleString;
-
-/**
- * A ResetLimitWrappedHornetQBuffer
- *
- * @author Tim Fox
- *
- */
-public class ResetLimitWrappedHornetQBuffer implements HornetQBuffer
-{
- private static final Logger log = Logger.getLogger(ResetLimitWrappedHornetQBuffer.class);
-
- private final int limit;
-
- private HornetQBuffer buffer;
-
- public ResetLimitWrappedHornetQBuffer(final int limit, final HornetQBuffer buffer)
- {
- this.limit = limit;
-
- this.buffer = buffer;
-
- this.resetReaderIndex();
- }
-
- public void setBuffer(HornetQBuffer buffer)
- {
- this.buffer = buffer;
- }
-
- public byte[] array()
- {
- return buffer.array();
- }
-
- public int capacity()
- {
- return buffer.capacity();
- }
-
- public void clear()
- {
- buffer.clear();
-
- buffer.setIndex(limit, limit);
- }
-
- public HornetQBuffer copy()
- {
- return buffer.copy();
- }
-
- public Object getUnderlyingBuffer()
- {
- return buffer.getUnderlyingBuffer();
- }
-
- public boolean readable()
- {
- return buffer.readable();
- }
-
- public int readableBytes()
- {
- return buffer.readableBytes();
- }
-
- public boolean readBoolean()
- {
- return buffer.readBoolean();
- }
-
- public byte readByte()
- {
- return buffer.readByte();
- }
-
- public void readBytes(byte[] bytes, int offset, int length)
- {
- buffer.readBytes(bytes, offset, length);
- }
-
- public void readBytes(byte[] bytes)
- {
- buffer.readBytes(bytes);
- }
-
- public char readChar()
- {
- return buffer.readChar();
- }
-
- public double readDouble()
- {
- return buffer.readDouble();
- }
-
- public int readerIndex()
- {
- return buffer.readerIndex();
- }
-
- public void readerIndex(int readerIndex)
- {
- if (readerIndex < limit)
- {
- readerIndex = limit;
- }
-
- buffer.readerIndex(readerIndex);
- }
-
- public float readFloat()
- {
- return buffer.readFloat();
- }
-
- public int readInt()
- {
- return buffer.readInt();
- }
-
- public int readInt(int pos)
- {
- return buffer.readInt(pos);
- }
-
- public long readLong()
- {
- return buffer.readLong();
- }
-
- public SimpleString readNullableSimpleString()
- {
- return buffer.readNullableSimpleString();
- }
-
- public String readNullableString()
- {
- return buffer.readNullableString();
- }
-
- public short readShort()
- {
- return buffer.readShort();
- }
-
- public SimpleString readSimpleString()
- {
- return buffer.readSimpleString();
- }
-
- public String readString()
- {
- return buffer.readString();
- }
-
- public short readUnsignedByte()
- {
- return buffer.readUnsignedByte();
- }
-
- public int readUnsignedShort()
- {
- return buffer.readUnsignedShort();
- }
-
- public String readUTF() throws Exception
- {
- return buffer.readUTF();
- }
-
- public void resetReaderIndex()
- {
- buffer.readerIndex(limit);
- }
-
- public void resetWriterIndex()
- {
- buffer.writerIndex(limit);
- }
-
- public void setIndex(int readerIndex, int writerIndex)
- {
- if (readerIndex < limit)
- {
- readerIndex = limit;
- }
- if (writerIndex < limit)
- {
- writerIndex = limit;
- }
- buffer.setIndex(readerIndex, writerIndex);
- }
-
- public void setInt(int pos, int val)
- {
- buffer.setInt(pos, val);
- }
-
- public HornetQBuffer slice(int index, int length)
- {
- return buffer.slice(index, length);
- }
-
- public boolean writable()
- {
- return buffer.writable();
- }
-
- public int writableBytes()
- {
- return buffer.writableBytes();
- }
-
- public void writeBoolean(boolean val)
- {
- buffer.writeBoolean(val);
- }
-
- public void writeByte(byte val)
- {
- buffer.writeByte(val);
- }
-
- public void writeBytes(byte[] bytes, int offset, int length)
- {
- buffer.writeBytes(bytes, offset, length);
- }
-
- public void writeBytes(byte[] bytes)
- {
- buffer.writeBytes(bytes);
- }
-
- public void writeBytes(HornetQBuffer src, int srcIndex, int length)
- {
- buffer.writeBytes(src, srcIndex, length);
- }
-
- public void writeChar(char val)
- {
- buffer.writeChar(val);
- }
-
- public void writeDouble(double val)
- {
- buffer.writeDouble(val);
- }
-
- public void writeFloat(float val)
- {
- buffer.writeFloat(val);
- }
-
- public void writeInt(int val)
- {
- buffer.writeInt(val);
- }
-
- public void writeLong(long val)
- {
- buffer.writeLong(val);
- }
-
- public void writeNullableSimpleString(SimpleString val)
- {
- buffer.writeNullableSimpleString(val);
- }
-
- public void writeNullableString(String val)
- {
- buffer.writeNullableString(val);
- }
-
- public int writerIndex()
- {
- return buffer.writerIndex();
- }
-
- public void writerIndex(int writerIndex)
- {
- if (writerIndex < limit)
- {
- writerIndex = limit;
- }
- buffer.writerIndex(writerIndex);
- }
-
- public void writeShort(short val)
- {
- buffer.writeShort(val);
- }
-
- public void writeSimpleString(SimpleString val)
- {
- buffer.writeSimpleString(val);
- }
-
- public void writeString(String val)
- {
- buffer.writeString(val);
- }
-
- public void writeUTF(String utf) throws Exception
- {
- buffer.writeUTF(utf);
- }
-
-}
Copied: branches/20-optimisation/src/main/org/hornetq/core/buffers/impl/ChannelBufferWrapper.java (from rev 8367, branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/ChannelBufferWrapper.java)
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/impl/ChannelBufferWrapper.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/impl/ChannelBufferWrapper.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -0,0 +1,573 @@
+/*
+ * 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.impl;
+
+import java.nio.ByteBuffer;
+
+import org.hornetq.core.buffers.HornetQBuffer;
+import org.hornetq.core.logging.Logger;
+import org.hornetq.utils.DataConstants;
+import org.hornetq.utils.SimpleString;
+import org.hornetq.utils.UTF8Util;
+import org.jboss.netty.buffer.ChannelBuffer;
+
+/**
+ *
+ * A ChannelBufferWrapper
+ *
+ * @author Tim Fox
+ *
+ *
+ */
+public class ChannelBufferWrapper implements HornetQBuffer
+{
+ private static final Logger log = Logger.getLogger(ChannelBufferWrapper.class);
+
+ protected ChannelBuffer buffer;
+
+ public ChannelBufferWrapper(final ChannelBuffer buffer)
+ {
+ this.buffer = buffer;
+ }
+
+ public boolean readBoolean()
+ {
+ return readByte() != 0;
+ }
+
+ public SimpleString readNullableSimpleString()
+ {
+ int b = readByte();
+ if (b == DataConstants.NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return readSimpleString();
+ }
+ }
+
+ public String readNullableString()
+ {
+ int b = readByte();
+ if (b == DataConstants.NULL)
+ {
+ return null;
+ }
+ else
+ {
+ return readString();
+ }
+ }
+
+ public SimpleString readSimpleString()
+ {
+ int len = readInt();
+ byte[] data = new byte[len];
+ readBytes(data);
+ return new SimpleString(data);
+ }
+
+ public String readString()
+ {
+ int len = readInt();
+ char[] chars = new char[len];
+ for (int i = 0; i < len; i++)
+ {
+ chars[i] = (char)readShort();
+ }
+ return new String(chars);
+ }
+
+ public String readUTF() throws Exception
+ {
+ return UTF8Util.readUTF(this);
+ }
+
+ public void writeBoolean(final boolean val)
+ {
+ writeByte((byte)(val ? -1 : 0));
+ }
+
+ public void writeNullableSimpleString(final SimpleString val)
+ {
+ if (val == null)
+ {
+ writeByte(DataConstants.NULL);
+ }
+ else
+ {
+ writeByte(DataConstants.NOT_NULL);
+ writeSimpleString(val);
+ }
+ }
+
+ public void writeNullableString(final String val)
+ {
+ if (val == null)
+ {
+ writeByte(DataConstants.NULL);
+ }
+ else
+ {
+ writeByte(DataConstants.NOT_NULL);
+ writeString(val);
+ }
+ }
+
+ public void writeSimpleString(final SimpleString val)
+ {
+ byte[] data = val.getData();
+ writeInt(data.length);
+ writeBytes(data);
+ }
+
+ public void writeString(final String val)
+ {
+ writeInt(val.length());
+ for (int i = 0; i < val.length(); i++)
+ {
+ writeShort((short)val.charAt(i));
+ }
+ }
+
+ public void writeUTF(final String utf) throws Exception
+ {
+ UTF8Util.saveUTF(this, utf);
+ }
+
+
+ public int capacity()
+ {
+ return buffer.capacity();
+ }
+
+
+ public ChannelBuffer channelBuffer()
+ {
+ return buffer;
+ }
+
+ public void clear()
+ {
+ buffer.clear();
+ }
+
+ public HornetQBuffer copy()
+ {
+ return new ChannelBufferWrapper(buffer.copy());
+ }
+
+ public HornetQBuffer copy(int index, int length)
+ {
+ return new ChannelBufferWrapper(buffer.copy(index, length));
+ }
+
+ public void discardReadBytes()
+ {
+ buffer.discardReadBytes();
+ }
+
+ public HornetQBuffer duplicate()
+ {
+ return new ChannelBufferWrapper(buffer.duplicate());
+ }
+
+ public byte getByte(int index)
+ {
+ return buffer.getByte(index);
+ }
+
+ public void getBytes(int index, byte[] dst, int dstIndex, int length)
+ {
+ buffer.getBytes(index, dst, dstIndex, length);
+ }
+
+ public void getBytes(int index, byte[] dst)
+ {
+ buffer.getBytes(index, dst);
+ }
+
+ public void getBytes(int index, ByteBuffer dst)
+ {
+ buffer.getBytes(index, dst);
+ }
+
+ public void getBytes(int index, HornetQBuffer dst, int dstIndex, int length)
+ {
+ buffer.getBytes(index, dst.channelBuffer(), dstIndex, length);
+ }
+
+ public void getBytes(int index, HornetQBuffer dst, int length)
+ {
+ buffer.getBytes(index, dst.channelBuffer(), length);
+ }
+
+ public void getBytes(int index, HornetQBuffer dst)
+ {
+ buffer.getBytes(index, dst.channelBuffer());
+ }
+
+ public char getChar(int index)
+ {
+ return (char)buffer.getShort(index);
+ }
+
+ public double getDouble(int index)
+ {
+ return Double.longBitsToDouble(buffer.getLong(index));
+ }
+
+ public float getFloat(int index)
+ {
+ return Float.intBitsToFloat(buffer.getInt(index));
+ }
+
+ public int getInt(int index)
+ {
+ return buffer.getInt(index);
+ }
+
+ public long getLong(int index)
+ {
+ return buffer.getLong(index);
+ }
+
+ public short getShort(int index)
+ {
+ return buffer.getShort(index);
+ }
+
+ public short getUnsignedByte(int index)
+ {
+ return buffer.getUnsignedByte(index);
+ }
+
+ public long getUnsignedInt(int index)
+ {
+ return buffer.getUnsignedInt(index);
+ }
+
+ public int getUnsignedShort(int index)
+ {
+ return buffer.getUnsignedShort(index);
+ }
+
+ public void markReaderIndex()
+ {
+ buffer.markReaderIndex();
+ }
+
+ public void markWriterIndex()
+ {
+ buffer.markWriterIndex();
+ }
+
+ public boolean readable()
+ {
+ return buffer.readable();
+ }
+
+ public int readableBytes()
+ {
+ return buffer.readableBytes();
+ }
+
+ public byte readByte()
+ {
+ return buffer.readByte();
+ }
+
+ public void readBytes(byte[] dst, int dstIndex, int length)
+ {
+ buffer.readBytes(dst, dstIndex, length);
+ }
+
+ public void readBytes(byte[] dst)
+ {
+ buffer.readBytes(dst);
+ }
+
+ public void readBytes(ByteBuffer dst)
+ {
+ buffer.readBytes(dst);
+ }
+
+ public void readBytes(HornetQBuffer dst, int dstIndex, int length)
+ {
+ buffer.readBytes(dst.channelBuffer(), dstIndex, length);
+ }
+
+ public void readBytes(HornetQBuffer dst, int length)
+ {
+ buffer.readBytes(dst.channelBuffer(), length);
+ }
+
+ public void readBytes(HornetQBuffer dst)
+ {
+ buffer.readBytes(dst.channelBuffer());
+ }
+
+ public HornetQBuffer readBytes(int length)
+ {
+ return new ChannelBufferWrapper(buffer.readBytes(length));
+ }
+
+ public char readChar()
+ {
+ return (char)buffer.readShort();
+ }
+
+ public double readDouble()
+ {
+ return Double.longBitsToDouble(buffer.readLong());
+ }
+
+ public int readerIndex()
+ {
+ return buffer.readerIndex();
+ }
+
+ public void readerIndex(int readerIndex)
+ {
+ buffer.readerIndex(readerIndex);
+ }
+
+ public float readFloat()
+ {
+ return Float.intBitsToFloat(buffer.readInt());
+ }
+
+ public int readInt()
+ {
+ return buffer.readInt();
+ }
+
+ public long readLong()
+ {
+ return buffer.readLong();
+ }
+
+ public short readShort()
+ {
+ return buffer.readShort();
+ }
+
+ public HornetQBuffer readSlice(int length)
+ {
+ return new ChannelBufferWrapper(buffer.readSlice(length));
+ }
+
+ public short readUnsignedByte()
+ {
+ return buffer.readUnsignedByte();
+ }
+
+ public long readUnsignedInt()
+ {
+ return buffer.readUnsignedInt();
+ }
+
+ public int readUnsignedShort()
+ {
+ return buffer.readUnsignedShort();
+ }
+
+ public void resetReaderIndex()
+ {
+ buffer.resetReaderIndex();
+ }
+
+ public void resetWriterIndex()
+ {
+ buffer.resetWriterIndex();
+ }
+
+ public void setByte(int index, byte value)
+ {
+ buffer.setByte(index, value);
+ }
+
+ public void setBytes(int index, byte[] src, int srcIndex, int length)
+ {
+ buffer.setBytes(index, src, srcIndex, length);
+ }
+
+ public void setBytes(int index, byte[] src)
+ {
+ buffer.setBytes(index, src);
+ }
+
+ public void setBytes(int index, ByteBuffer src)
+ {
+ buffer.setBytes(index, src);
+ }
+
+ public void setBytes(int index, HornetQBuffer src, int srcIndex, int length)
+ {
+ buffer.setBytes(index, src.channelBuffer(), srcIndex, length);
+ }
+
+ public void setBytes(int index, HornetQBuffer src, int length)
+ {
+ buffer.setBytes(index, src.channelBuffer(), length);
+ }
+
+ public void setBytes(int index, HornetQBuffer src)
+ {
+ buffer.setBytes(index, src.channelBuffer());
+ }
+
+ public void setChar(int index, char value)
+ {
+ buffer.setShort(index, (short)value);
+ }
+
+ public void setDouble(int index, double value)
+ {
+ buffer.setLong(index, Double.doubleToLongBits(value));
+ }
+
+ public void setFloat(int index, float value)
+ {
+ buffer.setInt(index, Float.floatToIntBits(value));
+ }
+
+ public void setIndex(int readerIndex, int writerIndex)
+ {
+ buffer.setIndex(readerIndex, writerIndex);
+ }
+
+ public void setInt(int index, int value)
+ {
+ buffer.setInt(index, value);
+ }
+
+ public void setLong(int index, long value)
+ {
+ buffer.setLong(index, value);
+ }
+
+ public void setShort(int index, short value)
+ {
+ buffer.setShort(index, value);
+ }
+
+ public void skipBytes(int length)
+ {
+ buffer.skipBytes(length);
+ }
+
+ public HornetQBuffer slice()
+ {
+ return new ChannelBufferWrapper(buffer.slice());
+ }
+
+ public HornetQBuffer slice(int index, int length)
+ {
+ return new ChannelBufferWrapper(buffer.slice(index, length));
+ }
+
+ public ByteBuffer toByteBuffer()
+ {
+ return buffer.toByteBuffer();
+ }
+
+ public ByteBuffer toByteBuffer(int index, int length)
+ {
+ return buffer.toByteBuffer(index, length);
+ }
+
+ public boolean writable()
+ {
+ return buffer.writable();
+ }
+
+ public int writableBytes()
+ {
+ return buffer.writableBytes();
+ }
+
+ public void writeByte(byte value)
+ {
+ buffer.writeByte(value);
+ }
+
+ public void writeBytes(byte[] src, int srcIndex, int length)
+ {
+ buffer.writeBytes(src, srcIndex, length);
+ }
+
+ public void writeBytes(byte[] src)
+ {
+ buffer.writeBytes(src);
+ }
+
+ public void writeBytes(ByteBuffer src)
+ {
+ buffer.writeBytes(src);
+ }
+
+ public void writeBytes(HornetQBuffer src, int srcIndex, int length)
+ {
+ buffer.writeBytes(src.channelBuffer(), srcIndex, length);
+ }
+
+ public void writeBytes(HornetQBuffer src, int length)
+ {
+ buffer.writeBytes(src.channelBuffer(), length);
+ }
+
+ public void writeChar(char chr)
+ {
+ buffer.writeShort((short)chr);
+ }
+
+ public void writeDouble(double value)
+ {
+ buffer.writeLong(Double.doubleToLongBits(value));
+ }
+
+ public void writeFloat(float value)
+ {
+ buffer.writeInt(Float.floatToIntBits(value));
+ }
+
+ public void writeInt(int value)
+ {
+ buffer.writeInt(value);
+ }
+
+ public void writeLong(long value)
+ {
+ buffer.writeLong(value);
+ }
+
+ public int writerIndex()
+ {
+ return buffer.writerIndex();
+ }
+
+ public void writerIndex(int writerIndex)
+ {
+ buffer.writerIndex(writerIndex);
+ }
+
+ public void writeShort(short value)
+ {
+ buffer.writeShort(value);
+ }
+
+}
Copied: branches/20-optimisation/src/main/org/hornetq/core/buffers/impl/ResetLimitWrappedHornetQBuffer.java (from rev 8368, branches/20-optimisation/src/main/org/hornetq/core/buffers/ResetLimitWrappedHornetQBuffer.java)
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/buffers/impl/ResetLimitWrappedHornetQBuffer.java (rev 0)
+++ branches/20-optimisation/src/main/org/hornetq/core/buffers/impl/ResetLimitWrappedHornetQBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -0,0 +1,98 @@
+/*
+ * 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.impl;
+
+import org.hornetq.core.buffers.HornetQBuffer;
+import org.hornetq.core.logging.Logger;
+
+/**
+ * A ResetLimitWrappedHornetQBuffer
+ *
+ * @author Tim Fox
+ *
+ */
+public class ResetLimitWrappedHornetQBuffer extends ChannelBufferWrapper
+{
+ private static final Logger log = Logger.getLogger(ResetLimitWrappedHornetQBuffer.class);
+
+ private final int limit;
+
+ public ResetLimitWrappedHornetQBuffer(final int limit, final HornetQBuffer buffer)
+ {
+ super(buffer.channelBuffer());
+
+ this.limit = limit;
+
+ if (writerIndex() < limit)
+ {
+ writerIndex(limit);
+ }
+
+ readerIndex(limit);
+ }
+
+ public void setBuffer(HornetQBuffer buffer)
+ {
+ this.buffer = buffer.channelBuffer();
+ }
+
+ public void clear()
+ {
+ buffer.clear();
+
+ buffer.setIndex(limit, limit);
+ }
+
+ public void readerIndex(int readerIndex)
+ {
+ if (readerIndex < limit)
+ {
+ readerIndex = limit;
+ }
+
+ buffer.readerIndex(readerIndex);
+ }
+
+ public void resetReaderIndex()
+ {
+ buffer.readerIndex(limit);
+ }
+
+ public void resetWriterIndex()
+ {
+ buffer.writerIndex(limit);
+ }
+
+ public void setIndex(int readerIndex, int writerIndex)
+ {
+ if (readerIndex < limit)
+ {
+ readerIndex = limit;
+ }
+ if (writerIndex < limit)
+ {
+ writerIndex = limit;
+ }
+ buffer.setIndex(readerIndex, writerIndex);
+ }
+
+ public void writerIndex(int writerIndex)
+ {
+ if (writerIndex < limit)
+ {
+ writerIndex = limit;
+ }
+ buffer.writerIndex(writerIndex);
+ }
+}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/ClientMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -34,9 +34,12 @@
void setDeliveryCount(int deliveryCount);
void acknowledge() throws HornetQException;
-
- //FIXME - the following are only used for large messages - they should be put somewhere else:
+ int getBodySize();
+
+ //FIXME - these are only used for large messages - they should be moved elsewhere
+
+
/** Sets the OutputStream that will receive the content of a message received in a non blocking way
* @throws HornetQException */
void setOutputStream(OutputStream out) throws HornetQException;
@@ -53,6 +56,5 @@
boolean waitOutputStreamCompletion(long timeMilliseconds) throws HornetQException;
void setBodyInputStream(InputStream bodyInputStream);
-
- int getBodySize();
+
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/ClientSession.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/ClientSession.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/ClientSession.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,11 +15,11 @@
import javax.transaction.xa.XAResource;
+import org.hornetq.core.buffers.HornetQBuffer;
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;
/*
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/LargeMessageBuffer.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/LargeMessageBuffer.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/LargeMessageBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,8 +15,8 @@
import java.io.OutputStream;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
* A LargeMessageBufferImpl
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientMessageImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -17,13 +17,13 @@
import java.io.InputStream;
import java.io.OutputStream;
-import org.hornetq.core.buffers.ResetLimitWrappedHornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
+import org.hornetq.core.buffers.impl.ResetLimitWrappedHornetQBuffer;
import org.hornetq.core.client.LargeMessageBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
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.utils.DataConstants;
import org.hornetq.utils.SimpleString;
@@ -68,11 +68,9 @@
final long expiration,
final long timestamp,
final byte priority,
- final HornetQBuffer buffer)
+ final int initialMessageBufferSize)
{
- super(type, durable, expiration, timestamp, priority, buffer);
-
- this.resetBuffer();
+ super(type, durable, expiration, timestamp, priority, initialMessageBufferSize);
}
public void onReceipt(final ClientConsumerInternal consumer)
@@ -174,7 +172,7 @@
{
try
{
- out.write(this.getWholeBuffer().array());
+ out.write(this.getWholeBuffer().toByteBuffer().array());
}
catch (IOException e)
{
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientMessageInternal.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.core.client.impl;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.ClientMessage;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
* A ClientMessageInternal
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientProducerCreditsImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -64,8 +64,6 @@
{
// credits += offset;
- // log.info("trying to acquire " + credits);
-
checkCredits(credits);
semaphore.acquire(credits);
@@ -73,8 +71,6 @@
public void receiveCredits(final int credits, final int offset)
{
- // log.info("receiving credits " + credits);
-
synchronized (this)
{
arriving -= credits;
@@ -120,8 +116,7 @@
}
if (toRequest != -1)
- {
- //log.info("sending request for credits " + toRequest);
+ {
requestCredits(toRequest);
}
}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientProducerImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.InputStream;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
@@ -28,7 +29,6 @@
import org.hornetq.core.remoting.impl.wireformat.SessionSendContinuationMessage;
import org.hornetq.core.remoting.impl.wireformat.SessionSendLargeMessage;
import org.hornetq.core.remoting.impl.wireformat.SessionSendMessage;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.SimpleString;
import org.hornetq.utils.TokenBucketLimiter;
import org.hornetq.utils.UUIDGenerator;
@@ -308,11 +308,11 @@
msg.getWholeBuffer().readerIndex(0);
}
- HornetQBuffer headerBuffer = HornetQChannelBuffers.buffer(headerSize);
+ HornetQBuffer headerBuffer = HornetQChannelBuffers.fixedBuffer(headerSize);
msg.encodeHeadersAndProperties(headerBuffer);
- SessionSendLargeMessage initialChunk = new SessionSendLargeMessage(headerBuffer.array());
+ SessionSendLargeMessage initialChunk = new SessionSendLargeMessage(headerBuffer.toByteBuffer().array());
channel.send(initialChunk);
@@ -359,7 +359,7 @@
final int chunkLength = Math.min((int)(bodySize - pos), minLargeMessageSize);
- final HornetQBuffer bodyBuffer = HornetQChannelBuffers.buffer(chunkLength);
+ final HornetQBuffer bodyBuffer = HornetQChannelBuffers.fixedBuffer(chunkLength);
context.encode(bodyBuffer, chunkLength);
@@ -367,7 +367,7 @@
lastChunk = pos >= bodySize;
- final SessionSendContinuationMessage chunk = new SessionSendContinuationMessage(bodyBuffer.array(),
+ final SessionSendContinuationMessage chunk = new SessionSendContinuationMessage(bodyBuffer.toByteBuffer().array(),
!lastChunk,
lastChunk && sendBlocking);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/ClientSessionImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -26,6 +26,7 @@
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -74,7 +75,6 @@
import org.hornetq.core.remoting.impl.wireformat.SessionXASetTimeoutResponseMessage;
import org.hornetq.core.remoting.impl.wireformat.SessionXAStartMessage;
import org.hornetq.core.remoting.spi.Connection;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.ConcurrentHashSet;
import org.hornetq.utils.IDGenerator;
import org.hornetq.utils.SimpleIDGenerator;
@@ -518,9 +518,7 @@
final long timestamp,
final byte priority)
{
- HornetQBuffer body = remotingConnection.createBuffer(initialMessagePacketSize);
-
- return new ClientMessageImpl(type, durable, expiration, timestamp, priority, body);
+ return new ClientMessageImpl(type, durable, expiration, timestamp, priority, initialMessagePacketSize);
}
public ClientMessage createClientMessage(final byte type, final boolean durable)
@@ -690,7 +688,7 @@
if (consumer != null)
{
- ClientMessageInternal clMessage = message.getClientMessage();
+ ClientMessageInternal clMessage = (ClientMessageInternal)message.getMessage();
if (trace)
{
@@ -699,7 +697,7 @@
clMessage.setFlowControlSize(message.getPacketSize());
- consumer.handleMessage(message.getClientMessage());
+ consumer.handleMessage(clMessage);
}
}
@@ -948,7 +946,7 @@
{
SessionSendMessage ssm = (SessionSendMessage)packet;
- sendAckHandler.sendAcknowledged(ssm.getClientMessage());
+ sendAckHandler.sendAcknowledged(ssm.getMessage());
}
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/client/impl/DelegatingSession.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/client/impl/DelegatingSession.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/DelegatingSession.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -19,6 +19,7 @@
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -32,7 +33,6 @@
import org.hornetq.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
import org.hornetq.core.remoting.impl.wireformat.SessionReceiveLargeMessage;
import org.hornetq.core.remoting.impl.wireformat.SessionReceiveMessage;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.ConcurrentHashSet;
import org.hornetq.utils.SimpleString;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/FailoverManagerImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -25,6 +25,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.ClientSession;
import org.hornetq.core.client.ClientSessionFactory;
import org.hornetq.core.client.SessionFailureListener;
@@ -47,7 +48,6 @@
import org.hornetq.core.remoting.spi.ConnectionLifeCycleListener;
import org.hornetq.core.remoting.spi.Connector;
import org.hornetq.core.remoting.spi.ConnectorFactory;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.version.Version;
import org.hornetq.utils.ConcurrentHashSet;
import org.hornetq.utils.ConfigurationHelper;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/client/impl/LargeMessageBufferImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -26,15 +26,15 @@
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
-import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.LargeMessageBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.SimpleString;
import org.hornetq.utils.UTF8Util;
+import org.jboss.netty.buffer.ChannelBuffer;
/**
* This class aggregates several SessionReceiveContinuationMessages as it was being handled by a single buffer.
@@ -44,7 +44,7 @@
*
*
*/
-public class LargeMessageBufferImpl implements HornetQChannelBuffer, LargeMessageBuffer
+public class LargeMessageBufferImpl implements LargeMessageBuffer
{
// Constants -----------------------------------------------------
@@ -359,7 +359,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 HornetQChannelBuffer dst, final int dstIndex, final int length)
+ public void getBytes(final int index, final HornetQBuffer dst, final int dstIndex, final int length)
{
byte[] destBytes = new byte[length];
getBytes(index, destBytes);
@@ -369,7 +369,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 HornetQChannelBuffer dst, final int dstIndex, final int length)
+ public void getBytes(final long index, final HornetQBuffer dst, final int dstIndex, final int length)
{
byte[] destBytes = new byte[length];
getBytes(index, destBytes);
@@ -520,7 +520,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 HornetQChannelBuffer src, final int srcIndex, final int length)
+ public void setBytes(final int index, final HornetQBuffer src, final int srcIndex, final int length)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
@@ -762,12 +762,12 @@
}
}
- public void getBytes(final int index, final HornetQChannelBuffer dst)
+ public void getBytes(final int index, final HornetQBuffer dst)
{
getBytes(index, dst, dst.writableBytes());
}
- public void getBytes(final int index, final HornetQChannelBuffer dst, final int length)
+ public void getBytes(final int index, final HornetQBuffer dst, final int length)
{
if (length > dst.writableBytes())
{
@@ -782,12 +782,12 @@
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void setBytes(final int index, final HornetQChannelBuffer src)
+ public void setBytes(final int index, final HornetQBuffer src)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void setBytes(final int index, final HornetQChannelBuffer src, final int length)
+ public void setBytes(final int index, final HornetQBuffer src, final int length)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
@@ -867,12 +867,12 @@
readBytes(dst, 0, dst.length);
}
- public void readBytes(final HornetQChannelBuffer dst)
+ public void readBytes(final HornetQBuffer dst)
{
readBytes(dst, dst.writableBytes());
}
- public void readBytes(final HornetQChannelBuffer dst, final int length)
+ public void readBytes(final HornetQBuffer dst, final int length)
{
if (length > dst.writableBytes())
{
@@ -882,7 +882,7 @@
dst.writerIndex(dst.writerIndex() + length);
}
- public void readBytes(final HornetQChannelBuffer dst, final int dstIndex, final int length)
+ public void readBytes(final HornetQBuffer dst, final int dstIndex, final int length)
{
getBytes(readerIndex, dst, dstIndex, length);
readerIndex += length;
@@ -951,32 +951,22 @@
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void writeBytes(final HornetQChannelBuffer src)
+ public void writeBytes(final HornetQBuffer src)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void writeBytes(final HornetQChannelBuffer src, final int length)
+ public void writeBytes(final HornetQBuffer src, final int length)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void writeBytes(final HornetQBuffer src, final int srcIndex, final int length)
- {
- throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
- }
-
- public void writeBytes(final HornetQChannelBuffer src, final int srcIndex, final int length)
- {
- throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
- }
-
public void writeBytes(final ByteBuffer src)
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
- public void writeBytes(final InputStream in, final int length) throws IOException
+ public int writeBytes(final InputStream in, final int length) throws IOException
{
throw new IllegalAccessError(READ_ONLY_ERROR_MESSAGE);
}
@@ -1190,7 +1180,7 @@
/* (non-Javadoc)
* @see org.hornetq.core.buffers.ChannelBuffer#compareTo(org.hornetq.core.buffers.ChannelBuffer)
*/
- public int compareTo(final HornetQChannelBuffer buffer)
+ public int compareTo(final HornetQBuffer buffer)
{
return -1;
}
@@ -1448,4 +1438,82 @@
}
+ public ChannelBuffer channelBuffer()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public HornetQBuffer copy(int index, int length)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public HornetQBuffer duplicate()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public char getChar(int index)
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public double getDouble(int index)
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public float getFloat(int index)
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public HornetQBuffer readBytes(int length)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public HornetQBuffer readSlice(int length)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void setChar(int index, char value)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setDouble(int index, double value)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setFloat(int index, float value)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public HornetQBuffer slice()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void writeBytes(HornetQBuffer src, int srcIndex, int length)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/cluster/impl/DiscoveryGroupImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -23,6 +23,7 @@
import java.util.List;
import java.util.Map;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.cluster.DiscoveryEntry;
import org.hornetq.core.cluster.DiscoveryGroup;
@@ -32,7 +33,6 @@
import org.hornetq.core.management.Notification;
import org.hornetq.core.management.NotificationService;
import org.hornetq.core.management.NotificationType;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.Pair;
import org.hornetq.utils.SimpleString;
import org.hornetq.utils.TypedProperties;
Modified: branches/20-optimisation/src/main/org/hornetq/core/config/TransportConfiguration.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/config/TransportConfiguration.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/config/TransportConfiguration.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -16,7 +16,7 @@
import java.util.HashMap;
import java.util.Map;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.UUIDGenerator;
/**
Modified: branches/20-optimisation/src/main/org/hornetq/core/journal/EncodingSupport.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/journal/EncodingSupport.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/EncodingSupport.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.journal;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
/**
*
Modified: branches/20-optimisation/src/main/org/hornetq/core/journal/SequentialFile.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/journal/SequentialFile.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/SequentialFile.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,8 +15,8 @@
import java.nio.ByteBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.impl.TimedBuffer;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
*
Modified: branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AIOSequentialFile.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AIOSequentialFile.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AIOSequentialFile.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -25,11 +25,11 @@
import org.hornetq.core.asyncio.AsynchronousFile;
import org.hornetq.core.asyncio.BufferCallback;
import org.hornetq.core.asyncio.impl.AsynchronousFileImpl;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
*
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AbstractJournalUpdateTask.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -18,12 +18,11 @@
import java.util.List;
import java.util.Set;
-import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.ConcurrentHashSet;
import org.hornetq.utils.Pair;
@@ -57,7 +56,7 @@
protected int nextOrderingID;
- private HornetQChannelBuffer writingChannel;
+ private HornetQBuffer writingChannel;
private final Set<Long> recordsSnapshot = new ConcurrentHashSet<Long>();
@@ -98,7 +97,7 @@
{
controlFile.open(1);
- HornetQChannelBuffer renameBuffer = HornetQChannelBuffers.dynamicBuffer(1);
+ HornetQBuffer renameBuffer = HornetQChannelBuffers.dynamicBuffer(1);
renameBuffer.writeInt(-1);
renameBuffer.writeInt(-1);
@@ -155,13 +154,13 @@
JournalImpl.writeAddRecord(-1,
1,
(byte)0,
- new JournalImpl.ByteArrayEncoding(filesToRename.array()),
- JournalImpl.SIZE_ADD_RECORD + filesToRename.array().length,
+ new JournalImpl.ByteArrayEncoding(filesToRename.toByteBuffer().array()),
+ JournalImpl.SIZE_ADD_RECORD + filesToRename.toByteBuffer().array().length,
renameBuffer);
ByteBuffer writeBuffer = fileFactory.newBuffer(renameBuffer.writerIndex());
- writeBuffer.put(renameBuffer.array(), 0, renameBuffer.writerIndex());
+ writeBuffer.put(renameBuffer.toByteBuffer().array(), 0, renameBuffer.writerIndex());
writeBuffer.rewind();
@@ -226,7 +225,7 @@
/**
* @return the writingChannel
*/
- protected HornetQChannelBuffer getWritingChannel()
+ protected HornetQBuffer getWritingChannel()
{
return writingChannel;
}
Modified: branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AbstractSequentialFile.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AbstractSequentialFile.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/AbstractSequentialFile.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -18,11 +18,11 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
* A AbstractSequentialFile
@@ -163,12 +163,12 @@
{
if (timedBuffer != null)
{
- timedBuffer.addBytes(bytes.array(), sync, callback);
+ timedBuffer.addBytes(bytes.toByteBuffer().array(), sync, callback);
}
else
{
ByteBuffer buffer = factory.newBuffer(bytes.capacity());
- buffer.put(bytes.array());
+ buffer.put(bytes.toByteBuffer().array());
buffer.rewind();
writeDirect(buffer, sync, callback);
}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalCompactor.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -21,7 +21,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
-import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.RecordInfo;
import org.hornetq.core.journal.SequentialFile;
@@ -83,7 +83,7 @@
}
else
{
- HornetQChannelBuffer input = HornetQChannelBuffers.wrappedBuffer(records.get(0).data);
+ HornetQBuffer 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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -41,7 +41,7 @@
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.EncodingSupport;
import org.hornetq.core.journal.IOCompletion;
@@ -54,7 +54,6 @@
import org.hornetq.core.journal.TestableJournal;
import org.hornetq.core.journal.TransactionFailureCallback;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.Pair;
import org.hornetq.utils.concurrent.LinkedBlockingDeque;
@@ -322,7 +321,7 @@
final EncodingSupport transactionData,
final int size,
final int numberOfRecords,
- final HornetQChannelBuffer bb) throws Exception
+ final HornetQBuffer bb) throws Exception
{
bb.writeByte(recordType);
bb.writeInt(fileID); // skip ID part
@@ -356,7 +355,7 @@
final byte recordType,
final EncodingSupport record,
final int size,
- final HornetQChannelBuffer bb)
+ final HornetQBuffer bb)
{
bb.writeByte(UPDATE_RECORD_TX);
bb.writeInt(fileID);
@@ -372,7 +371,7 @@
* @param txID
* @param bb
*/
- public static void writeRollback(final int fileID, final long txID, HornetQChannelBuffer bb)
+ public static void writeRollback(final int fileID, final long txID, HornetQBuffer bb)
{
bb.writeByte(ROLLBACK_RECORD);
bb.writeInt(fileID);
@@ -392,7 +391,7 @@
final byte recordType,
final EncodingSupport record,
final int size,
- final HornetQChannelBuffer bb)
+ final HornetQBuffer bb)
{
bb.writeByte(UPDATE_RECORD);
bb.writeInt(fileId);
@@ -415,7 +414,7 @@
final byte recordType,
final EncodingSupport record,
final int size,
- final HornetQChannelBuffer bb)
+ final HornetQBuffer bb)
{
bb.writeByte(ADD_RECORD);
bb.writeInt(fileId);
@@ -431,7 +430,7 @@
* @param size
* @param bb
*/
- public static void writeDeleteRecord(final int fileId, final long id, int size, HornetQChannelBuffer bb)
+ public static void writeDeleteRecord(final int fileId, final long id, int size, HornetQBuffer bb)
{
bb.writeByte(DELETE_RECORD);
bb.writeInt(fileId);
@@ -451,7 +450,7 @@
final long id,
final EncodingSupport record,
final int size,
- final HornetQChannelBuffer bb)
+ final HornetQBuffer bb)
{
bb.writeByte(DELETE_RECORD_TX);
bb.writeInt(fileID);
@@ -480,7 +479,7 @@
final byte recordType,
final EncodingSupport record,
final int size,
- final HornetQChannelBuffer bb)
+ final HornetQBuffer bb)
{
bb.writeByte(ADD_RECORD_TX);
bb.writeInt(fileID);
@@ -858,7 +857,7 @@
{
int size = SIZE_ADD_RECORD + record.getEncodeSize();
- HornetQChannelBuffer bb = newBuffer(size);
+ HornetQBuffer bb = newBuffer(size);
writeAddRecord(-1, id, recordType, record, size, bb); // fileID will be filled later
@@ -918,7 +917,7 @@
int size = SIZE_UPDATE_RECORD + record.getEncodeSize();
- HornetQChannelBuffer bb = newBuffer(size);
+ HornetQBuffer bb = newBuffer(size);
writeUpdateRecord(-1, id, recordType, record, size, bb);
@@ -982,7 +981,7 @@
int size = SIZE_DELETE_RECORD;
- HornetQChannelBuffer bb = newBuffer(size);
+ HornetQBuffer bb = newBuffer(size);
writeDeleteRecord(-1, id, size, bb);
@@ -1044,7 +1043,7 @@
int size = SIZE_ADD_RECORD_TX + record.getEncodeSize();
- HornetQChannelBuffer bb = newBuffer(size);
+ HornetQBuffer bb = newBuffer(size);
writeAddRecordTX(-1, txID, id, recordType, record, size, bb);
@@ -1093,7 +1092,7 @@
int size = SIZE_UPDATE_RECORD_TX + record.getEncodeSize();
- HornetQChannelBuffer bb = newBuffer(size);
+ HornetQBuffer bb = newBuffer(size);
writeUpdateRecordTX(-1, txID, id, recordType, record, size, bb);
@@ -1135,7 +1134,7 @@
{
int size = SIZE_DELETE_RECORD_TX + record.getEncodeSize();
- HornetQChannelBuffer bb = newBuffer(size);
+ HornetQBuffer bb = newBuffer(size);
writeDeleteRecordTransactional(-1, txID, id, record, size, bb);
@@ -1205,7 +1204,7 @@
{
int size = SIZE_COMPLETE_TRANSACTION_RECORD + transactionData.getEncodeSize() + DataConstants.SIZE_INT;
- HornetQChannelBuffer bb = newBuffer(size);
+ HornetQBuffer bb = newBuffer(size);
writeTransaction(-1, PREPARE_RECORD, txID, transactionData, size, -1, bb);
@@ -1267,7 +1266,7 @@
throw new IllegalStateException("Cannot find tx with id " + txID);
}
- HornetQChannelBuffer bb = newBuffer(SIZE_COMPLETE_TRANSACTION_RECORD);
+ HornetQBuffer bb = newBuffer(SIZE_COMPLETE_TRANSACTION_RECORD);
writeTransaction(-1,
COMMIT_RECORD,
@@ -1322,7 +1321,7 @@
throw new IllegalStateException("Cannot find tx with id " + txID);
}
- HornetQChannelBuffer bb = newBuffer(SIZE_ROLLBACK_RECORD);
+ HornetQBuffer bb = newBuffer(SIZE_ROLLBACK_RECORD);
writeRollback(-1, txID, bb);
@@ -3330,9 +3329,9 @@
}
}
- private HornetQChannelBuffer newBuffer(final int size)
+ private HornetQBuffer newBuffer(final int size)
{
- return HornetQChannelBuffers.buffer(size);
+ return HornetQChannelBuffers.fixedBuffer(size);
}
// Inner classes
Modified: branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalTransaction.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalTransaction.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/JournalTransaction.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -21,8 +21,8 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/journal/impl/TimedBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -21,10 +21,10 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import org.hornetq.core.buffers.HornetQBuffer;
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;
import org.hornetq.utils.VariableLatch;
/**
@@ -104,7 +104,7 @@
}
// Setting the interval for nano-sleeps
- buffer = HornetQChannelBuffers.buffer(bufferSize);
+ buffer = HornetQChannelBuffers.fixedBuffer(bufferSize);
buffer.clear();
bufferLimit = 0;
@@ -280,7 +280,7 @@
// Putting a byteArray on a native buffer is much faster, since it will do in a single native call.
// Using directBuffer.put(buffer) would make several append calls for each byte
- directBuffer.put(buffer.array(), 0, pos);
+ directBuffer.put(buffer.toByteBuffer().array(), 0, pos);
bufferObserver.flushBuffer(directBuffer, pendingSync, callbacks);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/management/impl/ManagementServiceImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -28,7 +28,6 @@
import javax.management.ObjectName;
import javax.management.StandardMBean;
-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 +410,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(), HornetQChannelBuffers.dynamicBuffer(1500));
+ ServerMessage reply = new ServerMessageImpl(storageManager.generateUniqueID(), 512);
String resourceName = message.getStringProperty(ManagementHelper.HDR_RESOURCE_NAME);
if (log.isDebugEnabled())
@@ -699,8 +698,9 @@
return;
}
- ServerMessage notificationMessage = new ServerMessageImpl(storageManager.generateUniqueID(),
- HornetQChannelBuffers.dynamicBuffer(1500));
+ long messageID = storageManager.generateUniqueID();
+
+ ServerMessage notificationMessage = new ServerMessageImpl(messageID, 512);
// 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/BodyEncoder.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/message/BodyEncoder.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/message/BodyEncoder.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -14,8 +14,8 @@
package org.hornetq.core.message;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import java.nio.ByteBuffer;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/message/Message.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -14,10 +14,12 @@
package org.hornetq.core.message;
import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Map;
import java.util.Set;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
+import org.hornetq.core.exception.HornetQException;
import org.hornetq.utils.SimpleString;
import org.hornetq.utils.TypedProperties;
@@ -67,7 +69,16 @@
HornetQBuffer getBodyBuffer();
-
+ void decodeFromBuffer(HornetQBuffer buffer);
+
+ HornetQBuffer encodeToBuffer();
+
+ int getEndOfMessagePosition();
+
+ int getEndOfBodyPosition();
+
+ void forceCopy();
+
// Properties
// ------------------------------------------------------------------
@@ -171,17 +182,17 @@
Map<String, Object> toMap();
+
// FIXME - All this stuff is only necessary here for large messages - it should be refactored to be put in a better place
-
-
+
int getHeadersAndPropertiesEncodeSize();
HornetQBuffer getWholeBuffer();
- void setBuffer(HornetQBuffer buffer);
-
void encodeHeadersAndProperties(HornetQBuffer buffer);
+ void decodeHeadersAndProperties(HornetQBuffer buffer);
+
long getLargeBodySize();
BodyEncoder getBodyEncoder();
@@ -190,12 +201,5 @@
InputStream getBodyInputStream();
- // Sending stuff
-
- boolean isEncodedToBuffer();
- void decodeFromWire(HornetQBuffer buffer);
-
- void decodeHeadersAndProperties(HornetQBuffer buffer);
-
}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/message/impl/MessageImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -22,8 +22,9 @@
import java.util.Map;
import java.util.Set;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
-import org.hornetq.core.buffers.ResetLimitWrappedHornetQBuffer;
+import org.hornetq.core.buffers.impl.ResetLimitWrappedHornetQBuffer;
import org.hornetq.core.client.LargeMessageBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
@@ -31,7 +32,6 @@
import org.hornetq.core.message.Message;
import org.hornetq.core.message.PropertyConversionException;
import org.hornetq.core.remoting.impl.wireformat.PacketImpl;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.SimpleString;
import org.hornetq.utils.TypedProperties;
@@ -73,7 +73,7 @@
public static final SimpleString HDR_FROM_CLUSTER = new SimpleString("_HQ_FROM_CLUSTER");
public static final SimpleString HDR_LAST_VALUE_NAME = new SimpleString("_HQ_LVQ_NAME");
-
+
// Attributes ----------------------------------------------------
protected long messageID;
@@ -96,10 +96,7 @@
protected HornetQBuffer buffer;
private int encodeSize;
-
- //This means does the buffer contain an accurate encoding of the message?
- protected boolean encodedToBuffer;
-
+
// Constructors --------------------------------------------------
protected MessageImpl()
@@ -121,7 +118,7 @@
final long expiration,
final long timestamp,
final byte priority,
- final HornetQBuffer buffer)
+ final int initialMessageBufferSize)
{
this();
this.type = type;
@@ -129,14 +126,29 @@
this.expiration = expiration;
this.timestamp = timestamp;
this.priority = priority;
- this.buffer = buffer;
+ createBody(initialMessageBufferSize);
}
-
- protected MessageImpl(final long messageID)
+
+ protected MessageImpl(final long messageID, final int initialMessageBufferSize)
{
this();
this.messageID = messageID;
+ createBody(initialMessageBufferSize);
}
+
+ private void createBody(final int initialMessageBufferSize)
+ {
+ buffer = HornetQChannelBuffers.dynamicBuffer(initialMessageBufferSize);
+
+ //There's a bug in netty which means a dynamic buffer won't resize until you write a byte
+ buffer.writeByte((byte)0);
+
+ int limit = PacketImpl.PACKET_HEADERS_SIZE + DataConstants.SIZE_INT;
+
+ buffer.setIndex(limit, limit);
+
+ endOfBodyPosition = -1;
+ }
// Message implementation ----------------------------------------
@@ -146,7 +158,7 @@
}
public void encodeHeadersAndProperties(final HornetQBuffer buffer)
- {
+ {
buffer.writeLong(messageID);
buffer.writeSimpleString(destination);
buffer.writeByte(type);
@@ -158,20 +170,6 @@
encodeSize = buffer.writerIndex() - PacketImpl.PACKET_HEADERS_SIZE;
}
- public void decodeFromWire(final HornetQBuffer buffer)
- {
- decodeHeadersAndProperties(buffer);
-
- this.buffer = buffer;
-
- this.encodedToBuffer = true;
- }
-
- public boolean isEncodedToBuffer()
- {
- return this.encodedToBuffer;
- }
-
public void decodeHeadersAndProperties(final HornetQBuffer buffer)
{
messageID = buffer.readLong();
@@ -590,43 +588,13 @@
{
return new DecodingContext();
}
-
- private ResetLimitWrappedHornetQBuffer bodyBuffer;
-
- public HornetQBuffer getBodyBuffer()
- {
- if (bodyBuffer == null)
- {
- if (buffer instanceof LargeMessageBuffer == false)
- {
- bodyBuffer = new ResetLimitWrappedHornetQBuffer(PacketImpl.PACKET_HEADERS_SIZE + DataConstants.SIZE_INT, buffer);
- }
- else
- {
- return buffer;
- }
- }
- return bodyBuffer;
- }
-
// Public --------------------------------------------------------
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
- protected 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);
- }
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
@@ -673,5 +641,139 @@
/* Priority */SIZE_BYTE +
/* PropertySize and Properties */properties.getEncodeSize();
}
+
+
+
+
+
+ private ResetLimitWrappedHornetQBuffer bodyBuffer;
+ public HornetQBuffer getBodyBuffer()
+ {
+ if (bodyBuffer == null)
+ {
+ if (buffer instanceof LargeMessageBuffer == false)
+ {
+ bodyBuffer = new ResetLimitWrappedHornetQBuffer(PacketImpl.PACKET_HEADERS_SIZE + DataConstants.SIZE_INT, buffer);
+ }
+ else
+ {
+ return buffer;
+ }
+ }
+
+ return bodyBuffer;
+ }
+
+
+
+ protected boolean bufferValid;
+
+ private int endOfBodyPosition;
+
+ private int endOfMessagePosition;
+
+ public void forceCopy()
+ {
+ // Must copy buffer before sending it
+ int wi = buffer.writerIndex();
+
+ this.buffer = buffer.copy(0, buffer.capacity());
+
+ this.buffer.setIndex(0, wi);
+ }
+
+ public int getEndOfMessagePosition()
+ {
+ return this.endOfMessagePosition;
+ }
+
+ public int getEndOfBodyPosition()
+ {
+ return this.endOfBodyPosition;
+ }
+
+ //Encode to journal or paging
+ public void encode(HornetQBuffer buff)
+ {
+ encodeToBuffer();
+
+ buff.writeBytes(buffer, PacketImpl.PACKET_HEADERS_SIZE, endOfMessagePosition - PacketImpl.PACKET_HEADERS_SIZE);
+ }
+
+ //Decode from journal or paging
+ public void decode(HornetQBuffer buff)
+ {
+ int start = buff.readerIndex();
+
+ endOfBodyPosition = buff.readInt();
+
+ endOfMessagePosition = buff.getInt(endOfBodyPosition - PacketImpl.PACKET_HEADERS_SIZE + start);
+
+ int endPos = endOfMessagePosition + start -
+ PacketImpl.PACKET_HEADERS_SIZE;
+
+ this.buffer.setIndex(0, PacketImpl.PACKET_HEADERS_SIZE);
+
+ buff.writeBytes(buffer, start, endPos - start);
+
+ decode();
+ }
+
+ public HornetQBuffer encodeToBuffer()
+ {
+ log.info("encoding msg to buffer, valid " + bufferValid);
+
+ if (!bufferValid)
+ {
+ if (endOfBodyPosition == -1)
+ {
+ //Means sending message for first time
+ endOfBodyPosition = buffer.writerIndex();
+
+ //write it
+ buffer.setInt(PacketImpl.PACKET_HEADERS_SIZE, endOfBodyPosition);
+
+ log.info("setting end of body pos as " + endOfBodyPosition);
+ }
+
+ // Position at end of body and skip past the message end position int
+ buffer.writerIndex(endOfBodyPosition + DataConstants.SIZE_INT);
+
+ encodeHeadersAndProperties(buffer);
+
+ // Write end of message position
+
+ this.endOfMessagePosition = buffer.writerIndex();
+
+ buffer.setInt(endOfBodyPosition, endOfMessagePosition);
+
+ this.bufferValid = true;
+ }
+
+ return buffer;
+ }
+
+ public void decode()
+ {
+ this.endOfBodyPosition = buffer.getInt(PacketImpl.PACKET_HEADERS_SIZE);
+
+ buffer.readerIndex(this.endOfBodyPosition + DataConstants.SIZE_INT);
+
+ this.decodeHeadersAndProperties(buffer);
+
+ this.endOfMessagePosition = buffer.readerIndex();
+
+ log.info("decoded end of body pos as " + this.endOfBodyPosition);
+
+ this.bufferValid = true;
+ }
+
+ public void decodeFromBuffer(HornetQBuffer buffer)
+ {
+ this.buffer = buffer;
+
+ decode();
+ }
+
}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PageImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -21,7 +21,7 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
@@ -98,7 +98,7 @@
buffer2.rewind();
- HornetQChannelBuffer fileBuffer = HornetQChannelBuffers.wrappedBuffer(buffer2);
+ HornetQBuffer fileBuffer = HornetQChannelBuffers.wrappedBuffer(buffer2);
fileBuffer.writerIndex(fileBuffer.capacity());
while (fileBuffer.readable())
@@ -147,10 +147,15 @@
public void write(final PagedMessage message) throws Exception
{
+ log.info("encode size is " + message.getEncodeSize());
+
ByteBuffer buffer = fileFactory.newBuffer(message.getEncodeSize() + SIZE_RECORD);
- HornetQChannelBuffer wrap = HornetQChannelBuffers.wrappedBuffer(buffer);
+ HornetQBuffer wrap = HornetQChannelBuffers.wrappedBuffer(buffer);
+ wrap.clear();
+ log.info("wrapped " + wrap.channelBuffer());
+
wrap.writeByte(START_BYTE);
wrap.writeInt(0);
int startIndex = wrap.writerIndex();
@@ -167,6 +172,8 @@
size.addAndGet(buffer.limit());
storageManager.pageWrite(message, pageId);
+
+ log.info("wrote page");
}
public void sync() throws Exception
Modified: branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PageTransactionInfoImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PageTransactionInfoImpl.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PageTransactionInfoImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -20,8 +20,8 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.paging.PageTransactionInfo;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
*
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PagedMessageImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -17,11 +17,11 @@
import static org.hornetq.utils.DataConstants.SIZE_INT;
import static org.hornetq.utils.DataConstants.SIZE_LONG;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.paging.PagedMessage;
import org.hornetq.core.persistence.StorageManager;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.LargeServerMessage;
import org.hornetq.core.server.ServerMessage;
import org.hornetq.core.server.impl.ServerMessageImpl;
Modified: branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/paging/impl/PagingStoreImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -283,8 +283,6 @@
{
long size = message.getMemoryEstimate();
- //log.info((add ? "adding" : "subtracting") + " message size " + size);
-
if (add)
{
checkReleaseProducerFlowControlCredits(size);
@@ -303,8 +301,6 @@
{
long size = MessageReferenceImpl.getMemoryEstimate();
- //log.info((add ? "adding" : "subtracting") + " reference size " + size);
-
if (add)
{
checkReleaseProducerFlowControlCredits(size);
Modified: branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/BatchingIDGenerator.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/BatchingIDGenerator.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/BatchingIDGenerator.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,10 +15,10 @@
import java.util.concurrent.atomic.AtomicLong;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.EncodingSupport;
import org.hornetq.core.journal.Journal;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.IDGenerator;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/JournalStorageManager.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -32,6 +32,7 @@
import javax.transaction.xa.Xid;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.exception.HornetQException;
@@ -59,7 +60,6 @@
import org.hornetq.core.postoffice.Binding;
import org.hornetq.core.postoffice.PostOffice;
import org.hornetq.core.remoting.impl.wireformat.XidCodecSupport;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.replication.ReplicationManager;
import org.hornetq.core.replication.impl.ReplicatedJournal;
import org.hornetq.core.server.JournalType;
@@ -739,7 +739,7 @@
}
case ADD_MESSAGE:
{
- ServerMessage message = new ServerMessageImpl(record.id);
+ ServerMessage message = new ServerMessageImpl(record.id, 50);
message.decode(buff);
@@ -1022,7 +1022,7 @@
}
case ADD_MESSAGE:
{
- ServerMessage message = new ServerMessageImpl(record.id);
+ ServerMessage message = new ServerMessageImpl(record.id, 50);
message.decode(buff);
Modified: branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/LargeServerMessageImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/LargeServerMessageImpl.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/journal/LargeServerMessageImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -18,11 +18,11 @@
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicInteger;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.BodyEncoder;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.LargeServerMessage;
import org.hornetq.core.server.MessageReference;
import org.hornetq.core.server.ServerMessage;
@@ -103,7 +103,6 @@
public void encodeBody(final HornetQBuffer bufferOut, BodyEncoder context, int size)
{
- log.info("large server message, encodebody");
try
{
// This could maybe be optimized (maybe reading directly into bufferOut)
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageLargeServerMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.core.persistence.impl.nullpm;
+import org.hornetq.core.buffers.HornetQBuffer;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/persistence/impl/nullpm/NullStorageManager.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -19,6 +19,7 @@
import javax.transaction.xa.Xid;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.paging.PageTransactionInfo;
@@ -29,7 +30,6 @@
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.postoffice.Binding;
import org.hornetq.core.postoffice.PostOffice;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.replication.ReplicationManager;
import org.hornetq.core.server.LargeServerMessage;
import org.hornetq.core.server.MessageReference;
Modified: branches/20-optimisation/src/main/org/hornetq/core/postoffice/impl/BindingsImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/postoffice/impl/BindingsImpl.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/postoffice/impl/BindingsImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -236,7 +236,7 @@
}
if (!routed)
- {
+ {
if (message.containsProperty(MessageImpl.HDR_FROM_CLUSTER))
{
routeFromCluster(message, context);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/postoffice/impl/PostOfficeImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -635,7 +635,6 @@
{
bindings.route(message, context);
}
-
if (context.getQueueCount() == 0)
{
// Send to DLA if appropriate
@@ -780,7 +779,7 @@
{
// First send a reset message
- ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID(), HornetQChannelBuffers.dynamicBuffer(50));
+ ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID(), 50);
message.setDestination(queueName);
message.putBooleanProperty(HDR_RESET_QUEUE_DATA, true);
@@ -885,7 +884,7 @@
}
Iterator<Queue> iter = context.getDurableQueues().iterator();
-
+
while (iter.hasNext())
{
Queue queue = iter.next();
@@ -980,7 +979,7 @@
private void addReferences(final List<MessageReference> refs)
{
for (MessageReference ref : refs)
- {
+ {
ref.getQueue().addLast(ref);
}
}
@@ -999,7 +998,7 @@
private ServerMessage createQueueInfoMessage(final NotificationType type, final SimpleString queueName)
{
- ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID(), HornetQChannelBuffers.dynamicBuffer(100));
+ ServerMessage message = new ServerMessageImpl(storageManager.generateUniqueID(), 50);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/Packet.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
/**
*
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/RemotingConnection.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/RemotingConnection.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/RemotingConnection.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,10 +15,10 @@
import java.util.List;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.remoting.spi.BufferHandler;
import org.hornetq.core.remoting.spi.Connection;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
* A RemotingConnection
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/AbstractBufferHandler.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/AbstractBufferHandler.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/AbstractBufferHandler.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -12,9 +12,9 @@
*/
package org.hornetq.core.remoting.impl;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.spi.BufferHandler;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/ChannelImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/ChannelImpl.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/ChannelImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -21,6 +21,7 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.Channel;
@@ -31,7 +32,6 @@
import org.hornetq.core.remoting.impl.wireformat.HornetQExceptionMessage;
import org.hornetq.core.remoting.impl.wireformat.PacketImpl;
import org.hornetq.core.remoting.impl.wireformat.PacketsConfirmedMessage;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
* A ChannelImpl
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/PacketDecoder.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/PacketDecoder.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/PacketDecoder.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -79,6 +79,7 @@
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.SESS_XA_START;
import static org.hornetq.core.remoting.impl.wireformat.PacketImpl.SESS_XA_SUSPEND;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.Packet;
import org.hornetq.core.remoting.impl.wireformat.CreateQueueMessage;
@@ -140,7 +141,6 @@
import org.hornetq.core.remoting.impl.wireformat.SessionXASetTimeoutMessage;
import org.hornetq.core.remoting.impl.wireformat.SessionXASetTimeoutResponseMessage;
import org.hornetq.core.remoting.impl.wireformat.SessionXAStartMessage;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
* A PacketDecoder
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/RemotingConnectionImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/RemotingConnectionImpl.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/RemotingConnectionImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -21,6 +21,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.Channel;
@@ -31,7 +32,6 @@
import org.hornetq.core.remoting.RemotingConnection;
import org.hornetq.core.remoting.impl.wireformat.PacketImpl;
import org.hornetq.core.remoting.spi.Connection;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.SimpleIDGenerator;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/invm/InVMConnection.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,13 +15,13 @@
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
+import org.hornetq.core.buffers.HornetQBuffer;
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;
import org.hornetq.core.remoting.spi.Connection;
import org.hornetq.core.remoting.spi.ConnectionLifeCycleListener;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.UUIDGenerator;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateQueueMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.SimpleString;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateReplicationSessionMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateSessionMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/CreateSessionResponseMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/HornetQExceptionMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,9 +13,9 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/PacketImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,10 +13,10 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.Packet;
import org.hornetq.core.remoting.RemotingConnection;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/PacketsConfirmedMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/Ping.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReattachSessionMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReattachSessionResponseMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationAddMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,9 +13,9 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.EncodingSupport;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
-import org.hornetq.utils.DataConstants;
+import org.hornetq.core.logging.Logger;
/**
* A ReplicationAddMessage
@@ -28,7 +28,10 @@
{
// Constants -----------------------------------------------------
+
+ private static final Logger log = Logger.getLogger(ReplicationAddMessage.class);
+
// Attributes ----------------------------------------------------
private long id;
@@ -76,6 +79,7 @@
buffer.writeBoolean(isUpdate);
buffer.writeLong(id);
buffer.writeByte(recordType);
+ log.info("encode size is " + encodingData.getEncodeSize());
buffer.writeInt(encodingData.getEncodeSize());
encodingData.encode(buffer);
}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationAddTXMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.EncodingSupport;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationCommitMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationCompareDataMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.JournalLoadInformation;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationDeleteMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationDeleteTXMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.EncodingSupport;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargeMessageBeingMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargeMessageWriteMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationLargemessageEndMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPageEventMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.SimpleString;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPageWriteMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,9 +13,9 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.paging.PagedMessage;
import org.hornetq.core.paging.impl.PagedMessageImpl;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationPrepareMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.EncodingSupport;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/ReplicationSyncContextMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
/**
* Message sent when a Replication Context is complete without any persistence replicated.
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/RollbackMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionAcknowledgeMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionBindingQueryMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.SimpleString;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionBindingQueryResponseMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -16,7 +16,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.SimpleString;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionConsumerCloseMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionConsumerFlowCreditMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionContinuationMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionCreateConsumerMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.SimpleString;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionDeleteQueueMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.SimpleString;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionExpiredMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionForceConsumerDelivery.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionProducerCreditsMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.SimpleString;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionQueueQueryMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.SimpleString;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionQueueQueryResponseMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.SimpleString;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveContinuationMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
Modified: 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 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveLargeMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionReceiveMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,22 +13,17 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.impl.ClientMessageImpl;
-import org.hornetq.core.client.impl.ClientMessageInternal;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.RemotingConnection;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
-import org.hornetq.core.server.ServerMessage;
+import org.hornetq.core.message.Message;
import org.hornetq.utils.DataConstants;
/**
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
- * @author <a href="mailto:ovidiu@feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
+ *
*/
-public class SessionReceiveMessage extends PacketImpl
+public class SessionReceiveMessage extends MessagePacket
{
// Constants -----------------------------------------------------
@@ -38,28 +33,22 @@
private long consumerID;
- private ClientMessageInternal clientMessage;
-
- private ServerMessage serverMessage;
-
private int deliveryCount;
- public SessionReceiveMessage(final long consumerID, final ServerMessage message, final int deliveryCount)
+ public SessionReceiveMessage(final long consumerID, final Message message, final int deliveryCount)
{
- super(SESS_RECEIVE_MSG);
-
+ super(SESS_RECEIVE_MSG, message);
+
this.consumerID = consumerID;
- this.serverMessage = message;
-
- this.clientMessage = null;
-
this.deliveryCount = deliveryCount;
+
+ message.forceCopy();
}
public SessionReceiveMessage()
{
- super(SESS_RECEIVE_MSG);
+ super(SESS_RECEIVE_MSG, new ClientMessageImpl());
}
// Public --------------------------------------------------------
@@ -68,129 +57,41 @@
{
return consumerID;
}
-
- public ClientMessageInternal getClientMessage()
+
+ public int getDeliveryCount()
{
- return clientMessage;
+ return deliveryCount;
}
- public ServerMessage getServerMessage()
- {
- return serverMessage;
- }
+ // Package protected ---------------------------------------------
- public int getDeliveryCount()
+ // Protected -----------------------------------------------------
+
+ protected void encodeExtraData(HornetQBuffer buffer)
{
- return deliveryCount;
- }
-
- @Override
- public HornetQBuffer encode(final RemotingConnection connection)
- {
- //We re-use the same packet buffer - but we need to change the extra data
-
- //Since many consumers could be delivering the same message concurrently, we must copy the buffer before sending
- //since otherwise they will all write different consumer ids and delivering counts on the same buffer concurrently
- //and indexes will get screwed up
-
- //TODO - optimise this
- HornetQBuffer origBuffer = serverMessage.getWholeBuffer();
-
- HornetQBuffer buffer = origBuffer.copy();
-
- buffer.setIndex(origBuffer.readerIndex(), origBuffer.writerIndex());
-
- if (serverMessage.isEncodedToBuffer())
- {
- //It's already encoded - we just need to change the extra data at the end
- //so we need to jump to the after body position
-
- buffer.setIndex(0, serverMessage.getEndMessagePosition());
- }
- else
- {
- int afterBody = buffer.writerIndex();
-
- //Message hasn't been encoded yet - probably it's something like a notification message generated on the server
-
- //End of message position
- buffer.writeInt(0);
-
- // We now write the message headers and properties
- serverMessage.encodeHeadersAndProperties(buffer);
-
- int endMessage = buffer.writerIndex();
-
- buffer.setInt(afterBody, endMessage);
-
- serverMessage.setEndMessagePosition(endMessage);
-
- //Now we need to fill in the afterBody
- buffer.setInt(PacketImpl.PACKET_HEADERS_SIZE, afterBody);
- }
-
buffer.writeLong(consumerID);
buffer.writeInt(deliveryCount);
-
- // Calculate the new packet size
- size = buffer.writerIndex();
-
- buffer.setIndex(0, 0);
-
- // Fill in the standard header fields
-
- int len = size - DataConstants.SIZE_INT;
- buffer.writeInt(len);
- buffer.writeByte(type);
- buffer.writeLong(channelID);
-
- buffer.writerIndex(size);
-
- return buffer;
}
-
- @Override
- public void decode(final HornetQBuffer buffer)
+
+ protected void decodeExtraData(HornetQBuffer buffer)
{
- channelID = buffer.readLong();
-
- clientMessage = new ClientMessageImpl();
-
- // We read the position of the end of the body - this is where the message headers and properties are stored
- int afterBody = buffer.readInt();
-
- //At this point standard headers have been decoded and we are positioned at the beginning of the body
- int bodyStart = buffer.readerIndex();
-
- // We now read message headers/properties
-
- buffer.readerIndex(afterBody);
-
- int endMessage = buffer.readInt();
-
- clientMessage.decodeFromWire(buffer);
-
- // And read the extra data
-
consumerID = buffer.readLong();
-
deliveryCount = buffer.readInt();
+ }
+ @Override
+ public void decodeRest(HornetQBuffer buffer)
+ {
+ //Buffer comes in after having read standard headers and positioned at Beginning of body part
- clientMessage.setDeliveryCount(deliveryCount);
+ message.decodeFromBuffer(buffer);
- size = buffer.readerIndex();
-
- // Set reader index back to beginning of body
-
- buffer.setIndex(bodyStart, afterBody);
+ decodeExtraData(buffer);
- clientMessage.setBuffer(buffer);
+ //Need to position buffer for reading
+
+ buffer.setIndex(PacketImpl.PACKET_HEADERS_SIZE + DataConstants.SIZE_INT, message.getEndOfBodyPosition());
}
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionRequestProducerCreditsMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
import org.hornetq.utils.SimpleString;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendContinuationMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendLargeMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionSendMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,22 +13,17 @@
package org.hornetq.core.remoting.impl.wireformat;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.Message;
-import org.hornetq.core.remoting.RemotingConnection;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
-import org.hornetq.core.server.ServerMessage;
import org.hornetq.core.server.impl.ServerMessageImpl;
-import org.hornetq.utils.DataConstants;
/**
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
- * @author <a href="mailto:csuconic@redhat.com">Clebert Suconic</a>
- *
+ *
* @version <tt>$Revision$</tt>
*/
-public class SessionSendMessage extends PacketImpl
+public class SessionSendMessage extends MessagePacket
{
// Constants -----------------------------------------------------
@@ -36,10 +31,6 @@
// Attributes ----------------------------------------------------
- private Message sentMessage;
-
- private ServerMessage receivedMessage;
-
private boolean requiresResponse;
// Static --------------------------------------------------------
@@ -48,163 +39,39 @@
public SessionSendMessage(final Message message, final boolean requiresResponse)
{
- super(SESS_SEND);
-
- sentMessage = message;
-
+ super(SESS_SEND, message);
+
this.requiresResponse = requiresResponse;
+
+ message.forceCopy();
}
-
+
public SessionSendMessage()
{
- super(SESS_SEND);
+ super(SESS_SEND, new ServerMessageImpl());
}
// Public --------------------------------------------------------
- public Message getClientMessage()
- {
- return sentMessage;
- }
-
- public ServerMessage getServerMessage()
- {
- return receivedMessage;
- }
-
public boolean isRequiresResponse()
{
return requiresResponse;
}
- @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:
- *
- * position of end of body: 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}
- *
- * position of end of encoded message headers/properties: int
- *
- * 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[]
- *
- *
- */
+ // Package protected ---------------------------------------------
- HornetQBuffer buffer = sentMessage.getWholeBuffer();
-
- // 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();
-
- //The next int is the position of after the encoded message headers/properties, so we skip this for now
- buffer.writeInt(0);
-
- // We now write the message headers and properties
- sentMessage.encodeHeadersAndProperties(buffer);
-
- //Write the position of the end of the message
-
- int endMessage = buffer.writerIndex();
-
- buffer.setInt(afterBody, endMessage);
-
- // We now write the extra data for the packet
+ // Protected -----------------------------------------------------
+
+ protected void encodeExtraData(HornetQBuffer buffer)
+ {
buffer.writeBoolean(requiresResponse);
-
- // We take note of the overall size of the packet
- size = buffer.writerIndex();
-
- // We now set the standard packet headers at the beginning of the buffer
-
- buffer.clear();
-
- 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
- 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
-
- HornetQBuffer newBuffer = buffer.copy();
-
- newBuffer.setIndex(PacketImpl.PACKET_HEADERS_SIZE + DataConstants.SIZE_INT, afterBody);
-
- this.sentMessage.setBuffer(newBuffer);
-
- return buffer;
}
-
- @Override
- public void decodeRest(final HornetQBuffer buffer)
+
+ protected void decodeExtraData(HornetQBuffer buffer)
{
- receivedMessage = new ServerMessageImpl();
-
- sentMessage = receivedMessage;
-
- // 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();
-
- buffer.setIndex(afterBody, buffer.writerIndex());
-
- int endMessage = buffer.readInt();
-
- receivedMessage.setEndMessagePosition(endMessage);
-
- // We now read message headers/properties
-
- receivedMessage.decodeFromWire(buffer);
-
- //We store the position of the end of the encoded message, where the extra data starts - this
- //will be needed if we re-deliver this packet, since we need to reset to there to rewrite the extra data
- //for the different packet
- //receivedMessage.setEndMessagePosition(endMessage);
-
- // And we read extra data in the packet
-
requiresResponse = buffer.readBoolean();
}
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
// Private -------------------------------------------------------
// Inner classes -------------------------------------------------
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXACommitMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,7 +15,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAEndMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,7 +15,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAForgetMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,7 +15,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAGetInDoubtXidsResponseMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -18,7 +18,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAGetTimeoutResponseMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAJoinMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,7 +15,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAPrepareMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,7 +15,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
/**
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAResponseMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAResumeMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,7 +15,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
/**
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXARollbackMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,7 +15,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
/**
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXASetTimeoutMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXASetTimeoutResponseMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,7 +13,7 @@
package org.hornetq.core.remoting.impl.wireformat;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/SessionXAStartMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,7 +15,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
/**
* @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/XidCodecSupport.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/XidCodecSupport.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/impl/wireformat/XidCodecSupport.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,7 +15,7 @@
import javax.transaction.xa.Xid;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.transaction.impl.XidImpl;
import org.hornetq.utils.DataConstants;
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/server/impl/RemotingServiceImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -25,6 +25,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.TransportConfiguration;
@@ -48,7 +49,6 @@
import org.hornetq.core.remoting.spi.BufferHandler;
import org.hornetq.core.remoting.spi.Connection;
import org.hornetq.core.remoting.spi.ConnectionLifeCycleListener;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.impl.HornetQPacketHandler;
import org.hornetq.utils.ConfigurationHelper;
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/BufferHandler.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/BufferHandler.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/BufferHandler.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -12,6 +12,8 @@
*/
package org.hornetq.core.remoting.spi;
+import org.hornetq.core.buffers.HornetQBuffer;
+
/**
* A BufferHandler
*
Modified: branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/Connection.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/Connection.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/Connection.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,6 +13,7 @@
package org.hornetq.core.remoting.spi;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
/**
Deleted: 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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/remoting/spi/HornetQBuffer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -1,130 +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.remoting.spi;
-
-import org.hornetq.utils.SimpleString;
-
-/**
- *
- * A HornetQBuffer
- *
- * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
- *
- */
-public interface HornetQBuffer
-{
- void writeByte(byte val);
-
- void writeBytes(byte[] bytes);
-
- void writeBytes(byte[] bytes, int offset, int length);
-
- void writeBytes(HornetQBuffer src, int srcIndex, int length);
-
- void writeInt(int val);
-
- void setInt(int pos, int val);
-
- void writeLong(long val);
-
- void writeShort(short val);
-
- void writeDouble(double val);
-
- void writeFloat(float val);
-
- void writeBoolean(boolean val);
-
- void writeChar(char val);
-
- void writeNullableString(String val);
-
- void writeString(String val);
-
- void writeSimpleString(SimpleString val);
-
- void writeNullableSimpleString(SimpleString val);
-
- void writeUTF(String utf) throws Exception;
-
- byte readByte();
-
- short readUnsignedByte();
-
- void readBytes(byte[] bytes);
-
- void readBytes(byte[] bytes, int offset, int length);
-
- int readInt();
-
- int readInt(int pos);
-
- long readLong();
-
- short readShort();
-
- int readUnsignedShort();
-
- double readDouble();
-
- float readFloat();
-
- boolean readBoolean();
-
- char readChar();
-
- String readString();
-
- String readNullableString();
-
- SimpleString readSimpleString();
-
- SimpleString readNullableSimpleString();
-
- String readUTF() throws Exception;
-
- int capacity();
-
- int readerIndex();
-
- void readerIndex(int readerIndex);
-
- int writerIndex();
-
- void writerIndex(int writerIndex);
-
- void setIndex(int readerIndex, int writerIndex);
-
- int readableBytes();
-
- int writableBytes();
-
- boolean readable();
-
- boolean writable();
-
- void clear();
-
- void resetReaderIndex();
-
- void resetWriterIndex();
-
- Object getUnderlyingBuffer();
-
- byte[] array();
-
- HornetQBuffer copy();
-
- HornetQBuffer slice(int index, int length);
-}
Modified: branches/20-optimisation/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/replication/impl/ReplicationManagerImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -17,6 +17,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.SessionFailureListener;
import org.hornetq.core.client.impl.FailoverManager;
import org.hornetq.core.exception.HornetQException;
@@ -43,7 +44,6 @@
import org.hornetq.core.remoting.impl.wireformat.ReplicationPageEventMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationPageWriteMessage;
import org.hornetq.core.remoting.impl.wireformat.ReplicationPrepareMessage;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.replication.ReplicationContext;
import org.hornetq.core.replication.ReplicationManager;
import org.hornetq.utils.ConcurrentHashSet;
Modified: branches/20-optimisation/src/main/org/hornetq/core/server/ServerMessage.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/server/ServerMessage.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/ServerMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -60,13 +60,6 @@
boolean page(long transactionID, boolean duplicateDetection) throws Exception;
boolean storeIsPaging();
-
- void setNeedsEncoding();
-
-
- void setEndMessagePosition(int pos);
-
- int getEndMessagePosition();
-
- void encodeMessageIDToBuffer();;
+
+ void encodeMessageIDToBuffer();
}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/cluster/impl/BroadcastGroupImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -20,13 +20,13 @@
import java.util.List;
import java.util.concurrent.ScheduledFuture;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.config.TransportConfiguration;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.management.Notification;
import org.hornetq.core.management.NotificationService;
import org.hornetq.core.management.NotificationType;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.cluster.BroadcastGroup;
import org.hornetq.utils.Pair;
import org.hornetq.utils.SimpleString;
@@ -227,7 +227,7 @@
}
}
- byte[] data = buff.array();
+ byte[] data = buff.toByteBuffer().array();
DatagramPacket packet = new DatagramPacket(data, data.length, groupAddress, groupPort);
Modified: branches/20-optimisation/src/main/org/hornetq/core/server/cluster/impl/RemoteQueueBindingImpl.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/core/server/cluster/impl/RemoteQueueBindingImpl.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/cluster/impl/RemoteQueueBindingImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -204,7 +204,7 @@
{
//There can be many remote bindings for the same node, we only want to add the message once to
//the s & f queue for that node
- context.getDurableQueues().add(storeAndForwardQueue);
+ context.addQueue(storeAndForwardQueue);
}
}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/impl/HornetQServerImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -1504,7 +1504,7 @@
for (int i = 0; i < numMessages; i++)
{
- ServerMessage msg = new ServerMessageImpl(storageManager.generateUniqueID(), HornetQChannelBuffers.wrappedBuffer(body));
+ ServerMessage msg = new ServerMessageImpl(storageManager.generateUniqueID(), 1500);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerConsumerImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -21,6 +21,7 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.impl.ClientConsumerImpl;
import org.hornetq.core.client.management.impl.ManagementHelper;
@@ -38,7 +39,6 @@
import org.hornetq.core.remoting.impl.wireformat.SessionReceiveContinuationMessage;
import org.hornetq.core.remoting.impl.wireformat.SessionReceiveLargeMessage;
import org.hornetq.core.remoting.impl.wireformat.SessionReceiveMessage;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.HandleStatus;
import org.hornetq.core.server.LargeServerMessage;
import org.hornetq.core.server.MessageReference;
@@ -347,7 +347,7 @@
promptDelivery(false);
ServerMessage forcedDeliveryMessage = new ServerMessageImpl(storageManager.generateUniqueID(),
- HornetQChannelBuffers.dynamicBuffer(100));
+ 50);
forcedDeliveryMessage.putLongProperty(ClientConsumerImpl.FORCED_DELIVERY_MESSAGE, sequence);
forcedDeliveryMessage.setDestination(messageQueue.getName());
@@ -668,12 +668,12 @@
if (!sentInitialPacket)
{
- HornetQBuffer headerBuffer = HornetQChannelBuffers.buffer(largeMessage.getHeadersAndPropertiesEncodeSize());
+ HornetQBuffer headerBuffer = HornetQChannelBuffers.fixedBuffer(largeMessage.getHeadersAndPropertiesEncodeSize());
largeMessage.encodeHeadersAndProperties(headerBuffer);
SessionReceiveLargeMessage initialPacket = new SessionReceiveLargeMessage(id,
- headerBuffer.array(),
+ headerBuffer.toByteBuffer().array(),
largeMessage.getLargeBodySize(),
ref.getDeliveryCount());
@@ -796,12 +796,12 @@
localChunkLen = (int)Math.min(sizePendingLargeMessage - positionPendingLargeMessage, minLargeMessageSize);
- HornetQBuffer bodyBuffer = HornetQChannelBuffers.buffer(localChunkLen);
+ HornetQBuffer bodyBuffer = HornetQChannelBuffers.fixedBuffer(localChunkLen);
context.encode(bodyBuffer, localChunkLen);
chunk = new SessionReceiveContinuationMessage(id,
- bodyBuffer.array(),
+ bodyBuffer.toByteBuffer().array(),
positionPendingLargeMessage + localChunkLen < sizePendingLargeMessage,
false);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerMessageImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -16,13 +16,11 @@
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicInteger;
-import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.message.Message;
+import org.hornetq.core.message.PropertyConversionException;
import org.hornetq.core.message.impl.MessageImpl;
import org.hornetq.core.paging.PagingStore;
import org.hornetq.core.remoting.impl.wireformat.PacketImpl;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.MessageReference;
import org.hornetq.core.server.Queue;
import org.hornetq.core.server.ServerMessage;
@@ -61,30 +59,17 @@
}
/*
- * Construct a MessageImpl from storage
+ * Construct a MessageImpl from storage, or notification
*/
- public ServerMessageImpl(final long messageID)
+ public ServerMessageImpl(final long messageID, final int initialMessageBufferSize)
{
- super(messageID);
+ super(messageID, initialMessageBufferSize);
}
/*
- * Constructor when creating a ServerMessage for sending - e.g. notification
- */
- public ServerMessageImpl(final long messageID, final HornetQBuffer buffer)
- {
- super(messageID);
-
- this.buffer = buffer;
-
- // Must align the body after the packet headers
- resetBuffer();
- }
-
- /*
* Copy constructor
*/
- protected ServerMessageImpl(final Message other)
+ protected ServerMessageImpl(final ServerMessageImpl other)
{
this();
messageID = other.getMessageID();
@@ -95,7 +80,8 @@
timestamp = other.getTimestamp();
priority = other.getPriority();
properties = new TypedProperties(other.getProperties());
- buffer = other.getWholeBuffer();
+ //Note, this is a shallow copy - does not copy the buffer
+ buffer = other.buffer;
}
public void setMessageID(final long id)
@@ -246,7 +232,7 @@
putLongProperty(HDR_ACTUAL_EXPIRY_TIME, actualExpiryTime);
}
- setNeedsEncoding();
+ bufferValid = false;
}
public void setPagingStore(final PagingStore pagingStore)
@@ -320,100 +306,223 @@
// Encoding stuff
- public void setNeedsEncoding()
+ public void encodeMessageIDToBuffer()
{
- // This wil force the message to be re-encoded if it gets sent to a client
- // Typically this is called after properties or headers are changed on the server side
- this.encodedToBuffer = false;
+ // We first set the message id - this needs to be set on the buffer since this buffer will be re-used
+
+ //log.info(System.identityHashCode(this) + " encoded message id " + messageID + " etb " + this.encodedToBuffer);
+
+ buffer.setLong(buffer.getInt(PacketImpl.PACKET_HEADERS_SIZE) + DataConstants.SIZE_INT, messageID);
}
- private int endMessagePosition;
+ @Override
+ public void putBooleanProperty(SimpleString key, boolean value)
+ {
+ super.putBooleanProperty(key, value);
+
+ bufferValid = false;
+ }
- public void setEndMessagePosition(int pos)
- {
- this.endMessagePosition = pos;
+ @Override
+ public void putBooleanProperty(String key, boolean value)
+ {
+ super.putBooleanProperty(key, value);
+
+ bufferValid = false;;
}
- public int getEndMessagePosition()
- {
- return this.endMessagePosition;
+ @Override
+ public void putByteProperty(SimpleString key, byte value)
+ {
+ super.putByteProperty(key, value);
+
+ bufferValid = false;
}
- public void encodeToWire()
- {
+ @Override
+ public void putByteProperty(String key, byte value)
+ {
+ super.putByteProperty(key, value);
+
+ bufferValid = false;
}
- // EncodingSupport implementation
+ @Override
+ public void putBytesProperty(SimpleString key, byte[] value)
+ {
+ super.putBytesProperty(key, value);
+
+ bufferValid = false;
+ }
- // Used when storing to/from journal
+ @Override
+ public void putBytesProperty(String key, byte[] value)
+ {
+ super.putBytesProperty(key, value);
+
+ bufferValid = false;
+ }
- public void encode(final HornetQBuffer buffer)
- {
- // Encode the message to a buffer for storage in the journal
+ @Override
+ public void putDoubleProperty(SimpleString key, double value)
+ {
+ super.putDoubleProperty(key, value);
+
+ bufferValid = false;
+ }
- if (this.encodedToBuffer)
- {
- // The body starts after the standard packet headers
- int bodyStart = PacketImpl.PACKET_HEADERS_SIZE;
+ @Override
+ public void putDoubleProperty(String key, double value)
+ {
+ super.putDoubleProperty(key, value);
+
+ bufferValid = false;
+ }
- int end = this.endMessagePosition;
-
- buffer.writeBytes(this.buffer, bodyStart, end - bodyStart);
- }
- else
- {
- // encodeToBuffer();
+ @Override
+ public void putFloatProperty(SimpleString key, float value)
+ {
+ super.putFloatProperty(key, value);
+
+ bufferValid = false;
+ }
- throw new IllegalStateException("Not encoded to buffer and storing to journal");
- }
+ @Override
+ public void putFloatProperty(String key, float value)
+ {
+ super.putFloatProperty(key, value);
+
+ bufferValid = false;
}
- public void decode(final HornetQBuffer buffer)
- {
- // TODO optimise
+ @Override
+ public void putIntProperty(SimpleString key, int value)
+ {
+ super.putIntProperty(key, value);
+
+ bufferValid = false;
+ }
- int start = buffer.readerIndex();
+ @Override
+ public void putIntProperty(String key, int value)
+ {
+ super.putIntProperty(key, value);
+
+ bufferValid = false;
+ }
- int bodyEndPos = buffer.readInt();
+ @Override
+ public void putLongProperty(SimpleString key, long value)
+ {
+ super.putLongProperty(key, value);
- this.endMessagePosition = buffer.readInt(bodyEndPos - PacketImpl.PACKET_HEADERS_SIZE + start);
+ bufferValid = false;
+ }
+
+ @Override
+ public void putLongProperty(String key, long value)
+ {
+ super.putLongProperty(key, value);
- int endPos = endMessagePosition + start -
- PacketImpl.PACKET_HEADERS_SIZE;
+ bufferValid = false;
+ }
- this.buffer = HornetQChannelBuffers.dynamicBuffer(1500);
+ @Override
+ public void putObjectProperty(SimpleString key, Object value) throws PropertyConversionException
+ {
+ super.putObjectProperty(key, value);
+
+ bufferValid = false;
+ }
- // work around Netty bug
- this.buffer.writeByte((byte)0);
+ @Override
+ public void putObjectProperty(String key, Object value) throws PropertyConversionException
+ {
+ super.putObjectProperty(key, value);
+
+ bufferValid = false;
+ }
- this.buffer.setIndex(0, PacketImpl.PACKET_HEADERS_SIZE);
+ @Override
+ public void putShortProperty(SimpleString key, short value)
+ {
+ super.putShortProperty(key, value);
+
+ bufferValid = false;
+ }
- this.buffer.writeBytes(buffer, start, endPos - start);
+ @Override
+ public void putShortProperty(String key, short value)
+ {
+ super.putShortProperty(key, value);
- // Position to beginning of encoded message headers/properties
+ bufferValid = false;
+ }
- this.buffer.readerIndex(0);
-
- //Position to beginning of encoded message headers/properties
+ @Override
+ public void putStringProperty(SimpleString key, SimpleString value)
+ {
+ super.putStringProperty(key, value);
- this.buffer.readerIndex(bodyEndPos + DataConstants.SIZE_INT);
+ bufferValid = false;
+ }
- this.decodeHeadersAndProperties(this.buffer);
+ @Override
+ public void putStringProperty(String key, String value)
+ {
+ super.putStringProperty(key, value);
- buffer.setIndex(endPos, buffer.capacity());
+ bufferValid = false;
+ }
+
+ @Override
+ public void putTypedProperties(TypedProperties otherProps)
+ {
+ super.putTypedProperties(otherProps);
- this.encodedToBuffer = true;
+ bufferValid = false;
}
- public void encodeMessageIDToBuffer()
- {
- // We first set the message id - this needs to be set on the buffer since this buffer will be re-used
+ @Override
+ public void setDestination(SimpleString destination)
+ {
+ super.setDestination(destination);
+
+ bufferValid = false;
+ }
- buffer.readerIndex(0);
+ @Override
+ public void setDurable(boolean durable)
+ {
+ super.setDurable(durable);
+
+ bufferValid = false;
+ }
- buffer.writerIndex(buffer.readInt(PacketImpl.PACKET_HEADERS_SIZE) + DataConstants.SIZE_INT);
+ @Override
+ public void setExpiration(long expiration)
+ {
+ super.setExpiration(expiration);
+
+ bufferValid = false;
+ }
- buffer.writeLong(messageID);
+ @Override
+ public void setPriority(byte priority)
+ {
+ super.setPriority(priority);
+
+ bufferValid = false;
}
+ @Override
+ public void setTimestamp(long timestamp)
+ {
+ super.setTimestamp(timestamp);
+
+ bufferValid = false;
+ }
+
+
+
}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/core/server/impl/ServerSessionImpl.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -28,7 +28,6 @@
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-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;
@@ -1435,8 +1434,7 @@
public void handleSendLargeMessage(final SessionSendLargeMessage packet)
{
- log.info("Got large message on server");
-
+
// need to create the LargeMessage before continue
long id = storageManager.generateUniqueID();
@@ -1456,10 +1454,10 @@
}
public void handleSend(final SessionSendMessage packet)
- {
+ {
Packet response = null;
- ServerMessage message = packet.getServerMessage();
+ ServerMessage message = (ServerMessage)packet.getMessage();
try
{
@@ -1597,8 +1595,6 @@
}
});
- //log.info("session requesting " + credits + " got " + gotCredits);
-
if (gotCredits > 0)
{
sendProducerCredits(holder, gotCredits, address);
@@ -1904,8 +1900,6 @@
*/
private void releaseOutStanding(final ServerMessage message, final int credits) throws Exception
{
- //log.info("releasing outstanding credits " + credits);
-
CreditManagerHolder holder = getCreditManagerHolder(message);
holder.outstandingCredits -= credits;
@@ -1949,8 +1943,6 @@
{
holder.outstandingCredits += credits;
- // log.info("sending producer credits " + credits);
-
Packet packet = new SessionProducerCreditsMessage(credits, address, -1);
channel.send(packet);
Deleted: 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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/ChannelBufferWrapper.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -1,418 +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.integration.transports.netty;
-
-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;
-import org.jboss.netty.buffer.ChannelBuffer;
-
-/**
- *
- * @author <a href="mailto:tlee@redhat.com">Trustin Lee</a>
- * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
- * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
- * @author <a href="mailto:clebert.suconic@jboss.com">Clebert Suconic</a>
- *
- * @version $Rev$, $Date$
- */
-public class ChannelBufferWrapper implements HornetQBuffer
-{
- private static final Logger log = Logger.getLogger(ChannelBufferWrapper.class);
-
- private final ChannelBuffer buffer;
-
- /**
- * @param buffer
- */
- public ChannelBufferWrapper(final ChannelBuffer buffer)
- {
- super();
- this.buffer = buffer;
- }
-
- public int capacity()
- {
- return buffer.capacity();
- }
-
- public void clear()
- {
- buffer.clear();
- }
-
- public boolean readable()
- {
- return buffer.readable();
- }
-
- public int readableBytes()
- {
- return buffer.readableBytes();
- }
-
- public byte readByte()
- {
- return buffer.readByte();
- }
-
- public void readBytes(final byte[] dst, final int dstIndex, final int length)
- {
- buffer.readBytes(dst, dstIndex, length);
- }
-
- public void readBytes(final byte[] dst)
- {
- buffer.readBytes(dst);
- }
-
- public int readerIndex()
- {
- return buffer.readerIndex();
- }
-
- public void readerIndex(final int readerIndex)
- {
- buffer.readerIndex(readerIndex);
- }
-
- public int readInt()
- {
- return buffer.readInt();
- }
-
- public int readInt(final int pos)
- {
- return buffer.getInt(pos);
- }
-
- public long readLong()
- {
- return buffer.readLong();
- }
-
- public short readShort()
- {
- return buffer.readShort();
- }
-
- public short readUnsignedByte()
- {
- return buffer.readUnsignedByte();
- }
-
- public int readUnsignedShort()
- {
- return buffer.readUnsignedShort();
- }
-
- public void resetReaderIndex()
- {
- buffer.resetReaderIndex();
- }
-
- public void resetWriterIndex()
- {
- buffer.resetWriterIndex();
- }
-
- public void setIndex(final int readerIndex, final int writerIndex)
- {
- buffer.setIndex(readerIndex, writerIndex);
- }
-
- public void setInt(final int index, final int value)
- {
- buffer.setInt(index, value);
- }
-
- public boolean writable()
- {
- return buffer.writable();
- }
-
- public int writableBytes()
- {
- return buffer.writableBytes();
- }
-
- public void writeByte(final byte value)
- {
- buffer.writeByte(value);
- }
-
- public void writeBytes(final byte[] src, final int srcIndex, final int length)
- {
- buffer.writeBytes(src, srcIndex, length);
- }
-
- public void writeBytes(final HornetQBuffer src, final int srcIndex, final int length)
- {
- byte bytes[] = new byte[length];
- src.readBytes(bytes, srcIndex, length);
- this.writeBytes(bytes);
- }
-
- public void writeBytes(final byte[] src)
- {
- buffer.writeBytes(src);
- }
-
- public void writeInt(final int value)
- {
- buffer.writeInt(value);
- }
-
- public void writeLong(final long value)
- {
- buffer.writeLong(value);
- }
-
- public int writerIndex()
- {
- return buffer.writerIndex();
- }
-
- public void writerIndex(final int writerIndex)
- {
- buffer.writerIndex(writerIndex);
- }
-
- public void writeShort(final short value)
- {
- buffer.writeShort(value);
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#array()
- */
- public byte[] array()
- {
- return buffer.toByteBuffer().array();
- }
-
- /* (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);
- }
-
- /* (non-Javadoc)
- * @see org.hornetq.core.remoting.spi.HornetQBuffer#getUnderlyingBuffer()
- */
- public Object getUnderlyingBuffer()
- {
- return buffer;
- }
-
- public HornetQBuffer copy()
- {
- return new ChannelBufferWrapper(buffer.copy(0, buffer.capacity()));
- }
-
- public HornetQBuffer slice(int index, int length)
- {
- return new ChannelBufferWrapper(buffer.slice(index, length));
- }
-
-}
Modified: branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQChannelHandler.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQChannelHandler.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQChannelHandler.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -12,6 +12,7 @@
*/
package org.hornetq.integration.transports.netty;
+import org.hornetq.core.buffers.impl.ChannelBufferWrapper;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.spi.BufferHandler;
Modified: branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/HornetQFrameDecoder.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,6 +15,7 @@
import static org.hornetq.utils.DataConstants.SIZE_INT;
+import org.hornetq.core.buffers.impl.ChannelBufferWrapper;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.spi.BufferHandler;
import org.hornetq.utils.DataConstants;
Modified: branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/NettyConnection.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/NettyConnection.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/integration/transports/netty/NettyConnection.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,12 +13,12 @@
package org.hornetq.integration.transports.netty;
-import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
+import org.hornetq.core.buffers.impl.ChannelBufferWrapper;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.remoting.spi.Connection;
import org.hornetq.core.remoting.spi.ConnectionLifeCycleListener;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
@@ -102,11 +102,7 @@
public HornetQBuffer createBuffer(final int size)
{
- ChannelBuffer cb = org.jboss.netty.buffer.ChannelBuffers.dynamicBuffer(size);
-
- HornetQBuffer buff = new ChannelBufferWrapper(cb);
-
- return buff;
+ return new ChannelBufferWrapper(ChannelBuffers.dynamicBuffer(size));
}
public Object getID()
@@ -121,24 +117,7 @@
public void write(HornetQBuffer buffer, final boolean flush)
{
- Object underlying = buffer.getUnderlyingBuffer();
-
- if (underlying instanceof ChannelBuffer == false)
- {
- //Need to copy it
-
- //TODO we can avoid this if we use Netty buffers everywhere!!
-
- HornetQBuffer hq = (HornetQBuffer)underlying;
-
- ChannelBuffer cb = ChannelBuffers.copiedBuffer(hq.array());
-
- cb.setIndex(hq.readerIndex(), hq.writerIndex());
-
- underlying = cb;
- }
-
- ChannelFuture future = channel.write(underlying);
+ ChannelFuture future = channel.write(buffer.channelBuffer());
if (flush)
{
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQBytesMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -19,10 +19,10 @@
import javax.jms.MessageEOFException;
import javax.jms.MessageFormatException;
+import org.hornetq.core.buffers.HornetQBuffer;
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;
/**
* This class implements javax.jms.BytesMessage.
@@ -157,7 +157,7 @@
checkRead();
try
{
- return getBuffer().readChar();
+ return (char)getBuffer().readShort();
}
catch (IndexOutOfBoundsException e)
{
@@ -196,7 +196,7 @@
checkRead();
try
{
- return getBuffer().readFloat();
+ return Float.intBitsToFloat(getBuffer().readInt());
}
catch (IndexOutOfBoundsException e)
{
@@ -209,7 +209,7 @@
checkRead();
try
{
- return getBuffer().readDouble();
+ return Double.longBitsToDouble(getBuffer().readLong());
}
catch (IndexOutOfBoundsException e)
{
@@ -279,7 +279,7 @@
public void writeChar(final char value) throws JMSException
{
checkWrite();
- getBuffer().writeChar(value);
+ getBuffer().writeShort((short)value);
}
public void writeInt(final int value) throws JMSException
@@ -297,13 +297,13 @@
public void writeFloat(final float value) throws JMSException
{
checkWrite();
- getBuffer().writeFloat(value);
+ getBuffer().writeInt(Float.floatToIntBits(value));
}
public void writeDouble(final double value) throws JMSException
{
checkWrite();
- getBuffer().writeDouble(value);
+ getBuffer().writeLong(Double.doubleToLongBits(value));
}
public void writeUTF(final String value) throws JMSException
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -33,6 +33,7 @@
import javax.jms.MessageNotReadableException;
import javax.jms.MessageNotWriteableException;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientSession;
@@ -41,7 +42,6 @@
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.PropertyConversionException;
import org.hornetq.core.message.impl.MessageImpl;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.jms.HornetQDestination;
import org.hornetq.utils.SimpleString;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQStreamMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -18,10 +18,12 @@
import javax.jms.MessageFormatException;
import javax.jms.StreamMessage;
+import org.hornetq.core.buffers.HornetQBuffer;
+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;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.utils.DataConstants;
/**
@@ -84,9 +86,11 @@
// Ignore
}
}
-
+
+ // For testing only
public HornetQStreamMessage()
{
+ this.message = new ClientMessageImpl((byte)0, false, 0, 0, (byte)4, 1500);
}
// Public --------------------------------------------------------
@@ -180,7 +184,7 @@
switch (type)
{
case DataConstants.CHAR:
- return getBuffer().readChar();
+ return (char)getBuffer().readShort();
default:
throw new MessageFormatException("Invalid conversion");
}
@@ -256,7 +260,7 @@
switch (type)
{
case DataConstants.FLOAT:
- return getBuffer().readFloat();
+ return Float.intBitsToFloat(getBuffer().readInt());
case DataConstants.STRING:
String s = getBuffer().readNullableString();
return Float.parseFloat(s);
@@ -279,9 +283,9 @@
switch (type)
{
case DataConstants.FLOAT:
- return getBuffer().readFloat();
+ return Float.intBitsToFloat(getBuffer().readInt());
case DataConstants.DOUBLE:
- return getBuffer().readDouble();
+ return Double.longBitsToDouble(getBuffer().readLong());
case DataConstants.STRING:
String s = getBuffer().readNullableString();
return Double.parseDouble(s);
@@ -310,15 +314,15 @@
case DataConstants.SHORT:
return String.valueOf(getBuffer().readShort());
case DataConstants.CHAR:
- return String.valueOf(getBuffer().readChar());
+ return String.valueOf((char)getBuffer().readShort());
case DataConstants.INT:
return String.valueOf(getBuffer().readInt());
case DataConstants.LONG:
return String.valueOf(getBuffer().readLong());
case DataConstants.FLOAT:
- return String.valueOf(getBuffer().readFloat());
+ return String.valueOf(Float.intBitsToFloat(getBuffer().readInt()));
case DataConstants.DOUBLE:
- return String.valueOf(getBuffer().readDouble());
+ return String.valueOf(Double.longBitsToDouble(getBuffer().readLong()));
case DataConstants.STRING:
return getBuffer().readNullableString();
default:
@@ -380,15 +384,15 @@
case DataConstants.SHORT:
return getBuffer().readShort();
case DataConstants.CHAR:
- return getBuffer().readChar();
+ return (char)getBuffer().readShort();
case DataConstants.INT:
return getBuffer().readInt();
case DataConstants.LONG:
return getBuffer().readLong();
case DataConstants.FLOAT:
- return getBuffer().readFloat();
+ return Float.intBitsToFloat(getBuffer().readInt());
case DataConstants.DOUBLE:
- return getBuffer().readDouble();
+ return Double.longBitsToDouble(getBuffer().readLong());
case DataConstants.STRING:
return getBuffer().readNullableString();
case DataConstants.BYTES:
@@ -426,7 +430,7 @@
{
checkWrite();
getBuffer().writeByte(DataConstants.CHAR);
- getBuffer().writeChar(value);
+ getBuffer().writeShort((short)value);
}
public void writeInt(final int value) throws JMSException
@@ -447,14 +451,14 @@
{
checkWrite();
getBuffer().writeByte(DataConstants.FLOAT);
- getBuffer().writeFloat(value);
+ getBuffer().writeInt(Float.floatToIntBits(value));
}
public void writeDouble(final double value) throws JMSException
{
checkWrite();
getBuffer().writeByte(DataConstants.DOUBLE);
- getBuffer().writeDouble(value);
+ getBuffer().writeLong(Double.doubleToLongBits(value));
}
public void writeString(final String value) throws JMSException
@@ -562,7 +566,7 @@
// Protected -----------------------------------------------------
// Private -------------------------------------------------------
-
+
private HornetQBuffer getBuffer()
{
return message.getBodyBuffer();
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/jms/client/HornetQTextMessage.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -18,10 +18,10 @@
import javax.jms.JMSException;
import javax.jms.TextMessage;
+import org.hornetq.core.buffers.HornetQBuffer;
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;
/**
Modified: branches/20-optimisation/src/main/org/hornetq/utils/TypedProperties.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/utils/TypedProperties.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/utils/TypedProperties.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -40,9 +40,9 @@
import java.util.Set;
import java.util.Map.Entry;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.PropertyConversionException;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
*
@@ -896,7 +896,7 @@
public FloatValue(final HornetQBuffer buffer)
{
- val = buffer.readFloat();
+ val = Float.intBitsToFloat(buffer.readInt());
}
public Object getValue()
@@ -907,7 +907,7 @@
public void write(final HornetQBuffer buffer)
{
buffer.writeByte(FLOAT);
- buffer.writeFloat(val);
+ buffer.writeInt(Float.floatToIntBits(val));
}
public int encodeSize()
@@ -928,7 +928,7 @@
public DoubleValue(final HornetQBuffer buffer)
{
- val = buffer.readDouble();
+ val = Double.longBitsToDouble(buffer.readLong());
}
public Object getValue()
@@ -939,7 +939,7 @@
public void write(final HornetQBuffer buffer)
{
buffer.writeByte(DOUBLE);
- buffer.writeDouble(val);
+ buffer.writeLong(Double.doubleToLongBits(val));
}
public int encodeSize()
@@ -959,7 +959,7 @@
public CharValue(final HornetQBuffer buffer)
{
- val = buffer.readChar();
+ val = (char)buffer.readShort();
}
public Object getValue()
@@ -970,7 +970,7 @@
public void write(final HornetQBuffer buffer)
{
buffer.writeByte(CHAR);
- buffer.writeChar(val);
+ buffer.writeShort((short)val);
}
public int encodeSize()
Modified: branches/20-optimisation/src/main/org/hornetq/utils/UTF8Util.java
===================================================================
--- branches/20-optimisation/src/main/org/hornetq/utils/UTF8Util.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/src/main/org/hornetq/utils/UTF8Util.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -16,8 +16,8 @@
import java.io.IOException;
import java.lang.ref.SoftReference;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
*
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/jms-tests/src/org/hornetq/jms/tests/message/MessageHeaderTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -33,7 +33,7 @@
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-import org.hornetq.core.buffers.HornetQChannelBuffers;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -45,7 +45,6 @@
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.jms.client.HornetQBytesMessage;
import org.hornetq.jms.client.HornetQMapMessage;
import org.hornetq.jms.client.HornetQMessage;
@@ -672,8 +671,7 @@
public void testCopyOnJBossMessage() throws JMSException
{
- HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
- ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
+ ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, 1000);
ClientSession session = new FakeSession(clientMessage);
HornetQMessage jbossMessage = HornetQMessage.createMessage(clientMessage, session);
jbossMessage.clearProperties();
@@ -688,8 +686,7 @@
public void testCopyOnForeignMessage() throws JMSException
{
- HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
- ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
+ ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, 1000);
ClientSession session = new FakeSession(clientMessage);
Message foreignMessage = new SimpleJMSMessage();
@@ -702,8 +699,7 @@
public void testCopyOnForeignBytesMessage() throws JMSException
{
- HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
- ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
+ ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, 1000);
ClientSession session = new FakeSession(clientMessage);
BytesMessage foreignBytesMessage = new SimpleJMSBytesMessage();
@@ -722,8 +718,7 @@
public void testCopyOnForeignMapMessage() throws JMSException
{
- HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
- ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
+ ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, 1000);
ClientSession session = new FakeSession(clientMessage);
MapMessage foreignMapMessage = new SimpleJMSMapMessage();
foreignMapMessage.setInt("int", 1);
@@ -736,9 +731,8 @@
public void testCopyOnForeignObjectMessage() throws JMSException
- {
- HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
- ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
+ {
+ ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, 1000);
ClientSession session = new FakeSession(clientMessage);
ObjectMessage foreignObjectMessage = new SimpleJMSObjectMessage();
@@ -751,8 +745,7 @@
public void testCopyOnForeignStreamMessage() throws JMSException
{
- HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
- ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
+ ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, 1000);
ClientSession session = new FakeSession(clientMessage);
StreamMessage foreignStreamMessage = new SimpleJMSStreamMessage();
@@ -768,8 +761,7 @@
public void testCopyOnForeignTextMessage() throws JMSException
{
- HornetQBuffer body = HornetQChannelBuffers.buffer(1024);
- ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, body);
+ ClientMessage clientMessage = new ClientMessageImpl(HornetQTextMessage.TYPE, true, 0, System.currentTimeMillis(), (byte)4, 1000);
ClientSession session = new FakeSession(clientMessage);
TextMessage foreignTextMessage = new SimpleJMSTextMessage();
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/InterceptorTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/InterceptorTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/InterceptorTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -77,7 +77,7 @@
{
SessionSendMessage p = (SessionSendMessage)packet;
- ServerMessage sm = p.getServerMessage();
+ ServerMessage sm = (ServerMessage)p.getMessage();
sm.putStringProperty(key, "orange");
}
@@ -109,7 +109,7 @@
{
SessionReceiveMessage p = (SessionReceiveMessage)packet;
- ClientMessage cm = p.getClientMessage();
+ ClientMessage cm = (ClientMessage)p.getMessage();
cm.putStringProperty(key, "orange");
}
@@ -171,7 +171,7 @@
{
SessionSendMessage p = (SessionSendMessage)packet;
- ServerMessage sm = p.getServerMessage();
+ ServerMessage sm = (ServerMessage)p.getMessage();
sm.putIntProperty(key, num);
@@ -224,7 +224,7 @@
{
SessionReceiveMessage p = (SessionReceiveMessage)packet;
- Message sm = p.getClientMessage();
+ Message sm = p.getMessage();
sm.putIntProperty(key, num);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/AckBatchSizeTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -92,7 +92,7 @@
ClientMessage m = consumer.receive(5000);
Queue q = (Queue)server.getPostOffice().getBinding(queueA).getBindable();
- assertEquals(numMessages, q.getDeliveringCount());
+ assertEquals(1, q.getDeliveringCount());
m.acknowledge();
assertEquals(0, q.getDeliveringCount());
sendSession.close();
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/CoreClientTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,6 +13,7 @@
package org.hornetq.tests.integration.client;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.ClientProducer;
@@ -23,7 +24,6 @@
import org.hornetq.core.config.TransportConfiguration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.HornetQ;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.jms.client.HornetQTextMessage;
@@ -79,7 +79,7 @@
ClientProducer producer = session.createProducer(QUEUE);
- final int numMessages = 10;
+ final int numMessages = 1000;
for (int i = 0; i < numMessages; i++)
{
@@ -117,8 +117,6 @@
assertEquals("testINVMCoreClient", buffer.readString());
message2.acknowledge();
-
- log.info("got message " + i);
}
session.close();
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/InVMNonPersistentMessageBufferTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/InVMNonPersistentMessageBufferTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/InVMNonPersistentMessageBufferTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -63,7 +63,18 @@
assertEquals(body, received.getBodyBuffer().readString());
}
+
+ public void testSimpleSendReceiveWithEmptyBody() throws Exception
+ {
+ ClientMessage message = session.createClientMessage(false);
+
+ ClientMessage received = sendAndReceive(message);
+ assertNotNull(received);
+
+ assertEquals(0, received.getBodySize());
+ }
+
public void testSendSameMessageMultipleTimes() throws Exception
{
ClientMessage message = session.createClientMessage(false);
@@ -74,8 +85,12 @@
int bodySize = message.getBodySize();
+ log.info("body size is " + bodySize);
+
for (int i = 0; i < 10; i++)
{
+ log.info("sending " + i);
+
ClientMessage received = sendAndReceive(message);
assertNotNull(received);
@@ -94,6 +109,7 @@
for (int i = 0; i < 10; i++)
{
+ log.info("iteration " + i);
final String body = RandomUtil.randomString();
message.getBodyBuffer().writeString(body);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/LargeMessageTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -19,7 +19,10 @@
import javax.transaction.xa.Xid;
import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
@@ -31,9 +34,8 @@
import org.hornetq.core.config.Configuration;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.Message;
+import org.hornetq.core.persistence.impl.journal.JournalStorageManager;
import org.hornetq.core.persistence.impl.journal.LargeServerMessageImpl;
-import org.hornetq.core.persistence.impl.journal.JournalStorageManager;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.Queue;
import org.hornetq.core.settings.impl.AddressSettings;
@@ -53,6 +55,13 @@
*/
public class LargeMessageTest extends LargeMessageTestBase
{
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite();
+
+ return suite;
+ }
+
// Constants -----------------------------------------------------
final static int RECEIVE_WAIT_TIME = 60000;
@@ -304,9 +313,9 @@
assertNotNull(msg);
msg.acknowledge();
assertEquals(1, msg.getDeliveryCount());
-
+
log.info("body buffer is " + msg.getBodyBuffer());
-
+
for (int i = 0; i < messageSize; i++)
{
assertEquals(getSamplebyte(i), msg.getBodyBuffer().readByte());
@@ -2202,29 +2211,24 @@
ClientProducer producer = session.createProducer(ADDRESS);
- // printBuffer("body to be sent : " , body);
-
ClientMessage message = null;
HornetQBuffer body = null;
for (int i = 0; i < 100; i++)
{
- HornetQBuffer bodyLocal = HornetQChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfBytes);
-
+ message = session.createClientMessage(true);
+
for (int j = 1; j <= numberOfBytes; j++)
{
- bodyLocal.writeInt(j);
+ message.getBodyBuffer().writeInt(j);
}
if (i == 0)
{
- body = bodyLocal;
+ body = message.getBodyBuffer();
}
-
- message = session.createClientMessage(true);
- message.setBuffer(bodyLocal);
-
+
producer.send(message);
}
@@ -2262,12 +2266,13 @@
try
{
- assertEqualsByteArrays(body.writerIndex(), body.array(), message2.getBodyBuffer().array());
+ assertEqualsByteArrays(body.writerIndex(), body.toByteBuffer().array(), message2.getBodyBuffer().toByteBuffer().
+ array());
}
catch (AssertionFailedError e)
{
- log.info("Expected buffer:" + dumbBytesHex(body.array(), 40));
- log.info("Arriving buffer:" + dumbBytesHex(message2.getBodyBuffer().array(), 40));
+ log.info("Expected buffer:" + dumbBytesHex(body.toByteBuffer().array(), 40));
+ log.info("Arriving buffer:" + dumbBytesHex(message2.getBodyBuffer().toByteBuffer().array(), 40));
throw e;
}
}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/PagingTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -19,6 +19,7 @@
import junit.framework.AssertionFailedError;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
@@ -29,7 +30,6 @@
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.impl.MessageImpl;
import org.hornetq.core.paging.impl.TestSupportPageStore;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.Queue;
import org.hornetq.core.settings.impl.AddressFullMessagePolicy;
@@ -130,6 +130,8 @@
producer.send(message);
}
+
+ log.info("** sent messages");
session.close();
@@ -175,7 +177,7 @@
catch (AssertionFailedError e)
{
log.info("Expected buffer:" + dumbBytesHex(body, 40));
- log.info("Arriving buffer:" + dumbBytesHex(message2.getBodyBuffer().array(), 40));
+ log.info("Arriving buffer:" + dumbBytesHex(message2.getBodyBuffer().toByteBuffer().array(), 40));
throw e;
}
}
@@ -455,7 +457,7 @@
catch (AssertionFailedError e)
{
log.info("Expected buffer:" + dumbBytesHex(body, 40));
- log.info("Arriving buffer:" + dumbBytesHex(message2.getBodyBuffer().array(), 40));
+ log.info("Arriving buffer:" + dumbBytesHex(message2.getBodyBuffer().toByteBuffer().array(), 40));
throw e;
}
}
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/SelfExpandingBufferTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/SelfExpandingBufferTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/SelfExpandingBufferTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,13 +13,13 @@
package org.hornetq.tests.integration.client;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
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.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.tests.util.RandomUtil;
import org.hornetq.tests.util.ServiceTestBase;
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/TemporaryQueueTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/TemporaryQueueTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/client/TemporaryQueueTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -72,7 +72,9 @@
session.createTemporaryQueue(address, queue);
ClientProducer producer = session.createProducer(address);
- producer.send(session.createClientMessage(false));
+ ClientMessage msg = session.createClientMessage(false);
+
+ producer.send(msg);
session.start();
ClientConsumer consumer = session.createConsumer(queue);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/clientcrash/DummyInterceptor.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/clientcrash/DummyInterceptor.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/clientcrash/DummyInterceptor.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -57,8 +57,8 @@
if (packet instanceof SessionReceiveMessage)
{
SessionReceiveMessage deliver = (SessionReceiveMessage)packet;
- log.debug("msg = " + deliver.getServerMessage().getClass().getName());
- deliver.getServerMessage().putStringProperty(new SimpleString("DummyInterceptor"), new SimpleString("was here"));
+ log.debug("msg = " + deliver.getMessage().getClass().getName());
+ deliver.getMessage().putStringProperty(new SimpleString("DummyInterceptor"), new SimpleString("was here"));
}
}
return true;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/bridge/BridgeTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -666,8 +666,6 @@
{
ClientMessage message = session0.createClientMessage(false);
- message.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
-
message.putIntProperty(propKey, i);
producer0.send(message);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/bridge/SimpleTransformer.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/bridge/SimpleTransformer.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/bridge/SimpleTransformer.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -14,8 +14,8 @@
package org.hornetq.tests.integration.cluster.bridge;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.ServerMessage;
import org.hornetq.core.server.cluster.Transformer;
import org.hornetq.utils.SimpleString;
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/distribution/ClusterTestBase.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -823,7 +823,7 @@
message.acknowledge();
}
- // log.info("consumer " + consumerIDs[i] +" returns " + count);
+ log.info("consumer " + consumerIDs[i] +" returns " + count);
}
else
{
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/distribution/SymmetricClusterTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/distribution/SymmetricClusterTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/distribution/SymmetricClusterTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -166,24 +166,33 @@
setupCluster();
startServers();
+
+ log.info("*** started servers");
setupSessionFactory(0, isNetty());
setupSessionFactory(1, isNetty());
setupSessionFactory(2, isNetty());
setupSessionFactory(3, isNetty());
setupSessionFactory(4, isNetty());
+
+ log.info("** created session factories");
createQueue(0, "queues.testaddress", "queue0", null, false);
+
createQueue(1, "queues.testaddress", "queue0", null, false);
createQueue(2, "queues.testaddress", "queue0", null, false);
createQueue(3, "queues.testaddress", "queue0", null, false);
createQueue(4, "queues.testaddress", "queue0", null, false);
+
+ log.info("**** created queues");
addConsumer(0, 0, "queue0", null);
addConsumer(1, 1, "queue0", null);
addConsumer(2, 2, "queue0", null);
addConsumer(3, 3, "queue0", null);
addConsumer(4, 4, "queue0", null);
+
+ log.info("*** created consumers");
waitForBindings(0, "queues.testaddress", 1, 1, true);
waitForBindings(1, "queues.testaddress", 1, 1, true);
@@ -197,7 +206,13 @@
waitForBindings(3, "queues.testaddress", 4, 4, false);
waitForBindings(4, "queues.testaddress", 4, 4, false);
+ log.info("** sending messages");
+
send(0, "queues.testaddress", 10, false, null);
+
+ log.info("** sent messages");
+
+ // this.checkReceive(0, 1, 2, 3, 4);
verifyReceiveRoundRobinInSomeOrder(10, 0, 1, 2, 3, 4);
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/LargeMessageFailoverTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/LargeMessageFailoverTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/LargeMessageFailoverTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -15,9 +15,9 @@
import junit.framework.TestSuite;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
* A LargeMessageFailoverTest
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/PagingFailoverTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -114,7 +114,6 @@
session.commit();
}
ClientMessage msg = session.createClientMessage(true);
- 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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/cluster/failover/ReplicatedDistributionTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -16,7 +16,6 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-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,8 +77,6 @@
{
ClientMessage msg = sessionOne.createClientMessage(true);
- msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
-
msg.putIntProperty(new SimpleString("key"), i);
producer.send(msg);
@@ -181,8 +178,7 @@
for (int i = 0; i < 100; i++)
{
- ClientMessage msg = sessionOne.createClientMessage(true);
- msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
+ ClientMessage msg = sessionOne.createClientMessage(true);
msg.putIntProperty(new SimpleString("key"), i);
producer.send(msg);
}
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/http/NettyHttpTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/http/NettyHttpTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/http/NettyHttpTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -20,13 +20,13 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.remoting.impl.AbstractBufferHandler;
import org.hornetq.core.remoting.spi.BufferHandler;
import org.hornetq.core.remoting.spi.Connection;
import org.hornetq.core.remoting.spi.ConnectionLifeCycleListener;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.integration.transports.netty.NettyAcceptor;
import org.hornetq.integration.transports.netty.NettyConnector;
import org.hornetq.integration.transports.netty.TransportConstants;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -24,6 +24,7 @@
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientConsumer;
import org.hornetq.core.client.ClientMessage;
@@ -34,7 +35,6 @@
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.message.impl.MessageImpl;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.Queue;
import org.hornetq.tests.util.ServiceTestBase;
@@ -590,7 +590,7 @@
protected HornetQBuffer createLargeBuffer(final int numberOfIntegers)
{
- HornetQBuffer body = HornetQChannelBuffers.buffer(DataConstants.SIZE_INT * numberOfIntegers);
+ HornetQBuffer body = HornetQChannelBuffers.fixedBuffer(DataConstants.SIZE_INT * numberOfIntegers);
for (int i = 0; i < numberOfIntegers; i++)
{
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/integration/largemessage/mock/MockConnector.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/integration/largemessage/mock/MockConnector.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/largemessage/mock/MockConnector.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -17,12 +17,12 @@
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.remoting.impl.invm.InVMConnection;
import org.hornetq.core.remoting.impl.invm.InVMConnector;
import org.hornetq.core.remoting.spi.BufferHandler;
import org.hornetq.core.remoting.spi.Connection;
import org.hornetq.core.remoting.spi.ConnectionLifeCycleListener;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
* A MockConnector
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/management/ManagementHelperTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -149,7 +149,6 @@
Object[] params = new Object[] { i, s, d, b, l, map, strArray, maps };
Message msg = new ClientMessageImpl();
- msg.setBuffer(HornetQChannelBuffers.dynamicBuffer(1024));
ManagementHelper.putOperationInvocation(msg, resource, operationName, params);
Object[] parameters = ManagementHelper.retrieveOperationParameters(msg);
@@ -215,8 +214,7 @@
Object[] params = new Object[] { "hello", map };
- Message msg = new ClientMessageImpl();
- msg.setBuffer(HornetQChannelBuffers.dynamicBuffer(1024));
+ Message msg = new ClientMessageImpl();
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/management/ManagementServiceImplTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -16,6 +16,7 @@
import static org.hornetq.tests.util.RandomUtil.randomSimpleString;
import static org.hornetq.tests.util.RandomUtil.randomString;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.management.impl.ManagementHelper;
import org.hornetq.core.config.Configuration;
@@ -25,7 +26,6 @@
import org.hornetq.core.management.QueueControl;
import org.hornetq.core.management.ResourceNames;
import org.hornetq.core.management.impl.ManagementServiceImpl;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.HornetQ;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.core.server.Queue;
@@ -67,9 +67,7 @@
server.start();
// invoke attribute and operation on the server
- ServerMessage message = new ServerMessageImpl();
- HornetQBuffer body = HornetQChannelBuffers.buffer(2048);
- message.setBuffer(body);
+ ServerMessage message = new ServerMessageImpl(1, 100);
ManagementHelper.putOperationInvocation(message,
ResourceNames.CORE_SERVER,
"createQueue",
@@ -92,9 +90,7 @@
server.start();
// invoke attribute and operation on the server
- ServerMessage message = new ServerMessageImpl();
- HornetQBuffer body = HornetQChannelBuffers.buffer(2048);
- message.setBuffer(body);
+ ServerMessage message = new ServerMessageImpl(1, 100);
ManagementHelper.putOperationInvocation(message,
ResourceNames.CORE_SERVER,
"thereIsNoSuchOperation");
@@ -116,9 +112,7 @@
server.start();
// invoke attribute and operation on the server
- ServerMessage message = new ServerMessageImpl();
- HornetQBuffer body = HornetQChannelBuffers.buffer(2048);
- message.setBuffer(body);
+ ServerMessage message = new ServerMessageImpl(1, 100);
ManagementHelper.putOperationInvocation(message,
"Resouce.Does.Not.Exist",
"toString");
@@ -140,9 +134,8 @@
server.start();
// invoke attribute and operation on the server
- ServerMessage message = new ServerMessageImpl();
- HornetQBuffer body = HornetQChannelBuffers.buffer(2048);
- message.setBuffer(body);
+ ServerMessage message = new ServerMessageImpl(1, 100);
+
ManagementHelper.putAttribute(message, ResourceNames.CORE_SERVER, "attribute.Does.Not.Exist");
ServerMessage reply = server.getManagementService().handleMessage(message);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/integration/replication/ReplicationTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -27,6 +27,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientSessionFactory;
import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
@@ -54,7 +55,6 @@
import org.hornetq.core.remoting.Packet;
import org.hornetq.core.remoting.RemotingConnection;
import org.hornetq.core.remoting.impl.invm.InVMConnectorFactory;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.replication.impl.ReplicatedJournal;
import org.hornetq.core.replication.impl.ReplicationManagerImpl;
import org.hornetq.core.server.HornetQServer;
@@ -288,12 +288,11 @@
assertEquals(0, manager.getActiveTokens().size());
- ServerMessage msg = new ServerMessageImpl();
+ ServerMessage msg = new ServerMessageImpl(1, 10);
SimpleString dummy = new SimpleString("dummy");
msg.setDestination(dummy);
- msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[10]));
-
+
replicatedJournal.appendAddRecordTransactional(23, 24, (byte)1, new FakeData());
PagedMessage pgmsg = new PagedMessageImpl(msg, -1);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/CompactingStressTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -186,7 +186,7 @@
byte[] buffer = new byte[10 * 1024];
ClientMessage msg = session.createClientMessage(true);
- 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(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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/LargeJournalStressTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -116,8 +116,7 @@
}
slowProd.send(session.createClientMessage(true));
}
- ClientMessage msg = session.createClientMessage(true);
- msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
+ ClientMessage msg = session.createClientMessage(true);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/MultiThreadConsumerStressTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -248,8 +248,7 @@
{
System.out.println(Thread.currentThread().getName() + "::received #" + i);
}
- ClientMessage msg = session.createClientMessage(true);
- msg.setBuffer(HornetQChannelBuffers.wrappedBuffer(new byte[1024]));
+ ClientMessage msg = session.createClientMessage(true);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/stress/journal/NIOMultiThreadCompactorStressTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -455,7 +455,7 @@
// System.out.println(Thread.currentThread().getName() + "::sent #" + i);
}
ClientMessage msg = session.createClientMessage(true);
- 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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/timing/util/UTF8Test.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.tests.timing.util;
+import org.hornetq.core.buffers.HornetQBuffer;
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 = HornetQChannelBuffers.buffer(10 * 1024);
+ HornetQBuffer buffer = HornetQChannelBuffers.fixedBuffer(10 * 1024);
long start = System.currentTimeMillis();
@@ -72,7 +72,7 @@
public void testReadUTF() throws Exception
{
- HornetQBuffer buffer = HornetQChannelBuffers.buffer(10 * 1024);
+ HornetQBuffer buffer = HornetQChannelBuffers.fixedBuffer(10 * 1024);
buffer.writeUTF(str);
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/client/impl/LargeMessageBufferTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -25,7 +25,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
-import org.hornetq.core.buffers.HornetQChannelBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.client.ClientMessage;
import org.hornetq.core.client.MessageHandler;
@@ -114,7 +114,7 @@
{
LargeMessageBufferImpl buffer = create15BytesSample();
- HornetQChannelBuffer dstBuffer = HornetQChannelBuffers.buffer(20);
+ HornetQBuffer dstBuffer = HornetQChannelBuffers.fixedBuffer(20);
dstBuffer.setIndex(0, 5);
@@ -168,7 +168,7 @@
public void testReadData() throws Exception
{
- HornetQChannelBuffer dynamic = HornetQChannelBuffers.dynamicBuffer(1);
+ HornetQBuffer dynamic = HornetQChannelBuffers.dynamicBuffer(1);
String str1 = RandomUtil.randomString();
String str2 = RandomUtil.randomString();
@@ -180,7 +180,7 @@
dynamic.writeDouble(d1);
dynamic.writeFloat(f1);
- LargeMessageBufferImpl readBuffer = splitBuffer(3, dynamic.array());
+ LargeMessageBufferImpl readBuffer = splitBuffer(3, dynamic.toByteBuffer().array());
assertEquals(str1, readBuffer.readUTF());
assertEquals(str2, readBuffer.readString());
@@ -197,7 +197,7 @@
{
clearData();
- HornetQChannelBuffer dynamic = HornetQChannelBuffers.dynamicBuffer(1);
+ HornetQBuffer dynamic = HornetQChannelBuffers.dynamicBuffer(1);
String str1 = RandomUtil.randomString();
String str2 = RandomUtil.randomString();
@@ -209,7 +209,7 @@
dynamic.writeDouble(d1);
dynamic.writeFloat(f1);
- LargeMessageBufferImpl readBuffer = splitBuffer(3, dynamic.array(), getTestFile());
+ LargeMessageBufferImpl readBuffer = splitBuffer(3, dynamic.toByteBuffer().array(), getTestFile());
assertEquals(str1, readBuffer.readUTF());
assertEquals(str2, readBuffer.readString());
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/filter/impl/FilterTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -102,16 +102,14 @@
public void testHQSize() throws Exception
{
message.setDestination(RandomUtil.randomSimpleString());
- message.setBuffer(HornetQChannelBuffers.wrappedBuffer(RandomUtil.randomBytes(1)));
+
assertTrue(message.getEncodeSize() < 1024);
-
+
Filter moreThan128 = FilterImpl.createFilter(new SimpleString("HQSize > 128"));
Filter lessThan1024 = FilterImpl.createFilter(new SimpleString("HQSize < 1024"));
assertFalse(moreThan128.match(message));
assertTrue(lessThan1024.match(message));
-
- 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/journal/impl/fakes/FakeSequentialFileFactory.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -20,12 +20,12 @@
import java.util.concurrent.ConcurrentHashMap;
import org.hornetq.core.asyncio.BufferCallback;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.IOCompletion;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.journal.impl.TimedBuffer;
import org.hornetq.core.logging.Logger;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
*
@@ -607,7 +607,7 @@
*/
public void write(HornetQBuffer bytes, boolean sync, IOCompletion callback) throws Exception
{
- writeDirect(ByteBuffer.wrap(bytes.array()), sync, callback);
+ writeDirect(bytes.toByteBuffer(), sync, callback);
}
@@ -616,7 +616,7 @@
*/
public void write(HornetQBuffer bytes, boolean sync) throws Exception
{
- writeDirect(ByteBuffer.wrap(bytes.array()), sync);
+ writeDirect(bytes.toByteBuffer(), sync);
}
/* (non-Javadoc)
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/SimpleEncoding.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/SimpleEncoding.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/journal/impl/fakes/SimpleEncoding.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.tests.unit.core.journal.impl.fakes;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.EncodingSupport;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
/**
* Provides a SimpleEncoding with a Fake Payload
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/message/impl/MessageImplTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -25,13 +25,9 @@
import java.util.Set;
-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;
import org.hornetq.core.message.Message;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
-import org.hornetq.core.server.impl.ServerMessageImpl;
import org.hornetq.tests.util.UnitTestCase;
import org.hornetq.utils.SimpleString;
@@ -53,14 +49,13 @@
{
bytes[i] = randomByte();
}
- HornetQBuffer body = HornetQChannelBuffers.wrappedBuffer(bytes);
-
+
final byte type = randomByte();
final boolean durable = randomBoolean();
final long expiration = randomLong();
final long timestamp = randomLong();
final byte priority = randomByte();
- Message message1 = new ClientMessageImpl(type, durable, expiration, timestamp, priority, body);
+ Message message1 = new ClientMessageImpl(type, durable, expiration, timestamp, priority, 100);
Message message = message1;
@@ -90,9 +85,7 @@
message.setPriority(priority2);
assertEquals(priority2, message.getPriority());
-
- message.setBuffer(body);
- assertTrue(body == message.getBodyBuffer());
+
}
}
@@ -254,7 +247,7 @@
assertEquals(msg1.getType(), msg2.getType());
- assertEqualsByteArrays(msg1.getBodyBuffer().array(), msg2.getBodyBuffer().array());
+ assertEqualsByteArrays(msg1.getBodyBuffer().toByteBuffer().array(), msg2.getBodyBuffer().toByteBuffer().array());
assertEquals(msg1.getDestination(), msg2.getDestination());
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PageImplTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -17,7 +17,7 @@
import java.util.ArrayList;
import java.util.List;
-import org.hornetq.core.buffers.HornetQChannelBuffers;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.journal.SequentialFile;
import org.hornetq.core.journal.SequentialFileFactory;
import org.hornetq.core.journal.impl.NIOSequentialFileFactory;
@@ -25,7 +25,6 @@
import org.hornetq.core.paging.impl.PageImpl;
import org.hornetq.core.paging.impl.PagedMessageImpl;
import org.hornetq.core.persistence.impl.nullpm.NullStorageManager;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.ServerMessage;
import org.hornetq.core.server.impl.ServerMessageImpl;
import org.hornetq.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory;
@@ -109,7 +108,7 @@
assertEquals(simpleDestination, (msgs.get(i).getMessage(null)).getDestination());
- assertEqualsByteArrays(buffers.get(i).array(), (msgs.get(i).getMessage(null)).getBodyBuffer().array());
+ assertEqualsByteArrays(buffers.get(i).toByteBuffer().array(), (msgs.get(i).getMessage(null)).getBodyBuffer().toByteBuffer().array());
}
impl.delete();
@@ -182,7 +181,7 @@
assertEquals(simpleDestination, (msgs.get(i).getMessage(null)).getDestination());
- assertEqualsByteArrays(buffers.get(i).array(), (msgs.get(i).getMessage(null)).getBodyBuffer().array());
+ assertEqualsByteArrays(buffers.get(i).toByteBuffer().array(), (msgs.get(i).getMessage(null)).getBodyBuffer().toByteBuffer().array());
}
impl.delete();
@@ -208,20 +207,15 @@
for (int i = 0; i < numberOfElements; i++)
{
- HornetQBuffer buffer = HornetQChannelBuffers.buffer(10);
+ ServerMessage msg = new ServerMessageImpl(i, 1000);
- for (int j = 0; j < buffer.capacity(); j++)
- {
- //buffer.writeByte(RandomUtil.randomByte());
- buffer.writeByte((byte)'b');
+ for (int j = 0; j < msg.getBodyBuffer().capacity(); j++)
+ {
+ msg.getBodyBuffer().writeByte((byte)'b');
}
- buffers.add(buffer);
+ buffers.add(msg.getBodyBuffer());
- ServerMessage msg = new ServerMessageImpl();
-
- msg.setMessageID(i);
-
msg.setDestination(simpleDestination);
page.write(new PagedMessageImpl(msg));
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingManagerImplTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -90,7 +90,7 @@
assertEquals(1, msgs.size());
- assertEqualsByteArrays(msg.getBodyBuffer().array(), (msgs.get(0).getMessage(null)).getBodyBuffer().array());
+ assertEqualsByteArrays(msg.getBodyBuffer().toByteBuffer().array(), (msgs.get(0).getMessage(null)).getBodyBuffer().toByteBuffer().array());
assertTrue(store.isPaging());
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/paging/impl/PagingStoreImplTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -28,6 +28,7 @@
import javax.transaction.xa.Xid;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.JournalLoadInformation;
import org.hornetq.core.journal.SequentialFile;
@@ -47,7 +48,6 @@
import org.hornetq.core.persistence.StorageManager;
import org.hornetq.core.postoffice.Binding;
import org.hornetq.core.postoffice.PostOffice;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.replication.ReplicationManager;
import org.hornetq.core.server.LargeServerMessage;
import org.hornetq.core.server.MessageReference;
@@ -107,7 +107,7 @@
assertEquals(nr1, trans.getNumberOfMessages());
- HornetQBuffer buffer = HornetQChannelBuffers.buffer(trans.getEncodeSize());
+ HornetQBuffer buffer = HornetQChannelBuffers.fixedBuffer(trans.getEncodeSize());
trans.encode(buffer);
@@ -295,7 +295,7 @@
for (int i = 0; i < 10; i++)
{
assertEquals(0, msg.get(i).getMessage(null).getMessageID());
- assertEqualsByteArrays(buffers.get(i).array(), msg.get(i).getMessage(null).getBodyBuffer().array());
+ assertEqualsByteArrays(buffers.get(i).toByteBuffer().array(), msg.get(i).getMessage(null).getBodyBuffer().toByteBuffer().array());
}
}
@@ -366,7 +366,7 @@
for (int i = 0; i < 5; i++)
{
assertEquals(0, msg.get(i).getMessage(null).getMessageID());
- assertEqualsByteArrays(buffers.get(pageNr * 5 + i).array(), msg.get(i).getMessage(null).getBodyBuffer().array());
+ assertEqualsByteArrays(buffers.get(pageNr * 5 + i).toByteBuffer().array(), msg.get(i).getMessage(null).getBodyBuffer().toByteBuffer().array());
}
}
@@ -410,7 +410,7 @@
assertEquals(0l, msgs.get(0).getMessage(null).getMessageID());
- assertEqualsByteArrays(buffers.get(0).array(), msgs.get(0).getMessage(null).getBodyBuffer().array());
+ assertEqualsByteArrays(buffers.get(0).toByteBuffer().array(), msgs.get(0).getMessage(null).getBodyBuffer().toByteBuffer().array());
assertEquals(1, storeImpl.getNumberOfPages());
@@ -596,7 +596,7 @@
buffers2.put(id, msg.getMessage(null));
assertNotNull(msgWritten);
assertEquals(msg.getMessage(null).getDestination(), msgWritten.getDestination());
- assertEqualsByteArrays(msgWritten.getBodyBuffer().array(), msg.getMessage(null).getBodyBuffer().array());
+ assertEqualsByteArrays(msgWritten.getBodyBuffer().toByteBuffer().array(), msg.getMessage(null).getBodyBuffer().toByteBuffer().array());
}
}
@@ -666,7 +666,7 @@
ServerMessage msgWritten = buffers2.remove(id);
assertNotNull(msgWritten);
assertEquals(msg.getMessage(null).getDestination(), msgWritten.getDestination());
- assertEqualsByteArrays(msgWritten.getBodyBuffer().array(), msg.getMessage(null).getBodyBuffer().array());
+ assertEqualsByteArrays(msgWritten.getBodyBuffer().toByteBuffer().array(), msg.getMessage(null).getBodyBuffer().toByteBuffer().array());
}
}
@@ -677,7 +677,7 @@
lastMessages.get(0).getMessage(null).getBodyBuffer().resetReaderIndex();
assertEquals(lastMessages.get(0).getMessage(null).getBodyBuffer().readLong(), lastMessageId);
- assertEqualsByteArrays(lastMessages.get(0).getMessage(null).getBodyBuffer().array(), lastMsg.getBodyBuffer().array());
+ assertEqualsByteArrays(lastMessages.get(0).getMessage(null).getBodyBuffer().toByteBuffer().array(), lastMsg.getBodyBuffer().toByteBuffer().array());
assertEquals(0, buffers2.size());
@@ -717,7 +717,7 @@
private HornetQBuffer createRandomBuffer(final long id, final int size)
{
- HornetQBuffer buffer = HornetQChannelBuffers.buffer(size + 8);
+ HornetQBuffer buffer = HornetQChannelBuffers.fixedBuffer(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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/persistence/impl/BatchIDGeneratorUnitTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -16,6 +16,7 @@
import java.io.File;
import java.util.ArrayList;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
import org.hornetq.core.journal.Journal;
import org.hornetq.core.journal.PreparedTransactionInfo;
@@ -24,7 +25,6 @@
import org.hornetq.core.journal.impl.NIOSequentialFileFactory;
import org.hornetq.core.persistence.impl.journal.BatchingIDGenerator;
import org.hornetq.core.persistence.impl.journal.JournalStorageManager;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.tests.util.UnitTestCase;
/**
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/postoffice/impl/BindingsImplTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -14,12 +14,14 @@
package org.hornetq.tests.unit.core.postoffice.impl;
import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import javax.transaction.xa.Xid;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.filter.Filter;
import org.hornetq.core.message.BodyEncoder;
@@ -28,7 +30,6 @@
import org.hornetq.core.postoffice.Binding;
import org.hornetq.core.postoffice.BindingType;
import org.hornetq.core.postoffice.impl.BindingsImpl;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.core.server.Bindable;
import org.hornetq.core.server.MessageReference;
import org.hornetq.core.server.Queue;
@@ -891,7 +892,79 @@
}
+ public void setEncodedToBuffer(boolean encoded)
+ {
+ // TODO Auto-generated method stub
+
+ }
+ public void decodeFromBuffer(HornetQBuffer buffer)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public HornetQBuffer encodeToBuffer()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int getBodySize()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public int getEndOfMessagePosition()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public void saveToOutputStream(OutputStream out) throws HornetQException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setBodyInputStream(InputStream bodyInputStream)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setOutputStream(OutputStream out) throws HornetQException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean waitOutputStreamCompletion(long timeMilliseconds) throws HornetQException
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void beforeDeliver()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void beforeSend()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void forceCopy()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+
}
class FakeFilter implements Filter
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/HornetQBufferTestBase.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/HornetQBufferTestBase.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/HornetQBufferTestBase.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -21,7 +21,7 @@
import static org.hornetq.tests.util.RandomUtil.randomLong;
import static org.hornetq.tests.util.RandomUtil.randomString;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.tests.util.RandomUtil;
import org.hornetq.tests.util.UnitTestCase;
import org.hornetq.utils.SimpleString;
@@ -269,9 +269,9 @@
byte[] bytes = randomBytes(128);
wrapper.writeBytes(bytes);
- byte[] array = wrapper.array();
+ byte[] array = wrapper.toByteBuffer().array();
assertEquals(wrapper.capacity(), array.length);
- assertEqualsByteArrays(128, bytes, wrapper.array());
+ assertEqualsByteArrays(128, bytes, wrapper.toByteBuffer().array());
}
public void testRewind() throws Exception
Deleted: 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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/ByteBufferWrapperTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -1,56 +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.tests.unit.core.remoting.impl;
-
-import java.nio.ByteBuffer;
-
-import org.hornetq.core.buffers.HornetQChannelBuffers;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
-import org.hornetq.tests.unit.core.remoting.HornetQBufferTestBase;
-
-/**
- * @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class ByteBufferWrapperTest extends HornetQBufferTestBase
-{
-
- // Constants -----------------------------------------------------
-
- // Attributes ----------------------------------------------------
-
- // Static --------------------------------------------------------
-
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
- // HornetQBufferTestBase overrides -----------------------------
-
- @Override
- protected HornetQBuffer createBuffer()
- {
- return HornetQChannelBuffers.wrappedBuffer(ByteBuffer.allocate(512));
- }
-
- // Package protected ---------------------------------------------
-
- // Protected -----------------------------------------------------
-
- // Private -------------------------------------------------------
-
- // Inner classes -------------------------------------------------
-}
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/ChannelBufferWrapper2Test.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.tests.unit.core.remoting.impl.netty;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.tests.unit.core.remoting.HornetQBufferTestBase;
/**
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/ChannelBufferWrapperTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/ChannelBufferWrapperTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/ChannelBufferWrapperTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -13,8 +13,8 @@
package org.hornetq.tests.unit.core.remoting.impl.netty;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
-import org.hornetq.integration.transports.netty.ChannelBufferWrapper;
+import org.hornetq.core.buffers.HornetQBuffer;
+import org.hornetq.core.buffers.impl.ChannelBufferWrapper;
import org.hornetq.tests.unit.core.remoting.HornetQBufferTestBase;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyAcceptorFactoryTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyAcceptorFactoryTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyAcceptorFactoryTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -16,6 +16,7 @@
import java.util.Map;
import java.util.concurrent.Executors;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.remoting.impl.AbstractBufferHandler;
@@ -23,7 +24,6 @@
import org.hornetq.core.remoting.spi.BufferHandler;
import org.hornetq.core.remoting.spi.Connection;
import org.hornetq.core.remoting.spi.ConnectionLifeCycleListener;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.integration.transports.netty.NettyAcceptor;
import org.hornetq.integration.transports.netty.NettyAcceptorFactory;
import org.hornetq.tests.util.UnitTestCase;
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -17,13 +17,13 @@
import java.util.Map;
import java.util.concurrent.Executors;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.remoting.impl.AbstractBufferHandler;
import org.hornetq.core.remoting.spi.BufferHandler;
import org.hornetq.core.remoting.spi.Connection;
import org.hornetq.core.remoting.spi.ConnectionLifeCycleListener;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.integration.transports.netty.NettyAcceptor;
import org.hornetq.integration.transports.netty.TransportConstants;
import org.hornetq.tests.util.UnitTestCase;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyConnectionTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -19,11 +19,11 @@
import java.util.LinkedList;
import java.util.List;
+import org.hornetq.core.buffers.HornetQBuffer;
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;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.integration.transports.netty.NettyConnection;
import org.hornetq.tests.util.UnitTestCase;
import org.jboss.netty.channel.Channel;
@@ -60,8 +60,7 @@
NettyConnection conn = new NettyConnection(channel, new MyListener());
conn.write(buff);
- assertEquals(1, channel.getWritten().size());
- assertEquals(buff.getUnderlyingBuffer(), channel.getWritten().get(0));
+ assertEquals(1, channel.getWritten().size());
}
public void testCreateBuffer() throws Exception
Modified: branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java
===================================================================
--- branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java 2009-11-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/core/remoting/impl/netty/NettyConnectorTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -17,12 +17,12 @@
import java.util.Map;
import java.util.concurrent.Executors;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.exception.HornetQException;
import org.hornetq.core.remoting.impl.AbstractBufferHandler;
import org.hornetq.core.remoting.spi.BufferHandler;
import org.hornetq.core.remoting.spi.Connection;
import org.hornetq.core.remoting.spi.ConnectionLifeCycleListener;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.integration.transports.netty.NettyConnector;
import org.hornetq.tests.util.UnitTestCase;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/util/TypedPropertiesTest.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -26,8 +26,8 @@
import java.util.Iterator;
+import org.hornetq.core.buffers.HornetQBuffer;
import org.hornetq.core.buffers.HornetQChannelBuffers;
-import org.hornetq.core.remoting.spi.HornetQBuffer;
import org.hornetq.tests.util.UnitTestCase;
import org.hornetq.utils.SimpleString;
import org.hornetq.utils.TypedProperties;
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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/unit/util/UTF8Test.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -19,8 +19,8 @@
import java.io.DataOutputStream;
import java.nio.ByteBuffer;
+import org.hornetq.core.buffers.HornetQBuffer;
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;
import org.hornetq.utils.DataConstants;
@@ -41,7 +41,7 @@
public void testValidateUTF() throws Exception
{
- HornetQBuffer buffer = HornetQChannelBuffers.buffer(60 * 1024);
+ HornetQBuffer buffer = HornetQChannelBuffers.fixedBuffer(60 * 1024);
byte[] bytes = new byte[20000];
@@ -75,7 +75,7 @@
testValidateUTFOnDataInputStream(str, HornetQChannelBuffers.dynamicBuffer(100));
- testValidateUTFOnDataInputStream(str, HornetQChannelBuffers.buffer(100 * 1024));
+ testValidateUTFOnDataInputStream(str, HornetQChannelBuffers.fixedBuffer(100 * 1024));
}
}
@@ -83,7 +83,7 @@
{
UTF8Util.saveUTF(wrap, str);
- DataInputStream data = new DataInputStream(new ByteArrayInputStream(wrap.array()));
+ DataInputStream data = new DataInputStream(new ByteArrayInputStream(wrap.toByteBuffer().array()));
String newStr = data.readUTF();
@@ -113,7 +113,7 @@
String str = new String(chars);
- HornetQBuffer buffer = HornetQChannelBuffers.buffer(0xffff + 4);
+ HornetQBuffer buffer = HornetQChannelBuffers.fixedBuffer(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-23 21:22:09 UTC (rev 8386)
+++ branches/20-optimisation/tests/src/org/hornetq/tests/util/UnitTestCase.java 2009-11-23 23:27:50 UTC (rev 8387)
@@ -833,7 +833,7 @@
protected ServerMessage generateMessage(long id)
{
- ServerMessage message = new ServerMessageImpl();
+ ServerMessage message = new ServerMessageImpl(id, 1000);
message.setMessageID(id);
15 years, 1 month
JBoss hornetq SVN: r8386 - branches/ClebertCallback/tests/src/org/hornetq/tests/integration/client.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2009-11-23 16:22:09 -0500 (Mon, 23 Nov 2009)
New Revision: 8386
Modified:
branches/ClebertCallback/tests/src/org/hornetq/tests/integration/client/MessageGroupingTest.java
Log:
Fixing onePhase XA Commit
Modified: branches/ClebertCallback/tests/src/org/hornetq/tests/integration/client/MessageGroupingTest.java
===================================================================
--- branches/ClebertCallback/tests/src/org/hornetq/tests/integration/client/MessageGroupingTest.java 2009-11-23 21:16:26 UTC (rev 8385)
+++ branches/ClebertCallback/tests/src/org/hornetq/tests/integration/client/MessageGroupingTest.java 2009-11-23 21:22:09 UTC (rev 8386)
@@ -433,7 +433,7 @@
assertTrue(latch.await(10, TimeUnit.SECONDS));
clientSession.end(xid, XAResource.TMSUCCESS);
clientSession.prepare(xid);
- clientSession.commit(xid, true);
+ clientSession.commit(xid, false);
assertEquals(dummyMessageHandler.list.size(), 50);
int i = 0;
for (ClientMessage message : dummyMessageHandler.list)
15 years, 1 month
JBoss hornetq SVN: r8385 - branches/ClebertCallback/src/main/org/hornetq/core/management/impl.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2009-11-23 16:16:26 -0500 (Mon, 23 Nov 2009)
New Revision: 8385
Modified:
branches/ClebertCallback/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java
Log:
Fixing onePhase XA Commit
Modified: branches/ClebertCallback/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java
===================================================================
--- branches/ClebertCallback/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java 2009-11-23 21:07:39 UTC (rev 8384)
+++ branches/ClebertCallback/src/main/org/hornetq/core/management/impl/HornetQServerControlImpl.java 2009-11-23 21:16:26 UTC (rev 8385)
@@ -437,7 +437,7 @@
if (XidImpl.toBase64String(xid).equals(transactionAsBase64))
{
Transaction transaction = resourceManager.removeTransaction(xid);
- transaction.commit();
+ transaction.commit(false);
server.getStorageManager().waitOnOperations(-1);
long recordID = server.getStorageManager().storeHeuristicCompletion(xid, true);
resourceManager.putHeuristicCompletion(recordID, xid, true);
15 years, 1 month
JBoss hornetq SVN: r8384 - in branches/ClebertCallback: tests/src/org/hornetq/tests/integration/largemessage and 1 other directory.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2009-11-23 16:07:39 -0500 (Mon, 23 Nov 2009)
New Revision: 8384
Modified:
branches/ClebertCallback/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java
branches/ClebertCallback/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java
Log:
Fixing onePhase XA Commit
Modified: branches/ClebertCallback/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java
===================================================================
--- branches/ClebertCallback/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java 2009-11-23 20:32:47 UTC (rev 8383)
+++ branches/ClebertCallback/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java 2009-11-23 21:07:39 UTC (rev 8384)
@@ -203,9 +203,9 @@
}
}
- if (xid != null && !onePhase)
+ if (xid != null)
{
- if (state != State.PREPARED)
+ if (onePhase && state != State.ACTIVE || !onePhase && state != State.PREPARED)
{
throw new IllegalStateException("Transaction is in invalid state " + state);
}
Modified: branches/ClebertCallback/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java
===================================================================
--- branches/ClebertCallback/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java 2009-11-23 20:32:47 UTC (rev 8383)
+++ branches/ClebertCallback/tests/src/org/hornetq/tests/integration/largemessage/LargeMessageTestBase.java 2009-11-23 21:07:39 UTC (rev 8384)
@@ -237,7 +237,7 @@
producer = session.createProducer(ADDRESS);
- session.commit(xid, true);
+ session.commit(xid, false);
xid = newXID();
session.start(xid, XAResource.TMNOFLAGS);
}
15 years, 1 month
JBoss hornetq SVN: r8383 - in branches/ClebertCallback/src/main/org/hornetq/core: transaction/impl and 1 other directory.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2009-11-23 15:32:47 -0500 (Mon, 23 Nov 2009)
New Revision: 8383
Modified:
branches/ClebertCallback/src/main/org/hornetq/core/journal/impl/JournalImpl.java
branches/ClebertCallback/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java
Log:
one phase fix
Modified: branches/ClebertCallback/src/main/org/hornetq/core/journal/impl/JournalImpl.java
===================================================================
--- branches/ClebertCallback/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-11-23 20:03:33 UTC (rev 8382)
+++ branches/ClebertCallback/src/main/org/hornetq/core/journal/impl/JournalImpl.java 2009-11-23 20:32:47 UTC (rev 8383)
@@ -1366,14 +1366,12 @@
try
{
+
if (tx == null)
{
- log.warn("Commit being called on an empty transaction, ignoring call. ID = " + txID);
- // Commit being called on an empty transaction
- callback.done();
- return;
+ throw new IllegalStateException("Cannot find tx with id " + txID);
}
-
+
ChannelBuffer bb = newBuffer(SIZE_COMPLETE_TRANSACTION_RECORD);
writeTransaction(-1,
Modified: branches/ClebertCallback/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java
===================================================================
--- branches/ClebertCallback/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java 2009-11-23 20:03:33 UTC (rev 8382)
+++ branches/ClebertCallback/src/main/org/hornetq/core/transaction/impl/TransactionImpl.java 2009-11-23 20:32:47 UTC (rev 8383)
@@ -203,18 +203,8 @@
}
}
- if (xid != null)
+ if (xid != null && !onePhase)
{
- if (onePhase)
- {
- if (state == State.ACTIVE)
- {
- // Why do we need a prepare record on the onePhase optimization?
- // Why we can't just go straight to commit, if we are doing one phase anyway?
- state = State.PREPARED;
-// prepare();
- }
- }
if (state != State.PREPARED)
{
throw new IllegalStateException("Transaction is in invalid state " + state);
@@ -246,6 +236,8 @@
// We use the Callback even for non persistence
// If we are using non-persistence with replication, the replication manager will have
// to execute this runnable in the correct order
+ // This also will only use a different thread if there are any IO pendings.
+ // If the IO finished early by the time we got here, we won't need an executor
storageManager.afterCompleteOperations(new IOAsyncTask()
{
15 years, 1 month
JBoss hornetq SVN: r8382 - in branches/ClebertCallback/native: src and 1 other directory.
by do-not-reply@jboss.org
Author: clebert.suconic(a)jboss.com
Date: 2009-11-23 15:03:33 -0500 (Mon, 23 Nov 2009)
New Revision: 8382
Modified:
branches/ClebertCallback/native/bin/libHornetQAIO64.so
branches/ClebertCallback/native/src/Version.h
Log:
64 bits compilation and versioning
Modified: branches/ClebertCallback/native/bin/libHornetQAIO64.so
===================================================================
(Binary files differ)
Modified: branches/ClebertCallback/native/src/Version.h
===================================================================
--- branches/ClebertCallback/native/src/Version.h 2009-11-23 19:59:38 UTC (rev 8381)
+++ branches/ClebertCallback/native/src/Version.h 2009-11-23 20:03:33 UTC (rev 8382)
@@ -1,5 +1,5 @@
#ifndef _VERSION_NATIVE_AIO
-#define _VERSION_NATIVE_AIO 26
+#define _VERSION_NATIVE_AIO 27
#endif
15 years, 1 month