seda.sandStorm.lib.aDisk
Class AFile

java.lang.Object
  extended by seda.sandStorm.core.SimpleSink
      extended by seda.sandStorm.lib.aDisk.AFile
All Implemented Interfaces:
ProfilableIF, SinkIF

public class AFile
extends SimpleSink

This class represents an asynchronous file I/O interface.

To use this class, the user creates an AFile corresponding to a given filename. AFile implements SinkIF, and as such you can enqueue I/O requests to be performed on this file; all such requests must be subclasses of AFileRequest. The read, write, and seek methods are also provided for convenience.

See Also:
SinkIF, AFileRequest

Field Summary
private  SinkIF compQ
           
private  java.lang.String fname
           
private  AFileImpl impl
           
 
Constructor Summary
AFile(java.lang.String name, SinkIF compQ, boolean create, boolean readOnly)
          Open the file with the given pathname.
 
Method Summary
 void close()
          Close the file after all enqueued requests have completed.
 boolean enqueue_lossy(QueueElementIF req)
          Enqueues the given request (which must be an AFileRequest) to the file.
 void enqueue_many(QueueElementIF[] elements)
          Enqueues the given requests (which must be AFileRequests) to the file.
 void enqueue(QueueElementIF req)
          Enqueues the given request (which must be an AFileRequest) to the file.
 void flush()
          Causes a SinkFlushedEvent to be posted on the file's completion queue when all pending requests have completed.
 java.lang.String getFilename()
           
(package private)  AFileImpl getImpl()
          Returns the implementation-specific object representing this AFile.
 void read(BufferElement buf)
          Enqueues a read request at the current file offset.
 void read(BufferElement buf, int offset)
          Enqueues a read request at the given file offset.
 void seek(int offset)
          Position the file to the given offset.
 AFileStat stat()
          Return information on the properties of the file.
 java.lang.String toString()
           
 void write(BufferElement buf)
          Enqueues a write request at the current file offset.
 void write(BufferElement buf, int offset)
          Enqueues a write request at the given file offset.
 
Methods inherited from class seda.sandStorm.core.SimpleSink
enqueue_abort, enqueue_commit, enqueue_prepare, getEnqueuePredicate, profileSize, setEnqueuePredicate, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fname

private java.lang.String fname

impl

private AFileImpl impl

compQ

private SinkIF compQ
Constructor Detail

AFile

public AFile(java.lang.String name,
             SinkIF compQ,
             boolean create,
             boolean readOnly)
      throws java.io.IOException
Open the file with the given pathname.

Parameters:
name - A system-dependent filename.
compQ - The default completion queue on which read and write completion events will be posted. A completion queue can be specified for each individual request by setting the 'compQ' field in the associated AFileRequest.
create - If true, creates the file if it does not exist.
create - If true, opens the file in read-only mode.
Throws:
java.io.FileNotFoundException - If the file does not exist and 'create' is false.
java.io.IOException
Method Detail

enqueue

public void enqueue(QueueElementIF req)
             throws SinkException
Enqueues the given request (which must be an AFileRequest) to the file.

Specified by:
enqueue in interface SinkIF
Specified by:
enqueue in class SimpleSink
Parameters:
req - The QueueElementIF to enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full.
SinkClosedException - Indicates that the sink is no longer being serviced.
SinkException

enqueue_lossy

public boolean enqueue_lossy(QueueElementIF req)
Enqueues the given request (which must be an AFileRequest) to the file.

Specified by:
enqueue_lossy in interface SinkIF
Overrides:
enqueue_lossy in class SimpleSink
Parameters:
req - The QueueElementIF to enqueue
Returns:
true if the element was enqueued, false otherwise.

enqueue_many

public void enqueue_many(QueueElementIF[] elements)
                  throws SinkException
Enqueues the given requests (which must be AFileRequests) to the file.

Specified by:
enqueue_many in interface SinkIF
Overrides:
enqueue_many in class SimpleSink
Parameters:
elements - The element array to enqueue
Throws:
SinkFullException - Indicates that the sink is temporarily full.
SinkClosedException - Indicates that the sink is no longer being serviced.
SinkException

write

public void write(BufferElement buf)
           throws SinkException
Enqueues a write request at the current file offset.

Throws:
SinkException

write

public void write(BufferElement buf,
                  int offset)
           throws SinkException
Enqueues a write request at the given file offset. This is equivalent to a call to seek() before write().

Throws:
SinkException

read

public void read(BufferElement buf)
          throws SinkException
Enqueues a read request at the current file offset.

Throws:
SinkException

read

public void read(BufferElement buf,
                 int offset)
          throws SinkException
Enqueues a read request at the given file offset. This is equivalent to a call to seek() before read().

Throws:
SinkException

seek

public void seek(int offset)
          throws SinkException
Position the file to the given offset. As with read and writes, seek requests are performed asynchronously; only read and write requests enqueued after the seek operation will use the new file offset.

Throws:
SinkException

stat

public AFileStat stat()
Return information on the properties of the file.


getFilename

public java.lang.String getFilename()

close

public void close()
Close the file after all enqueued requests have completed. Disallows any additional requests to be enqueued on this file. A SinkClosedEvent will be posted on the file's completion queue when the close is complete.


flush

public void flush()
Causes a SinkFlushedEvent to be posted on the file's completion queue when all pending requests have completed.


getImpl

AFileImpl getImpl()
Returns the implementation-specific object representing this AFile. Package access only.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object