Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.codehaus.activemq.journal.impl
Class JournalImpl

    java.lang.Object
      org.codehaus.activemq.journal.impl.JournalImpl

All Implemented Interfaces:
  Journal

public class JournalImpl
extends 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:

- Conncurrent 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 inactivated (due to a new mark) are resized to thier 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.

This class is a thing wrapper around a LogFileManager. It may be possible to extends this class so that it manages multiple LogFileManager objects to allow logging to multiple physical disks.

Version:
  $Revision: 1.3 $

Field Summary
`(package private) LogFileManager` | `manager`
`(package private) LongSequenceGenerator` | `sequenceGenerator`

Constructor Summary
`JournalImpl()`
`JournalImpl(File logDirectory)`
`JournalImpl(File logDirectory, int segments, int segmentSize)`

Method Summary
`void` | `close()` Close the Journal.
`RecordLocation` | `getMark()` Obtains the mark that was set in the Journal.
`RecordLocation` | `getNextRecordLocation(RecordLocation lastLocation)` Allows you to get the next RecordLocation after the `location` that is in the journal.
`byte[]` | `read(RecordLocation location)` Reads a previously written record from the journal.
`void` | `setJournalEventListener(JournalEventListener eventListener)` Registers a `JournalEventListener` that will receive notifications from the Journal.
`void` | `setMark(RecordLocation recordLocator, boolean force)` Informs the journal that all the journal space up to the `location` is no longer needed and can be reclaimed for reuse.
`String` | `toString()`
`RecordLocation` | `write(byte[] data, boolean sync)` Writes a byte array `record` to the journal.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### manager

    LogFileManager manager

### sequenceGenerator

    LongSequenceGenerator sequenceGenerator

Constructor Detail

### JournalImpl

    public JournalImpl()
                throws IOException

### JournalImpl

    public JournalImpl(File logDirectory)
                throws IOException

### JournalImpl

    public JournalImpl(File logDirectory,
                       int segments,
                       int segmentSize)
                throws IOException

Method Detail

### write

    public RecordLocation write(byte[] data,
                                boolean sync)
                         throws IOException

  Description copied from interface: `Journal`
  Writes a byte array `record` to the journal. If `sync` is true, then this call blocks until the data has landed on the physical disk. Otherwise, this call returns imeadiatly.

  Specified by:
    `write` in interface `Journal`
  Parameters:
    `data` - - the data to be written to disk.
    `sync` - - If this call should block until the data lands on disk.
  Returns:
    RecordLocation the location where the data will be written to on disk.
  Throws:
    `IOException`
  See Also:
    `Journal.write(byte[], boolean)`

### setMark

    public void setMark(RecordLocation recordLocator,
                        boolean force)
                 throws InvalidRecordLocationException,
                        IOException

  Description copied from interface: `Journal`
  Informs the journal that all the journal space up to the `location` is no longer needed and can be reclaimed for reuse.

  Specified by:
    `setMark` in interface `Journal`
  Parameters:
    `recordLocator` - the location of the record to mark. All record locations before the marked location will no longger be vaild.
    `force` - if this call should block until the mark is set on the journal.
  Throws:
    `InvalidRecordLocationException` - if `location` parameter is out of range. It cannot be a location that is before the current mark.
    `IOException` - if the record could not be read.
  See Also:
    `Journal.setMark(org.codehaus.activemq.journal.RecordLocation, boolean)`

### getMark

    public RecordLocation getMark()

  Description copied from interface: `Journal`
  Obtains the mark that was set in the Journal.

  Specified by:
    `getMark` in interface `Journal`
  Returns:
    the mark that was set in the Journal.
  See Also:
    `Journal.getMark()`

### close

    public void close()
               throws IOException

  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.

  Specified by:
    `close` in interface `Journal`
  Throws:
    `IOException` - if an error occurs while the journal is being closed.
  See Also:
    `Journal.close()`

### setJournalEventListener

    public void setJournalEventListener(JournalEventListener eventListener)

  Description copied from interface: `Journal`
  Registers a `JournalEventListener` that will receive notifications from the Journal.

  Specified by:
    `setJournalEventListener` in interface `Journal`
  Parameters:
    `eventListener` - object that will receive journal events.
  See Also:
    `Journal.setJournalEventListener(org.codehaus.activemq.journal.JournalEventListener)`

### getNextRecordLocation

    public RecordLocation getNextRecordLocation(RecordLocation lastLocation)
                                         throws IOException,
                                                InvalidRecordLocationException

  Description copied from interface: `Journal`
  Allows you to get the next RecordLocation after the `location` that is in the journal.

  Specified by:
    `getNextRecordLocation` in interface `Journal`
  Parameters:
    `lastLocation` - the reference location the is used to find the next location. To get the oldest location available in the journal, `location` should be set to null.
  Returns:
    the next record location
  Throws:
    `InvalidRecordLocationException`
    `IOException`
  See Also:
    `Journal.getNextRecordLocation(org.codehaus.activemq.journal.RecordLocation)`

### read

    public byte[] read(RecordLocation location)
                throws InvalidRecordLocationException,
                       IOException

  Description copied from interface: `Journal`
  Reads a previously written record from the journal.

  Specified by:
    `read` in interface `Journal`
  Parameters:
    `location` - is where to read the record from.
  Returns:
    the data previously written at the `location`.
  Throws:
    `IOException` - if the record could not be read.
    `InvalidRecordLocationException` - if `location` parameter is out of range. It cannot be a location that is before the current mark.
  See Also:
    `Journal.getNextRecordLocation(org.codehaus.activemq.journal.RecordLocation)`

### toString

    public String toString()

  See Also:
    `Object.toString()`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2004 Protique, Ltd.. All Rights Reserved.