|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface FileSystem
This is the public (client-visible) interface for a file system
implementation. A file system contains Entity
:s, commonly
EFile
:s and Directory
:s, but perhaps also other entity types
if supported by the file system implementation or provided by a
CapabilityProvider
. Entities are organized in a directory hierarchy
with the root directory as the root node. All entities have a
Directory
parent entity except for the root directory whose parent is
null
. An entity's location in the hierarchy and its location relative
to other entities are represented by EntityLocation
objects.
There are several different FileSystem
implementations. They differ
in how they store file and file system data. One implementation is the Ram
file system that stores data in-memory. Another implementation is the FS file
system that uses a regular file system to store its data. Both file systems
present the same interface to clients and files can be copied back and forth
between the two. This makes the client implementation independent of how file
data happen to be stored at its current deploy location. (As long as it does
not require capabilities that are file system-specific.)
A file system is instantiated by using a file system implementation's
FileSystemBuilder
and perhaps by adding additional capabilities via
CapabilityProvider
:s.
Entity
:s in a file system are entities in the true sense of the word.
A consequence of that is that entities cannot be moved between different file
systems; only copied. (See Entity
for more discussion on entities.)
FileSystem
implementations are designed for concurrent access by
several threads. Locking can be enabled for a file system by calling
FileSystemBuilder.enableLocking()
.
To get sufficiently exclusive access to an entity in a locking file system, a
client thread can lock it for reading or writing. Many Entity
methods
require that the calling thread holds a lock when calling them. The locking
semantics are the same as for Java's ReadWriteLock
:
EntityLockAdapterFactory
.
Entities does not enforce any specific locking strategy (the order in which
locks are acquired); that is up to the client implementation to decide. The
entity utility objects (such as Directories
) use a
strategy where locks are acquired top-down in the file system hierarchy. If
several entities in the same directory are locked, the locks are acquired in
hashCode
order. Since locks are reentrant, that strategy might be
overridden by the client.
Read only file systems are trivially thread-safe and they don't use any locking. Their locking methods are still callable, though.
A file system may use an AccessController
to grant or deny access to
entities. If no access controller is used, all clients have access to all
entities. The access control mechanism should not be seen as a full-blown
security solution; rather as a support for implementing a security solution.
It is, for instance, possible for a client without write access to an entity
to write lock it and in that way deny other clients access to it.
File system implementations prefer to have exclusive access to the underlying
file system, especially for operations other than creating new files or
directories. How gracefully a file system can handle changes made by other
clients depend on the implementation of EntityValidityControlStrategy
used and on the file system implementation itself. An exception to the rule
is when the file system client uses a
DirectoryMonitorer
to monitor a directory for
changes (for incoming files, for instance).
Individual entities as well as the entire file system can be configured to be
Observable
for updates. All events sent by entities are also sent
from the file system. The event handling can be enabled when the file system
is created by calling FileSystemBuilder.enableEvents()
.
A short note on error handling: EntityFS use unchecked exceptions to
signal errors. All exceptions thrown by EntityFS methods inherit
FileSystemException
. The documentation for some methods declare
specific exceptions that are thrown for specific error conditions, but other
exceptions might be thrown as well by for other errors. To be sure to catch
all EntityFS exceptions, catch FileSystemException
. For a discussion
on checked versus unchecked exceptions, see
this Wikipedia article.
In addition to the methods defined in this interface, methods implemented in
FileSystems
may be of use for file system clients.
FileSystems
Method Summary | ||
---|---|---|
void |
close()
Close and discard this file system instance. |
|
AccessController |
getAccessController()
Get the file system's access controller. |
|
int |
getBufferSize()
Get the buffer size configured when creating the file system. |
|
|
getCapability(FileSystemCapabilityType<T> type)
Get a supported FileSystemCapability . |
|
|
getCapabilityForEntity(EntityView ev,
EntityCapabilityType<T> type)
Get a supported EntityCapability for an Entity (or an
entity viewed by an EntityView . |
|
LockAcquiringStrategy |
getLockAcquiringStrategy()
Get the file system's lock acquiring strategy object. |
|
EntityLockAdapterFactory |
getLockAdapterFactory()
Get the file system's lock adapter factory. |
|
LockCommandExecutor |
getLockCommandExecutor()
Get the file system's lock command executor. |
|
LogAdapter |
getLogAdapter()
Convenient alternative to calling getLogAdapterHolder().getLogAdapter() . |
|
LogAdapterHolder |
getLogAdapterHolder()
Get the file system's current LogAdapterHolder . |
|
String |
getName()
Get the file system's name. |
|
Directory |
getRootDirectory()
Get the file system's root directory. |
|
Set<FileSystemCapabilityType<?>> |
getSupportedCapabilities()
Get the set of all supported file system capability types for this file system. |
|
Set<EntityCapabilityType<?>> |
getSupportedEntityCapabilities()
Get the set of all supported entity capability types for this file system. |
|
Directory |
getTemporaryFilesDirectory()
Get the directory where this file system keeps its temporary files. |
|
boolean |
isAccessControlling()
Does the file system use any kind of access controls? |
|
boolean |
isLocking()
Does the file system do any kind of entity locking? Read only file systems never use any locking. |
|
boolean |
isReadOnly()
Is the file system read only? |
|
void |
setReadOnly(boolean readOnly)
Set this file system read only true or read/write false . |
|
void |
setTemporaryFilesDirectory(Directory d)
Set the directory where this file system keeps its temporary files. |
|
boolean |
supportsCapability(FileSystemCapabilityType<?> type)
Check if the file system supports a specific FileSystemCapability
. |
|
boolean |
supportsCapabilityForEntity(EntityView ev,
EntityCapabilityType<?> type)
Check if an Entity (or an entity viewed by an EntityView
supports a specific EntityCapability . |
|
boolean |
supportsCapabilityForEntityType(EntityType et,
EntityCapabilityType<?> type)
Check if a entity type supports a capability type in this file system. |
Methods inherited from interface org.entityfs.event.Observable |
---|
addObserver, countObservers, deleteObserver, deleteObservers |
Method Detail |
---|
String getName()
boolean isReadOnly()
true
if the file system is read only, false
if it
is read/write.void setReadOnly(boolean readOnly)
true
or read/write false
.
File systems that are created read only cannot be set read/write. If this
method is called with a false
argument on a read only file
system, the method exits silently. (No exception is thrown.)
readOnly
- Should the file system be set read only?boolean isLocking()
EntityLockAdapterFactory
that
is used.
true
if the file system is locking, false
if not.boolean isAccessControlling()
true
if the file system is access controlling, false
if not.LogAdapterHolder getLogAdapterHolder()
LogAdapterHolder
.
LogAdapterHolder
.getLogAdapter()
LogAdapter getLogAdapter()
getLogAdapterHolder().getLogAdapter()
.
The LogAdapter
returned from this method should not be saved by
the client. (Not for a long time, anyway.) Save the file system's
LogAdapterHolder
instead or let the client call getLogAdapter()
every time it wants to log.
LogAdapter
.getLogAdapterHolder()
EntityLockAdapterFactory getLockAdapterFactory()
LockAdapter
:s for their own locking.
LockAcquiringStrategy getLockAcquiringStrategy()
Directory getRootDirectory()
void setTemporaryFilesDirectory(Directory d) throws IllegalArgumentException
d
- The Directory
for temporary files. The directory must be
in this file system.
IllegalArgumentException
- If the directory is not in this file
system.getTemporaryFilesDirectory()
Directory getTemporaryFilesDirectory()
setTemporaryFilesDirectory(Directory)
before calling this
method.
null
if it has not
been set.AccessController getAccessController()
DisabledAccessController.INSTANCE
if access controls are
disabled.LockCommandExecutor getLockCommandExecutor()
This is used, for instance, by utility classes to acquire locks required for access control checks and other operations.
The default LockCommandExecutor
implementation is
LockCommandExecutorImpl
. Some
AccessController
:s may require other implementations.
boolean supportsCapability(FileSystemCapabilityType<?> type)
FileSystemCapability
. Capabilities are either supported directly by file system
implementations or by CapabilityProvider
:s given to the file
system at creation time.
type
- The capability's FileSystemCapabilityType
.
true
if the file system supports the capability, false
if not.getCapability(FileSystemCapabilityType)
<T extends FileSystemCapability> T getCapability(FileSystemCapabilityType<T> type) throws UnsupportedCapabilityException
FileSystemCapability
.
type
- The capability's FileSystemCapabilityType
.
UnsupportedCapabilityException
- If the requested capability is not
supported by the file system.supportsCapability(FileSystemCapabilityType)
Set<FileSystemCapabilityType<?>> getSupportedCapabilities()
boolean supportsCapabilityForEntity(EntityView ev, EntityCapabilityType<?> type)
Entity
(or an entity viewed by an EntityView
supports a specific EntityCapability
. Capabilities are either
supported directly by file system implementations or by
CapabilityProvider
:s given to the file system at creation time.
ev
- The EntityView
to check for.type
- The capability's EntityCapabilityType
.
true
if the entity supports the capability, false
if not.getCapabilityForEntity(EntityView, EntityCapabilityType)
,
supportsCapabilityForEntityType(EntityType, EntityCapabilityType)
,
EntityView.supportsCapability(EntityCapabilityType)
boolean supportsCapabilityForEntityType(EntityType et, EntityCapabilityType<?> type)
CapabilityProvider
:s given to the file system at creation
time.
There may be exceptions to the result returned by this method for certain
special entities (i.e. the root directory). For querying about
capabilities of existing entities, use the
EntityView.supportsCapability(EntityCapabilityType)
method
instead.
et
- The entity type.type
- The entity capability type.
true
if the capability type is supported by the supplied
entity type in this file systems. (There may be exceptions to that rule,
however. See above.)supportsCapabilityForEntity(EntityView, EntityCapabilityType)
<T extends EntityCapability> T getCapabilityForEntity(EntityView ev, EntityCapabilityType<T> type) throws UnsupportedCapabilityException
EntityCapability
for an Entity
(or an
entity viewed by an EntityView
.
ev
- The EntityView
to get the capability object for.type
- The capability's EntityCapabilityType
.
EntityCapability
object for the Entity
.
UnsupportedCapabilityException
- If the capability is not supported
by the Entity
.supportsCapabilityForEntity(EntityView, EntityCapabilityType)
,
EntityView.getCapability(EntityCapabilityType)
Set<EntityCapabilityType<?>> getSupportedEntityCapabilities()
int getBufferSize()
void close()
Different file system implementations implement this differently. File systems that are built on open files (the Zip file system, for instance), close that file.
This should be implemented so that it is possible to call close
several times on the same file system instance without getting any
errors.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |