org.entityfs.impl
Class AbstractFileSystemBuilder<T extends FileSystemBuilder<T>>

java.lang.Object
  extended by org.entityfs.impl.AbstractFileSystemBuilder<T>
Type Parameters:
T - The concrete file system builder type.
All Implemented Interfaces:
FileSystemBuilder<T>
Direct Known Subclasses:
AbstractFileSystemBuilderImpl

public abstract class AbstractFileSystemBuilder<T extends FileSystemBuilder<T>>
extends Object
implements FileSystemBuilder<T>

This abstract base class can serve as the starting point for an FileSystemBuilder implementation.

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

Field Summary
 
Fields inherited from interface org.entityfs.FileSystemBuilder
DEFAULT_BUFFER_SIZE
 
Constructor Summary
protected AbstractFileSystemBuilder(LogAdapter la, EntityValidityControlStrategy evcs)
           
 
Method Summary
 T addCapabilityProvider(CapabilityProvider cp)
          Add a capability provider to the file system.
 T addCapabilityProviders(Collection<? extends CapabilityProvider> c)
          Add a collection of capability providers.
 T disableAccessControls()
          Disable access controls in the file system altogether.
 T disableEntityValidityControls()
          Disable entity validity controls altogether.
 T enableLocking()
          Enable locking for the file system with default values for the lock acquiring strategy and the lock adapter factory.
 AccessController getAccessController()
          Get the file system's access controller.
 int getBufferSize()
          Get the size of temporary buffers in the file system.
 Collection<CapabilityProvider> getCapabilityProviders()
          Get the file system's capability providers.
protected  Collection<CapabilityProvider> getCapabilityProvidersInternal()
          Get the file system's capability providers, cast to CapabilityProviderImplementation.
 EntityValidityControlStrategy getEntityValidityControlStrategy()
          Get the file system's entity validity control strategy.
 LockAcquiringStrategy getLockAcquiringStrategy()
          Get the file system's lock acquiring strategy.
 EntityLockAdapterFactory getLockAdapterFactory()
          Get the file system's lock adapter factory.
 LockCommandExecutor getLockCommandExecutor()
          Get the org.entityfs.lock.cmd.LockCommandExecutor.
 LogAdapter getLogAdapter()
          Get the file system's log adapter, if set.
 String getName()
          Get the file system's name, if set.
protected  T getThis()
          Get this cast to its actual type.
 T setAccessController(AccessController ac)
          Set an access controller.
 T setBufferSize(int size)
          Set the size of temporary buffers in the file system.
 T setEntityValidityControlStrategy(EntityValidityControlStrategy evcs)
          Set the entity validity control strategy -- the strategy for validating existing entities.
 T setLockAcquiringStrategy(LockAcquiringStrategy las)
          Set the lock acquiring strategy.
 T setLockAdapterFactory(EntityLockAdapterFactory laf)
          Set the lock adapter factory.
 T setLockCommandExecutor(LockCommandExecutor lce)
          Set a new org.entityfs.lock.cmd.LockCommandExecutor.
 T setLogAdapter(LogAdapter la)
          Set the file system's log adapter.
 T setName(String name)
          Set the file system's optional name.
protected  Collection<String> validate()
          Validate that we can create a file system with the current properties.
 
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
create, enableEvents, isLockingSupported
 

Constructor Detail

AbstractFileSystemBuilder

protected AbstractFileSystemBuilder(LogAdapter la,
                                    EntityValidityControlStrategy evcs)
Method Detail

getThis

protected final T getThis()
Get this cast to its actual type. This is useful for returning the right type of this when implementing setter methods that return the called object.

Returns:
this cast to its actual type.

setLogAdapter

public T setLogAdapter(LogAdapter la)
Set the file system's log adapter.

Specified by:
setLogAdapter in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Parameters:
la - A log adapter.
Returns:
this
See Also:
FileSystem.getLogAdapterHolder()

getLogAdapter

public LogAdapter getLogAdapter()
Get the file system's log adapter, if set.

Specified by:
getLogAdapter in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
The file system's log adapter, if set.

setLockCommandExecutor

public T setLockCommandExecutor(LockCommandExecutor lce)
Set a new org.entityfs.lock.cmd.LockCommandExecutor.

The default org.entityfs.lock.cmd.LockCommandExecutor is the LockCommandExecutorImpl. Some AccessController implementations may require other LockCommandExecutor implementations.

Parameters:
lce - The new LockCommandExecutor.
Returns:
this.

getLockCommandExecutor

public LockCommandExecutor getLockCommandExecutor()
Get the org.entityfs.lock.cmd.LockCommandExecutor.

Returns:
The org.entityfs.lock.cmd.LockCommandExecutor.

setLockAcquiringStrategy

public T setLockAcquiringStrategy(LockAcquiringStrategy las)
Set the lock acquiring strategy.

Specified by:
setLockAcquiringStrategy in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Parameters:
las - The lock acquiring strategy.
Returns:
this.

