Skip to content
Snippets Groups Projects
Commit 8b381759 authored by tpylak's avatar tpylak
Browse files

LMS-823 refactoring: move last-modification checking autside of the FileStoreLocal

SVN: 10651
parent 4b9cd1b2
No related branches found
No related tags found
No related merge requests found
...@@ -24,14 +24,28 @@ public interface ILastModificationChecker ...@@ -24,14 +24,28 @@ public interface ILastModificationChecker
* Returns the last time when there was a write access to <var>item</var>. * Returns the last time when there was a write access to <var>item</var>.
* *
* @param item The {@link StoreItem} to check. * @param item The {@link StoreItem} to check.
* @param stopWhenFindYounger The time measured from the beginning of the epoch. If &gt; 0, * @param stopWhenFindYounger The time measured from the beginning of the epoch. If &gt; 0, the
* the recursive search for younger file will be stopped when a file or directory * recursive search for younger file will be stopped when a file or directory is
* is found that is younger than the time specified in this parameter. Supposed * found that is younger than the time specified in this parameter. Supposed to be
* to be used when one does not care about the absolutely youngest entry, but * used when one does not care about the absolutely youngest entry, but only, if
* only, if there are entries that are "young enough". * there are entries that are "young enough".
* @return The time (in milliseconds since the start of the epoch) when <var>resource</var> * @return The time (in milliseconds since the start of the epoch) when <var>resource</var> was
* was last changed or error status if checking failed. * last changed or error status if checking failed.
*/ */
public StatusWithResult<Long> lastChanged(StoreItem item, long stopWhenFindYounger); public StatusWithResult<Long> lastChanged(StoreItem item, long stopWhenFindYounger);
/**
* Returns the last time when there was a write access to <var>item</var>.
*
* @param item The {@link StoreItem} to check.
* @param stopWhenFindYoungerRelative The age of the item. If &gt; 0, the recursive search for
* younger file will be stopped when a file or directory is found that is younger
* than the specified age (in other words is smaller than
* <code>System.currentTimeMillis() - stopWhenYoungerRelative</code>).
* @return The time (in milliseconds since the start of the epoch) when <var>resource</var> was
* last changed or error status if checking failed.
*/
public StatusWithResult<Long> lastChangedRelative(StoreItem item,
long stopWhenFindYoungerRelative);
} }
\ No newline at end of file
/*
* Copyright 2009 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.common.filesystem;
import java.io.File;
import ch.systemsx.cisd.common.exceptions.StatusWithResult;
import ch.systemsx.cisd.common.exceptions.UnknownLastChangedException;
/**
* @author Tomasz Pylak
*/
public class LastModificationChecker implements ILastModificationChecker
{
private final File parentDir;
public LastModificationChecker(File parentDir)
{
this.parentDir = parentDir;
}
public final StatusWithResult<Long> lastChanged(final StoreItem item,
final long stopWhenFindYounger)
{
try
{
long lastChanged =
FileUtilities.lastChanged(getChildFile(item), true, stopWhenFindYounger);
return StatusWithResult.<Long> create(lastChanged);
} catch (UnknownLastChangedException ex)
{
return createLastChangedError(item, ex);
}
}
public final StatusWithResult<Long> lastChangedRelative(final StoreItem item,
final long stopWhenFindYoungerRelative)
{
try
{
long lastChanged =
FileUtilities.lastChangedRelative(getChildFile(item), true,
stopWhenFindYoungerRelative);
return StatusWithResult.<Long> create(lastChanged);
} catch (UnknownLastChangedException ex)
{
return createLastChangedError(item, ex);
}
}
private static StatusWithResult<Long> createLastChangedError(final StoreItem item,
UnknownLastChangedException ex)
{
String errorMsg =
String.format("Could not determine \"last changed time\" of %s: %s", item, ex
.getCause());
return StatusWithResult.<Long> createError(errorMsg);
}
protected final File getChildFile(final StoreItem item)
{
return new File(parentDir, item.getName());
}
}
...@@ -62,31 +62,10 @@ public interface IFileStore extends ISelfTestable, ILastModificationChecker ...@@ -62,31 +62,10 @@ public interface IFileStore extends ISelfTestable, ILastModificationChecker
*/ */
public BooleanStatus exists(StoreItem item); public BooleanStatus exists(StoreItem item);
/** /** @see ILastModificationChecker#lastChanged(StoreItem, long) */
* Returns the last time when there was a write access to <var>item</var>.
*
* @param item The {@link StoreItem} to check.
* @param stopWhenFindYounger The time measured from the beginning of the epoch. If &gt; 0, the
* recursive search for younger file will be stopped when a file or directory is
* found that is younger than the time specified in this parameter. Supposed to be
* used when one does not care about the absolutely youngest entry, but only, if
* there are entries that are "young enough".
* @return The time (in milliseconds since the start of the epoch) when <var>resource</var> was
* last changed or error status if checking failed.
*/
public StatusWithResult<Long> lastChanged(StoreItem item, long stopWhenFindYounger); public StatusWithResult<Long> lastChanged(StoreItem item, long stopWhenFindYounger);
/** /** @see ILastModificationChecker#lastChangedRelative(StoreItem, long) */
* Returns the last time when there was a write access to <var>item</var>.
*
* @param item The {@link StoreItem} to check.
* @param stopWhenFindYoungerRelative The age of the item. If &gt; 0, the recursive search for
* younger file will be stopped when a file or directory is found that is younger
* than the specified age (in other words is smaller than
* <code>System.currentTimeMillis() - stopWhenYoungerRelative</code>).
* @return The time (in milliseconds since the start of the epoch) when <var>resource</var> was
* last changed or error status if checking failed.
*/
public StatusWithResult<Long> lastChangedRelative(StoreItem item, public StatusWithResult<Long> lastChangedRelative(StoreItem item,
long stopWhenFindYoungerRelative); long stopWhenFindYoungerRelative);
......
...@@ -26,8 +26,8 @@ import org.apache.log4j.Logger; ...@@ -26,8 +26,8 @@ import org.apache.log4j.Logger;
import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException; import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException;
import ch.systemsx.cisd.common.exceptions.Status; import ch.systemsx.cisd.common.exceptions.Status;
import ch.systemsx.cisd.common.exceptions.StatusWithResult; import ch.systemsx.cisd.common.exceptions.StatusWithResult;
import ch.systemsx.cisd.common.exceptions.UnknownLastChangedException;
import ch.systemsx.cisd.common.filesystem.FileUtilities; import ch.systemsx.cisd.common.filesystem.FileUtilities;
import ch.systemsx.cisd.common.filesystem.LastModificationChecker;
import ch.systemsx.cisd.common.filesystem.StoreItem; import ch.systemsx.cisd.common.filesystem.StoreItem;
import ch.systemsx.cisd.common.highwatermark.HighwaterMarkWatcher; import ch.systemsx.cisd.common.highwatermark.HighwaterMarkWatcher;
import ch.systemsx.cisd.common.highwatermark.HostAwareFileWithHighwaterMark; import ch.systemsx.cisd.common.highwatermark.HostAwareFileWithHighwaterMark;
...@@ -62,6 +62,8 @@ public class FileStoreLocal extends AbstractFileStore implements IExtendedFileSt ...@@ -62,6 +62,8 @@ public class FileStoreLocal extends AbstractFileStore implements IExtendedFileSt
private final boolean skipAccessibilityTest; private final boolean skipAccessibilityTest;
private final LastModificationChecker lastModificationChecker;
public FileStoreLocal(final HostAwareFileWithHighwaterMark hostAwareFileWithHighwaterMark, public FileStoreLocal(final HostAwareFileWithHighwaterMark hostAwareFileWithHighwaterMark,
final String description, final IFileSysOperationsFactory factory, final String description, final IFileSysOperationsFactory factory,
final boolean skipAccessibilityTest) final boolean skipAccessibilityTest)
...@@ -71,6 +73,7 @@ public class FileStoreLocal extends AbstractFileStore implements IExtendedFileSt ...@@ -71,6 +73,7 @@ public class FileStoreLocal extends AbstractFileStore implements IExtendedFileSt
this.remover = factory.getRemover(); this.remover = factory.getRemover();
this.mover = factory.getMover(); this.mover = factory.getMover();
this.highwaterMarkWatcher = createHighwaterMarkWatcher(hostAwareFileWithHighwaterMark); this.highwaterMarkWatcher = createHighwaterMarkWatcher(hostAwareFileWithHighwaterMark);
this.lastModificationChecker = new LastModificationChecker(getPath());
} }
private final static HighwaterMarkWatcher createHighwaterMarkWatcher( private final static HighwaterMarkWatcher createHighwaterMarkWatcher(
...@@ -96,39 +99,13 @@ public class FileStoreLocal extends AbstractFileStore implements IExtendedFileSt ...@@ -96,39 +99,13 @@ public class FileStoreLocal extends AbstractFileStore implements IExtendedFileSt
public final StatusWithResult<Long> lastChanged(final StoreItem item, public final StatusWithResult<Long> lastChanged(final StoreItem item,
final long stopWhenFindYounger) final long stopWhenFindYounger)
{ {
try return lastModificationChecker.lastChanged(item, stopWhenFindYounger);
{
long lastChanged =
FileUtilities.lastChanged(getChildFile(item), true, stopWhenFindYounger);
return StatusWithResult.<Long> create(lastChanged);
} catch (UnknownLastChangedException ex)
{
return createLastChangedError(item, ex);
}
} }
public final StatusWithResult<Long> lastChangedRelative(final StoreItem item, public final StatusWithResult<Long> lastChangedRelative(final StoreItem item,
final long stopWhenFindYoungerRelative) final long stopWhenFindYoungerRelative)
{ {
try return lastModificationChecker.lastChangedRelative(item, stopWhenFindYoungerRelative);
{
long lastChanged =
FileUtilities.lastChangedRelative(getChildFile(item), true,
stopWhenFindYoungerRelative);
return StatusWithResult.<Long> create(lastChanged);
} catch (UnknownLastChangedException ex)
{
return createLastChangedError(item, ex);
}
}
private static StatusWithResult<Long> createLastChangedError(final StoreItem item,
UnknownLastChangedException ex)
{
String errorMsg =
String.format("Could not determine \"last changed time\" of %s: %s", item, ex
.getCause());
return StatusWithResult.<Long> createError(errorMsg);
} }
public final BooleanStatus checkDirectoryFullyAccessible(final long timeOutMillis) public final BooleanStatus checkDirectoryFullyAccessible(final long timeOutMillis)
......
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