org.backsource.utils.io
Class DotLock

java.lang.Object
  extended byorg.backsource.utils.io.DotLock

public class DotLock
extends java.lang.Object

Simple, portable file locking using .lock files.

WARNING. This lock implementation has several flaws:



Example
 File f = new File("apa");
 DotLocl.aquire(f);
 // do stuff with f
 DotLocl.release(f);
 

Version:
$Id: DotLock.java,v 1.1.1.1 2004/05/19 12:07:30 pra Exp $
Author:
Jens Askengren

Field Summary
static java.lang.String LOCK_SUFFIX
           
static long POLL_TIME
           
 
Constructor Summary
DotLock()
           
 
Method Summary
static void aquire(java.io.File f)
          Aquire the lock for the file @param f.
static boolean aquire(java.io.File f, long timeout)
          Aquire the lock for the file @param f, wait a most @param timeout milliseconds for the lock to be released.
static long getLockAge(java.io.File f)
           
static java.io.File getLockFile(java.io.File f)
           
static boolean isLocked(java.io.File f)
           
static boolean release(java.io.File f)
          Release the lock for file @param f
static boolean tryLock(java.io.File f)
          Try to aquire the lock for file @param f.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCK_SUFFIX

public static final java.lang.String LOCK_SUFFIX
See Also:
Constant Field Values

POLL_TIME

public static final long POLL_TIME
See Also:
Constant Field Values
Constructor Detail

DotLock

public DotLock()
Method Detail

tryLock

public static boolean tryLock(java.io.File f)
                       throws java.io.IOException
Try to aquire the lock for file @param f. Fail emediately if the file is already locked.

Throws:
java.io.IOException - if the lockfile could not be created

aquire

public static void aquire(java.io.File f)
                   throws java.io.IOException
Aquire the lock for the file @param f. If the file is locked, wait until the lock is released.

Throws:
java.io.IOException - if the lockfile could not be created
java.lang.SecurityException - if the securitymanager denies write access to the lock file

aquire

public static boolean aquire(java.io.File f,
                             long timeout)
                      throws java.io.IOException
Aquire the lock for the file @param f, wait a most @param timeout milliseconds for the lock to be released.

Throws:
java.io.IOException - if the lockfile could not be created
java.lang.SecurityException - if the securitymanager denies write access to the lock file

release

public static boolean release(java.io.File f)
Release the lock for file @param f


isLocked

public static boolean isLocked(java.io.File f)

getLockFile

public static java.io.File getLockFile(java.io.File f)

getLockAge

public static long getLockAge(java.io.File f)


Copyright © 2000-2004 Backsource. All Rights Reserved.