Package org.syncany.plugins.transfer
Class RemoteTransaction
- java.lang.Object
-
- org.syncany.plugins.transfer.RemoteTransaction
-
public class RemoteTransaction extends java.lang.Object
This class represents a transaction in a remote system. It will keep track of what files are to be added and ensures atomic operation.
-
-
Constructor Summary
Constructors Constructor Description RemoteTransaction(Config config, TransferManager transferManager)
RemoteTransaction(Config config, TransferManager transferManager, TransactionTO transactionTO)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
commit()
Commits this transaction by performing the required upload and delete operations.void
commit(java.io.File localTransactionFile, TransactionRemoteFile remoteTransactionFile)
Does exactly the same as the parameterless version, except it does not create and upload the transactionfile.void
delete(RemoteFile remoteFile)
Adds the deletion of a file to this transaction.boolean
isEmpty()
Returns whether the transaction is empty.void
upload(java.io.File localFile, RemoteFile remoteFile)
Adds a file to this transaction.void
writeToFile(Transformer transformer, java.io.File transactionFile)
This method serializes the current state of theRemoteTransaction
to a file.
-
-
-
Constructor Detail
-
RemoteTransaction
public RemoteTransaction(Config config, TransferManager transferManager)
-
RemoteTransaction
public RemoteTransaction(Config config, TransferManager transferManager, TransactionTO transactionTO)
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Returns whether the transaction is empty.
-
upload
public void upload(java.io.File localFile, RemoteFile remoteFile) throws StorageException
Adds a file to this transaction. Generates a temporary file to store it.- Throws:
StorageException
-
delete
public void delete(RemoteFile remoteFile) throws StorageException
Adds the deletion of a file to this transaction. Generates a temporary file to store it while the transaction is being finalized.- Throws:
StorageException
-
commit
public void commit() throws StorageException
Commits this transaction by performing the required upload and delete operations. The method first moves all files to the temporary remote location. If no errors occur, all files are moved to their final location.The method first writes a
TransactionRemoteFile
containing all actions to be performed and then uploads this file. Then it uploads new files (added byupload()
and moves deleted files to a temporary location (deleted bydelete()
.If this was successful, the transaction file is deleted and the temporary files. After deleting the transaction file, the transaction is successfully committed.
- Throws:
StorageException
-
commit
public void commit(java.io.File localTransactionFile, TransactionRemoteFile remoteTransactionFile) throws StorageException
Does exactly the same as the parameterless version, except it does not create and upload the transactionfile. Instead it uses the files that are passed. Used for resuming existing transactions. Only call this function if resuming cannot cause invalid states.- Throws:
StorageException
-
writeToFile
public void writeToFile(Transformer transformer, java.io.File transactionFile) throws StorageException
This method serializes the current state of theRemoteTransaction
to a file.- Parameters:
transactionFile
- The file where the transaction will be written to.- Throws:
StorageException
-
-