krati.core.array.basic
Class ArrayFile

java.lang.Object
  extended by krati.core.array.basic.ArrayFile

public class ArrayFile
extends Object

ArrayFile is not thread safe.

 Version 0:
 +--------------------------+
 |Header                    |
 |--------------------------|
 |Storage Version    | long | 
 |LWM Scn            | long |
 |HWM Scn            | long |
 |Array Length       | int  |
 |Data Element Size  | int  |
 |--------------------------|
 | Array data begins at 1024|
 |                          |
 +--------------------------+
 


Field Summary
static int ARRAY_HEADER_LENGTH
           
static long STORAGE_VERSION
           
 
Constructor Summary
ArrayFile(File file, int initialLength, int elementSize)
          Creates a new ArrayFile based on a given length and element size.
 
Method Summary
 void close()
           
protected  DataWriter createWriter(File file, long fileLength)
           
 void flush()
           
 String getAbsolutePath()
           
 int getArrayLength()
           
 String getCanonicalPath()
           
 int getElementSize()
           
 long getHwmScn()
           
 long getLwmScn()
           
 String getName()
           
 String getPath()
           
protected  long getPosition(int index)
           
 long getVersion()
           
protected  void initCheck()
           
 void load(MemoryIntArray intArray)
          Load data into a memory-based int array.
 void load(MemoryLongArray longArray)
          Load data into a memory-based long array.
 void load(MemoryShortArray shortArray)
          Load data into a memory-based short array.
 int[] loadIntArray()
          Load the main array.
 long[] loadLongArray()
          Load the main array.
 short[] loadShortArray()
          Load the main array.
 void reset(int[] intArray)
           
 void reset(int[] intArray, long maxScn)
           
 void reset(long[] longArray)
           
 void reset(long[] longArray, long maxScn)
           
 void reset(MemoryIntArray intArray)
           
 void reset(MemoryIntArray intArray, long maxScn)
           
 void reset(MemoryLongArray longArray)
           
 void reset(MemoryLongArray longArray, long maxScn)
           
 void reset(MemoryShortArray shortArray)
           
 void reset(MemoryShortArray shortArray, long maxScn)
           
 void reset(short[] shortArray)
           
 void reset(short[] shortArray, long maxScn)
           
 void setArrayLength(int arrayLength, File renameToFile)
           
<T extends EntryValue>
void
update(List<Entry<T>> entryList)
          Apply entries to the array file.
protected  void writeArrayLength(int value)
           
protected  void writeElementSize(int value)
           
protected  void writeHwmScn(long value)
           
 void writeInt(int index, int value)
          Writes an int value at a specified index in the array.
 void writeLong(int index, long value)
          Writes a long value at a specified index in the array.
protected  void writeLwmScn(long value)
           
 void writeShort(int index, short value)
          Writes a short value at a specified index in the array.
protected  void writeVersion(long value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STORAGE_VERSION

public static final long STORAGE_VERSION
See Also:
Constant Field Values

ARRAY_HEADER_LENGTH

public static final int ARRAY_HEADER_LENGTH
See Also:
Constant Field Values
Constructor Detail

ArrayFile

public ArrayFile(File file,
                 int initialLength,
                 int elementSize)
          throws IOException
Creates a new ArrayFile based on a given length and element size.

Parameters:
file - the file on disk
initialLength - the initial length (number of elements) of array
elementSize - the size (number of bytes) of every array element
Throws:
IOException
Method Detail

createWriter

protected DataWriter createWriter(File file,
                                  long fileLength)

initCheck

protected void initCheck()
                  throws IOException
Throws:
IOException

getName

public final String getName()

getPath

public final String getPath()

getAbsolutePath

public final String getAbsolutePath()

getCanonicalPath

public final String getCanonicalPath()
                              throws IOException
Throws:
IOException

getVersion

public final long getVersion()

getLwmScn

public final long getLwmScn()

getHwmScn

public final long getHwmScn()

getArrayLength

public final int getArrayLength()

getElementSize

public final int getElementSize()

flush

public void flush()
           throws IOException
Throws:
IOException

close

public void close()
           throws IOException
Throws:
IOException

load

public void load(MemoryIntArray intArray)
          throws IOException
Load data into a memory-based int array.

Throws:
IOException

load

public void load(MemoryLongArray longArray)
          throws IOException
Load data into a memory-based long array.

Throws:
IOException

load

public void load(MemoryShortArray shortArray)
          throws IOException
Load data into a memory-based short array.

Throws:
IOException

loadIntArray

public int[] loadIntArray()
                   throws IOException
Load the main array.

Returns:
an int array
Throws:
IOException

loadLongArray

public long[] loadLongArray()
                     throws IOException
Load the main array.

Returns:
a long array
Throws:
IOException

loadShortArray

public short[] loadShortArray()
                       throws IOException
Load the main array.

Returns:
a short array
Throws:
IOException

getPosition

protected long getPosition(int index)

writeInt

public void writeInt(int index,
                     int value)
              throws IOException
Writes an int value at a specified index in the array. This method does not update hwmScn and lwmScn in the array file.

Parameters:
index - an index in the array.
value - int value
Throws:
IOException

writeLong

public void writeLong(int index,
                      long value)
               throws IOException
Writes a long value at a specified index in the array. This method does not update hwmScn and lwmScn in the array file.

Parameters:
index - an index in the array.
value - long value
Throws:
IOException

writeShort

public void writeShort(int index,
                       short value)
                throws IOException
Writes a short value at a specified index in the array. This method does not update hwmScn and lwmScn in the array file.

Parameters:
index - an index in the array.
value - short value
Throws:
IOException

update

public <T extends EntryValue> void update(List<Entry<T>> entryList)
            throws IOException
Apply entries to the array file. The method will flatten entry data and sort it by position. So the array file can be updated sequentially to reduce disk seeking time. This method updates hwmScn and lwmScn in the array file.

Parameters:
entryList -
Throws:
IOException

writeVersion

protected void writeVersion(long value)
                     throws IOException
Throws:
IOException

writeLwmScn

protected void writeLwmScn(long value)
                    throws IOException
Throws:
IOException

writeHwmScn

protected void writeHwmScn(long value)
                    throws IOException
Throws:
IOException

writeArrayLength

protected void writeArrayLength(int value)
                         throws IOException
Throws:
IOException

writeElementSize

protected void writeElementSize(int value)
                         throws IOException
Throws:
IOException

reset

public void reset(MemoryIntArray intArray)
           throws IOException
Throws:
IOException

reset

public void reset(MemoryIntArray intArray,
                  long maxScn)
           throws IOException
Throws:
IOException

reset

public void reset(MemoryLongArray longArray)
           throws IOException
Throws:
IOException

reset

public void reset(MemoryLongArray longArray,
                  long maxScn)
           throws IOException
Throws:
IOException

reset

public void reset(MemoryShortArray shortArray)
           throws IOException
Throws:
IOException

reset

public void reset(MemoryShortArray shortArray,
                  long maxScn)
           throws IOException
Throws:
IOException

reset

public void reset(int[] intArray)
           throws IOException
Throws:
IOException

reset

public void reset(int[] intArray,
                  long maxScn)
           throws IOException
Throws:
IOException

reset

public void reset(long[] longArray)
           throws IOException
Throws:
IOException

reset

public void reset(long[] longArray,
                  long maxScn)
           throws IOException
Throws:
IOException

reset

public void reset(short[] shortArray)
           throws IOException
Throws:
IOException

reset

public void reset(short[] shortArray,
                  long maxScn)
           throws IOException
Throws:
IOException

setArrayLength

public void setArrayLength(int arrayLength,
                           File renameToFile)
                    throws IOException
Throws:
IOException


Copyright © 2011. All Rights Reserved.