org.planx.io
Class MultiFileSystem

java.lang.Object
  extended by org.planx.io.MultiFileSystem
All Implemented Interfaces:
FileSystem

public class MultiFileSystem
extends Object
implements FileSystem

Combines several FileSystems into one providing transparent access to all of them. Operations involving lookup of a file system based on a Locator have O(N) performance where N is the number of FileSystems associated with this MultiFileSystem. The lookup is done by calling FileSystem.isContained(Locator) on every file system until a file system returns true.

Subclasses may override the lookup(Locator) method to change the lookup implementation.

Author:
Thomas Ambus

Constructor Summary
MultiFileSystem()
          Creates an empty MultiFileSystem.
MultiFileSystem(FileSystem allocFs)
          Creates a MultiFileSystem using the specified file system for allocation of new data.
 
Method Summary
 void addFileSystem(FileSystem fs)
          Adds the specified file system to this MultiFileSystem.
 Bound all()
          Allocates data in the file system designated for new allocations.
 Bound allocate()
          Allocates data in the file system designated for new allocations.
 Bound allocate(long size)
          Allocates data in the file system designated for new allocations.
 void clear()
          Frees all data in this FileSystem.
 void clearModified()
          Clears the modified status of all the file systems.
 void close()
          Closes all the contained file systems.
 void free(Bound l)
          Frees the space occupied by the specified Bound.
 FileSystem getAllocationFileSystem()
          Returns the file system designated for new allocations of data or null if none exists.
 PositionalData getData(Locator l)
          Returns a PositionalData for reading and writing to the FileSystem at the specified location.
 Bound getMeta()
          Unsupported - returns null.
 SourceId id()
          Returns the SourceId of the allocation file system.
 boolean isContained(Locator l)
          Returns true if and only if the specified locator is contained in any of the file systems associated with this MultiFileSystem.
 boolean isModified()
          Returns true if any of the file systems are modified.
 boolean isReadOnly()
          Returns true only if all the file systems are read-only.
 FileSystem lookup(Locator l)
          Returns the FileSystem containing the specified locator or returns null if none of the file systems contains the locator.
 void removeFileSystem(FileSystem fs)
          Removes the specified file system from this MultiFileSystem.
 void setAllocationFileSystem(FileSystem allocFs)
          Sets the file system designated for new allocations of data.
 void setMeta(Bound b)
          Unsupported.
 void setReadOnly(boolean isReadOnly)
          Sets the read-only status of all the file systems.
 long size()
          Returns the total size of all associated file systems.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiFileSystem

public MultiFileSystem()
Creates an empty MultiFileSystem. Allocation operations will not be supported.


MultiFileSystem

public MultiFileSystem(FileSystem allocFs)
Creates a MultiFileSystem using the specified file system for allocation of new data. That file system will also be considered part of this file system.

Method Detail

addFileSystem

public void addFileSystem(FileSystem fs)
Adds the specified file system to this MultiFileSystem.


removeFileSystem

public void removeFileSystem(FileSystem fs)
Removes the specified file system from this MultiFileSystem.


getAllocationFileSystem

public FileSystem getAllocationFileSystem()
Returns the file system designated for new allocations of data or null if none exists.


setAllocationFileSystem

public void setAllocationFileSystem(FileSystem allocFs)
Sets the file system designated for new allocations of data. The file system will automatically be added to the systems contained in this MultiFileSystem. Any previous allocation file system will not be removed automatically.


id

public SourceId id()
            throws IOException
Returns the SourceId of the allocation file system.

Specified by:
id in interface FileSystem
Throws:
IOException

allocate

public Bound allocate()
               throws IOException
Allocates data in the file system designated for new allocations.

Specified by:
allocate in interface FileSystem
Throws:
IOException - if an I/O error occurred.

allocate

public Bound allocate(long size)
               throws IOException
Allocates data in the file system designated for new allocations.

Specified by:
allocate in interface FileSystem
Throws:
IOException - if an I/O error occurred or the specified amount of bytes could not be allocated.

all

public Bound all()
          throws IOException
Allocates data in the file system designated for new allocations.

Specified by:
all in interface FileSystem
Throws:
IOException - if an I/O error occurred.

free

public void free(Bound l)
          throws IOException
Description copied from interface: FileSystem
Frees the space occupied by the specified Bound.

Specified by:
free in interface FileSystem
Throws:
IOException - if an I/O error occurred.
InvalidSourceIdException - if the file system identifier of the locator is invalid.
OutOfBoundsException - if the locator is out of bounds.

getMeta

public Bound getMeta()
              throws IOException
Unsupported - returns null.

Specified by:
getMeta in interface FileSystem
Throws:
IOException

setMeta

public void setMeta(Bound b)
             throws IOException
Unsupported.

Specified by:
setMeta in interface FileSystem
Throws:
IOException

clear

public void clear()
           throws IOException
Description copied from interface: FileSystem
Frees all data in this FileSystem.

Specified by:
clear in interface FileSystem
Throws:
IOException

getData

public PositionalData getData(Locator l)
                       throws IOException
Description copied from interface: FileSystem
Returns a PositionalData for reading and writing to the FileSystem at the specified location.

Specified by:
getData in interface FileSystem
Throws:
IOException - if an I/O error occurred.
InvalidSourceIdException - if the file system identifier of the locator is invalid.
OutOfBoundsException - if the locator is out of bounds.

size

public long size()
          throws IOException
Returns the total size of all associated file systems.

Specified by:
size in interface FileSystem
Throws:
IOException - if an I/O error occurred.

isModified

public boolean isModified()
                   throws IOException
Returns true if any of the file systems are modified.

Specified by:
isModified in interface FileSystem
Throws:
IOException

clearModified

public void clearModified()
                   throws IOException
Clears the modified status of all the file systems.

Specified by:
clearModified in interface FileSystem
Throws:
IOException

isReadOnly

public boolean isReadOnly()
                   throws IOException
Returns true only if all the file systems are read-only.

Specified by:
isReadOnly in interface FileSystem
Throws:
IOException

setReadOnly

public void setReadOnly(boolean isReadOnly)
                 throws IOException
Sets the read-only status of all the file systems.

Specified by:
setReadOnly in interface FileSystem
Throws:
IOException

close

public void close()
           throws IOException
Closes all the contained file systems.

Specified by:
close in interface FileSystem
Throws:
IOException - if an I/O error occurred.

isContained

public boolean isContained(Locator l)
Returns true if and only if the specified locator is contained in any of the file systems associated with this MultiFileSystem.

Specified by:
isContained in interface FileSystem

lookup

public FileSystem lookup(Locator l)
                  throws IOException
Returns the FileSystem containing the specified locator or returns null if none of the file systems contains the locator. Subclasses may override this method to change lookup implementation.

Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2004-2005 Plan-X. All Rights Reserved.