getLockAcquiringStrategy

public LockAcquiringStrategy getLockAcquiringStrategy()
Get the file system's lock acquiring strategy.

Specified by:
getLockAcquiringStrategy in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
The file system's lock acquiring strategy.

setLockAdapterFactory

public T setLockAdapterFactory(EntityLockAdapterFactory laf)
Set the lock adapter factory.

Specified by:
setLockAdapterFactory in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Parameters:
laf - A lock adapter factory.
Returns:
this

getLockAdapterFactory

public EntityLockAdapterFactory getLockAdapterFactory()
Get the file system's lock adapter factory.

Specified by:
getLockAdapterFactory in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
The file system's lock adapter factory.

enableLocking

public T enableLocking()
                                             throws UnsupportedOperationException
Enable locking for the file system with default values for the lock acquiring strategy and the lock adapter factory. The locking will be read/write.

This is equivalent to calling setLockAcquiringStrategy(LockAcquiringStrategy) with a SimpleLockAcquiringStrategy and then setLockAdapterFactory(EntityLockAdapterFactory) with a NonFairReadWriteEntityLockAdapterFactory.

Specified by:
enableLocking in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
this
Throws:
UnsupportedOperationException - If the file system being built does not support locking.
See Also:
FileSystemBuilder.isLockingSupported()

setEntityValidityControlStrategy

public T setEntityValidityControlStrategy(EntityValidityControlStrategy evcs)
Set the entity validity control strategy -- the strategy for validating existing entities. This strategy is invoked whenever an entity method is called to check if the entity's backing file or directory is still present in the file system backend.

If this is set to null, the validity controls are disabled altogether. If a backing file or directory disappears in a file system without validity controls, for instance by someone deleting it directly in the backing file system, this may lead to strange errors.

Specified by:
setEntityValidityControlStrategy in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Parameters:
evcs - The validity control strategy, or null to disable the validation.
Returns:
this
See Also:
disableEntityValidityControls()

disableEntityValidityControls

public T disableEntityValidityControls()
Disable entity validity controls altogether. Do this only if you can be sure that no other process will modify the files and directories in the backing file system.

Specified by:
disableEntityValidityControls in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
this
See Also:
setEntityValidityControlStrategy(EntityValidityControlStrategy)

getEntityValidityControlStrategy

public EntityValidityControlStrategy getEntityValidityControlStrategy()
Get the file system's entity validity control strategy.

Specified by:
getEntityValidityControlStrategy in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
The file system's entity validity control strategy.

setAccessController

public T setAccessController(AccessController ac)
Set an access controller.

Specified by:
setAccessController in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Parameters:
ac - An access controller.
Returns:
this.

disableAccessControls

public T disableAccessControls()
Disable access controls in the file system altogether.

Access controls are disabled by default, so normally there should be no reason for calling this method.

Specified by:
disableAccessControls in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
this.

getAccessController

public AccessController getAccessController()
Get the file system's access controller.

Specified by:
getAccessController in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
The file system's access controller.

setName

public T setName(String name)
Set the file system's optional name. The name is used for logging and statistics.

Specified by:
setName in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Parameters:
name - The file system name,
Returns:
this.

getName

public String getName()
Get the file system's name, if set.

Specified by:
getName in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
The file system's name.

addCapabilityProvider

public T addCapabilityProvider(CapabilityProvider cp)
Add a capability provider to the file system. Capability providers are used to extend a file system's functionality.

Specified by:
addCapabilityProvider in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Parameters:
cp - A capability provider.
Returns:
this.
See Also:
addCapabilityProviders(Collection)

addCapabilityProviders

public T addCapabilityProviders(Collection<? extends CapabilityProvider> c)
Add a collection of capability providers.

Specified by:
addCapabilityProviders in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Parameters:
c - A collection of capability providers.
Returns:
this
See Also:
addCapabilityProvider(CapabilityProvider)

getCapabilityProviders

public Collection<CapabilityProvider> getCapabilityProviders()
Get the file system's capability providers.

Specified by:
getCapabilityProviders in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
The file system's capability providers.

getCapabilityProvidersInternal

protected Collection<CapabilityProvider> getCapabilityProvidersInternal()
Get the file system's capability providers, cast to CapabilityProviderImplementation.

Returns:
The file system's capability providers.

setBufferSize

public T setBufferSize(int size)
Set the size of temporary buffers in the file system. The size determines the size of temporary buffers use by the file system implementations for copying, etc. The default value is FileSystemBuilder.DEFAULT_BUFFER_SIZE.

Specified by:
setBufferSize in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Parameters:
size - The size of temporary buffers.
Returns:
this.

getBufferSize

public int getBufferSize()
Get the size of temporary buffers in the file system.

Specified by:
getBufferSize in interface FileSystemBuilder<T extends FileSystemBuilder<T>>
Returns:
The size of temporary buffers in the file system.

validate

protected Collection<String> validate()
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()).

Returns:
A Collection of error messages. Can be empty but never null.