public class Journal extends Object
Location object. | Modifier and Type | Class and Description |
|---|---|
static class |
Journal.ReadType |
static class |
Journal.WriteType |
| Constructor and Description |
|---|
Journal() |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the journal.
|
void |
compact()
Compact the journal, reducing size of logs containing deleted entries and
completely removing empty (with only deleted entries) logs.
|
void |
delete(Location location)
Delete the record at the given
Location.Deletes cause first a batch sync and always are logical: records will be actually deleted at log cleanup time. |
File |
getDirectory()
Get the journal directory containing log files.
|
File |
getDirectoryArchive()
Get the optional archive directory used to archive cleaned up log files.
|
long |
getDisposeInterval()
Get the milliseconds interval for resources disposal.
|
String |
getFilePrefix()
Get the prefix for log files.
|
List<File> |
getFiles()
Get the files part of this journal.
|
String |
getFileSuffix()
Get the suffix for log files.
|
int |
getMaxFileLength()
Get the max length of each log file.
|
int |
getMaxWriteBatchSize()
Get the max size in bytes of the write batch: must always be equal or
less than the max file length.
|
ReplicationTarget |
getReplicationTarget()
Get the
ReplicationTarget to replicate batch writes to. |
boolean |
isArchiveFiles()
Return true if cleaned up log files should be archived, false otherwise.
|
boolean |
isChecksum()
Return true if records checksum is enabled, false otherwise.
|
boolean |
isPhysicalSync()
Return true if every disk write is followed by a physical disk sync,
synchronizing file descriptor properties and flushing hardware buffers,
false otherwise.
|
void |
open()
Open the journal, eventually recovering it if already existent.
|
byte[] |
read(Location location,
Journal.ReadType read)
Read the record stored at the given
Location, either by syncing
with the disk state (if ReadType.SYNC) or by taking advantage of
speculative disk reads (if ReadType.ASYNC); the latter is faster,
while the former is slower but will suddenly detect deleted records. |
Iterable<Location> |
redo()
Return an iterable to replay the journal by going through all records
locations.
|
Iterable<Location> |
redo(Location start)
Return an iterable to replay the journal by going through all records
locations starting from the given one.
|
void |
setArchiveFiles(boolean archiveFiles)
Set true if cleaned up log files should be archived, false otherwise.
|
void |
setChecksum(boolean checksumWrites)
Set true if records checksum is enabled, false otherwise.
|
void |
setDirectory(File directory)
Set the journal directory containing log files.
|
void |
setDirectoryArchive(File directoryArchive)
Set the optional archive directory used to archive cleaned up log files.
|
void |
setDisposeInterval(long disposeInterval)
Set the milliseconds interval for resources disposal: i.e., un-accessed
files will be closed.
|
void |
setDisposer(ScheduledExecutorService disposer)
Set the ScheduledExecutorService to use for internal resources disposing.
|
void |
setFilePrefix(String filePrefix)
Set the prefix for log files.
|
void |
setFileSuffix(String fileSuffix)
Set the suffix for log files.
|
void |
setMaxFileLength(int maxFileLength)
Set the max length of each log file.
|
void |
setMaxWriteBatchSize(int maxWriteBatchSize)
Set the max size in bytes of the write batch: must always be equal or
less than the max file length.
|
void |
setPhysicalSync(boolean physicalSync)
Set true if every disk write must be followed by a physical disk sync,
synchronizing file descriptor properties and flushing hardware buffers,
false otherwise.
|
void |
setRecoveryErrorHandler(RecoveryErrorHandler recoveryErrorHandler)
Set the RecoveryErrorHandler to invoke in case of checksum errors.
|
void |
setReplicationTarget(ReplicationTarget replicationTarget)
Set the
ReplicationTarget to replicate batch writes to. |
void |
setWriter(Executor writer)
Set the Executor to use for writing new record entries.
|
void |
sync()
Sync asynchronously written records on disk.
|
String |
toString() |
void |
truncate()
Truncate the journal, removing all log files.
|
Iterable<Location> |
undo()
Return an iterable to replay the journal in reverse, starting with the
newest location and ending with the first.
|
Iterable<Location> |
undo(Location end)
Return an iterable to replay the journal in reverse, starting with the
newest location and ending with the specified end location.
|
Location |
write(byte[] data,
Journal.WriteType write)
Write the given byte buffer record, either sync (if
WriteType.SYNC) or async (if WriteType.ASYNC), and
returns the stored Location.A sync write causes all previously batched async writes to be synced too. |
Location |
write(byte[] data,
Journal.WriteType write,
WriteCallback callback)
Write the given byte buffer record, either sync (if
WriteType.SYNC) or async (if WriteType.ASYNC), and
returns the stored Location.A sync write causes all previously batched async writes to be synced too. The provided callback will be invoked if sync is completed or if some error occurs during syncing. |
public void open()
throws IOException
IOExceptionpublic void close()
throws IOException
IOExceptionpublic void compact()
throws ClosedJournalException,
IOException
IOExceptionClosedJournalExceptionpublic void sync()
throws ClosedJournalException,
IOException
IOExceptionClosedJournalExceptionpublic void truncate()
throws OpenJournalException,
IOException
IOExceptionOpenJournalExceptionpublic byte[] read(Location location, Journal.ReadType read) throws ClosedJournalException, CompactedDataFileException, IOException
Location, either by syncing
with the disk state (if ReadType.SYNC) or by taking advantage of
speculative disk reads (if ReadType.ASYNC); the latter is faster,
while the former is slower but will suddenly detect deleted records.location - read - IOExceptionClosedJournalExceptionCompactedDataFileExceptionpublic Location write(byte[] data, Journal.WriteType write) throws ClosedJournalException, IOException
WriteType.SYNC) or async (if WriteType.ASYNC), and
returns the stored Location.data - write - IOExceptionClosedJournalExceptionpublic Location write(byte[] data, Journal.WriteType write, WriteCallback callback) throws ClosedJournalException, IOException
WriteType.SYNC) or async (if WriteType.ASYNC), and
returns the stored Location.data - write - callback - IOExceptionClosedJournalExceptionpublic void delete(Location location) throws ClosedJournalException, CompactedDataFileException, IOException
Location.location - IOExceptionClosedJournalExceptionCompactedDataFileExceptionpublic Iterable<Location> redo() throws ClosedJournalException, CompactedDataFileException, IOException
IOExceptionClosedJournalExceptionCompactedDataFileExceptionpublic Iterable<Location> redo(Location start) throws ClosedJournalException, CompactedDataFileException, IOException
start - IOExceptionCompactedDataFileExceptionClosedJournalExceptionpublic Iterable<Location> undo() throws ClosedJournalException, CompactedDataFileException, IOException
IOExceptionCompactedDataFileExceptionClosedJournalExceptionpublic Iterable<Location> undo(Location end) throws ClosedJournalException, CompactedDataFileException, IOException
end - IOExceptionCompactedDataFileExceptionClosedJournalExceptionpublic int getMaxFileLength()
public void setMaxFileLength(int maxFileLength)
public File getDirectory()
public void setDirectory(File directory)
public String getFilePrefix()
public void setFilePrefix(String filePrefix)
filePrefix - public File getDirectoryArchive()
public void setDirectoryArchive(File directoryArchive)
directoryArchive - public boolean isArchiveFiles()
public void setArchiveFiles(boolean archiveFiles)
archiveFiles - public void setReplicationTarget(ReplicationTarget replicationTarget)
ReplicationTarget to replicate batch writes to.replicationTarget - public ReplicationTarget getReplicationTarget()
ReplicationTarget to replicate batch writes to.public String getFileSuffix()
public void setFileSuffix(String fileSuffix)
fileSuffix - public boolean isChecksum()
public void setChecksum(boolean checksumWrites)
checksumWrites - public boolean isPhysicalSync()
public void setPhysicalSync(boolean physicalSync)
public int getMaxWriteBatchSize()
public void setMaxWriteBatchSize(int maxWriteBatchSize)
maxWriteBatchSize - public void setDisposeInterval(long disposeInterval)
disposeInterval - public long getDisposeInterval()
public void setWriter(Executor writer)
writer - public void setDisposer(ScheduledExecutorService disposer)
writer - public void setRecoveryErrorHandler(RecoveryErrorHandler recoveryErrorHandler)
recoveryErrorHandler - Copyright © 2014. All Rights Reserved.