|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.neeve.rog.log.RogLogReader
public final class RogLogReader
The transaction log reader.
The transaction log reader allows one to read through a log's 'entries'. The reader allows the user to do a 'raw' read of the log entries or a 'transactional' read of the log. A raw read returns individual entries from the log while a transactional read returns sets of entries logically grouped by application transaction. The following code samples illustrate how to do a raw and transactional read of a log and print out the logged objects as JSON strings.
Raw Read Sample
// Create and open a log
RogLog log = RogLog.create("ems");
log.open();
// Create a log reader
RogLogReader reader = log.createReader();
// Register message/object factories.
reader.registerFactory([user's X message/object factory])
// Read and print entry objects as JSON strings.
RogLog.Entry entry;
reader.rewind();
while ((entry = reader.next()) != null) {
System.out.println(((IRogJsonizable)entry.getObject()).toJsonString());
entry.dispose();
}
Transactional Read Sample
// Create and open a log
RogLog log = RogLog.create("ems");
log.open();
// Create a log reader
RogLogReader reader = log.createReader();
// Register message/object factories.
reader.registerFactory([user's X message/object factory])
// Read and print entry objects as JSON strings.
RogLogReader.Transaction transaction;
reader.rewind();
while ((transaction = reader.nextTransaction()) != null) {
for (RogLog.Entry entry : transaction.getEntries()) {
System.out.println(((IRogJsonizable)entry.getObject()).toJsonString());
entry.dispose();
}
}
Nested Class Summary | |
---|---|
static interface |
RogLogReader.SkipCallback
Callback invoked during the skip operation |
static class |
RogLogReader.Transaction
Represents a transaction log transaction (entries grouped by application transaction) |
static interface |
RogLogReader.TransactionSkipCallback
Callback invoked during the skip operation |
Method Summary | |
---|---|
void |
close()
The close method should be called on any RogLogReader to release
the resources it holds. |
RogLog.Stats |
computeStats()
Computes statistics for the log by scanning through all remaining entries. |
RogLog.Entry |
getEntryAt(long filePosition)
Gets an entry located at the specified position in the file. |
RogLog.Stats |
getStats()
Gets the statistics of what this reader has read so far. |
RogLog |
log()
Return the parent log |
RogLog.Entry |
next()
Returns the next entry in the log. |
RogLogReader.Transaction |
nextTransaction()
Returns the next transaction in the log. |
static void |
registerFactory(Object factory)
Register a factory. |
RogLogReader |
rewind()
Rewinds the reader, and resets its statistics |
void |
seek(long pos)
Positions the reader at the given file position, and resets its statistics. |
void |
setLazyDeserialization(boolean lazyDeserialization)
Sets whether or not objects are eagerly deserialized as they are read from the log. |
RogLogReader |
skip(int count,
RogLogReader.SkipCallback cb)
Skips a certain number of objects in the log. |
RogLogReader |
skipTransaction(int count,
RogLogReader.TransactionSkipCallback cb)
Skips a certain number of transactions in the log. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static final void registerFactory(Object factory)
factory
- The factory to register.public void setLazyDeserialization(boolean lazyDeserialization)
lazyDeserialization
- The lazy deserialization setting.public final RogLog log()
public final RogLog.Entry next() throws Exception
This method returns the next complete log entry. The method returns null if no more entries are in the log.
Exception
public final RogLogReader.Transaction nextTransaction() throws Exception
This method returns the next complete transaction in the log. The method returns null if no more transactions are in the log.
Exception
public final RogLogReader skip(int count, RogLogReader.SkipCallback cb) throws IOException
Note: that usage of this message will not correctly updates transaction statistics.
IOException
public final RogLogReader skipTransaction(int count, RogLogReader.TransactionSkipCallback cb) throws Exception
Exception
public final void seek(long pos) throws IOException
RogLog.Entry.getFilePosition()
The reposition will attempt to validate that the position is a valid log
position, and if it is not the current file pointer will be left untouched.
pos
- The position
IOException
public final RogLogReader rewind() throws IOException
IOException
public RogLog.Stats getStats()
public RogLog.Stats computeStats() throws Exception
Exception
- if there is an error reading the logpublic RogLog.Entry getEntryAt(long filePosition) throws Exception
filePosition
- The file position from which to read.
RogLog.Entry
y at the given position or null if there
is no entry at the given position.
Exception
- If there is an error reading a packet from the specified
position.
This method does not update file pointers and may be called in
interleaved with calls to next()
or nextTransaction()
.
public final void close() throws Exception
RogLogReader
to release
the resources it holds. If a reader is created via RogLog.createReader()
with a value of false, A caller must close the reader when finished with it to release
underlying resources since a non shared reader hold it own file handle.
Exception
- If there is an error closing the reader.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |