Package org.jitsi.impl.fileaccess
Class FailSafeTransactionImpl
- java.lang.Object
-
- org.jitsi.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
Constructors Modifier Constructor Description protectedFailSafeTransactionImpl(File file)Creates a new transaction.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginTransaction()Begins a new transaction.voidcommit()Closes the transaction and commit the changes.voidrestoreFile()Ensure that the file accessed is in a coherent state.voidrollback()Closes the transaction and cancels the changes.
-
-
-
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, IOExceptionEnsure that the file accessed is in a coherent state. This function is useful to do a failsafe read without starting a transaction.- Specified by:
restoreFilein interfaceFailSafeTransaction- Throws:
IllegalStateException- if the file doesn't exists anymoreIOException- if an IOException occurs during the file restoration
-
beginTransaction
public void beginTransaction() throws IllegalStateException, IOExceptionBegins 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:
beginTransactionin interfaceFailSafeTransaction- Throws:
IllegalStateException- if the file doesn't exists anymoreIOException- if an IOException occurs during the transaction creation
-
commit
public void commit() throws IllegalStateExceptionCloses the transaction and commit the changes. Everything written in the file during the transaction is saved.- Specified by:
commitin interfaceFailSafeTransaction- Throws:
IllegalStateException- if the file doesn't exists anymore
-
rollback
public void rollback() throws IllegalStateException, IOExceptionCloses the transaction and cancels the changes. Everything written in the file during the transaction is NOT saved.- Specified by:
rollbackin interfaceFailSafeTransaction- Throws:
IllegalStateException- if the file doesn't exists anymoreIOException- if an IOException occurs during the operation
-
-