Author: clebert.suconic(a)jboss.com
Date: 2009-11-23 14:59:38 -0500 (Mon, 23 Nov 2009)
New Revision: 8381
Modified:
branches/ClebertCallback/src/main/org/hornetq/core/journal/impl/NIOSequentialFile.java
branches/ClebertCallback/tests/src/org/hornetq/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java
Log:
small tweak
Modified:
branches/ClebertCallback/src/main/org/hornetq/core/journal/impl/NIOSequentialFile.java
===================================================================
---
branches/ClebertCallback/src/main/org/hornetq/core/journal/impl/NIOSequentialFile.java 2009-11-23
18:34:17 UTC (rev 8380)
+++
branches/ClebertCallback/src/main/org/hornetq/core/journal/impl/NIOSequentialFile.java 2009-11-23
19:59:38 UTC (rev 8381)
@@ -155,6 +155,8 @@
log.warn("Couldn't get lock after 60 seconds on closing
AsynchronousFileImpl::" + this.getFileName());
}
}
+
+ maxIOSemaphore = null;
notifyAll();
}
@@ -252,6 +254,19 @@
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);
@@ -271,7 +286,7 @@
{
doInternalWrite(bytes, sync, callback);
}
- catch (Exception e)
+ catch (Throwable e)
{
log.warn("Exception on submitting write", e);
callback.onError(HornetQException.IO_ERROR, e.getMessage());
Modified:
branches/ClebertCallback/tests/src/org/hornetq/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java
===================================================================
---
branches/ClebertCallback/tests/src/org/hornetq/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java 2009-11-23
18:34:17 UTC (rev 8380)
+++
branches/ClebertCallback/tests/src/org/hornetq/tests/unit/core/journal/impl/SequentialFileFactoryTestBase.java 2009-11-23
19:59:38 UTC (rev 8381)
@@ -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;
/**
@@ -224,19 +226,19 @@
ByteBuffer bb3 = factory.wrapBuffer(bytes3);
long initialPos = sf.position();
- sf.writeDirect(bb1, true);
+ sf.write(wrapBuffer(bb1), true);
long bytesWritten = sf.position() - initialPos;
assertEquals(calculateRecordSize(bytes1.length, sf.getAlignment()), bytesWritten);
initialPos = sf.position();
- sf.writeDirect(bb2, true);
+ sf.write(wrapBuffer(bb2), true);
bytesWritten = sf.position() - initialPos;
assertEquals(calculateRecordSize(bytes2.length, sf.getAlignment()), bytesWritten);
initialPos = sf.position();
- sf.writeDirect(bb3, true);
+ sf.write(wrapBuffer(bb3), true);
bytesWritten = sf.position() - initialPos;
assertEquals(calculateRecordSize(bytes3.length, sf.getAlignment()), bytesWritten);
@@ -296,20 +298,20 @@
ByteBuffer bb3 = factory.wrapBuffer(bytes3);
long initialPos = sf.position();
- sf.writeDirect(bb1, true);
+ sf.write(wrapBuffer(bb1), true);
long bytesWritten = sf.position() - initialPos;
assertEquals(bb1.limit(), bytesWritten);
initialPos = sf.position();
- sf.writeDirect(bb2, true);
+ sf.write(wrapBuffer(bb2), true);
bytesWritten = sf.position() - initialPos;
assertEquals(bb2.limit(), bytesWritten);
initialPos = sf.position();
- sf.writeDirect(bb3, true);
+ sf.write(wrapBuffer(bb3), true);
bytesWritten = sf.position() - initialPos;
assertEquals(bb3.limit(), bytesWritten);
@@ -373,7 +375,7 @@
ByteBuffer bb1 = factory.wrapBuffer(bytes1);
long initialPos = sf.position();
- sf.writeDirect(bb1, true);
+ sf.write(wrapBuffer(bb1), true);
long bytesWritten = sf.position() - initialPos;
assertEquals(bb1.limit(), bytesWritten);
@@ -385,23 +387,27 @@
bb1 = factory.wrapBuffer(bytes1);
- sf.writeDirect(bb1, true);
+ sf.write(wrapBuffer(bb1), true);
fail("Should throw exception");
}
catch (Exception e)
{
- // OK
}
sf.open();
- sf.writeDirect(bb1, true);
+ sf.write(wrapBuffer(bb1), true);
sf.close();
}
// Private ---------------------------------
+
+ private HornetQBuffer wrapBuffer(ByteBuffer buffer)
+ {
+ return ChannelBuffers.wrappedBuffer(buffer);
+ }
protected void checkFill(final SequentialFile file, final int pos, final int size,
final byte fillChar) throws Exception
{