Class DiskJournal

java.lang.Object
bitronix.tm.journal.DiskJournal
All Implemented Interfaces:
Journal, Service

public class DiskJournal extends Object implements Journal
Simple implementation of a journal that writes on a two-files disk log.

Files are pre-allocated in size, never grow and when the first one is full, dangling records are copied to the second file and logging starts again on the latter.

This implementation is not highly efficient but quite robust and simple. It is based on one of the implementations proposed by Mike Spille.

Configurable properties are all starting with bitronix.tm.journal.disk.

Author:
lorban
See Also:
  • Constructor Details

    • DiskJournal

      public DiskJournal()
      Create an uninitialized disk journal. You must call open() prior you can use it.
  • Method Details

    • log

      public void log(int status, Uid gtrid, Set<String> uniqueNames) throws IOException
      Log a new transaction status to journal. Note that the DiskJournal will not check the flow of the transaction. If you call this method with erroneous data, it will be added to the journal anyway.
      Specified by:
      log in interface Journal
      Parameters:
      status - transaction status to log. See Status constants.
      gtrid - raw GTRID of the transaction.
      uniqueNames - unique names of the ResourceBeans participating in this transaction.
      Throws:
      IOException - in case of disk IO failure or if the disk journal is not open.
    • force

      public void force() throws IOException
      Force active log file to synchronize with the underlying disk device.
      Specified by:
      force in interface Journal
      Throws:
      IOException - in case of disk IO failure or if the disk journal is not open.
    • open

      public void open() throws IOException
      Open the disk journal. Files are checked for integrity and DiskJournal will refuse to open corrupted log files. If files are not present on disk, this method will create and pre-allocate them.
      Specified by:
      open in interface Journal
      Throws:
      IOException - in case of disk IO failure.
    • close

      public void close() throws IOException
      Close the disk journal and the underlying files.
      Specified by:
      close in interface Journal
      Throws:
      IOException - in case of disk IO failure.
    • shutdown

      public void shutdown()
      Description copied from interface: Service
      Shutdown the service and free all held resources.
      Specified by:
      shutdown in interface Service
    • collectDanglingRecords

      public Map<Uid,TransactionLogRecord> collectDanglingRecords() throws IOException
      Collect all dangling records of the active log file.
      Specified by:
      collectDanglingRecords in interface Journal
      Returns:
      a Map using Uid objects GTRID as key and TransactionLogRecord as value
      Throws:
      IOException - in case of disk IO failure or if the disk journal is not open.