Skip to content
Snippets Groups Projects
Commit e26bda0a authored by ribeaudc's avatar ribeaudc
Browse files

[LMS-414]

add: - 'mayHandle(File)' to 'IPathHandler'.
- WatermarkWatcher to 'common' package.
- TODO in 'DefaultStorageProcessor'.
remove: - TODO from 'DataMover'.
- TODO from 'AbstractStorageProcessor'.
change: - 'IStoreRootDirectoryProvider' renamed to 'IStoreRootDirectoryHolder'.

SVN: 5988
parent 5f06af33
No related branches found
No related tags found
No related merge requests found
......@@ -22,11 +22,9 @@ import java.util.Timer;
import ch.systemsx.cisd.common.Constants;
import ch.systemsx.cisd.common.utilities.DirectoryScanningTimerTask;
import ch.systemsx.cisd.common.utilities.FileUtilities;
import ch.systemsx.cisd.common.utilities.IPathHandler;
import ch.systemsx.cisd.common.utilities.IStoreHandler;
import ch.systemsx.cisd.common.utilities.ITerminable;
import ch.systemsx.cisd.common.utilities.ITriggerable;
import ch.systemsx.cisd.common.utilities.StoreItem;
import ch.systemsx.cisd.common.utilities.TimerHelper;
import ch.systemsx.cisd.common.utilities.TriggeringTimerTask;
import ch.systemsx.cisd.datamover.filesystem.FileStoreFactory;
......@@ -155,23 +153,10 @@ public class DataMover
final DirectoryScanningTimerTask outgoingMovingTask =
new DirectoryScanningTimerTask(readyToMoveDir, FileUtilities.ACCEPT_ALL_FILTER,
asPathHandler(remoteStoreMover));
remoteStoreMover);
return new DataMoverProcess(outgoingMovingTask, "Final Destination Mover");
}
// TODO 2007-10-10, Tomasz Pylak: remove this when DirectoryScanningTimerTask will work
// with IStoreHandler. This is a quick hack.
private static IPathHandler asPathHandler(final IStoreHandler storeHandler)
{
return new IPathHandler()
{
public void handle(File path)
{
storeHandler.handle(new StoreItem(path.getName()));
}
};
}
private IStoreHandler createRemotePathMover(IFileStore source, FileStore destination)
{
return RemoteMonitoredMoverFactory.create(source, destination, parameters);
......
......@@ -77,8 +77,8 @@ public class LocalProcessor implements IPathHandler, IRecoverableTimerTaskFactor
private final File extraCopyDirOrNull;
private LocalProcessor(Parameters parameters, File inputDir, File outputDir, File tempDir,
IFileSysOperationsFactory factory)
private LocalProcessor(final Parameters parameters, final File inputDir, final File outputDir,
final File tempDir, final IFileSysOperationsFactory factory)
{
this.parameters = parameters;
this.inputDir = inputDir;
......@@ -89,8 +89,8 @@ public class LocalProcessor implements IPathHandler, IRecoverableTimerTaskFactor
this.mover = factory.getMover();
}
public static final LocalProcessor create(Parameters parameters, File inputDir, File outputDir,
File bufferDir, IFileSysOperationsFactory factory)
public static final LocalProcessor create(final Parameters parameters, final File inputDir,
final File outputDir, final File bufferDir, final IFileSysOperationsFactory factory)
{
final LocalProcessor handlerAndRecoverable =
new LocalProcessor(parameters, inputDir, outputDir, bufferDir, factory);
......@@ -134,7 +134,7 @@ public class LocalProcessor implements IPathHandler, IRecoverableTimerTaskFactor
for (int i = 0; i < files.length; i++)
{
File file = files[i];
final File file = files[i];
if (fileExists(inputDir, file))
{
FileUtilities.deleteRecursively(file); // partial copy, delete it
......@@ -154,69 +154,13 @@ public class LocalProcessor implements IPathHandler, IRecoverableTimerTaskFactor
}
}
private static boolean fileExists(File inputDir, File file)
private static boolean fileExists(final File inputDir, final File file)
{
return new File(inputDir, file.getName()).exists();
}
// ----------------
public void handle(File path)
{
final boolean continueProcessing = doMoveManualOrClean(path);
if (continueProcessing == false)
{
return; // stop processing
}
File extraTmpCopy = null;
if (extraCopyDirOrNull != null)
{
extraTmpCopy = new File(tempDir, path.getName());
if (extraTmpCopy.exists())
{
operationLog.warn(String.format(
"Half-finished extra copy directory '%s' exists - removing it.",
extraTmpCopy.getAbsolutePath()));
if (FileUtilities.deleteRecursively(extraTmpCopy) == false)
{
notificationLog.error(String.format(
"Removal of half-finished extra copy directory '%s' failed.",
extraTmpCopy.getAbsolutePath()));
return;
}
}
extraTmpCopy = copier.tryCopy(path, tempDir, null);
if (extraTmpCopy == null)
{
notificationLog.error(String.format("Creating extra copy of '%s' failed.", path));
return;
}
}
final File movedFile = mover.tryMove(path, outputDir);
if (movedFile == null)
{
notificationLog.error(String.format(
"Moving '%s' to '%s' for final moving process failed.", path, outputDir));
return;
}
if (extraTmpCopy != null)
{
assert extraCopyDirOrNull != null;
File extraCopy = mover.tryMove(extraTmpCopy, extraCopyDirOrNull);
if (extraCopy == null)
{
notificationLog.error(String.format(
"Moving temporary extra copy '%s' to destination '%s' failed.",
extraTmpCopy, extraCopyDirOrNull));
}
}
}
// @return true if processing needs to continue, false otherwise
private boolean doMoveManualOrClean(File file)
private boolean doMoveManualOrClean(final File file)
{
final EFileManipResult manualMoveStatus = doManualIntervention(file);
if (manualMoveStatus == EFileManipResult.FAILURE)
......@@ -239,7 +183,7 @@ public class LocalProcessor implements IPathHandler, IRecoverableTimerTaskFactor
}
// @return true if the whole resource was deleted
private boolean doCleansing(File resource)
private boolean doCleansing(final File resource)
{
final RegexFileFilter cleansingFilter = new RegexFileFilter();
final Pattern cleansingRegex = parameters.tryGetCleansingRegex();
......@@ -261,7 +205,7 @@ public class LocalProcessor implements IPathHandler, IRecoverableTimerTaskFactor
CONTINUE, FAILURE, STOP
}
private EFileManipResult doManualIntervention(File resource)
private EFileManipResult doManualIntervention(final File resource)
{
final File manualInterventionDir = parameters.tryGetManualInterventionDir();
if (manualInterventionDir == null)
......@@ -280,7 +224,7 @@ public class LocalProcessor implements IPathHandler, IRecoverableTimerTaskFactor
if (needsManualIntervention)
{
log(resource, "Moving to manual intervention directory");
File movedFile = mover.tryMove(resource, manualInterventionDir);
final File movedFile = mover.tryMove(resource, manualInterventionDir);
return (movedFile != null) ? EFileManipResult.STOP : EFileManipResult.FAILURE;
} else
{
......@@ -288,7 +232,7 @@ public class LocalProcessor implements IPathHandler, IRecoverableTimerTaskFactor
}
}
private static void log(File path, String description)
private static void log(final File path, final String description)
{
if (operationLog.isInfoEnabled())
{
......@@ -296,7 +240,7 @@ public class LocalProcessor implements IPathHandler, IRecoverableTimerTaskFactor
}
}
private static void logManualIntervention(File path, boolean needsManualIntervention)
private static void logManualIntervention(final File path, final boolean needsManualIntervention)
{
if (manualInterventionLog.isInfoEnabled())
{
......@@ -307,4 +251,66 @@ public class LocalProcessor implements IPathHandler, IRecoverableTimerTaskFactor
}
}
//
// IPathHandler
//
public final void handle(final File path)
{
final boolean continueProcessing = doMoveManualOrClean(path);
if (continueProcessing == false)
{
return; // stop processing
}
File extraTmpCopy = null;
if (extraCopyDirOrNull != null)
{
extraTmpCopy = new File(tempDir, path.getName());
if (extraTmpCopy.exists())
{
operationLog.warn(String.format(
"Half-finished extra copy directory '%s' exists - removing it.",
extraTmpCopy.getAbsolutePath()));
if (FileUtilities.deleteRecursively(extraTmpCopy) == false)
{
notificationLog.error(String.format(
"Removal of half-finished extra copy directory '%s' failed.",
extraTmpCopy.getAbsolutePath()));
return;
}
}
extraTmpCopy = copier.tryCopy(path, tempDir, null);
if (extraTmpCopy == null)
{
notificationLog.error(String.format("Creating extra copy of '%s' failed.", path));
return;
}
}
final File movedFile = mover.tryMove(path, outputDir);
if (movedFile == null)
{
notificationLog.error(String.format(
"Moving '%s' to '%s' for final moving process failed.", path, outputDir));
return;
}
if (extraTmpCopy != null)
{
assert extraCopyDirOrNull != null;
final File extraCopy = mover.tryMove(extraTmpCopy, extraCopyDirOrNull);
if (extraCopy == null)
{
notificationLog.error(String.format(
"Moving temporary extra copy '%s' to destination '%s' failed.",
extraTmpCopy, extraCopyDirOrNull));
}
}
}
public final boolean mayHandle(final File path)
{
return true;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment