Class JournalImpl
- java.lang.Object
-
- org.apache.activeio.journal.active.JournalImpl
-
- All Implemented Interfaces:
Journal
public final class JournalImpl extends java.lang.Object implements Journal
A high speed Journal implementation. Inspired by the ideas of the Howl project but tailored to the needs of ActiveMQ. This Journal provides the following features:- Concurrent writes are batched into a single write/force done by a background thread.
- Uses preallocated logs to avoid disk fragmentation and performance degregation.
- The number and size of the preallocated logs are configurable.
- Uses direct ByteBuffers to write data to log files.
- Allows logs to grow in case of an overflow condition so that overflow exceptions are not not thrown. Grown logs that are inactivate (due to a new mark) are resized to their original size.
- No limit on the size of the record written to the journal
- Should be possible to extend so that multiple physical disk are used concurrently to increase throughput and decrease latency.
- Version:
- $Revision: 1.1 $
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_PACKET_SIZE
static int
DEFAULT_POOL_SIZE
-
Constructor Summary
Constructors Constructor Description JournalImpl(java.io.File logDirectory)
JournalImpl(java.io.File logDirectory, int logFileCount, int logFileSize)
JournalImpl(java.io.File logDirectory, int logFileCount, int logFileSize, java.io.File archiveDirectory)
JournalImpl(LogFileManager logFile)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
close()
Deprecated.void
dispose()
int
getInitialLogFileSize()
java.io.File
getLogDirectory()
RecordLocation
getMark()
Obtains the mark that was set in the Journal.RecordLocation
getNextRecordLocation(RecordLocation lastLocation)
Allows you to get the next RecordLocation after thelocation
that is in the journal.protected java.io.IOException
handleExecutionException(java.util.concurrent.ExecutionException e)
Packet
read(RecordLocation l)
Reads a previously written record from the journal.void
setJournalEventListener(JournalEventListener eventListener)
Registers aJournalEventListener
that will receive notifications from the Journal.void
setMark(RecordLocation l, boolean force)
Informs the journal that all the journal space up to thelocation
is no longer needed and can be reclaimed for reuse.java.lang.String
toString()
RecordLocation
write(Packet data, boolean sync)
Writes a {@see Packet} of data to the journal.
-
-
-
Constructor Detail
-
JournalImpl
public JournalImpl(java.io.File logDirectory) throws java.io.IOException
- Throws:
java.io.IOException
-
JournalImpl
public JournalImpl(java.io.File logDirectory, int logFileCount, int logFileSize) throws java.io.IOException
- Throws:
java.io.IOException
-
JournalImpl
public JournalImpl(java.io.File logDirectory, int logFileCount, int logFileSize, java.io.File archiveDirectory) throws java.io.IOException
- Throws:
java.io.IOException
-
JournalImpl
public JournalImpl(LogFileManager logFile)
-
-
Method Detail
-
write
public RecordLocation write(Packet data, boolean sync) throws java.io.IOException
Description copied from interface:Journal
Writes a {@see Packet} of data to the journal. Ifsync
is true, then this call blocks until the data has landed on the physical disk. Otherwise, this enqueues the write request and returns.
-
setMark
public void setMark(RecordLocation l, boolean force) throws InvalidRecordLocationException, java.io.IOException
Description copied from interface:Journal
Informs the journal that all the journal space up to thelocation
is no longer needed and can be reclaimed for reuse.- Specified by:
setMark
in interfaceJournal
- Parameters:
recordLocator
-force
-- Throws:
InvalidRecordLocationException
java.io.IOException
java.lang.InterruptedException
-
getMark
public RecordLocation getMark()
Description copied from interface:Journal
Obtains the mark that was set in the Journal.
-
getNextRecordLocation
public RecordLocation getNextRecordLocation(RecordLocation lastLocation) throws java.io.IOException, InvalidRecordLocationException
Description copied from interface:Journal
Allows you to get the next RecordLocation after thelocation
that is in the journal.- Specified by:
getNextRecordLocation
in interfaceJournal
- Parameters:
lastLocation
-- Returns:
- Throws:
java.io.IOException
InvalidRecordLocationException
-
handleExecutionException
protected java.io.IOException handleExecutionException(java.util.concurrent.ExecutionException e) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public Packet read(RecordLocation l) throws java.io.IOException, InvalidRecordLocationException
Description copied from interface:Journal
Reads a previously written record from the journal.- Specified by:
read
in interfaceJournal
- Parameters:
location
-- Returns:
- Throws:
InvalidRecordLocationException
java.io.IOException
-
setJournalEventListener
public void setJournalEventListener(JournalEventListener eventListener)
Description copied from interface:Journal
Registers aJournalEventListener
that will receive notifications from the Journal.- Specified by:
setJournalEventListener
in interfaceJournal
- Parameters:
eventListener
- object that will receive journal events.
-
close
public void close() throws java.io.IOException
Deprecated.Description copied from interface:Journal
Close the Journal. This is blocking operation that waits for any pending put opperations to be forced to disk. Once the Journal is closed, all other methods of the journal should throw IllegalStateException.
-
dispose
public void dispose()
-
getLogDirectory
public java.io.File getLogDirectory()
- Returns:
-
getInitialLogFileSize
public int getInitialLogFileSize()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-