org.javaseis.io
Class ExtentManager

java.lang.Object
  extended by org.javaseis.io.ExtentManager
All Implemented Interfaces:
java.io.Serializable

public class ExtentManager
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Nested Class Summary
 class ExtentManager.ExtentListCompare
          Manage VirtualIO extents for spreading data across multiple file systems
 class ExtentManager.ExtentListContains
           
 
Field Summary
protected  int currentDirIndex
           
protected  ExtentListEntry currentExtent
           
protected  java.lang.String extentBaseName
           
protected  long extentCreateSize
           
protected  java.lang.String[] extentDirs
           
protected  java.util.List<ExtentListEntry> extentList
           
protected  ExtentPolicy extentPolicy
           
protected  SeisProperties extentProperties
           
protected  long ioTime
           
protected  boolean isChanged
           
protected  long lockTime
           
static java.util.logging.Logger LOG
           
protected  long maxFreeSpace
           
protected  long minFreeSpace
           
protected  boolean readOnly
           
protected  long t0
           
protected  boolean trackTime
           
protected static java.lang.String vfioHeader
           
protected  boolean vfioLock
           
protected  int vfioMaxFiles
           
protected  long vfioMaxPosition
           
protected  int vfioNdirs
           
protected  int vfioNfiles
           
protected  boolean vfioOpen
           
protected static java.lang.String vfioVersion
           
 
Constructor Summary
ExtentManager(java.lang.String virtualFileProperties, java.lang.String mode, java.lang.String[] altDirectories)
          Create an extent manager for an existing virtual file
ExtentManager(java.lang.String virtualFileProperties, java.lang.String extentBaseName, java.lang.String[] extentDirectories, long fileLength, int numExtents)
          Create an extent manager for a new virtual file
ExtentManager(java.lang.String virtualFileProperties, java.lang.String extentBaseName, java.lang.String[] extentDirectories, long fileLength, int numExtents, ExtentPolicy policy)
          Create an extent manager for a new virtual file
ExtentManager(java.lang.String virtualFileProperties, java.lang.String extentBaseName, java.lang.String[] extentDirectories, long fileLength, int numExtents, ExtentPolicy policy, IParallelContext pc)
          Create an extent manager for a new virtual file in a parallel context
 
Method Summary
 int addExtent(long startPosition, long extentSizeBytes)
          Add an extent to a virtual file.
protected  void allocateExtents()
          Create all extents for a new virtual file based on extentPolicy
 void close()
          Close this extent manager and release resources
 void create(java.lang.String virtualFileProperties, java.lang.String[] extentDirectories)
          Check extent directories for validity and create Virtual File Properties
static boolean delete(java.lang.String path)
          Delete the extents and properties files used by this virtual file
 boolean deleteExtents()
          Delete the extents for this virtual file
 boolean extentExists(long position)
          Determine if the virtual file has an existing extent that contains a specified file position in bytes
 java.lang.String findExtent(long position)
          Search for the extent that contains a given file position
 int getExtentIndex(long position)
          Return the index in the extent list of the extent that contains a specified file position.
 java.lang.String getExtentPath(int index)
          Return the path of the extent specified by index in the extent list
 long getExtentSize()
           
 float getIoTime()
          Return the time in seconds spent in lock routines
 float getLockTime()
          Return the time in seconds spent in lock routines
 long getStartOffset()
           
static boolean isVirtual(java.lang.String path)
          Return true if a path points to a valid virtual file
static void main(java.lang.String[] args)
          Test harness for basic functionality.
 void reload()
          Reload properties from disk
 boolean setMinMaxSpace(long minSpaceBytes, long maxSpaceBytes)
          Set the min and max space parameters for POLICY_MINMAX Directories with space less than minSpaceBytes are excluded as locations, directories with space greater than maxSpaceBytes are preferred over the rest.
protected  void setPolicy(ExtentPolicy policy)
          Set the policy to use for allocating extents to directories, from: ExentPolicy
 void trackTime(boolean trackTime)
          Set flag for I/O and lock time tracking
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentDirIndex

protected int currentDirIndex

currentExtent

protected ExtentListEntry currentExtent

extentBaseName

protected java.lang.String extentBaseName

extentCreateSize

protected long extentCreateSize

extentDirs

protected java.lang.String[] extentDirs

extentList

protected java.util.List<ExtentListEntry> extentList

extentPolicy

protected ExtentPolicy extentPolicy

extentProperties

protected SeisProperties extentProperties

ioTime

protected long ioTime

isChanged

protected boolean isChanged

lockTime

protected long lockTime

LOG

public static final java.util.logging.Logger LOG

maxFreeSpace

protected long maxFreeSpace

minFreeSpace

protected long minFreeSpace

readOnly

protected boolean readOnly

t0

protected long t0

trackTime

protected boolean trackTime

vfioHeader

protected static java.lang.String vfioHeader

vfioLock

protected boolean vfioLock

vfioMaxFiles

protected int vfioMaxFiles

vfioMaxPosition

protected long vfioMaxPosition

vfioNdirs

protected int vfioNdirs

vfioNfiles

protected int vfioNfiles

vfioOpen

protected boolean vfioOpen

vfioVersion

protected static java.lang.String vfioVersion
Constructor Detail

ExtentManager

public ExtentManager(java.lang.String virtualFileProperties,
                     java.lang.String mode,
                     java.lang.String[] altDirectories)
              throws SeisException
Create an extent manager for an existing virtual file

