org.exolab.jms.tranlog
Class TransactionLog

java.lang.Object
  |
  +--org.exolab.jms.tranlog.TransactionLog

public class TransactionLog
extends java.lang.Object

The resource manager uses transaction logs to record the persistent records for the resource manager in case of recovery. All records are logged sequentially and each records has an associated XID. Log files have a finite size, after which they are closed and a new log file is opened. There is only one current transaction log file per resource manager.


Constructor Summary
TransactionLog(java.lang.String name, boolean create)
          Create a transaction log with the specified name, which includes the directory it will reside in.
 
Method Summary
 boolean canGarbageCollect()
          Check if we can garbage collect this transaction log.
 void close()
          Close the transaction log
 void destroy()
          Destroy this transaction log, which basically removes it from the file system
 boolean equals(java.lang.Object obj)
           
 java.lang.String getName()
          Return the name of the transaction log file
 void logTransactionData(ExternalXid txid, long expiry, java.lang.String rid, java.lang.Object data)
          Add an DataTransactionLogEntry using the specified txid, rid and data
 void logTransactionState(ExternalXid txid, long expiry, java.lang.String rid, TransactionState state)
          Add an StateTransactionLogEntry using the specified txid, rid and state
 java.util.HashMap recover()
          Force a recovery of this log file.
 long size()
          Return the size of the transaction log file.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionLog

public TransactionLog(java.lang.String name,
                      boolean create)
               throws TransactionLogException
Create a transaction log with the specified name, which includes the directory it will reside in. If the create flag is true then it will create the log file. If the create flag is false then it will assume that the log file already exists and will attempt to open it.

Attempting to create a file that already exists or open a non-exisitent log file with throw the TransactionLogException exception.

Parameters:
name - - the name of the transaction log absolute or final
vreate - - flag inidicating whether to open or create the log
Throws:
TransactionLogException -  
Method Detail

getName

public java.lang.String getName()
Return the name of the transaction log file
Returns:
String

logTransactionState

public void logTransactionState(ExternalXid txid,
                                long expiry,
                                java.lang.String rid,
                                TransactionState state)
                         throws TransactionLogException
Add an StateTransactionLogEntry using the specified txid, rid and state
Parameters:
txid - - the transaction identifier
expiry - - expiry time for the transaction
rid - - the resource identifier
state - - the transaction log state
Throws:
TransactionLogException - - if the entry cannot be created

logTransactionData

public void logTransactionData(ExternalXid txid,
                               long expiry,
                               java.lang.String rid,
                               java.lang.Object data)
                        throws TransactionLogException
Add an DataTransactionLogEntry using the specified txid, rid and data
Parameters:
txid - - the transaction identifier
expiry - - transaction expiry time
rid - - the resource identifier
data - - the opaque data to write
Throws:
TransactionLogException - - if the entry cannot be created

close

public void close()
           throws TransactionLogException
Close the transaction log
Throws:
TransactionLogException - - if it fails to close the log

size

public long size()
Return the size of the transaction log file.
Returns:
long - the length of the file

recover

public java.util.HashMap recover()
                          throws TransactionLogException
Force a recovery of this log file. This will close the output file stream if one is opened and then read each entry from the log file and send it to the specified listener, if one is allocated.

The returned data structure is a HashMap, where the key is a ExternalXid and the entries are LinkedList of BaseTransactionLogEntry objects

Returns:
HashMap - a list of open transactions
Throws:
TransactionLogException - - if there is a prob recovering

canGarbageCollect

public boolean canGarbageCollect()
Check if we can garbage collect this transaction log. It will go through the log file and check to see whether there are any open transaction. If there are no open transactions the it is a candidate for garage collection
Returns:
boolean - true if we can garbage collect; false otherwise

destroy

public void destroy()
             throws TransactionLogException
Destroy this transaction log, which basically removes it from the file system
Throws:
TransactionLogException -  

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object


Copyright © 1999-2007 The OpenJMS Group. All Rights Reserved.