com.bigdata.rawstore
Class SimpleMemoryRawStore

java.lang.Object
  extended by com.bigdata.rawstore.AbstractRawStore
      extended by com.bigdata.rawstore.AbstractRawWormStore
          extended by com.bigdata.rawstore.SimpleMemoryRawStore
All Implemented Interfaces:
ICounterSetAccess, IAddressManager, IRawStore, IWORM

public class SimpleMemoryRawStore
extends AbstractRawWormStore

A purely transient append-only implementation useful when data need to be buffered in memory. The writes are stored in an ArrayList.

Note: it is safe to NOT call close() on this implementation. The implementation does not contain things like ExecutorServices that would hang around unless explicitly shutdown.

Version:
$Id: SimpleMemoryRawStore.java 2547 2010-03-24 20:44:07Z thompsonbry $
Author:
Bryan Thompson
See Also:
TemporaryRawStore}, which provides a more scalable solution for temporary data.

Field Summary
protected  int nextOffset
          The #of bytes written so far.
protected  ArrayList<byte[]> records
          The buffered records in the order written.
 
Fields inherited from class com.bigdata.rawstore.AbstractRawWormStore
am
 
Fields inherited from interface com.bigdata.rawstore.IAddressManager
NULL
 
Constructor Summary
SimpleMemoryRawStore()
          Uses an initial capacity of 1000 records.
SimpleMemoryRawStore(int capacity)
           
 
Method Summary
 void close()
          Close the store immediately, but does not clear any records for the store from the IGlobalLRU.
 void deleteResources()
          Deletes the backing file(s) (if any) and clears any records for the store from the IGlobalLRU.
 void destroy()
          Closes the store immediately (if open), deletes its persistent resources, and clears any records for the store from the IGlobalLRU.
 void force(boolean metadata)
          Force the data to stable storage.
 CounterSet getCounters()
          Return performance counters.
 File getFile()
          This always returns null.
 IResourceMetadata getResourceMetadata()
          A description of this store in support of the scale-out architecture.
 UUID getUUID()
          Return the UUID which identifies this IRawStore.
 boolean isFullyBuffered()
          True iff the store is fully buffered (all reads are against memory).
 boolean isOpen()
          true iff the store is open.
 boolean isReadOnly()
          true iff the store does not allow writes.
 boolean isStable()
          True iff backed by stable storage.
 ByteBuffer read(long addr)
          Read the data (unisolated).
 long size()
          The #of application data bytes written on the store (does not count any headers or root blocks that may exist for the store).
 long write(ByteBuffer data)
          Write the data (unisolated).
 
Methods inherited from class com.bigdata.rawstore.AbstractRawWormStore
getAddressManager, getByteCount, getOffset, getOffsetBits, getPhysicalAddress, toAddr, toString
 
Methods inherited from class com.bigdata.rawstore.AbstractRawStore
abortContext, delete, delete, detachContext, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nextOffset

protected int nextOffset
The #of bytes written so far. This is used to generate the address values returned by write(ByteBuffer). This is necessary in order for this implementation to assign addresses in the same manner as they would be assigned by an implementation using an append only byte[] or file.


records

protected final ArrayList<byte[]> records
The buffered records in the order written. If a record is deleted then that element in the list will be a [null] value.

Constructor Detail

SimpleMemoryRawStore

public SimpleMemoryRawStore()
Uses an initial capacity of 1000 records.


SimpleMemoryRawStore

public SimpleMemoryRawStore(int capacity)
Parameters:
capacity - The #of records that you expect to store (non-negative). If the capacity is exceeded then the internal ArrayList will be grown as necessary.
Method Detail

isOpen

public boolean isOpen()
Description copied from interface: IRawStore
true iff the store is open.

Returns:
true iff the store is open.

isReadOnly

public boolean isReadOnly()
Description copied from interface: IRawStore
true iff the store does not allow writes.


isStable

public boolean isStable()
Description copied from interface: IRawStore
True iff backed by stable storage.


isFullyBuffered

public boolean isFullyBuffered()
Description copied from interface: IRawStore
True iff the store is fully buffered (all reads are against memory). Implementations MAY change the value returned by this method over the life cycle of the store, e.g., to conserve memory a store may drop or decrease its buffer if it is backed by disk.

Note: This does not guarantee that the OS will not swap the buffer onto disk.


getUUID

public UUID getUUID()
Description copied from interface: IRawStore
Return the UUID which identifies this IRawStore. This supports both IRawStore.getResourceMetadata() and the LRUNexus.


getResourceMetadata

public IResourceMetadata getResourceMetadata()
Description copied from interface: IRawStore
A description of this store in support of the scale-out architecture.


getFile

public File getFile()
This always returns null.


close

public void close()
Description copied from interface: IRawStore
Close the store immediately, but does not clear any records for the store from the IGlobalLRU.


deleteResources

public void deleteResources()
Description copied from interface: IRawStore
Deletes the backing file(s) (if any) and clears any records for the store from the IGlobalLRU.


destroy

public void destroy()
Description copied from interface: IRawStore
Closes the store immediately (if open), deletes its persistent resources, and clears any records for the store from the IGlobalLRU. Does NOT throw an IllegalStateException if the store is already closed, but still deletes the backing resources.

See Also:
IRawStore.deleteResources()

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).

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.

force

public void force(boolean metadata)
Description copied from interface: IRawStore
Force the data to stable storage. While this is NOT sufficient to guarantee an atomic commit, the data must be forced to disk as part of an atomic commit protocol.

Parameters:
metadata - If true, then force both the file contents and the file metadata to disk.

size

public long size()
Description copied from interface: IRawStore
The #of application data bytes written on the store (does not count any headers or root blocks that may exist for the store).


getCounters

public CounterSet getCounters()
Description copied from interface: ICounterSetAccess
Return performance counters.



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