Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.fileaccess
Class FailSafeTransactionImpl

java.lang.Object
  extended by net.java.sip.communicator.impl.fileaccess.FailSafeTransactionImpl
All Implemented Interfaces:
FailSafeTransaction

public class FailSafeTransactionImpl
extends Object
implements FailSafeTransaction

A failsafe transaction class. By failsafe we mean here that the file concerned always stays in a coherent state. This class use the transactional model.

Author:
Benoit Pradelle

Constructor Summary
protected FailSafeTransactionImpl(File file)
          Creates a new transaction.
 
Method Summary
 void beginTransaction()
          Begins a new transaction.
 void commit()
          Closes the transaction and commit the changes.
 void restoreFile()
          Ensure that the file accessed is in a coherent state.
 void rollback()
          Closes the transation and cancel the changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FailSafeTransactionImpl

protected FailSafeTransactionImpl(File file)
                           throws NullPointerException
Creates a new transaction.

Parameters:
file - The file associated with this transaction
Throws:
NullPointerException - if the file is null
Method Detail

restoreFile

public void restoreFile()
                 throws IllegalStateException,
                        IOException
Ensure that the file accessed is in a coherent state. This function is useful to do a failsafe read without starting a transaction.

Specified by:
restoreFile in interface FailSafeTransaction
Throws:
IllegalStateException - if the file doesn't exists anymore
IOException - if an IOException occurs during the file restoration

beginTransaction

public void beginTransaction()
                      throws IllegalStateException,
                             IOException
Begins a new transaction. If a transaction is already active, commits the changes and begin a new transaction. A transaction can be closed by a commit or rollback operation. When the transaction begins, the file is restored to a coherent state if needed.

Specified by:
beginTransaction in interface FailSafeTransaction
Throws:
IllegalStateException - if the file doesn't exists anymore
IOException - if an IOException occurs during the transaction creation

commit

public void commit()
            throws IllegalStateException,
                   IOException
Closes the transaction and commit the changes. Everything written in the file during the transaction is saved.

Specified by:
commit in interface FailSafeTransaction
Throws:
IllegalStateException - if the file doesn't exists anymore
IOException - if an IOException occurs during the operation

rollback

public void rollback()
              throws IllegalStateException,
                     IOException
Closes the transation and cancel the changes. Everything written in the file during the transaction is NOT saved.

Specified by:
rollback in interface FailSafeTransaction
Throws:
IllegalStateException - if the file doesn't exists anymore
IOException - if an IOException occurs during the operation

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.