Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.arjuna.ats.arjuna.utils
Class FileLock

    java.lang.Object
      com.arjuna.ats.arjuna.utils.FileLock

public class FileLock
extends java.lang.Object

Sometimes it is necessary to lock a file at the disk level. Since there is no native Java way of locking a file, we have to implement our own. Unfortunately, it appears as though we can only assume that rename is atomic. We base the locking on this then: rename the lock file and update it with the lock owners. How it works: for every file we want to lock we create an _lock file. This file contains information about who is locking the file, and in what mode. (Single writer, multiple readers.) To guarantee atomicity of update, we move (rename) the actual file each time we want to lock it and update the lock file. When this is done, we move (rename) it back. Almost like a two-phase commit protocol! Currently we don't support re-entrant locking.

Since:
  JTS 1.0.
Version:
  $Id: FileLock.java 2342 2006-03-30 13:06:17Z $
Author:
  Mark Little (mark@arjuna.com)

Field Summary
`static int` | `defaultRetry`
`static int` | `defaultTimeout`
`static int` | `F_RDLCK`
`static int` | `F_WRLCK`

Constructor Summary
`FileLock(java.io.File name)`
`FileLock(java.io.File name, long timeout, long retry)`

Method Summary
`void` | `finalize()`
`boolean` | `lock(int lmode)`
`boolean` | `lock(int lmode, boolean create)`
`static java.lang.String` | `modeString(int mode)`
`boolean` | `unlock()`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### F_RDLCK

    public static final int F_RDLCK

See Also:
  Constant Field Values

### F_WRLCK

    public static final int F_WRLCK

See Also:
  Constant Field Values

### defaultTimeout

    public static final int defaultTimeout

See Also:
  Constant Field Values

### defaultRetry

    public static final int defaultRetry

See Also:
  Constant Field Values

Constructor Detail

### FileLock

    public FileLock(java.io.File name)

### FileLock

    public FileLock(java.io.File name,
                    long timeout,
                    long retry)

Method Detail

### finalize

    public void finalize()

### lock

    public boolean lock(int lmode)

  Since:
    JTS 2.1.1.

### lock

    public boolean lock(int lmode,
                        boolean create)

### unlock

    public boolean unlock()

### modeString

    public static java.lang.String modeString(int mode)

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD