@Immutable public final class FsLockController extends FsLockModelDecoratingController<FsController<? extends FsLockModel>>
FsLockModel,
FsNeedsWriteLockException| Modifier and Type | Class and Description |
|---|---|
private class |
FsLockController.GetClosedIcon |
private class |
FsLockController.GetOpenIcon |
private class |
FsLockController.Input |
private static interface |
FsLockController.IOOperation<T> |
private class |
FsLockController.IsReadOnly |
private class |
FsLockController.LockInputStream |
private class |
FsLockController.LockOutputStream |
private class |
FsLockController.LockReadOnlyFile |
private class |
FsLockController.LockSeekableByteChannel |
private class |
FsLockController.Nio2Input |
private class |
FsLockController.Nio2Output |
private class |
FsLockController.Output |
private static class |
FsLockController.SocketFactory |
private static class |
FsLockController.ThreadLocalUtilFactory |
private static class |
FsLockController.ThreadUtil |
| Modifier and Type | Field and Description |
|---|---|
private static BitField<FsSyncOption> |
NOT_WAIT_CLOSE_IO |
private ReentrantReadWriteLock.ReadLock |
readLock |
private static FsLockController.SocketFactory |
SOCKET_FACTORY |
private static ThreadLocal<FsLockController.ThreadUtil> |
threadUtil |
private ReentrantReadWriteLock.WriteLock |
writeLock |
WAIT_TIMEOUT_MILLISdelegate| Constructor and Description |
|---|
FsLockController(FsController<? extends FsLockModel> controller)
Constructs a new file system lock controller.
|
| Modifier and Type | Method and Description |
|---|---|
(package private) void |
close(Closeable closeable) |
Icon |
getClosedIcon()
Deprecated.
|
FsEntry |
getEntry(FsEntryName name)
Returns the file system entry for the given name or
null if it
doesn't exist. |
InputSocket<?> |
getInputSocket(FsEntryName name,
BitField<FsInputOption> options)
Returns an input socket for reading the contents of the file system
entry addressed by the given name from the file system.
|
Icon |
getOpenIcon()
Deprecated.
|
OutputSocket<?> |
getOutputSocket(FsEntryName name,
BitField<FsOutputOption> options,
Entry template)
Returns an output socket for writing the contents of the entry addressed
by the given name to the file system.
|
boolean |
isExecutable(FsEntryName name)
Returns
false if the named file system entry is not executable. |
boolean |
isReadable(FsEntryName name)
Returns
false if the named file system entry is not readable. |
boolean |
isReadOnly()
Returns
true if and only if the file system is read-only. |
boolean |
isWritable(FsEntryName name)
Returns
false if the named file system entry is not writable. |
private <T> T |
locked(FsLockController.IOOperation<T> operation,
Lock lock)
Tries to call the given consistent operation while holding the given
lock.
|
void |
mknod(FsEntryName name,
Entry.Type type,
BitField<FsOutputOption> options,
Entry template)
Creates or replaces and finally links a chain of one or more entries
for the given entry
name into the file system. |
protected ReentrantReadWriteLock.ReadLock |
readLock() |
(package private) <T> T |
readLocked(FsLockController.IOOperation<T> operation) |
(package private) <T> T |
readOrWriteLocked(FsLockController.IOOperation<T> operation) |
void |
setReadOnly(FsEntryName name)
Sets the named file system entry as read-only.
|
boolean |
setTime(FsEntryName name,
BitField<Entry.Access> types,
long value,
BitField<FsOutputOption> options)
Makes an attempt to set the last access time of all types in the given
bit field for the file system entry with the given name.
|
boolean |
setTime(FsEntryName name,
Map<Entry.Access,Long> times,
BitField<FsOutputOption> options)
Makes an attempt to set the last access time of all types in the given
map for the file system entry with the given name.
|
<X extends IOException> |
sync(BitField<FsSyncOption> options,
ExceptionHandler<? super FsSyncException,X> handler)
Commits all unsynchronized changes to the contents of this file system
to its parent file system,
releases the associated resources (e.g. target archive files) for
access by third parties (e.g. other processes), cleans up any temporary
allocated resources (e.g. temporary files) and purges any cached data.
|
void |
unlink(FsEntryName name,
BitField<FsOutputOption> options)
Removes the named file system entry from the file system.
|
protected ReentrantReadWriteLock.WriteLock |
writeLock() |
(package private) <T> T |
writeLocked(FsLockController.IOOperation<T> operation) |
checkWriteLockedByCurrentThread, isWriteLockedByCurrentThreadgetParent, toStringgetModel, getMountPoint, isTouched, setTouchedequals, hashCode, sync, syncprivate static final BitField<FsSyncOption> NOT_WAIT_CLOSE_IO
private final ReentrantReadWriteLock.ReadLock readLock
private static final FsLockController.SocketFactory SOCKET_FACTORY
private static final ThreadLocal<FsLockController.ThreadUtil> threadUtil
private final ReentrantReadWriteLock.WriteLock writeLock
public FsLockController(FsController<? extends FsLockModel> controller)
controller - the decorated file system controller.void close(Closeable closeable) throws IOException
IOException@Deprecated public Icon getClosedIcon() throws IOException
FsControllerJTree.getClosedIcon in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>IOException - on any I/O failure.public FsEntry getEntry(FsEntryName name) throws IOException
FsControllernull if it
doesn't exist.
Modifying the returned entry does not show any effect on the file system
and may result in an UnsupportedOperationException.getEntry in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - the name of the file system entry.null if no file system entry
exists for the given name.IOException - on any I/O failure.public InputSocket<?> getInputSocket(FsEntryName name, BitField<FsInputOption> options)
FsControllergetInputSocket in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - the file system entry name.options - the input options.InputSocket.@Deprecated public Icon getOpenIcon() throws IOException
FsControllerJTree.getOpenIcon in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>IOException - on any I/O failure.public OutputSocket<?> getOutputSocket(FsEntryName name, BitField<FsOutputOption> options, @CheckForNull Entry template)
FsControllertemplate is not null, then the output entry shall
have as many of its properties copied as reasonable, e.g. the last
modification time.getOutputSocket in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - a file system entry name.options - a bit field of output options.template - a nullable template for the properties of the output
entry.OutputSocket.public boolean isExecutable(FsEntryName name) throws IOException
FsControllerfalse if the named file system entry is not executable.
The implementation in the class FsController always returns
false.
isExecutable in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - the name of the file system entry.false if the named file system entry is not executable.IOException - on any I/O failure.public boolean isReadable(FsEntryName name) throws IOException
FsControllerfalse if the named file system entry is not readable.isReadable in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - the name of the file system entry.false if the named file system entry is not readable.IOException - on any I/O failure.public boolean isReadOnly()
throws IOException
FsControllertrue if and only if the file system is read-only.isReadOnly in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>true if and only if the file system is read-only.IOException - on any I/O failure.public boolean isWritable(FsEntryName name) throws IOException
FsControllerfalse if the named file system entry is not writable.isWritable in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - the name of the file system entry.false if the named file system entry is not writable.IOException - on any I/O failure.private <T> T locked(FsLockController.IOOperation<T> operation, Lock lock) throws IOException
If this is the first execution of this method on the call stack of the
current thread, then the lock gets acquired using Lock.lock().
Once the lock has been acquired the operation gets called.
If this fails for some reason and the thrown exception chain contains a
FsNeedsLockRetryException, then the lock gets temporarily
released and the current thread gets paused for a small random time
interval before this procedure starts over again.
Otherwise, the exception chain gets just passed on to the caller.
If this is not the first execution of this method on the call
stack of the current thread, then the lock gets acquired using
Lock.tryLock() instead.
If this fails, an FsNeedsLockRetryException gets created and
passed to the given exception handler for mapping before finally
throwing the resulting exception by executing
throw handler.fail(new FsNeedsLockRetryException()).
Once the lock has been acquired the operation gets called.
If this fails for some reason then the exception chain gets just passed
on to the caller.
This algorithm prevents dead locks effectively by temporarily unwinding
the stack and releasing all locks for a small random time interval.
Note that this requires some minimal cooperation by the operation:
Whenever it throws an exception, it MUST leave its resources in a
consistent state so that it can get retried again!
Mind that this is standard requirement for any FsController.
T - The return type of the operation.operation - The atomic operation.lock - The lock to hold while calling the operation.IOException - As thrown by the operation.FsNeedsLockRetryException - See above.public void mknod(FsEntryName name, Entry.Type type, BitField<FsOutputOption> options, Entry template) throws IOException
FsControllername into the file system.mknod in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - the file system entry name.type - the file system entry type.options - the file system output options.
If FsOutputOption.CREATE_PARENTS is set, any missing
parent directories will be created and linked into the file
system with its last modification time set to the system's
current time.template - if not null, then the file system entry
at the end of the chain shall inherit as much properties from
this entry as possible - with the exception of its name and type.IOException - on any I/O failure, including but not limited to
these reasons:
name contains characters which are not
supported by the file system.
FsOutputOption.EXCLUSIVE is set or the entry is a
directory.
createParents is
false.
protected ReentrantReadWriteLock.ReadLock readLock()
readLock in class FsLockModelDecoratingController<FsController<? extends FsLockModel>><T> T readLocked(FsLockController.IOOperation<T> operation) throws IOException
IOException<T> T readOrWriteLocked(FsLockController.IOOperation<T> operation) throws IOException
IOExceptionpublic void setReadOnly(FsEntryName name) throws IOException
FsControllersetReadOnly in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - the name of the file system entry.IOException - on any I/O failure or if this operation is not
supported.public boolean setTime(FsEntryName name, BitField<Entry.Access> types, long value, BitField<FsOutputOption> options) throws IOException
FsControllerfalse is returned or an IOException is thrown, then
still some of the last access times may have been set.
Whether or not this is an atomic operation is specific to the
implementation.setTime in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - the file system entry name.types - the access types.value - the last access time.options - the file system output options.true if and only if setting the access time for all
types in types succeeded.IOException - on any I/O failure.public boolean setTime(FsEntryName name, Map<Entry.Access,Long> times, BitField<FsOutputOption> options) throws IOException
FsControllerfalse is returned or an IOException is thrown, then
still some of the last access times may have been set.
Whether or not this is an atomic operation is specific to the
implementation.setTime in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - the file system entry name.times - the access times.options - the file system output options.true if and only if setting the access time for all
types in times succeeded.IOException - on any I/O failure.public <X extends IOException> void sync(BitField<FsSyncOption> options, ExceptionHandler<? super FsSyncException,X> handler) throws IOException
FsControllersync in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>X - The type of the IOException to throw at the
discretion of the exception handler.options - a bit field of synchronization options.handler - the exception handling strategy for consuming input
FsSyncExceptions and mapping them to output
IOExceptions.IOException - on any other (not necessarily I/O related) failure.public void unlink(FsEntryName name, BitField<FsOutputOption> options) throws IOException
FsControllerunlink in class FsDecoratingController<FsLockModel,FsController<? extends FsLockModel>>name - the file system entry name.options - output options for this operation.IOException - on any I/O failure.protected ReentrantReadWriteLock.WriteLock writeLock()
writeLock in class FsLockModelDecoratingController<FsController<? extends FsLockModel>><T> T writeLocked(FsLockController.IOOperation<T> operation) throws IOException
IOExceptionCopyright © 2005-2012 Schlichtherle IT Services. All Rights Reserved.