Class JournalImpl

  • All Implemented Interfaces:
    Journal

    public final class JournalImpl
    extends java.lang.Object
    implements Journal
    A high speed Journal implementation. Inspired by the ideas of the Howl project but tailored to the needs of ActiveMQ.

    This Journal provides the following features:

    • Concurrent writes are batched into a single write/force done by a background thread.
    • Uses preallocated logs to avoid disk fragmentation and performance degregation.
    • The number and size of the preallocated logs are configurable.
    • Uses direct ByteBuffers to write data to log files.
    • Allows logs to grow in case of an overflow condition so that overflow exceptions are not not thrown. Grown logs that are inactivate (due to a new mark) are resized to their original size.
    • No limit on the size of the record written to the journal
    • Should be possible to extend so that multiple physical disk are used concurrently to increase throughput and decrease latency.

    Version:
    $Revision: 1.1 $
    • Field Detail

      • DEFAULT_POOL_SIZE

        public static final int DEFAULT_POOL_SIZE
      • DEFAULT_PACKET_SIZE

        public static final int DEFAULT_PACKET_SIZE
    • Constructor Detail

      • JournalImpl

        public JournalImpl​(java.io.File logDirectory)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • JournalImpl

        public JournalImpl​(java.io.File logDirectory,
                           int logFileCount,
                           int logFileSize)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • JournalImpl

        public JournalImpl​(java.io.File logDirectory,
                           int logFileCount,
                           int logFileSize,
                           java.io.File archiveDirectory)
                    throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • write

        public RecordLocation write​(Packet data,
                                    boolean sync)
                             throws java.io.IOException
        Description copied from interface: Journal
        Writes a {@see Packet} of data to the journal. If sync is true, then this call blocks until the data has landed on the physical disk. Otherwise, this enqueues the write request and returns.
        Specified by:
        write in interface Journal
        sync - - If this call should block until the data lands on disk.
        Returns:
        RecordLocation the location where the data will be written to on disk.
        Throws:
        java.io.IOException - if the write failed.
      • getMark

        public RecordLocation getMark()
        Description copied from interface: Journal
        Obtains the mark that was set in the Journal.
        Specified by:
        getMark in interface Journal
        Returns:
      • handleExecutionException

        protected java.io.IOException handleExecutionException​(java.util.concurrent.ExecutionException e)
                                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • setJournalEventListener

        public void setJournalEventListener​(JournalEventListener eventListener)
        Description copied from interface: Journal
        Registers a JournalEventListener that will receive notifications from the Journal.
        Specified by:
        setJournalEventListener in interface Journal
        Parameters:
        eventListener - object that will receive journal events.
      • close

        public void close()
                   throws java.io.IOException
        Deprecated.
        Description copied from interface: Journal
        Close the Journal. This is blocking operation that waits for any pending put opperations to be forced to disk. Once the Journal is closed, all other methods of the journal should throw IllegalStateException.
        Specified by:
        close in interface Journal
        Throws:
        java.io.IOException - if an error occurs while the journal is being closed.
        See Also:
        dispose()
      • dispose

        public void dispose()
      • getLogDirectory

        public java.io.File getLogDirectory()
        Returns:
      • getInitialLogFileSize

        public int getInitialLogFileSize()
      • toString

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