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, File directory, String file, int maxIO, Executor writerExecutor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidblockingWriteDirect(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 AtomicIntegergetDebugCounter(Exception location)static AtomicIntegergetDebugCounter(String strLocation)booleanisOpen()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(ByteBuffer bytes)intread(ByteBuffer bytes, IOCallback callback)longsize()voidsync()StringtoString()voidwriteDirect(ByteBuffer bytes, boolean sync)Write directly to the file without using intermediate any buffervoidwriteDirect(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, File directory, String file, int maxIO, 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 IOExceptionthis.maxIO represents the default maxIO. Some operations while initializing files on the journal may require a different maxIO- Throws:
IOException
-
map
public ByteBuffer map(int position, long size) throws IOException
- Throws:
IOException
-
clearDebug
public static void clearDebug()
-
printDebug
public static void printDebug()
-
getDebugCounter
public static AtomicInteger getDebugCounter(Exception location)
-
getDebugCounter
public static AtomicInteger getDebugCounter(String strLocation)
-
open
public void open(int maxIO, boolean useExecutor) throws IOExceptionDescription copied from interface:SequentialFileThe maximum number of simultaneous writes accepted- Throws:
IOException
-
fill
public void fill(int size) throws IOException- Throws:
IOException
-
close
public void close() throws IOException, InterruptedException, ActiveMQException- Specified by:
closein interfaceSequentialFile- Overrides:
closein classAbstractSequentialFile- Throws:
IOException- we declare throwing IOException because sub-classes need to do itInterruptedExceptionActiveMQException
-
close
public void close(boolean waitSync, boolean blockOnPending) throws IOException, InterruptedException, 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.
-
read
public int read(ByteBuffer bytes) throws 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:
Exception
-
read
public int read(ByteBuffer bytes, IOCallback callback) throws IOException, 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:
IOExceptionActiveMQIllegalStateException
-
sync
public void sync() throws IOException- Throws:
IOException
-
size
public long size() throws IOException- Throws:
IOException
-
position
public void position(long pos) throws IOException- Specified by:
positionin interfaceSequentialFile- Overrides:
positionin classAbstractSequentialFile- Throws:
IOException- only declare exception due to signature. Sub-class needs it.
-
cloneFile
public SequentialFile cloneFile()
-
writeDirect
public void writeDirect(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(ByteBuffer bytes, boolean sync) throws Exception
Description 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:
Exception
-
blockingWriteDirect
public void blockingWriteDirect(ByteBuffer bytes, boolean sync, boolean releaseBuffer) throws Exception
Description 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:
Exception
-
copyTo
public void copyTo(SequentialFile dstFile) throws IOException
- Specified by:
copyToin interfaceSequentialFile- Overrides:
copyToin classAbstractSequentialFile- Throws:
IOException
-
-