krati.core.array.basic
Class StaticShortArray

java.lang.Object
  extended by krati.core.array.basic.StaticShortArray
All Implemented Interfaces:
Array, ShortArray, RecoverableArray<EntryValueShort>, Persistable

public class StaticShortArray
extends Object
implements ShortArray

StaticShortArray: Fixed-Size Persistent ShortArray Implementation. This class is not thread-safe by design. It is expected that the conditions below hold within one JVM.

    1. There is one and only one instance of StaticShortArray for a given home directory.
    2. There is one and only one thread is calling the setData method at any given time. 
 
It is expected that this class is used in the case of multiple readers and single writer.

Author:
jwu

Field Summary
protected  ArrayFile _arrayFile
           
protected  File _directory
           
protected  EntryFactory<V> _entryFactory
           
protected  ArrayEntryManager<V> _entryManager
           
protected  int _length
           
 
Constructor Summary
StaticShortArray(int length, int entrySize, int maxEntries, File homeDirectory)
          Create a fixed-length persistent short array.
 
Method Summary
 void clear()
          Clears this Array.
 short get(int index)
          Gets data at a specified index.
 File getDirectory()
           
 EntryFactory<V> getEntryFactory()
           
 ArrayEntryManager<V> getEntryManager()
           
 long getHWMark()
          Gets the high water mark.
 short[] 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, short value, long scn)
          Sets data at a specified index.
 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

StaticShortArray

public StaticShortArray(int length,
                        int entrySize,
                        int maxEntries,
                        File homeDirectory)
                 throws Exception
Create a fixed-length persistent short array.

Parameters:
length - the length of this array
entrySize - the size of redo entry (i.e., batch size)
maxEntries - the number of redo entries required for updating the underlying array file
homeDirectory - the home directory of this array
Throws:
Exception - if this array cannot be created.
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 short get(int index)
Description copied from interface: ShortArray
Gets data at a specified index.

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

set

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

Specified by:
set in interface ShortArray
Throws:
Exception

getInternalArray

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

Specified by:
getInternalArray in interface ShortArray
Returns:
short array.

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.