xmlBlaster 1.5.1 API

org.xmlBlaster.util.recorder.file
Class FileIO

java.lang.Object
  extended byorg.xmlBlaster.util.recorder.file.FileIO

public class FileIO
extends java.lang.Object

This is the generic interface to the harddisk.

It recovers on restart as the current situation is stored as well.

To use this, you supply an implementation of

Performance is on a standard harddisk and 600 MHz intel server:

In SYNC mode, the harddisk is synced after any data written. SYNC is usually left off, as an application crash can be recovered without.

You can call readNext(false) and need to commit when you have processed the retrieved data successully with saveCurrReadPos(). If your processing fails without a saveCurrReadPos() call the subsequent readNext() gets the same data again.

File Format: "data....."

TODO:
- If the file is never read empty it grows and grows ...
- The mode DISCARD_OLDEST does not shrink the file size

See the util.recorder requirement.

See Also:
FileIOTest

Field Summary
private  long currReadPos
           
private  java.io.File file
           
private  java.lang.String fileName
           
private  boolean firstLost
           
private  boolean firstUnread
           
private  Global glob
           
private  long lastReadPos
           
private static java.util.logging.Logger log
           
private  long LOST_POS
           
private  long maxEntries
           
private  java.lang.String ME
           
private  int mode
           
private  int modeDiscard
           
private  int modeDiscardOldest
           
private  int modeException
           
private  long numFileDeleteLost
          Remember number of lost data when file was killed by somebody
private  long numLost
           
private  long numUnread
           
private  java.io.RandomAccessFile ra
           
private  long UNREAD_POS
           
private  I_UserDataHandler userDataHandler
           
private  boolean useSync
           
 
Constructor Summary
FileIO(Global glob, java.lang.String fileName, I_UserDataHandler userDataHandler, long maxEntries, boolean useSync)
           
 
Method Summary
 void destroy()
          Destroy data
 long getCurrReadPos()
          Read the first 8 bytes contain the offset to data to be read
 long getNumFileDeleteLost()
          Returns the number of lost data objects when the file was deleted by somebody.
 long getNumLost()
          Counter for lost messages in 'discard' or 'discardOldest' mode

 long getNumUnread()
          The number of unread data entities.
 void initialize()
          Initializes on first startup or reloads an existing file.
 java.io.File mkfile(java.lang.String fullName)
          Creates recursive all directories, assuming file name is the last part of the path
 java.lang.Object readNext(boolean autoCommit)
          You can call readNext(false) and need to commit when you have processed the retrieved data successully with saveCurrReadPos().
 void saveCurrReadPos()
          Write the first 8 bytes containing the offset to data to be read
 void setModeDiscard()
          Throw the message away if queue is full - the message is silently lost!
 void setModeDiscardOldest()
          Throw the oldest message away if queue is full - the message is silently lost!
 void setModeException()
          Default you get an Exception if queue is full
 void shutdown()
          Don't loose data
 boolean undo()
          Undo the last read, not that this is not thread save!

Only one single undo is supported

 void writeNext(java.lang.Object data)
          Write more data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log

ME

private final java.lang.String ME
See Also:
Constant Field Values

glob

private final Global glob

currReadPos

private long currReadPos

lastReadPos

private long lastReadPos

file

private java.io.File file

ra

private java.io.RandomAccessFile ra

numUnread

private long numUnread

firstUnread

private boolean firstUnread

UNREAD_POS

private final long UNREAD_POS
See Also:
Constant Field Values

firstLost

private boolean firstLost

numLost

private long numLost

LOST_POS

private final long LOST_POS
See Also:
Constant Field Values

numFileDeleteLost

private long numFileDeleteLost
Remember number of lost data when file was killed by somebody


useSync

private boolean useSync

userDataHandler

private final I_UserDataHandler userDataHandler

fileName

private java.lang.String fileName

maxEntries

private long maxEntries

modeException

private final int modeException
See Also:
Constant Field Values

modeDiscardOldest

private final int modeDiscardOldest
See Also:
Constant Field Values

modeDiscard

private final int modeDiscard
See Also:
Constant Field Values

mode

private int mode
Constructor Detail

FileIO

public FileIO(Global glob,
              java.lang.String fileName,
              I_UserDataHandler userDataHandler,
              long maxEntries,
              boolean useSync)
       throws java.io.IOException
Parameters:
maxEntries - < 0 sets it to unlimited
userDataHandler - Your implementation of your data format marshalling
Method Detail

initialize

public void initialize()
                throws java.io.IOException
Initializes on first startup or reloads an existing file.

Throws:
java.io.IOException

mkfile

public java.io.File mkfile(java.lang.String fullName)
                    throws java.io.IOException
Creates recursive all directories, assuming file name is the last part of the path

Returns:
The new file handle
Throws:
java.io.IOException

readNext

public java.lang.Object readNext(boolean autoCommit)
                          throws java.io.IOException,
                                 XmlBlasterException
You can call readNext(false) and need to commit when you have processed the retrieved data successully with saveCurrReadPos(). If your processing fails without a saveCurrReadPos() call the subsequent readNext() gets the same data again.

Throws:
XmlBlasterException - /> "FileRecorder.FileLost" If file disappeared, you can proceed
Of an XmlBlasterExeption from the user data handler
java.io.IOException
XmlBlasterException

undo

public boolean undo()
Undo the last read, not that this is not thread save!

Only one single undo is supported

Returns:
true if undo was possible

writeNext

public void writeNext(java.lang.Object data)
               throws java.io.IOException,
                      XmlBlasterException
Write more data.

Throws:
XmlBlasterException - /> "ErrorCode.FileRecorder.FileLost" If file disappeared, we create a new and store the message
"ErrorCode.RESOURCE_OVERFLOW_QUEUE_ENTRIES" Maximum size reached in Exception mode
Of an XmlBlasterExeption from the user data handler
java.io.IOException
XmlBlasterException

saveCurrReadPos

public final void saveCurrReadPos()
                           throws java.io.IOException
Write the first 8 bytes containing the offset to data to be read

Throws:
java.io.IOException

getCurrReadPos

public final long getCurrReadPos()
                          throws java.io.IOException
Read the first 8 bytes contain the offset to data to be read

Throws:
java.io.IOException

getNumUnread

public final long getNumUnread()
The number of unread data entities.


getNumLost

public long getNumLost()
Counter for lost messages in 'discard' or 'discardOldest' mode


getNumFileDeleteLost

public final long getNumFileDeleteLost()
Returns the number of lost data objects when the file was deleted by somebody.


setModeDiscard

public void setModeDiscard()
Throw the message away if queue is full - the message is silently lost!


setModeDiscardOldest

public void setModeDiscardOldest()
Throw the oldest message away if queue is full - the message is silently lost!


setModeException

public void setModeException()
Default you get an Exception if queue is full


shutdown

public void shutdown()
Don't loose data


destroy

public void destroy()
Destroy data


xmlBlaster 1.5.1 API

Copyright © 1999-2007 The xmlBlaster.org contributers.