| FileLock {R.filelocks} | R Documentation |
Package: R.filelocks
Class FileLock
Object
~~|
~~+--FileLock
Directly known subclasses:
NullFileLock
public static class FileLock
extends Object
The FileLock class provides method for locking and releasing files.
FileLock(con=NULL, pathname=NULL, pathnameL=NULL, ..., .core=TRUE)
con |
A connection. |
pathname, pathnameL |
Pathnames. |
... |
Not used. |
.core |
Internal only. |
This class is instantiated via static methods *tryLock() and
*lock(). It should never be instantiated via the constructor.
Methods:
as.character | - | |
getConnection | - | |
getPathname | - | |
isLocked | - | |
lock | - | |
release | - | |
tryLock | - |
Methods inherited from Object:
$, $<-, [[, [[<-, as.character, attach, attachLocally, clearCache, clone, detach, equals, extend, finalize, gc, getEnvironment, getFields, getInstantiationTime, getStaticInstance, hasField, hashCode, ll, load, objectSize, print, save
Henrik Bengtsson (http://www.braju.com/R/)
[1] http://en.wikipedia.org/wiki/File_locking
# The file to be locked (note, it does not have to exists) pathname <- "foo.txt" # Try to lock the above file lockA <- FileLock$tryLock(pathname) print(lockA) # Try to lock it again (should not work) lockB <- FileLock$tryLock(pathname) print(lockB) # Release the lock release(lockA) # Try to lock again lockC <- FileLock$lock(pathname); print(lockC) # Oops, we forget to release... rm(lockC) # However, the garbage collector will release it, # which is forced to run whenever the file appears # to be locked. This is why the following works. # Try to lock it lockA <- FileLock$tryLock(pathname) print(lockA) # Try to lock it again (should not work) lockB <- FileLock$tryLock(pathname) print(lockB) # Clean up and remove any stray file locks rm(lockA, lockB) gc()