org.knime.core.util
Class VMFileLocker

java.lang.Object
  extended by org.knime.core.util.VMFileLocker

public final class VMFileLocker
extends Object

Locks file exclusively for this VM - but accepts multiple locks within this VM.

Author:
ohl, University of Konstanz

Field Summary
static String LOCK_FILE
          filename of lock file.
 
Method Summary
static boolean isLockedForVM(File dir)
           
static boolean lockForVM(File dir)
          Locks the specified directory (by creating a ".knimeLock" file and placing an exclusive lock on it).
static void unlockForVM(File dir)
          Unlocks the specified dir.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCK_FILE

public static final String LOCK_FILE
filename of lock file.

See Also:
Constant Field Values
Method Detail

lockForVM

public static boolean lockForVM(File dir)
Locks the specified directory (by creating a ".knimeLock" file and placing an exclusive lock on it). Multiple lock requests on the same dir (within the same VM) will succeed. Other instances will not be able to lock the file. Each call to lock must be eventually followed by a call to unlock. Locks are released if the VM is gone.

Parameters:
dir - to lock
Returns:
true if the dir was locked, false if it is already locked (by another instance) or the file could not be created (if the dir is r/o).

unlockForVM

public static void unlockForVM(File dir)
Unlocks the specified dir. It must have been locked before! If the dir was locked multiple times it decrements the lock count. (See #lockForVM.)

Parameters:
dir - to release one lock from

isLockedForVM

public static boolean isLockedForVM(File dir)
Parameters:
dir - to test
Returns:
true if this VM has a lock on the specified directory


Copyright, 2003 - 2012. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.