krati.store
Class AbstractDataArray

java.lang.Object
  extended by krati.store.AbstractDataArray
All Implemented Interfaces:
Array, DataArray, Persistable
Direct Known Subclasses:
DynamicDataArray, StaticDataArray

public abstract class AbstractDataArray
extends Object
implements DataArray, Persistable

AbstractDataArray

Author:
jwu Sep 24, 2010

Field Summary
protected  AddressArray _addrArray
           
protected  SimpleDataArray _dataArray
           
protected  File _homeDir
           
protected  String _homePath
           
 
Constructor Summary
protected AbstractDataArray(int length, int batchSize, int numSyncBatches, File homeDirectory, SegmentFactory segmentFactory, int segmentFileSizeMB, double segmentCompactFactor)
          Constructs a data array.
 
Method Summary
 void clear()
          Clears this Array.
protected abstract  AddressArray createAddressArray(int length, int batchSize, int numSyncBatches, File homeDirectory)
           
 byte[] get(int index)
          Gets data at a specified index.
 int get(int index, byte[] dst)
          Gets data at a specified index into a byte array.
 int get(int index, byte[] dst, int offset)
          Gets data at a specified index into a byte array.
 File getHomeDir()
           
 String getHomePath()
           
 long getHWMark()
          Gets the high water mark.
 int getLength(int index)
           
 long getLWMark()
          Gets the low water mark.
 String getStatus()
           
 boolean hasData(int index)
           
 boolean hasIndex(int index)
           
 int length()
           
 void persist()
          Persist all updates from memory buffer into redo log files in non-blocking mode.
 void saveHWMark(long endOfPeriod)
          Save the high water mark.
 void set(int index, byte[] data, int offset, int length, long scn)
          Sets data at a specified index.
 void set(int index, byte[] data, long scn)
          Sets data at a specified index.
 void sync()
          Force all updates from memory buffer and redo log files to synchronize with the underlying persistent file in blocking mode.
 int transferTo(int index, WritableByteChannel channel)
          Transfers data at a given index to a writable file channel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_dataArray

protected final SimpleDataArray _dataArray

_addrArray

protected final AddressArray _addrArray

_homePath

protected final String _homePath

_homeDir

protected final File _homeDir
Constructor Detail

AbstractDataArray

protected AbstractDataArray(int length,
                            int batchSize,
                            int numSyncBatches,
                            File homeDirectory,
                            SegmentFactory segmentFactory,
                            int segmentFileSizeMB,
                            double segmentCompactFactor)
                     throws Exception
Constructs a data array.

Parameters:
length - - the array length
batchSize - - the number of updates per update batch, i.e. the redo entry size
numSyncBatches - - the number of update batches required for updating the underlying address array
homeDirectory - - the home directory of data array
segmentFactory - - the segment factory
segmentFileSizeMB - - the segment size in MB
segmentCompactFactor - - the segment load threshold, below which a segment is eligible for compaction
Throws:
Exception
Method Detail

createAddressArray

protected abstract AddressArray createAddressArray(int length,
                                                   int batchSize,
                                                   int numSyncBatches,
                                                   File homeDirectory)
                                            throws Exception
Throws:
Exception

getHomeDir

public File getHomeDir()

getHomePath

public String getHomePath()

getStatus

public String getStatus()

length

public int length()
Specified by:
length in interface Array
Returns:
the current length of this Array.

hasIndex

public boolean hasIndex(int index)
Specified by:
hasIndex in interface Array
Returns:
a boolean indicating an index is in the range of this Array.

get

public byte[] get(int index)
Description copied from interface: DataArray
Gets data at a specified index.

Specified by:
get in interface DataArray
Parameters:
index - data index in DataArray
Returns:
data at a specified index

get

public int get(int index,
               byte[] dst)
Description copied from interface: DataArray
Gets data at a specified index into a byte array.

Specified by:
get in interface DataArray
Parameters:
index - data index in DataArray
dst - the byte array to write to
Returns:
the number of bytes written to the byte array.

get

public int get(int index,
               byte[] dst,
               int offset)
Description copied from interface: DataArray
Gets data at a specified index into a byte array.

Specified by:
get in interface DataArray
Parameters:
index - data index in DataArray
dst - the byte array to write to
offset - the offset of byte array from where data will be written
Returns:
the number of bytes written to the byte array.

getLength

public int getLength(int index)
Specified by:
getLength in interface DataArray
Returns:
the length of data at a specified index

hasData

public boolean hasData(int index)
Specified by:
hasData in interface DataArray
Returns:
true if data exists at a given index. Otherwise, false.

set

public void set(int index,
                byte[] data,
                long scn)
         throws Exception
Description copied from interface: DataArray
Sets data at a specified index.

Specified by:
set in interface DataArray
Parameters:
index - data index in DataArray
data - data to write to DataArray
Throws:
Exception

set

public void set(int index,
                byte[] data,
                int offset,
                int length,
                long scn)
         throws Exception
Description copied from interface: DataArray
Sets data at a specified index.

Specified by:
set in interface DataArray
Parameters:
index - data index in DataArray
data - data to write to DataArray
offset - the offset of the data array to start read
length - the length of data to read from the data array
Throws:
Exception

transferTo

public int transferTo(int index,
                      WritableByteChannel channel)
Description copied from interface: DataArray
Transfers data at a given index to a writable file channel.

Specified by:
transferTo in interface DataArray
Parameters:
index - data index in DataArray
channel - channel to transfer data to
Returns:
the number of bytes transferred.

clear

public void clear()
Description copied from interface: Array
Clears this Array.

Specified by:
clear in interface Array

getHWMark

public long getHWMark()
Description copied from interface: Persistable
Gets the high water mark.

Specified by:
getHWMark in interface Persistable

getLWMark

public long getLWMark()
Description copied from interface: Persistable
Gets the low water mark.

Specified by:
getLWMark in interface Persistable

saveHWMark

public void saveHWMark(long endOfPeriod)
                throws Exception
Description copied from interface: Persistable
Save the high water mark.

Specified by:
saveHWMark in interface Persistable
Throws:
Exception

persist

public void persist()
             throws IOException
Description copied from interface: Persistable
Persist all updates from memory buffer into redo log files in non-blocking mode.

Specified by:
persist in interface Persistable
Throws:
IOException

sync

public void sync()
          throws IOException
Description copied from interface: Persistable
Force all updates from memory buffer and redo log files to synchronize with the underlying persistent file in blocking mode.

Specified by:
sync in interface Persistable
Throws:
IOException


Copyright © 2011. All Rights Reserved.