diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/IncomingProcessor.java b/datamover/source/java/ch/systemsx/cisd/datamover/IncomingProcessor.java index 119ffc8b7105562baf4531d505183b337afd1945..f5af0bb0fc6db9484a270f3939b6aeef23a50714 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/IncomingProcessor.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/IncomingProcessor.java @@ -17,9 +17,9 @@ import ch.systemsx.cisd.common.utilities.ITerminable; import ch.systemsx.cisd.common.utilities.NamePrefixFileFilter; import ch.systemsx.cisd.common.utilities.DirectoryScanningTimerTask.IPathHandler; import ch.systemsx.cisd.datamover.common.MarkerFile; -import ch.systemsx.cisd.datamover.filesystem.LocalFileSystem; import ch.systemsx.cisd.datamover.filesystem.RemoteMonitoredMoverFactory; import ch.systemsx.cisd.datamover.filesystem.intf.IFileSysOperationsFactory; +import ch.systemsx.cisd.datamover.filesystem.intf.IPathMover; import ch.systemsx.cisd.datamover.filesystem.intf.IReadPathOperations; import ch.systemsx.cisd.datamover.utils.FileStore; import ch.systemsx.cisd.datamover.utils.LocalBufferDirs; @@ -55,6 +55,8 @@ public class IncomingProcessor private final IFileSysOperationsFactory factory; private final IReadPathOperations incomingReadOperations; + + private final IPathMover pathMover; private final LocalBufferDirs bufferDirs; @@ -78,6 +80,7 @@ public class IncomingProcessor this.prefixForIncoming = parameters.getPrefixForIncoming(); this.isIncomingRemote = parameters.getTreatIncomingAsRemote(); this.incomingReadOperations = factory.getReadPathOperations(); + this.pathMover = factory.getMover(); this.factory = factory; this.bufferDirs = bufferDirs; } @@ -214,9 +217,9 @@ public class IncomingProcessor return RemoteMonitoredMoverFactory.create(sourceHost, destinationDirectory, destinationHost, factory, parameters); } - private static File tryMoveLocal(File sourceFile, File destinationDir, String prefixTemplate) + private File tryMoveLocal(File sourceFile, File destinationDir, String prefixTemplate) { - return LocalFileSystem.tryMoveLocal(sourceFile, destinationDir, prefixTemplate); + return pathMover.tryMove(sourceFile, destinationDir, prefixTemplate); } // ------------------- recovery ------------------------ diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/LocalProcessor.java b/datamover/source/java/ch/systemsx/cisd/datamover/LocalProcessor.java index b48ccc18a687f1de9bf1b4c749e71bbd3a435671..e85af7565c79515bc7ccdf34e417bb678a34c8c6 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/LocalProcessor.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/LocalProcessor.java @@ -30,9 +30,9 @@ import ch.systemsx.cisd.common.utilities.FileUtilities; import ch.systemsx.cisd.common.utilities.RegexFileFilter; import ch.systemsx.cisd.common.utilities.DirectoryScanningTimerTask.IPathHandler; import ch.systemsx.cisd.common.utilities.RegexFileFilter.PathType; -import ch.systemsx.cisd.datamover.filesystem.LocalFileSystem; import ch.systemsx.cisd.datamover.filesystem.intf.IFileSysOperationsFactory; import ch.systemsx.cisd.datamover.filesystem.intf.IPathImmutableCopier; +import ch.systemsx.cisd.datamover.filesystem.intf.IPathMover; import ch.systemsx.cisd.datamover.filesystem.intf.IReadPathOperations; import ch.systemsx.cisd.datamover.utils.LazyPathHandler; @@ -54,6 +54,8 @@ public class LocalProcessor implements IPathHandler private final IPathImmutableCopier copier; + private final IPathMover mover; + private final IReadPathOperations readOperations; // output: from here data are moved when processing is finished. @@ -78,6 +80,7 @@ public class LocalProcessor implements IPathHandler this.outgoingHandler = outgoingHandler; this.extraCopyDirOrNull = parameters.tryGetExtraCopyDir(); this.copier = factory.getImmutableCopier(); + this.mover = factory.getMover(); this.readOperations = factory.getReadPathOperations(); } @@ -118,7 +121,7 @@ public class LocalProcessor implements IPathHandler // could change. We move the copy to that directory to ensure clean recovery from errors. if (extraCopyDirOrNull != null) { - LocalFileSystem.tryMoveLocal(file, extraCopyDirOrNull); + mover.tryMove(file, extraCopyDirOrNull); } } } @@ -165,7 +168,7 @@ public class LocalProcessor implements IPathHandler } } - final File movedFile = LocalFileSystem.tryMoveLocal(path, outputDir); + final File movedFile = mover.tryMove(path, outputDir); if (movedFile != null) { outgoingHandler.handle(movedFile); @@ -179,7 +182,7 @@ public class LocalProcessor implements IPathHandler if (extraTmpCopy != null) { assert extraCopyDirOrNull != null; - File extraCopy = LocalFileSystem.tryMoveLocal(extraTmpCopy, extraCopyDirOrNull); + File extraCopy = mover.tryMove(extraTmpCopy, extraCopyDirOrNull); if (extraCopy == null) { notificationLog.error(String.format("Moving temporary extra copy '%s' to destination '%s' failed.", @@ -248,7 +251,7 @@ public class LocalProcessor implements IPathHandler { log(resource, "Moving to manual intervention directory"); File manualInterventionDir = parameters.getManualInterventionDirectory(); - File movedFile = LocalFileSystem.tryMoveLocal(resource, manualInterventionDir); + File movedFile = mover.tryMove(resource, manualInterventionDir); return (movedFile != null) ? EFileManipResult.STOP : EFileManipResult.FAILURE; } else { diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/FileSysOperationsFactory.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/FileSysOperationsFactory.java index aa8d7c72533a92a68c00a793666531ca05aad9f6..917b60ad0c87ddf28f22391204f3440fb4ca9e5b 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/FileSysOperationsFactory.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/FileSysOperationsFactory.java @@ -34,6 +34,7 @@ import ch.systemsx.cisd.datamover.filesystem.impl.RecursiveHardLinkMaker; import ch.systemsx.cisd.datamover.filesystem.intf.IFileSysOperationsFactory; import ch.systemsx.cisd.datamover.filesystem.intf.IPathCopier; import ch.systemsx.cisd.datamover.filesystem.intf.IPathImmutableCopier; +import ch.systemsx.cisd.datamover.filesystem.intf.IPathMover; import ch.systemsx.cisd.datamover.filesystem.intf.IPathRemover; import ch.systemsx.cisd.datamover.filesystem.intf.IReadPathOperations; import ch.systemsx.cisd.datamover.filesystem.remote.XcopyCopier; @@ -273,4 +274,9 @@ public class FileSysOperationsFactory implements IFileSysOperationsFactory return copyProcess; } } + + public IPathMover getMover() + { + return new LocalPathMover(); + } } diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/LocalFileSystem.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/LocalPathMover.java similarity index 88% rename from datamover/source/java/ch/systemsx/cisd/datamover/filesystem/LocalFileSystem.java rename to datamover/source/java/ch/systemsx/cisd/datamover/filesystem/LocalPathMover.java index 3ee858b70e2bc87efff97cd76c5e45f439486154..ae2e2a6e509c830359d7e808fbceb32cae90b27b 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/LocalFileSystem.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/LocalPathMover.java @@ -25,37 +25,33 @@ import org.apache.log4j.Logger; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.utilities.FileUtilities; +import ch.systemsx.cisd.datamover.filesystem.intf.IPathMover; /** * Basic file system operations helper. * * @author Tomasz Pylak on Aug 27, 2007 */ -public class LocalFileSystem +public class LocalPathMover implements IPathMover { - private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, LocalFileSystem.class); + private static final Logger operationLog = LogFactory.getLogger(LogCategory.OPERATION, LocalPathMover.class); - private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY, LocalFileSystem.class); + private static final Logger notificationLog = LogFactory.getLogger(LogCategory.NOTIFY, LocalPathMover.class); // TODO 2007-09-11, Bernd Rinn: make this configurable + /** The maximal number of retries when the move operation fails. */ private static final int MAX_RETRIES_ON_FAILURE = 12; + /** The time to sleep when the move operation has failed before retrying it. */ private static final long MILLIS_TO_SLEEP_ON_FAILURE = 5000; - /** - * Moves source file to destination directory. - */ - public static File tryMoveLocal(File sourceFile, File destinationDir) + public File tryMove(File sourceFile, File destinationDir) { - return tryMoveLocal(sourceFile, destinationDir, ""); + return tryMove(sourceFile, destinationDir, ""); } - /** - * Moves source file to destination directory, putting <var>prefixTemplate</var> in front of its name after - * replacing '%t' with the current time stamp. - */ - public static File tryMoveLocal(File sourcePath, File destinationDirectory, String prefixTemplate) + public File tryMove(File sourcePath, File destinationDirectory, String prefixTemplate) { assert destinationDirectory != null; assert FileUtilities.checkDirectoryFullyAccessible(destinationDirectory, "destination") == null : "Directory is not fully accessible " diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/IFileSysOperationsFactory.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/IFileSysOperationsFactory.java index c3cb7f56023d8ed92edad0e72d89872460c0be21..884995dbd44a430f7e85ba495e6bc9f5bfbdb610 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/IFileSysOperationsFactory.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/IFileSysOperationsFactory.java @@ -29,6 +29,8 @@ public interface IFileSysOperationsFactory public IPathImmutableCopier getImmutableCopier(); public IPathRemover getRemover(); + + public IPathMover getMover(); public IReadPathOperations getReadPathOperations(); } \ No newline at end of file diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/IPathMover.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/IPathMover.java new file mode 100644 index 0000000000000000000000000000000000000000..3f01f5e5944f4bac4f96e4ac93e7a417e67c4110 --- /dev/null +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/intf/IPathMover.java @@ -0,0 +1,41 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.datamover.filesystem.intf; + +import java.io.File; + +/** + * A roles that allows moving paths within a file system, possibly adding a prefix. + * + * @author Bernd Rinn + */ +public interface IPathMover +{ + + /** + * Moves source path (file or directory) to destination directory, putting <var>prefixTemplate</var> in front of + * its name, where any occurrence of '%t' in the template is replaced with the current time stamp. + */ + public File tryMove(File sourcePath, File destinationDirectory, String prefixTemplate); + + /** + * Moves source path (file or directory) to destination directory. + */ + public File tryMove(File sourcePath, File destinationDir); + + +}