org.javaseis.io
Class VirtualIO

java.lang.Object
  extended by org.javaseis.io.VirtualIO

public class VirtualIO
extends java.lang.Object

The VirtualIO class provides I/O support for datasets potentially spread across multiple file systems. In this implementation, allocation of extents is handled by an ExtentManager class (org.javaseis.io.ExtentManager) which handles the details of looking for space, keeping track of extents, etc.

Author:
Chuck Mosher for JavaSeis.org

Field Summary
protected  java.nio.channels.FileChannel _dataChannel
           
protected  java.io.File _dataFile
           
protected  java.lang.String _dataMode
           
protected  java.io.RandomAccessFile _dataStream
           
protected  long _extentCreateSize
           
protected  ExtentManager _extentManager
           
protected  java.lang.String _extentName
           
protected  long _extentSize
           
protected  long _extentStartOffset
           
protected  int _fileIndex
           
protected  long _fileOffset
           
protected  java.lang.String _filePath
           
protected  long _filePosition
           
protected  long _ioTime
           
protected  boolean _isChanged
           
protected  boolean _isReadOnly
           
protected  boolean _isVirtual
           
static java.util.logging.Logger _logger
           
static java.util.logging.Level _logLevel
           
protected  long _numBytes
           
protected  long _t0
           
protected  long _t0v
           
protected  boolean _trackTime
           
protected  long _virtualTime
           
protected static int MAX_FILES
           
 
Constructor Summary
VirtualIO(java.lang.String path)
          Open a VFIO non-virtual file for subsequent I/O operations.
VirtualIO(java.lang.String path, java.lang.String openMode)
          Open a VFIO file for subsequent I/O operations.
VirtualIO(java.lang.String path, java.lang.String openMode, java.lang.String[] alternateDirectories)
          Open a VFIO file for subsequent I/O operations.
VirtualIO(java.lang.String path, java.lang.String extentBaseName, java.lang.String[] extentDirs, long fileSize, int numExtents)
          Create a VFIO virtual file for subsequent I/O operations.
VirtualIO(java.lang.String path, java.lang.String extentBaseName, java.lang.String[] extentDirs, long fileSize, int numExtents, ExtentPolicy policy, IParallelContext pc)
          Create a VFIO virtual file in a parallel context.
 
Method Summary
 void allocateExtents()
           
 void close()
          Closes a VFIO file.
 boolean delete()
          Closes and deletes a open Virtual file.
static boolean delete(java.lang.String path)
          If the path to the file exists and represents a virtual file, delete the extents for the file and then the properties file defining the extents.
 void flush()
          Flushes a VFIO data to disk.
 java.io.FileDescriptor getFD()
           
 long getIoBytes()
          Return number of bytes read and/or written if I/O rate tracking is enabled
 float getIoRate()
          Return I/O rate in MegaBytes per second (MB/s)
 float getIoTime()
          Return current I/O time in seconds if I/O rate tracking is enabled
 float getLoadTime()
          Return overhead time spent in Virtual File Properties load/store operations
 float getLockTime()
          Return overhead time spent in Virtual File Properties lock operations
 java.lang.String getPath()
          Returns the VFIO file path.
 float getVirtualRate()
          Return effectve I/O rate including overhead time
 float getVirtualTime()
          Return total time spent in Virtual File operations
 boolean isVirtual()
          Returns the virtual status flag.
static boolean isVirtual(java.lang.String path)
          Test to see if a file represents a virtual file.
static void log(java.util.logging.Level logLevel, java.lang.String message)
           
static void main(java.lang.String[] args)
          Simple test harness for VirtualIO class
 void open(java.lang.String path, java.lang.String openMode, java.lang.String[] alternateDirectories)
          Constructs (and opens) a VFIO file for subsequent I/O operations.
protected  void openExtent(long newPosition)
          Opens the extent that containts the specified position.
protected  void openNonVirtual()
          Opens a VFIO non-virtual file.
protected  void openVirtual()
          Opens a VFIO non-virtual file.
 int read(java.nio.ByteBuffer buffer)
          Reads from data channel to buffer.
 int readBuffer(java.nio.ByteBuffer buffer)
          Reads from data channel to buffer.
 int readBuffer(java.nio.ByteBuffer buffer, int len)
          Reads from data channel to buffer.
static void setLogLevel(java.util.logging.Level logLevel)
           
 long setPosition(long newPosition)
          Sets the position for subsequent VFIO operations.
 void trackTime(boolean flag)
          Set flag that determines if I/O rate is tracked
 int write(java.nio.ByteBuffer buffer)
          Writes from buffer to data channel.
 int writeBuffer(java.nio.ByteBuffer buffer)
          Writes from buffer to data channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_dataChannel

protected java.nio.channels.FileChannel _dataChannel

_dataFile

protected java.io.File _dataFile

_dataMode

protected java.lang.String _dataMode

_dataStream

protected java.io.RandomAccessFile _dataStream

_extentCreateSize

protected long _extentCreateSize

_extentManager

protected ExtentManager _extentManager

_extentName

protected java.lang.String _extentName

_extentSize

protected long _extentSize

_extentStartOffset

protected long _extentStartOffset

_fileIndex

protected int _fileIndex

_fileOffset

protected long _fileOffset

_filePath

protected java.lang.String _filePath

_filePosition

protected long _filePosition

_ioTime

protected long _ioTime

_isChanged

protected boolean _isChanged

_isReadOnly

protected boolean _isReadOnly

_isVirtual

protected boolean _isVirtual

_logger

public static final java.util.logging.Logger _logger

_logLevel

public static java.util.logging.Level _logLevel

_numBytes

protected long _numBytes

_t0

protected long _t0

_t0v

protected long _t0v

_trackTime

protected boolean _trackTime

_virtualTime

protected long _virtualTime

MAX_FILES

protected static int MAX_FILES
Constructor Detail

VirtualIO

public VirtualIO(java.lang.String path)
          throws SeisException
Open a VFIO non-virtual file for subsequent I/O operations. The file is opened in read/write mode, and is created if it does not exist.

Parameters:
path - The file path.
Throws:
SeisException - Thrown on create or open errors error.

VirtualIO

public VirtualIO(java.lang.String path,
                 java.lang.String openMode)
          throws SeisException
Open a VFIO file for subsequent I/O operations.

Parameters:
path - The file path.
openMode - "rw" for "read/write"; "r" for "read only".
Throws:
SeisException - Thrown on open error.

VirtualIO

public VirtualIO(java.lang.String path,
                 java.lang.String openMode,
                 java.lang.String[] alternateDirectories)
          throws SeisException
Open a VFIO file for subsequent I/O operations.

Parameters:
path - The file path.
openMode - "rw" for "read/write"; "r" for "read only".
alternateDirectories - A list of alternate directories to search for extents (in case of a rename)
Throws:
SeisException - Thrown on open error.

VirtualIO

public VirtualIO(java.lang.String path,
                 java.lang.String extentBaseName,
                 java.lang.String[] extentDirs,
                 long fileSize,
                 int numExtents)
          throws SeisException
Create a VFIO virtual file for subsequent I/O operations.

Parameters:
path - The file path.
extentName - The name of the file extent.
extentDirs - The directories to use for virtual file extents.
extentSize - The maximum size for virtual file extents.
Throws:
SeisException - Thrown on file creation or other ExtentManager errors

VirtualIO

public VirtualIO(java.lang.String path,
                 java.lang.String extentBaseName,
                 java.lang.String[] extentDirs,
                 long fileSize,
                 int numExtents,
                 ExtentPolicy policy,
                 IParallelContext pc)
          throws SeisException
Create a VFIO virtual file in a parallel context.

Parameters:
path - The file path.
extentName - The name of the file extent.
extentDirs - The directories to use for virtual file extents.
extentSize - The maximum size for virtual file extents.
Throws:
SeisException - Thrown on file creation or other ExtentManager errors
Method Detail

allocateExtents

public void allocateExtents()
                     throws SeisException
Throws:
SeisException

close

public void close()
           throws SeisException
Closes a VFIO file.

Throws:
SeisException - Thrown on close error.

delete

public boolean delete()
Closes and deletes a open Virtual file.

Returns:
true if file(s) deleted successfully; otherwise false.

delete

public static boolean delete(java.lang.String path)
If the path to the file exists and represents a virtual file, delete the extents for the file and then the properties file defining the extents. If the file exists and is not virtual, the file itself is deleted.

Parameters:
path - full path to the virtual file to be deleted
Returns:
true if the file was found and deleted successfully

flush

public void flush()
           throws SeisException
Flushes a VFIO data to disk.

Throws:
SeisException - Thrown on flush error.

getFD

public java.io.FileDescriptor getFD()

getIoBytes

public long getIoBytes()
Return number of bytes read and/or written if I/O rate tracking is enabled

Returns:
number of bytes, 0 if rate tracking is disabled

getIoRate

public float getIoRate()
Return I/O rate in MegaBytes per second (MB/s)

Returns:
I/O rate in MB/s if rate tracking is enabled, 0 otherise

getIoTime

public float getIoTime()
Return current I/O time in seconds if I/O rate tracking is enabled

Returns:
elapsed time spent in I/O routines in seconds, 0 if rate tracking is disabled

getLoadTime

public float getLoadTime()
Return overhead time spent in Virtual File Properties load/store operations

Returns:
overhead time in seconds

getLockTime

public float getLockTime()
Return overhead time spent in Virtual File Properties lock operations

Returns:
overhead time in seconds

getPath

public java.lang.String getPath()
Returns the VFIO file path.

Returns:
The file path.

getVirtualRate

public float getVirtualRate()
Return effectve I/O rate including overhead time

Returns:
effective I/O rate in Mb/s

getVirtualTime

public float getVirtualTime()
Return total time spent in Virtual File operations

Returns:
overhead time in seconds

isVirtual

public boolean isVirtual()
Returns the virtual status flag.

Returns:
true if virtual; false if non-virtual.

isVirtual

public static boolean isVirtual(java.lang.String path)
Test to see if a file represents a virtual file.

Parameters:
path - full path name to be tested
Returns:
true if the file is virtual

log

public static void log(java.util.logging.Level logLevel,
                       java.lang.String message)

main

public static void main(java.lang.String[] args)
                 throws SeisException
Simple test harness for VirtualIO class

Parameters:
args - not used
Throws:
SeisException - on test errors

open

public void open(java.lang.String path,
                 java.lang.String openMode,
                 java.lang.String[] alternateDirectories)
          throws SeisException
Constructs (and opens) a VFIO file for subsequent I/O operations.

Parameters:
path - The file path.
extentName - The name of the file extent.
openMode - "rw" for "read/write"; "r" for "read only".
extentDirs - An array of extent directories, or "null" to use those in the properties file.
Throws:
SeisException - Thrown on open error.

openExtent

protected void openExtent(long newPosition)
                   throws SeisException
Opens the extent that containts the specified position. The extent is created if it does not already exist. An exception is thrown if the extent does not exist for read-only mode.

Parameters:
newPosition - The file position for which the containing extent should be opened.
Throws:
SeisException - Thrown on extent open errors.

openNonVirtual

protected void openNonVirtual()
                       throws SeisException
Opens a VFIO non-virtual file.

Throws:
SeisException - Thrown on open error.

openVirtual

protected void openVirtual()
                    throws SeisException
Opens a VFIO non-virtual file.

Throws:
SeisException - Thrown on open error.

read

public int read(java.nio.ByteBuffer buffer)
         throws SeisException
Reads from data channel to buffer.

Parameters:
buffer - The buffer to hold data read from channel.
Returns:
The number of bytes read.
Throws:
SeisException - Thrown on buffer read errors.

readBuffer

public int readBuffer(java.nio.ByteBuffer buffer)
               throws SeisException
Reads from data channel to buffer.

Parameters:
buffer - The buffer to hold data read from channel.
Returns:
The number of bytes read.
Throws:
SeisException - Thrown on buffer read errors.

readBuffer

public int readBuffer(java.nio.ByteBuffer buffer,
                      int len)
               throws SeisException
Reads from data channel to buffer.

Parameters:
buffer - The buffer to hold data read from channel.
Returns:
The number of bytes read.
Throws:
SeisException - Thrown on buffer read errors.

setLogLevel

public static void setLogLevel(java.util.logging.Level logLevel)

setPosition

public long setPosition(long newPosition)
                 throws SeisException
Sets the position for subsequent VFIO operations.

Parameters:
newPosition - The new file position.
Returns:
The file position.
Throws:
SeisException - Thrown on positioning errors.

trackTime

public void trackTime(boolean flag)
Set flag that determines if I/O rate is tracked

Parameters:
flag - true if I/O time is to be tracked

write

public int write(java.nio.ByteBuffer buffer)
          throws SeisException
Writes from buffer to data channel.

Parameters:
buffer - The buffer of data to write to channel.
Returns:
The number of bytes written.
Throws:
SeisException - Thrown on buffer write errors.

writeBuffer

public int writeBuffer(java.nio.ByteBuffer buffer)
                throws SeisException
Writes from buffer to data channel.

Parameters:
buffer - The buffer of data to write to channel.
Returns:
The number of bytes written.
Throws:
SeisException - Thrown on buffer write errors.