public class FileSaveTransactionRunnable extends StartableTransactionRunnable<TransactionRunnable>
Constructor and Description |
---|
FileSaveTransactionRunnable(File toSave,
File tempFile,
File backupFile,
ReadWriteLock lock,
FileSerializer serializer)
The Constructor.
|
FileSaveTransactionRunnable(File toSave,
File tempFile,
File backupFile,
ReadWriteLock lock,
StreamProvider provider)
The Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected void |
onCommit() |
protected void |
onComplete() |
protected void |
onPreRun() |
protected void |
onRollback() |
protected void |
onRun() |
start
asProvider, getProvidedContext
commit, complete, getContext, preRun, rollback, run, runIn
public FileSaveTransactionRunnable(File toSave, File tempFile, File backupFile, ReadWriteLock lock, StreamProvider provider)
toSave
- the file to put the content in.tempFile
- a temporary file, this should not contain anything important as it will be deleted
and must not be altered while the operation is running. This will contain the data
until onCommit when it is renamed to the toSave file.backupFile
- a temporary file, this should not contain anything important as it will be deleted
and must not be altered while the operation is running. This will contain whatever
was in the toSave file prior, just in case onRollback must be called.lock
- a ReadWriteLock whose writeLock will be locked as the beginning of the process and
unlocked when complete.provider
- a StreamProvider to get the data to put into the file.public FileSaveTransactionRunnable(File toSave, File tempFile, File backupFile, ReadWriteLock lock, FileSerializer serializer)
toSave
- the file to put the content in.tempFile
- a temporary file, this should not contain anything important as it will be deleted
and must not be altered while the operation is running. This will contain the data
until onCommit when it is renamed to the toSave file.backupFile
- a temporary file, this should not contain anything important as it will be deleted
and must not be altered while the operation is running. This will contain whatever
was in the toSave file prior, just in case onRollback must be called.lock
- a ReadWriteLock whose writeLock will be locked as the beginning of the process and
unlocked when complete.serializer
- a FileSerializer in charge to serializing what need to be serialize to the file.protected void onPreRun() throws IOException
Obtain the lock and make sure the temporary and backup files are deleted.
onPreRun
in class TransactionRunnable<TransactionRunnable>
IOException
TransactionRunnable.preRun()
protected void onRun() throws Exception
Write the data from the provider to the temporary file.
onRun
in class TransactionRunnable<TransactionRunnable>
Exception
TransactionRunnable.run()
protected void onCommit()
Move whatever is in the main file location into backup and move the temp file into the main location.
onCommit
in class TransactionRunnable<TransactionRunnable>
TransactionRunnable.onCommit()
protected void onRollback()
onRollback
in class TransactionRunnable<TransactionRunnable>
protected void onComplete() throws IOException
Once this is called, there is no going back. Remove temporary and backup files and unlock the lock.
onComplete
in class TransactionRunnable<TransactionRunnable>
IOException
TransactionRunnable.onComplete()
Copyright © 2004–2021 XWiki. All rights reserved.