From 7f500206e78efcd9d01c895e487c5c31ae9fdce8 Mon Sep 17 00:00:00 2001 From: ribeaudc <ribeaudc> Date: Tue, 3 Jun 2008 13:55:20 +0000 Subject: [PATCH] change: - Put a timeout to 'RsyncCopier'. remove: - 'FileUtilities.isAvailable', use 'FileUtils.waitFor' instead. SVN: 6431 --- .../filesystem/remote/rsync/RsyncCopier.java | 14 +++++++++++--- .../datamover/filesystem/store/FileStoreLocal.java | 4 +++- .../filesystem/remote/CopyActivityMonitorTest.java | 3 ++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncCopier.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncCopier.java index e125a4c44d4..de724104048 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncCopier.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/remote/rsync/RsyncCopier.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.apache.commons.lang.time.DateUtils; import org.apache.log4j.Logger; import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException; @@ -42,6 +43,12 @@ import ch.systemsx.cisd.datamover.filesystem.remote.rsync.RsyncVersionChecker.Rs public final class RsyncCopier implements IPathCopier { + /** + * The maximal period to wait for the <code>rsync</code> list process to finish before killing + * it (<i>30s</i>). + */ + private static final long MILLIS_TO_WAIT_BEFORE_TIMEOUT = 30 * DateUtils.MILLIS_PER_SECOND; + /** * The {@link Status} returned if the process was terminated by {@link Process#destroy()}. */ @@ -156,8 +163,8 @@ public final class RsyncCopier implements IPathCopier // { // return false; // } - return true; - } + return true; + } /** * Checks whether the <code>rsync</code> can be executed and has a version >= 2.6.0. @@ -217,7 +224,8 @@ public final class RsyncCopier implements IPathCopier createCommandLine(sourcePath, sourceHostOrNull, destinationDirectory, destinationHostOrNull); final ProcessResult processResult = - ProcessExecutionHelper.run(commandLine, operationLog, machineLog); + ProcessExecutionHelper.run(commandLine, operationLog, machineLog, + MILLIS_TO_WAIT_BEFORE_TIMEOUT); processResult.log(); return createStatus(processResult); } diff --git a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreLocal.java b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreLocal.java index 7b4483bf123..808e089c4db 100644 --- a/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreLocal.java +++ b/datamover/source/java/ch/systemsx/cisd/datamover/filesystem/store/FileStoreLocal.java @@ -19,6 +19,8 @@ package ch.systemsx.cisd.datamover.filesystem.store; import java.io.File; import java.io.IOException; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.time.DateUtils; import org.apache.log4j.Logger; import ch.systemsx.cisd.common.exceptions.CheckedExceptionTunnel; @@ -113,7 +115,7 @@ public class FileStoreLocal extends FileStore implements IExtendedFileStore public final String tryCheckDirectoryFullyAccessible(final long timeOutMillis) { - final boolean available = FileUtilities.isAvailable(getPath(), timeOutMillis); + final boolean available = FileUtils.waitFor(getPath(), (int) (timeOutMillis / DateUtils.MILLIS_PER_SECOND)); if (available == false) { return String.format( diff --git a/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java b/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java index 52d2f4cfcb2..24a477c84d4 100644 --- a/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java +++ b/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java @@ -345,7 +345,8 @@ public class CopyActivityMonitorTest private final static class PathLastChangedCheckerStalled implements ILastChangedChecker { - private final long MAX_TIME = System.currentTimeMillis() + INACTIVITY_PERIOD_MILLIS * 2; + private final static long MAX_TIME = + System.currentTimeMillis() + INACTIVITY_PERIOD_MILLIS * 2; public long lastChangedRelative(StoreItem item, long stopWhenFindYoungerRelative) { -- GitLab