bitronix.tm.journal
Class TransactionLogAppender

java.lang.Object
  extended by bitronix.tm.journal.TransactionLogAppender

public class TransactionLogAppender
extends java.lang.Object

Used to write TransactionLogRecord objects to a log file.

© Bitronix Software

Author:
lorban

Field Summary
static int END_RECORD
          int-encoded "xntB" ASCII string.
 
Constructor Summary
TransactionLogAppender(java.io.File file, long maxFileLength)
          Create an appender that will write to specified file up to the specified maximum length.
 
Method Summary
 void close()
          Close the appender and the underlying file.
protected  void doForce()
           
 void force()
          Force flushing the logs to disk
 TransactionLogCursor getCursor()
          Creates a cursor on this journal file allowing iteration of its records.
 TransactionLogHeader getHeader()
          Return a TransactionLogHeader that allows reading and controlling the log file's header.
 java.lang.String toString()
           
 boolean writeLog(TransactionLogRecord tlog)
          Write a TransactionLogRecord to disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

END_RECORD

public static final int END_RECORD
int-encoded "xntB" ASCII string. This will be useful after swapping log files since we will potentially overwrite old logs not necessarily of the same size. Very useful when debugging and eventually restoring broken log files.

See Also:
Constant Field Values
Constructor Detail

TransactionLogAppender

public TransactionLogAppender(java.io.File file,
                              long maxFileLength)
                       throws java.io.IOException
Create an appender that will write to specified file up to the specified maximum length. All disk access are synchronized arround the RandomAccessFile object, including header calls.

Parameters:
file - the underlying File used to write to disk.
maxFileLength - size of the file on disk that can never be bypassed.
Throws:
java.io.IOException - if an I/O error occurs.
Method Detail

getHeader

public TransactionLogHeader getHeader()
Return a TransactionLogHeader that allows reading and controlling the log file's header.

Returns:
this log file's TransactionLogHeader

writeLog

public boolean writeLog(TransactionLogRecord tlog)
                 throws java.io.IOException
Write a TransactionLogRecord to disk.

Parameters:
tlog - the record to write to disk.
Returns:
true if there was room in the log file and the log was written, false otherwise.
Throws:
java.io.IOException - if an I/O error occurs.

close

public void close()
           throws java.io.IOException
Close the appender and the underlying file.

Throws:
java.io.IOException - if an I/O error occurs.

getCursor

public TransactionLogCursor getCursor()
                               throws java.io.IOException
Creates a cursor on this journal file allowing iteration of its records. This opens a new read-only file descriptor independent of the write-only one still used for writing transaction logs.

Returns:
a TransactionLogCursor.
Throws:
java.io.IOException - if an I/O error occurs.

force

public void force()
           throws java.io.IOException
Force flushing the logs to disk

Throws:
java.io.IOException - if an I/O error occurs.

toString

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

doForce

protected void doForce()
                throws java.io.IOException
Throws:
java.io.IOException