Description Usage Arguments Details Fields and Methods Author(s) References Examples
Package: R.synchronize
Class FileLock
Object
~~|
~~+--
FileLock
Directly known subclasses:
NullFileLock
public static class FileLock
extends Object
The FileLock class provides method for locking and releasing files.
1 |
con |
A |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # 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()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.