org.entityfs.lock
Interface WriteLockable

All Superinterfaces:
Lockable
All Known Subinterfaces:
Deletable, Directory, DirectoryImplementation, DirectoryView, DirectoryViewImplementation, ECMetadata, EFile, EFileImplementation, Entity, EntityAcceptingEntity<T>, EntityAcceptingEntityImplementation<T>, EntityAcceptingEntityView<T>, EntityAcceptingEntityViewImplementation<T>, EntityImplementation, EntityView, EntityViewImplementation, RandomlyAccessibleFile, ReadWritableFile, ReadWriteLockable, SymbolicLink, SymbolicLinkImplementation, SymbolicLinkView, SymbolicLinkViewImplementation, WritableFile
All Known Implementing Classes:
AbstractEntityAcceptingEntityImpl, AbstractEntityAcceptingEntityView, AbstractEntityImpl, AbstractEntityViewImpl, AbstractLockable, AbstractReadWritableFile, AbstractReadWriteLockableProxy, AbstractWritableFile, ByteArrayReadableFile, ByteArrayWritableFile, DirectoryImpl, DirectoryViewImpl, ECMetadataImpl, FileDelegateReadWritableFileAdapter, FileImpl, FileWritableFile, GZipWritableFile, ManualEntityListable, ManualNamedReadableFile, MetadataFileAdapter, ReadWritableFileAdapter, SymbolicLinkImpl, SymbolicLinkViewImpl

public interface WriteLockable
extends Lockable

This interface is implemented by classes that can be locked for writing. This can for instance be an entity, or a write-enabled aspect of an entity, such as WritableFile.

Since:
1.0
Author:
Karl Gustafsson
See Also:
WriteLockable
In_jar:
entityfs-core

Method Summary
 EntityLock getWriteLock()
          Get the write lock without locking it.
 boolean isWriteLockedByCurrentThread()
          Does the calling thread hold a write lock for the lockable object (this)?
 EntityLock lockForWriting()
          Lock the object for writing and return the lock.
 

Method Detail

getWriteLock

EntityLock getWriteLock()
Get the write lock without locking it.

This method always returns a lock, even if the object's file system is not locking or if the object is read only.

Returns:
The lockable's write lock. This might be unlocked or locked by someone else.
Permissions_required:
None.

lockForWriting

EntityLock lockForWriting()
                          throws LockTimeoutException
Lock the object for writing and return the lock. How the lock is acquired is determined by the EntityLockAdapterFactory and LockAcquiringStrategy used. If this is called on an object that is somehow connected to an Entity object, that entity's file systems' lock adapter factory and lock acquiring strategy is used. A write lock can be downgraded to a read lock (by calling ReadLockable.lockForReading() and then releasing the write lock).

An entity in a locking read only file system may still be locked for writing.

For more discussions on locks and locking, see Entity and FileSystem.

This method always returns a lock, even if the file system is not locking.

Returns:
A locked write lock.
Throws:
LockTimeoutException - If the lock acquiring timed out. (It is up to the LockAcquiringStrategy to decide if lock acquiring can time out.)
Permissions_required:
None.

isWriteLockedByCurrentThread

boolean isWriteLockedByCurrentThread()
Does the calling thread hold a write lock for the lockable object (this)?

Returns:
true if the lockable object is write locked by the current thread.
Permissions_required:
None.