Class NIOSequentialFile
- java.lang.Object
-
- org.apache.activemq.artemis.core.io.AbstractSequentialFile
-
- org.apache.activemq.artemis.core.io.nio.NIOSequentialFile
-
- All Implemented Interfaces:
SequentialFile
public class NIOSequentialFile extends AbstractSequentialFile
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.activemq.artemis.core.io.AbstractSequentialFile
AbstractSequentialFile.LocalBufferObserver
-
-
Field Summary
-
Fields inherited from class org.apache.activemq.artemis.core.io.AbstractSequentialFile
directory, factory, file, fileSize, position, timedBuffer, timedBufferObserver
-
-
Constructor Summary
Constructors Constructor Description NIOSequentialFile(SequentialFileFactory factory, java.io.File directory, java.lang.String file, int maxIO, java.util.concurrent.Executor writerExecutor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidblockingWriteDirect(java.nio.ByteBuffer bytes, boolean sync, boolean releaseBuffer)Write directly to the file without using any intermediate buffer and wait completion.
IfreleaseBufferistruethe providedbytesshould be released throughSequentialFileFactory.releaseBuffer(ByteBuffer), if supported.intcalculateBlockStart(int position)static voidclearDebug()SequentialFilecloneFile()voidclose()voidclose(boolean waitSync, boolean blockOnPending)When closing a file from a finalize block, you cant wait on syncs or anything like that.voidcopyTo(SequentialFile dstFile)protected TimedBufferObservercreateTimedBufferObserver()voidfill(int size)static java.util.concurrent.atomic.AtomicIntegergetDebugCounter(java.lang.Exception location)static java.util.concurrent.atomic.AtomicIntegergetDebugCounter(java.lang.String strLocation)booleanisOpen()java.nio.ByteBuffermap(int position, long size)voidopen()this.maxIO represents the default maxIO.voidopen(int maxIO, boolean useExecutor)The maximum number of simultaneous writes acceptedvoidposition(long pos)static voidprintDebug()intread(java.nio.ByteBuffer bytes)intread(java.nio.ByteBuffer bytes, IOCallback callback)longsize()voidsync()java.lang.StringtoString()voidwriteDirect(java.nio.ByteBuffer bytes, boolean sync)Write directly to the file without using intermediate any buffervoidwriteDirect(java.nio.ByteBuffer bytes, boolean sync, IOCallback callback)Write directly to the file without using any buffer-
Methods inherited from class org.apache.activemq.artemis.core.io.AbstractSequentialFile
delete, exists, fits, getFile, getFileName, getJavaFile, newBuffer, position, renameTo, setTimedBuffer, write, write, write, write
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.activemq.artemis.core.io.SequentialFile
afterComplete
-
-
-
-
Constructor Detail
-
NIOSequentialFile
public NIOSequentialFile(SequentialFileFactory factory, java.io.File directory, java.lang.String file, int maxIO, java.util.concurrent.Executor writerExecutor)
-
-
Method Detail
-
createTimedBufferObserver
protected TimedBufferObserver createTimedBufferObserver()
- Overrides:
createTimedBufferObserverin classAbstractSequentialFile
-
calculateBlockStart
public int calculateBlockStart(int position)
-
isOpen
public boolean isOpen()
-
open
public void open() throws java.io.IOExceptionthis.maxIO represents the default maxIO. Some operations while initializing files on the journal may require a different maxIO- Throws:
java.io.IOException
-
map
public java.nio.ByteBuffer map(int position, long size) throws java.io.IOException- Throws:
java.io.IOException
-
clearDebug
public static void clearDebug()
-
printDebug
public static void printDebug()
-
getDebugCounter
public static java.util.concurrent.atomic.AtomicInteger getDebugCounter(java.lang.Exception location)
-
getDebugCounter
public static java.util.concurrent.atomic.AtomicInteger getDebugCounter(java.lang.String strLocation)
-
open
public void open(int maxIO, boolean useExecutor) throws java.io.IOExceptionDescription copied from interface:SequentialFileThe maximum number of simultaneous writes accepted- Throws:
java.io.IOException
-
fill
public void fill(int size) throws java.io.IOException- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException, java.lang.InterruptedException, org.apache.activemq.artemis.api.core.ActiveMQException- Specified by:
closein interfaceSequentialFile- Overrides:
closein classAbstractSequentialFile- Throws:
java.io.IOException- we declare throwing IOException because sub-classes need to do itjava.lang.InterruptedExceptionorg.apache.activemq.artemis.api.core.ActiveMQException
-
close
public void close(boolean waitSync, boolean blockOnPending) throws java.io.IOException, java.lang.InterruptedException, org.apache.activemq.artemis.api.core.ActiveMQExceptionDescription copied from interface:SequentialFileWhen closing a file from a finalize block, you cant wait on syncs or anything like that. otherwise the VM may hung. Especially on the testsuite.- Throws:
java.io.IOExceptionjava.lang.InterruptedExceptionorg.apache.activemq.artemis.api.core.ActiveMQException
-
read
public int read(java.nio.ByteBuffer bytes) throws java.lang.Exception- Parameters:
bytes- the ByteBuffer must be compatible with the SequentialFile implementation (AIO or NIO). To be safe, use a buffer from the correspondingSequentialFileFactory.newBuffer(int).- Throws:
java.lang.Exception
-
read
public int read(java.nio.ByteBuffer bytes, IOCallback callback) throws java.io.IOException, org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException- Parameters:
bytes- the ByteBuffer must be compatible with the SequentialFile implementation (AIO or NIO). To be safe, use a buffer from the correspondingSequentialFileFactory.newBuffer(int).- Throws:
java.io.IOExceptionorg.apache.activemq.artemis.api.core.ActiveMQIllegalStateException
-
sync
public void sync() throws java.io.IOException- Throws:
java.io.IOException
-
size
public long size() throws java.io.IOException- Throws:
java.io.IOException
-
position
public void position(long pos) throws java.io.IOException- Specified by:
positionin interfaceSequentialFile- Overrides:
positionin classAbstractSequentialFile- Throws:
java.io.IOException- only declare exception due to signature. Sub-class needs it.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
cloneFile
public SequentialFile cloneFile()
-
writeDirect
public void writeDirect(java.nio.ByteBuffer bytes, boolean sync, IOCallback callback)Description copied from interface:SequentialFileWrite directly to the file without using any buffer- Parameters:
bytes- the ByteBuffer must be compatible with the SequentialFile implementation (AIO or NIO). To be safe, use a buffer from the correspondingSequentialFileFactory.newBuffer(int).
-
writeDirect
public void writeDirect(java.nio.ByteBuffer bytes, boolean sync) throws java.lang.ExceptionDescription copied from interface:SequentialFileWrite directly to the file without using intermediate any buffer- Parameters:
bytes- the ByteBuffer must be compatible with the SequentialFile implementation (AIO or NIO). To be safe, use a buffer from the correspondingSequentialFileFactory.newBuffer(int).- Throws:
java.lang.Exception
-
blockingWriteDirect
public void blockingWriteDirect(java.nio.ByteBuffer bytes, boolean sync, boolean releaseBuffer) throws java.lang.ExceptionDescription copied from interface:SequentialFileWrite directly to the file without using any intermediate buffer and wait completion.
IfreleaseBufferistruethe providedbytesshould be released throughSequentialFileFactory.releaseBuffer(ByteBuffer), if supported.- Parameters:
bytes- the ByteBuffer must be compatible with the SequentialFile implementation (AIO or NIO). IfreleaseBufferistrueuse a buffer fromSequentialFileFactory.newBuffer(int),SequentialFileFactory.allocateDirectBuffer(int)otherwise.sync- iftruewill durable flush the written data on the file,falseotherwisereleaseBuffer- iftruewill release the buffer,falseotherwise- Throws:
java.lang.Exception
-
copyTo
public void copyTo(SequentialFile dstFile) throws java.io.IOException
- Specified by:
copyToin interfaceSequentialFile- Overrides:
copyToin classAbstractSequentialFile- Throws:
java.io.IOException
-
-