Class 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.
    • 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 the RemoteTransaction to a file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Returns whether the transaction is empty.
      • 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 by upload() and moves deleted files to a temporary location (deleted by delete().

        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