Chapter 4. File systems

Table of Contents

Creating a file system
Tuning file system parameters
Closing a file system

The FileSystem interface represents a file system. It contains a directory hierarchy containing EFile and Directory entities, and it has a set of policy and strategy objects. It always holds a reference to the root Directory.

A FileSystem is created from a FileSystemBuilder object[1].


All setter methods of a FileSystemBuilder return the builder object. This makes it possibly to chain setter method invocations together as is shown in many of the examples below.

File systems have an optional name that, if set, should be unique within the current system. [2] The name can be used by applications to identify different file system instances. It is not used by EntityFS at all.

Example 4.1. Creating a file system-backed file system

// Create a file system with default settings except for a custom name
FileSystem fs1 = new FSRWFileSystemBuilder().
  setName("My first file system").
  setRoot(new File("/tmp/fs1")).
  create();

// Create a file system with no event handling and relaxed validity controls
// for entities. (See FSRWFileSystemBuilder API docs.)
FileSystem fs2 = new FSRWFileSystemBuilder().
  setName("My second file system").
  setRoot(new File("/tmp/fs2")).
  disableEntityValidityControls().
  // Enable entity locking
  enableLocking().
  create();

Example 4.2. Creating a Jar file-backed file system on a file in another file system

// fs is another file system
EFile jarFile = Directories.getFile(fs.getRootDirectory(), "myapp.jar");

FileSystem jfs = new JarFileSystemBuilder().
  setName("My Jar file system").
  setJarFile(jarFile).
  create();

By default, file systems are created with a minimal set of features. This can be tuned by configuring the file system builder differently. Also, the default validity control settings for the file system may be more defensive than what is required by the client. By setting less safe values, the file system's performance may increase somewhat.

The following is a list of common file system builder properties:

accessController

A file system can use an AccessController to limit access to entities. It can be used by applications to implement their access control policies. See Chapter 13, Access controls. Access controls are disabled by default.

bufferSize

The size of temporary in-memory buffers used by the file system. Different file system implementations use this for different things. The default value is 8192 bytes.

entityValidityControlStrategy

The strategy used for verifying that entities are still present in the backend whenever they are used. The default strategy for this is file system-specific. If it is known when the file system is created that no other processes will ever modify its contents, this can be disabled by calling disableEntityValidityControls on the file system builder.

events

By calling enableEvents, a client can make the entire FileSystem as well as individual entities Observable for EntityEvent:s. See Chapter 9, Entity events.

lockAcquiringStrategy

The strategy for acquiring file system EntityLock:s. See Chapter 7, Locking and multi-threaded access. Entity locking is disabled by default. It can be enabled by calling enableLocking on the file system builder.

lockCommandExecutor

Utility class for locking entity locks in accordance with the file system's locking strategy. Entity locking is disabled by default. It can be enabled by calling enableLocking on the file system builder. See Chapter 7, Locking and multi-threaded access.

lockAdapterFactory

A factory used for creating locks. Entity locking can be enabled by calling enableLocking on the file system builder. See Chapter 7, Locking and multi-threaded access.

Different file system implementations may also have their own, implementation-specific tunable parameters. For details, see the API documentation for each file system implementation.

File system implementations that use backend resources, for instance the Zip file system, require that the client closes the file system when it is not needed anymore. Calling close makes the file system release all open resources.



[1] The builder design pattern is discussed in for example GoF.

[2] The definition of the word system is application-specific; it might be a single JVM or a cluster of application servers.