From a140b73e9761b7bc53b6b801648bb03c2f5824a9 Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 17 Aug 2007 13:52:40 +0000 Subject: [PATCH] new method to test if a particular file is or is related to the target of a lock git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@432 be28352e-c001-0410-b1a7-c7978e42abec --- src/uk/ac/vamsas/client/simpleclient/FileLock.java | 19 +++++++++++++++++-- src/uk/ac/vamsas/client/simpleclient/Lock.java | 7 +++++++ .../ac/vamsas/client/simpleclient/NativeLock.java | 6 ++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/uk/ac/vamsas/client/simpleclient/FileLock.java b/src/uk/ac/vamsas/client/simpleclient/FileLock.java index 9201702..40ee9cf 100644 --- a/src/uk/ac/vamsas/client/simpleclient/FileLock.java +++ b/src/uk/ac/vamsas/client/simpleclient/FileLock.java @@ -64,7 +64,7 @@ public class FileLock extends Lock { super(lockfile); // try and get a lock. try { - _lock = new File(lockfile.getParentFile(), lockfile.getName()+"."+_LockSuffix); + _lock = make_lockForTarget(lockfile); if (!ensureLockFile(block)) { log.debug("Couldn't get lock on "+_lock); tidy(); @@ -87,7 +87,14 @@ public class FileLock extends Lock { + lockfile.getAbsolutePath(),e); } } - + /** + * + * @param lockfile target of lock + * @return file object that will be locked for lockfile + */ + private File make_lockForTarget(File lockfile) { + return new File(lockfile.getParentFile(), lockfile.getName()+"."+_LockSuffix); + } private boolean openRaFile() throws IOException { if (target==null) return false; @@ -208,4 +215,12 @@ public class FileLock extends Lock { log.debug("Failed to getRaChannel on target "+target); return null; } + public boolean isTargetLockFile(File afile) { + if (isLocked()) + { + if (target.equals(afile) || make_lockForTarget(target).equals(afile)) + return true; + } + return false; + } } diff --git a/src/uk/ac/vamsas/client/simpleclient/Lock.java b/src/uk/ac/vamsas/client/simpleclient/Lock.java index a124745..bd968fb 100644 --- a/src/uk/ac/vamsas/client/simpleclient/Lock.java +++ b/src/uk/ac/vamsas/client/simpleclient/Lock.java @@ -34,6 +34,13 @@ public abstract class Lock { target = lockfile; } /** + * test whether the given file is a target or related to the lock + * on the target file. + * @param afile a file + * @return true if target is locked and afile is related to target + */ + public abstract boolean isTargetLockFile(File afile); + /** * * @return true if lock is held on the target */ diff --git a/src/uk/ac/vamsas/client/simpleclient/NativeLock.java b/src/uk/ac/vamsas/client/simpleclient/NativeLock.java index f980f45..ccaa407 100644 --- a/src/uk/ac/vamsas/client/simpleclient/NativeLock.java +++ b/src/uk/ac/vamsas/client/simpleclient/NativeLock.java @@ -172,4 +172,10 @@ public class NativeLock extends Lock { return null; } + public boolean isTargetLockFile(File afile) { + if (isLocked() && target.equals(afile)) + return true; + return false; + } + } -- 1.7.10.2