Parameters:
virtualFileProperties - file containing virtual file properties
mode - Open mode for file, "r" for read only, "rw" for read/write
altDirectories - An optional list of alternate directories to search
Throws:
SeisException - on file not found, invalid directories, or permissions

ExtentManager

public ExtentManager(java.lang.String virtualFileProperties,
                     java.lang.String extentBaseName,
                     java.lang.String[] extentDirectories,
                     long fileLength,
                     int numExtents)
              throws SeisException
Create an extent manager for a new virtual file

Parameters:
virtualFileProperties - path name for the virtual file properties to create
extentBaseName - base name for extents
extentDirectories - locations where extents can be created
fileLength - file length in bytes
numExtents - number of extents to break file into
Throws:
SeisException - on file system errors

ExtentManager

public ExtentManager(java.lang.String virtualFileProperties,
                     java.lang.String extentBaseName,
                     java.lang.String[] extentDirectories,
                     long fileLength,
                     int numExtents,
                     ExtentPolicy policy)
              throws SeisException
Create an extent manager for a new virtual file

Parameters:
virtualFileProperties - path name for the virtual file properties to create
extentBaseName - base name for extents
extentDirectories - locations where extents can be created
fileLength - file length in bytes
numExtents - number of extents to break file into
Throws:
SeisException - on file system errors

ExtentManager

public ExtentManager(java.lang.String virtualFileProperties,
                     java.lang.String extentBaseName,
                     java.lang.String[] extentDirectories,
                     long fileLength,
                     int numExtents,
                     ExtentPolicy policy,
                     IParallelContext pc)
              throws SeisException
Create an extent manager for a new virtual file in a parallel context

Parameters:
parallelContext - - parallel context to use for synchronized creation
virtualFileProperties - path name for the virtual file properties to create
extentBaseName - base name for extents
extentDirectories - locations where extents can be created
fileLength - file length in bytes
numExtents - number of extents to break file into
Throws:
SeisException - on file system errors
Method Detail

addExtent

public int addExtent(long startPosition,
                     long extentSizeBytes)
              throws SeisException
Add an extent to a virtual file. The file is locked and reloaded to be sure that some other process hasn't snuck in and added the extent already.

Parameters:
startPosition - starting position in bytes for the extent
extentSizeBytes - size of the extent to be added in bytes
Returns:
index of the new extent, or the index of an existing extent
Throws:
SeisException - on extent creation errors

allocateExtents

protected void allocateExtents()
                        throws SeisException
Create all extents for a new virtual file based on extentPolicy

Throws:
SeisException

close

public void close()
           throws SeisException
Close this extent manager and release resources

Throws:
SeisException - on property file errors

create

public void create(java.lang.String virtualFileProperties,
                   java.lang.String[] extentDirectories)
            throws SeisException
Check extent directories for validity and create Virtual File Properties

Parameters:
virtualFileProperties -
extentDirectories -
Throws:
SeisException - on create errors

delete

public static boolean delete(java.lang.String path)
Delete the extents and properties files used by this virtual file

Parameters:
path - full path to the properties file for the virtual file
Returns:

deleteExtents

public boolean deleteExtents()
Delete the extents for this virtual file

Returns:
true if all extents were deleted, false otherwise

extentExists

public boolean extentExists(long position)
Determine if the virtual file has an existing extent that contains a specified file position in bytes

Parameters:
position - Virtual File file position in bytes
Returns:
true if the extent exists, false if not

findExtent

public java.lang.String findExtent(long position)
Search for the extent that contains a given file position

Parameters:
position - file position for the search
Returns:
path name for the extent that contains this position

getExtentIndex

public int getExtentIndex(long position)
Return the index in the extent list of the extent that contains a specified file position.

Parameters:
position - location in the virtual file in bytes
Returns:
index in the extent list of the extent that contains this position

getExtentPath

public java.lang.String getExtentPath(int index)
Return the path of the extent specified by index in the extent list

Parameters:
index - index of the desired extent
Returns:
path name of the extent

getExtentSize

public long getExtentSize()

getIoTime

public float getIoTime()
Return the time in seconds spent in lock routines

Returns:
lock time in seconds

getLockTime

public float getLockTime()
Return the time in seconds spent in lock routines

Returns:
lock time in seconds

getStartOffset

public long getStartOffset()

isVirtual

public static boolean isVirtual(java.lang.String path)
Return true if a path points to a valid virtual file

Parameters:
path - full path name to virtual file properties
Returns:
true if this is a valid virtual file

main

public static void main(java.lang.String[] args)
                 throws SeisException
Test harness for basic functionality.

Parameters:
args -
Throws:
SeisException

reload

public void reload()
            throws SeisException
Reload properties from disk

Throws:
SeisException - on I/O errors

setMinMaxSpace

public boolean setMinMaxSpace(long minSpaceBytes,
                              long maxSpaceBytes)
Set the min and max space parameters for POLICY_MINMAX Directories with space less than minSpaceBytes are excluded as locations, directories with space greater than maxSpaceBytes are preferred over the rest.

Parameters:
minSpaceBytes - minimum space in bytes
maxSpaceBytes - maximum space in bytes
Returns:
true on success, false on parameter out of rage errors.

setPolicy

protected void setPolicy(ExtentPolicy policy)
Set the policy to use for allocating extents to directories, from: ExentPolicy

Parameters:
policy - one of the valid policy selections

trackTime

public void trackTime(boolean trackTime)
Set flag for I/O and lock time tracking

Parameters:
trackTime - set to true to turn on time tracking