krati.core.array.basic
Class DynamicIntArray

java.lang.Object
  extended by krati.core.array.basic.DynamicIntArray
All Implemented Interfaces:
Array, DynamicArray, IntArray, ArrayExpandListener, RecoverableArray<EntryValueInt>, Persistable

public class DynamicIntArray
extends Object
implements IntArray, DynamicArray, ArrayExpandListener

DynamicIntArray

Author:
jwu

Field Summary
protected  ArrayFile _arrayFile
           
protected  File _directory
           
protected  EntryFactory<V> _entryFactory
           
protected  ArrayEntryManager<V> _entryManager
           
protected  int _length
           
 
Constructor Summary
DynamicIntArray(int entrySize, int maxEntries, File directory)
           
 
Method Summary
 void arrayExpanded(DynamicArray dynArray)
           
 void clear()
          Clears this Array.
 void expandCapacity(int index)
          Expands the capacity of array to accommodate a given index.
 int get(int index)
          Gets data at a specified index.
 File getDirectory()
           
 EntryFactory<V> getEntryFactory()
           
 ArrayEntryManager<V> getEntryManager()
           
 long getHWMark()
          Gets the high water mark.
 int[] getInternalArray()
          Gets the internal primitive array.
 long getLWMark()
          Gets the low water mark.
 boolean hasIndex(int index)
           
protected  void init()
          Loads data from the array file.
protected  void initArrayFile()
           
 int length()
           
protected  void loadArrayFileData()
           
protected  ArrayFile openArrayFile(File file, int initialLength, int elementSize)
           
 void persist()
          Persists this array.
 void saveHWMark(long endOfPeriod)
          Sync-up the high water mark to a given value.
 void set(int index, int value, long scn)
          Sets data at a specified index.
 int subArrayLength()
           
 void sync()
          Sync array file with all entry logs.
 void updateArrayFile(List<Entry<V>> entryList)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface krati.array.Array
hasIndex, length
 

Field Detail

_length

protected int _length

_directory

protected File _directory

_arrayFile

protected ArrayFile _arrayFile

_entryFactory

protected EntryFactory<V extends EntryValue> _entryFactory

_entryManager

protected ArrayEntryManager<V extends EntryValue> _entryManager
Constructor Detail

DynamicIntArray

public DynamicIntArray(int entrySize,
                       int maxEntries,
                       File directory)
                throws Exception
Throws:
Exception
Method Detail

loadArrayFileData

protected void loadArrayFileData()

saveHWMark

public void saveHWMark(long endOfPeriod)
Sync-up the high water mark to a given value.

Specified by:
saveHWMark in interface Persistable
Parameters:
endOfPeriod -

clear

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

Specified by:
clear in interface Array

get

public int get(int index)
Description copied from interface: IntArray
Gets data at a specified index.

Specified by:
get in interface IntArray
Returns:
data at a specified index

set

public void set(int index,
                int value,
                long scn)
         throws Exception
Description copied from interface: IntArray
Sets data at a specified index.

Specified by:
set in interface IntArray
Throws:
Exception

getInternalArray

public int[] getInternalArray()
Description copied from interface: IntArray
Gets the internal primitive array.

Specified by:
getInternalArray in interface IntArray
Returns:
int array.

expandCapacity

public void expandCapacity(int index)
                    throws Exception
Description copied from interface: DynamicArray
Expands the capacity of array to accommodate a given index.

Specified by:
expandCapacity in interface DynamicArray
Parameters:
index - an index in the array
Throws:
Exception

arrayExpanded

public void arrayExpanded(DynamicArray dynArray)
Specified by:
arrayExpanded in interface ArrayExpandListener

subArrayLength

public final int subArrayLength()

init

protected void init()
             throws IOException
Loads data from the array file.

Throws:
IOException

openArrayFile

protected final ArrayFile openArrayFile(File file,
                                        int initialLength,
                                        int elementSize)
                                 throws IOException
Throws:
IOException

initArrayFile

protected void initArrayFile()

getDirectory

public File getDirectory()
Specified by:
getDirectory in interface RecoverableArray<V extends EntryValue>

getEntryFactory

public EntryFactory<V> getEntryFactory()
Specified by:
getEntryFactory in interface RecoverableArray<V extends EntryValue>

getEntryManager

public ArrayEntryManager<V> getEntryManager()

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.

length

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

sync

public void sync()
          throws IOException
Sync array file with all entry logs. The writer will be blocked until all entry logs are applied.

Specified by:
sync in interface Persistable
Throws:
IOException

persist

public void persist()
             throws IOException
Persists this array.

Specified by:
persist in interface Persistable
Throws:
IOException

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

updateArrayFile

public void updateArrayFile(List<Entry<V>> entryList)
                     throws IOException
Specified by:
updateArrayFile in interface RecoverableArray<V extends EntryValue>
Throws:
IOException


Copyright © 2011. All Rights Reserved.