com.bigdata.journal
Class BasicBufferStrategy

java.lang.Object
  extended by com.bigdata.rawstore.AbstractRawStore
      extended by com.bigdata.rawstore.AbstractRawWormStore
          extended by com.bigdata.journal.AbstractBufferStrategy
              extended by com.bigdata.journal.BasicBufferStrategy
All Implemented Interfaces:
IBufferStrategy, IAddressManager, IMRMW, IMROW, IRawStore, IStoreSerializer, IWORM
Direct Known Subclasses:
DiskBackedBufferStrategy, TransientBufferStrategy

public abstract class BasicBufferStrategy
extends AbstractBufferStrategy

Implements logic to read from and write on a buffer. This is sufficient for a BufferMode.Transient implementation or a BufferMode.Mapped implementation, but the BufferMode.Direct implementation needs to also implement write through to the disk.

Version:
$Id: BasicBufferStrategy.java 2265 2009-10-26 12:51:06Z thompsonbry $
Author:
Bryan Thompson

Field Summary
protected  long extent
          The current length of the backing file in bytes.
protected  long userExtent
          The size of the user data space in bytes.
 
Fields inherited from class com.bigdata.journal.AbstractBufferStrategy
bufferMode, ERR_ADDRESS_IS_NULL, ERR_ADDRESS_NOT_WRITTEN, ERR_BAD_RECORD_SIZE, ERR_BUFFER_EMPTY, ERR_BUFFER_NULL, ERR_INT32, ERR_NOT_OPEN, ERR_READ_ONLY, ERR_RECORD_LENGTH_ZERO, ERR_TRUNCATE, initialExtent, log, maximumExtent, nextOffset, WARN
 
Fields inherited from class com.bigdata.rawstore.AbstractRawWormStore
am
 
Fields inherited from class com.bigdata.rawstore.AbstractRawStore
serializer
 
Fields inherited from interface com.bigdata.rawstore.IAddressManager
NULL
 
Method Summary
 void close()
          Releases the buffer.
protected  ByteBuffer getBufferView(boolean readOnly)
           
 CounterSet getCounters()
          FIXME Counters need to be added here for the DirectBufferStrategy, MappedBufferStrategy, and TransientBufferStrategy.
 long getExtent()
          The current size of the journal in bytes.
 long getUserExtent()
          The size of the user data extent in bytes.
 ByteBuffer read(long addr)
          Read the data (unisolated).
 long transferTo(RandomAccessFile out)
          Note: This is synchronized so that concurrent writers must block during this operation.
 void truncate(long newExtent)
          Note: This is synchronized since it MAY be invoked directly while concurrent writers are running and not just from AbstractBufferStrategy.overflow(long).
 long write(ByteBuffer data)
          Write the data (unisolated).
 
Methods inherited from class com.bigdata.journal.AbstractBufferStrategy
assertOpen, closeForWrites, destroy, getBufferMode, getInitialExtent, getMaximumExtent, getNextOffset, getResourceMetadata, getUUID, isOpen, isReadOnly, overflow, size, transferFromDiskTo
 
Methods inherited from class com.bigdata.rawstore.AbstractRawWormStore
getAddressManager, getByteCount, getOffset, getOffsetBits, packAddr, toAddr, toString, unpackAddr
 
Methods inherited from class com.bigdata.rawstore.AbstractRawStore
deserialize, deserialize, deserialize, serialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.bigdata.journal.IBufferStrategy
getHeaderSize, readRootBlock, writeRootBlock
 
Methods inherited from interface com.bigdata.rawstore.IRawStore
deleteResources, force, getFile, isFullyBuffered, isStable
 
Methods inherited from interface com.bigdata.rawstore.IAddressManager
getByteCount, getOffset, packAddr, toAddr, toString, unpackAddr
 
Methods inherited from interface com.bigdata.rawstore.IStoreSerializer
deserialize, deserialize, deserialize, serialize
 

Field Detail

extent

protected long extent
The current length of the backing file in bytes.


userExtent

protected long userExtent
The size of the user data space in bytes.

Method Detail

getBufferView

protected ByteBuffer getBufferView(boolean readOnly)
Parameters:
readOnly -
Returns:

getExtent

public long getExtent()
Description copied from interface: IBufferStrategy
The current size of the journal in bytes. When the journal is backed by a disk file this is the actual size on disk of that file. The initial value for this property is set by Options.INITIAL_EXTENT.


getUserExtent

public long getUserExtent()
Description copied from interface: IBufferStrategy
The size of the user data extent in bytes.

Note: The size of the user extent is always generally smaller than the value reported by IBufferStrategy.getExtent() since the latter also reports the space allocated to the journal header and root blocks.


close

public void close()
Releases the buffer.

Specified by:
close in interface IRawStore
Overrides:
close in class AbstractBufferStrategy

write

public long write(ByteBuffer data)
Description copied from interface: IRawStore
Write the data (unisolated).

Parameters:
data - The data. The bytes from the current Buffer.position() to the Buffer.limit() will be written and the Buffer.position() will be advanced to the Buffer.limit() . The caller may subsequently modify the contents of the buffer without changing the state of the store (i.e., the data are copied into the store).
Returns:
A long integer formed that encodes both the offset from which the data may be read and the #of bytes to be read. See IAddressManager.

read

public ByteBuffer read(long addr)
Description copied from interface: IRawStore
Read the data (unisolated).

Parameters:
addr - A long integer that encodes both the offset from which the data will be read and the #of bytes to be read. See IAddressManager.toAddr(int, long).
Returns:
The data read. The buffer will be flipped to prepare for reading (the position will be zero and the limit will be the #of bytes read).

truncate

public void truncate(long newExtent)
Note: This is synchronized since it MAY be invoked directly while concurrent writers are running and not just from AbstractBufferStrategy.overflow(long).

Parameters:
newExtent - The new extent of the journal. This value represent the total extent of the journal, including any root blocks together with the user extent.

transferTo

public long transferTo(RandomAccessFile out)
                throws IOException
Note: This is synchronized so that concurrent writers must block during this operation.

Parameters:
out - The file to which the buffer contents will be transferred.
Returns:
The #of bytes written.
Throws:
IOException

getCounters

public CounterSet getCounters()
FIXME Counters need to be added here for the DirectBufferStrategy, MappedBufferStrategy, and TransientBufferStrategy.



Copyright © 2006-2009 SYSTAP, LLC. All Rights Reserved.