public void setRemoteTempLocation(TempRemoteFile tempRemoteFile) { remoteTempLocation = tempRemoteFile.getName(); }
/** * Adds the deletion of a file to this transaction. Generates a temporary file * to store it while the transaction is being finalized. */ public void delete(RemoteFile remoteFile) throws StorageException { TempRemoteFile temporaryRemoteFile = new TempRemoteFile(remoteFile); logger.log(Level.INFO, "- Adding file to TX for DELETE: " + remoteFile + "-> Temp. remote file: " + temporaryRemoteFile); ActionTO action = new ActionTO(); action.setType(ActionType.DELETE); action.setRemoteLocation(remoteFile); action.setRemoteTempLocation(temporaryRemoteFile); transactionTO.addAction(action); }
/** * Adds a file to this transaction. Generates a temporary file to store it. */ public void upload(File localFile, RemoteFile remoteFile) throws StorageException { TempRemoteFile temporaryRemoteFile = new TempRemoteFile(remoteFile); logger.log(Level.INFO, "- Adding file to TX for UPLOAD: " + localFile + " -> Temp. remote file: " + temporaryRemoteFile + ", final location: " + remoteFile); ActionTO action = new ActionTO(); action.setType(ActionType.UPLOAD); action.setLocalTempLocation(localFile); action.setRemoteLocation(remoteFile); action.setRemoteTempLocation(temporaryRemoteFile); transactionTO.addAction(action); }
new Object[] { remoteFile.getName(), tempRemoteFile.getName() });
/** * Adds the opposite actions (rollback actions) for the given unfinished actions * to the rollback transaction. */ private void rollbackActions(List<ActionTO> unfinishedActions) throws StorageException { for (ActionTO action : unfinishedActions) { logger.log(Level.INFO, "- Needs to be rolled back: " + action); switch (action.getType()) { case UPLOAD: delete(action.getRemoteFile()); delete(action.getTempRemoteFile()); break; case DELETE: try { logger.log(Level.INFO, "- Rollback action: Moving " + action.getTempRemoteFile().getName() + " to " + action.getRemoteFile().getName()); move(action.getTempRemoteFile(), action.getRemoteFile()); } catch (StorageMoveException e) { logger.log(Level.WARNING, "Restoring deleted file failed. This might be a problem if the original: " + action.getRemoteFile() + " also does not exist.", e); } break; default: throw new RuntimeException("Transaction contains invalid type: " + action.getType() + ". This should not happen."); } } }