|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.vamsas.client.simpleclient.Lock
uk.ac.vamsas.client.simpleclient.FileLock
File based Locking mechanism to get around some bizarre limitations of JarEntry seeking. Abstract locks have a target file, to which access is controlled when a lock is held. Native locks on WindowsXP seem to conflict with Jar seek operations, so a file lock creates an advisory lock. Method: A lock file is created, if it doesn't already exist - the naming convention is TargetFile+suffixSeparator+_LockSuffix. A lock is obtained by locking the lock file with a native lock. The NativeLock is used for this.
Field Summary | |
protected static java.lang.String |
_LockSuffix
|
Fields inherited from class uk.ac.vamsas.client.simpleclient.Lock |
log, rafile |
Constructor Summary | |
FileLock(java.io.File lockfile,
boolean block)
|
Method Summary | |
protected void |
finalize()
|
java.io.BufferedOutputStream |
getBufferedOutputStream(boolean clear)
return buffered output stream to locked file. |
java.io.FileInputStream |
getFileInputStream(boolean atStart)
gets Locked Stream for reading from |
java.io.FileOutputStream |
getFileOutputStream(boolean clear)
gets Locked stream to write to FileInput always starts at the *end* of the file (after any truncation) |
java.nio.channels.FileChannel |
getRaChannel()
|
java.io.RandomAccessFile |
getRaFile()
|
boolean |
isLocked()
|
boolean |
isTargetLockFile(java.io.File afile)
test whether the given file is a target or related to the lock on the target file. |
long |
length()
safe lock target length() function. |
void |
release()
release lock and close all managed channels to file |
void |
release(boolean closeChannel)
optionally close the open random access channel on the file when releasing lock |
Methods inherited from class uk.ac.vamsas.client.simpleclient.Lock |
getBufferedInputStream |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static java.lang.String _LockSuffix
Constructor Detail |
public FileLock(java.io.File lockfile, boolean block)
lockfile
- block
- true means thread blocks until FileLock is obtained.Method Detail |
public boolean isLocked()
isLocked
in class Lock
public void release()
Lock
release
in class Lock
public void release(boolean closeChannel)
Lock
release
in class Lock
closeChannel
- public java.io.FileInputStream getFileInputStream(boolean atStart) throws java.io.IOException
Lock
getFileInputStream
in class Lock
atStart
- true to start reading at beginning of file.
java.io.IOException
public java.io.FileOutputStream getFileOutputStream(boolean clear) throws java.io.IOException
Lock
getFileOutputStream
in class Lock
clear
- true means file will be cleared to zero length
java.io.IOException
public java.io.BufferedOutputStream getBufferedOutputStream(boolean clear) throws java.io.IOException
Lock
getBufferedOutputStream
in class Lock
clear
- - true means file is truncated to 0 length before writing
java.io.IOException
public long length()
Lock
length
in class Lock
protected void finalize() throws java.lang.Throwable
finalize
in class Lock
java.lang.Throwable
public java.io.RandomAccessFile getRaFile() throws java.io.IOException
getRaFile
in class Lock
java.io.IOException
public java.nio.channels.FileChannel getRaChannel() throws java.io.IOException
getRaChannel
in class Lock
java.io.IOException
public boolean isTargetLockFile(java.io.File afile)
Lock
isTargetLockFile
in class Lock
afile
- a file
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |