Class NIOSequentialFile

    • Constructor Detail

      • NIOSequentialFile

        public NIOSequentialFile​(SequentialFileFactory factory,
                                 java.io.File directory,
                                 java.lang.String file,
                                 int maxIO,
                                 java.util.concurrent.Executor writerExecutor)
    • Method Detail

      • calculateBlockStart

        public int calculateBlockStart​(int position)
      • isOpen

        public boolean isOpen()
      • open

        public void open()
                  throws java.io.IOException
        this.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.IOException
        Description copied from interface: SequentialFile
        The 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:
        close in interface SequentialFile
        Overrides:
        close in class AbstractSequentialFile
        Throws:
        java.io.IOException - we declare throwing IOException because sub-classes need to do it
        java.lang.InterruptedException
        org.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.ActiveMQException
        Description copied from interface: SequentialFile
        When 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.IOException
        java.lang.InterruptedException
        org.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 corresponding SequentialFileFactory.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 corresponding SequentialFileFactory.newBuffer(int).
        Throws:
        java.io.IOException
        org.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:
        position in interface SequentialFile
        Overrides:
        position in class AbstractSequentialFile
        Throws:
        java.io.IOException - only declare exception due to signature. Sub-class needs it.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • writeDirect

        public void writeDirect​(java.nio.ByteBuffer bytes,
                                boolean sync,
                                IOCallback callback)
        Description copied from interface: SequentialFile
        Write 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 corresponding SequentialFileFactory.newBuffer(int).
      • writeDirect

        public void writeDirect​(java.nio.ByteBuffer bytes,
                                boolean sync)
                         throws java.lang.Exception
        Description copied from interface: SequentialFile
        Write 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 corresponding SequentialFileFactory.newBuffer(int).
        Throws:
        java.lang.Exception
      • blockingWriteDirect

        public void blockingWriteDirect​(java.nio.ByteBuffer bytes,
                                        boolean sync,
                                        boolean releaseBuffer)
                                 throws java.lang.Exception
        Description copied from interface: SequentialFile
        Write directly to the file without using any intermediate buffer and wait completion.
        If releaseBuffer is true the provided bytes should be released through SequentialFileFactory.releaseBuffer(ByteBuffer), if supported.
        Parameters:
        bytes - the ByteBuffer must be compatible with the SequentialFile implementation (AIO or NIO). If releaseBuffer is true use a buffer from SequentialFileFactory.newBuffer(int), SequentialFileFactory.allocateDirectBuffer(int) otherwise.
        sync - if true will durable flush the written data on the file, false otherwise
        releaseBuffer - if true will release the buffer, false otherwise
        Throws:
        java.lang.Exception