org.entityfs.ram
Class RamFileSystemBuilder

java.lang.Object
  extended by org.entityfs.impl.AbstractFileSystemBuilder<T>
      extended by org.entityfs.impl.impl.AbstractFileSystemBuilderImpl<RamFileSystemBuilder>
          extended by org.entityfs.ram.RamFileSystemBuilder
All Implemented Interfaces:
FileSystemBuilder<RamFileSystemBuilder>

public class RamFileSystemBuilder
extends AbstractFileSystemBuilderImpl<RamFileSystemBuilder>
implements FileSystemBuilder<RamFileSystemBuilder>

This is a builder object for building read/write Ram file systems. A Ram file system keeps all file system data in-memory. It can have an optional size limit (other than the Java process' max heap space...).

File data in the Ram file system is partitioned into file segments. The default size of a file segment is 4096 bytes. A file can never occupy less space in memory than its segment size (plus other internal file data (instance variables)).

Since:
1.0
Author:
Karl Gustafsson
In_jar:
entityfs-ram

Field Summary
static int DEFAULT_FILE_SEGMENT_SIZE_BYTES
          The default file segment size is 4096 bytes.
static long DEFAULT_MAX_FILE_SYSTEM_SIZE_BYTES
          The default maximum file system size is -1 bytes (unlimited size).
 
Fields inherited from interface org.entityfs.FileSystemBuilder
DEFAULT_BUFFER_SIZE
 
Constructor Summary
RamFileSystemBuilder()
          Create a builder with default settings: LogAdapter: DefaultLogAdapter.DEFAULT_ADAPTER EntityValidityControlStrategy: null (the backend is only accessible through the file system)
 
Method Summary
protected  AdapterFactory createAdapterFactory()
          Subclasses implement this to create the right AdapterFactory implementation.
protected  ChildEntityManagerFactory<EntityImplementation> createDefaultChildEntityManagerFactory(FileSystemAdapter fsa, LogAdapterHolder lah)
          Create a default ChildEntityManagerFactory if none is set.
protected  FileSystemImplementation createFileSystem(SupportObjects fso, FileSystemDelegate fsd)
          Subclasses implement this to return a new file system instance.
protected  FileSystemDelegate createFileSystemDelegate(FileSystemAdapter fsa)
          This method is implemented by a subclass to create the file system delegate to use.
 int getFileSegmentSizeBytes()
          Get the Ram file segment size in bytes.
 long getMaxFileSystemSizeBytes()
          Get the maximum size of the file system data in bytes.
 boolean isLockingSupported()
          Does the file system being built support locking?
protected  boolean isReadOnly()
          Subclasses implement this method to tell if the file system they are about to create is read only.
 RamFileSystemBuilder setFileSegmentSizeBytes(int noBytes)
          Set the size of a Ram file segment.
 RamFileSystemBuilder setMaxFileSystemSizeBytes(long size)
          Set the maximum size of the file system data in bytes.
protected  Collection<String> validate()
          Validate that we can create a file system with the current properties.
 
Methods inherited from class org.entityfs.impl.impl.AbstractFileSystemBuilderImpl
create, enableEvents, getChildEntityManagerFactory, getEventManager, isFileSystemSupportedByAllCapabilities, setChildEntityManagerFactory, setEventManager
 
Methods inherited from class org.entityfs.impl.AbstractFileSystemBuilder
addCapabilityProvider, addCapabilityProviders, disableAccessControls, disableEntityValidityControls, enableLocking, getAccessController, getBufferSize, getCapabilityProviders, getCapabilityProvidersInternal, getEntityValidityControlStrategy, getLockAcquiringStrategy, getLockAdapterFactory, getLockCommandExecutor, getLogAdapter, getName, getThis, setAccessController, setBufferSize, setEntityValidityControlStrategy, setLockAcquiringStrategy, setLockAdapterFactory, setLockCommandExecutor, setLogAdapter, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.entityfs.FileSystemBuilder
addCapabilityProvider, addCapabilityProviders, create, disableAccessControls, disableEntityValidityControls, enableEvents, enableLocking, getAccessController, getBufferSize, getCapabilityProviders, getEntityValidityControlStrategy, getLockAcquiringStrategy, getLockAdapterFactory, getLogAdapter, getName, setAccessController, setBufferSize, setEntityValidityControlStrategy, setLockAcquiringStrategy, setLockAdapterFactory, setLogAdapter, setName
 

Field Detail

DEFAULT_FILE_SEGMENT_SIZE_BYTES

public static final int DEFAULT_FILE_SEGMENT_SIZE_BYTES
The default file segment size is 4096 bytes.

See Also:
Constant Field Values

DEFAULT_MAX_FILE_SYSTEM_SIZE_BYTES

public static final long DEFAULT_MAX_FILE_SYSTEM_SIZE_BYTES
The default maximum file system size is -1 bytes (unlimited size).

See Also:
Constant Field Values
Constructor Detail

RamFileSystemBuilder

public RamFileSystemBuilder()
Create a builder with default settings:

Method Detail

setFileSegmentSizeBytes

public RamFileSystemBuilder setFileSegmentSizeBytes(int noBytes)
Set the size of a Ram file segment. The default value is 4096 bytes.

Parameters:
noBytes - The Ram file segment in bytes.
Returns:
The builder object (this).

getFileSegmentSizeBytes

public int getFileSegmentSizeBytes()
Get the Ram file segment size in bytes.

Returns:
The Ram file segment size in bytes.

setMaxFileSystemSizeBytes

public RamFileSystemBuilder setMaxFileSystemSizeBytes(long size)
Set the maximum size of the file system data in bytes. The size set here does not take the memory size of file system objects into account, only the accumulated size of allocated file segments. Set the max size to -1 to have "unlimited" maximum size. (The available heap space for the Java process sets the effective limit.)

The default max file system size is set to -1 ("unlimited" size).

Parameters:
size - The maximum size for the file system. Set to -1 for "unlimited" size.
Returns:
The builder object (this).

getMaxFileSystemSizeBytes

public long getMaxFileSystemSizeBytes()
Get the maximum size of the file system data in bytes.

Returns:
The maximum size of the file system data in bytes, or -1 if the file system can have "unlimited" size.

createAdapterFactory

protected AdapterFactory createAdapterFactory()
Description copied from class: AbstractFileSystemBuilderImpl
Subclasses implement this to create the right AdapterFactory implementation.

This method is called from AbstractFileSystemBuilderImpl.create().

Specified by:
createAdapterFactory in class AbstractFileSystemBuilderImpl<RamFileSystemBuilder>
Returns:
An AdapterFactory implementation.

createDefaultChildEntityManagerFactory

protected ChildEntityManagerFactory<EntityImplementation> createDefaultChildEntityManagerFactory(FileSystemAdapter fsa,
                                                                                                 LogAdapterHolder lah)
Description copied from class: AbstractFileSystemBuilderImpl
Create a default ChildEntityManagerFactory if none is set.

The default implementation creates a ChildEntityManagerFactoryImpl. That implementation can let entity objects be garbage collected, which is fine for file systems that are backed by another file system, such as the FS file system or the Zip file system. For file systems where the entities themselves contain all file data, such as the RAM file system, another implementation must be used.

This method is called from AbstractFileSystemBuilderImpl.create().

Overrides:
createDefaultChildEntityManagerFactory in class AbstractFileSystemBuilderImpl<RamFileSystemBuilder>
Parameters:
fsa - The file system adapter
lah - The log adapter holder.
Returns:
An instance of the default ChildEntityManagerFactory.

createFileSystemDelegate

protected FileSystemDelegate createFileSystemDelegate(FileSystemAdapter fsa)
Description copied from class: AbstractFileSystemBuilderImpl
This method is implemented by a subclass to create the file system delegate to use.

This method is called from AbstractFileSystemBuilderImpl.create().

Specified by:
createFileSystemDelegate in class AbstractFileSystemBuilderImpl<RamFileSystemBuilder>
Parameters:
fsa - The file system adapter.
Returns:
A file system delegate.

createFileSystem

protected FileSystemImplementation createFileSystem(SupportObjects fso,
                                                    FileSystemDelegate fsd)
Description copied from class: AbstractFileSystemBuilderImpl
Subclasses implement this to return a new file system instance. The returned instance does not have any root directory set (yet).

This method is called from AbstractFileSystemBuilderImpl.create().

Specified by:
createFileSystem in class AbstractFileSystemBuilderImpl<RamFileSystemBuilder>
Parameters:
fso - A collection of support objects.
fsd - The file system delegate.
Returns:
A file system implementation.

validate

protected Collection<String> validate()
Description copied from class: AbstractFileSystemBuilder
Validate that we can create a file system with the current properties. Subclasses can override to add more validation checks (but be sure to call super.validate()).

Overrides:
validate in class AbstractFileSystemBuilder<RamFileSystemBuilder>
Returns:
A Collection of error messages. Can be empty but never null.

isLockingSupported

public boolean isLockingSupported()
Description copied from interface: FileSystemBuilder
Does the file system being built support locking?

Specified by:
isLockingSupported in interface FileSystemBuilder<RamFileSystemBuilder>
Returns:
true.
See Also:
FileSystemBuilder.enableLocking()

isReadOnly

protected boolean isReadOnly()
Description copied from class: AbstractFileSystemBuilderImpl
Subclasses implement this method to tell if the file system they are about to create is read only.

This method is called from AbstractFileSystemBuilderImpl.create().

Specified by:
isReadOnly in class AbstractFileSystemBuilderImpl<RamFileSystemBuilder>
Returns:
false, always.