|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectkrati.core.array.SimpleDataArray
public class SimpleDataArray
SimpleDataArray: Simple Persistent DataArray. 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 SimpleDataArray for a given home directory. 2. There is one and only one thread calling setData and transferTo methods at any given time.It is expected that this class is used in the case of multiple readers and single writer.
Field Summary | |
---|---|
protected AddressArray |
_addressArray
|
protected AddressFormat |
_addressFormat
|
protected krati.core.array.SimpleDataArrayCompactor |
_compactor
|
protected Segment |
_segment
|
protected double |
_segmentCompactFactor
|
protected SegmentManager |
_segmentManager
|
Constructor Summary | |
---|---|
SimpleDataArray(AddressArray addressArray,
SegmentManager segmentManager)
Constructs a DataArray with Segment Compact Factor default to 0.5. |
|
SimpleDataArray(AddressArray addressArray,
SegmentManager segmentManager,
double segmentCompactFactor)
Constructs a DataArray. |
Method Summary | |
---|---|
void |
clear()
Clears this Array. |
protected boolean |
consumeCompactionBatch()
|
protected void |
consumeCompactionBatches()
|
protected void |
decrOriginalSegmentLoad(int index)
|
byte[] |
get(int index)
Gets data at a given index. |
int |
get(int index,
byte[] data)
Gets data at a given index. |
int |
get(int index,
byte[] data,
int offset)
Gets data at a given index. |
protected long |
getAddress(int index)
|
protected LongArray |
getAddressArray()
|
protected Segment |
getCurrentSegment()
|
long |
getHWMark()
Gets the high water mark. |
int |
getLength(int index)
|
long |
getLWMark()
Gets the low water mark. |
protected double |
getSegmentCompactFactor()
|
protected SegmentManager |
getSegmentManager()
|
boolean |
hasData(int index)
|
boolean |
hasIndex(int index)
|
protected void |
init()
|
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 given index. |
void |
set(int index,
byte[] data,
long scn)
Sets data at a given index. |
protected void |
setAddress(int index,
long value,
long scn)
|
protected void |
setCompactionAddress(int index,
long value,
long scn)
|
void |
sync()
Force all updates from memory buffer and redo log files to synchronize with the underlying persistent file in blocking mode. |
protected void |
syncCompactor()
|
int |
transferTo(int index,
WritableByteChannel channel)
Transfers data at a given index to a writable channel. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected volatile Segment _segment
protected final AddressFormat _addressFormat
protected final AddressArray _addressArray
protected final SegmentManager _segmentManager
protected final krati.core.array.SimpleDataArrayCompactor _compactor
protected final double _segmentCompactFactor
Constructor Detail |
---|
public SimpleDataArray(AddressArray addressArray, SegmentManager segmentManager)
addressArray
- the array of addresses (i.e. pointers to Segment).segmentManager
- the segment manager for loading, creating, freeing, maintaining segments.public SimpleDataArray(AddressArray addressArray, SegmentManager segmentManager, double segmentCompactFactor)
addressArray
- the array of addresses (i.e. pointers to Segment).segmentManager
- the segment manager for loading, creating, freeing, maintaining segments.segmentCompactFactor
- the load factor below which a segment is eligible for compaction. The recommended value is 0.5.Method Detail |
---|
protected boolean consumeCompactionBatch()
protected void consumeCompactionBatches()
protected void syncCompactor()
protected void init()
protected long getAddress(int index)
protected void setAddress(int index, long value, long scn) throws Exception
Exception
protected void setCompactionAddress(int index, long value, long scn) throws Exception
Exception
protected LongArray getAddressArray()
protected double getSegmentCompactFactor()
protected SegmentManager getSegmentManager()
protected Segment getCurrentSegment()
protected void decrOriginalSegmentLoad(int index)
public boolean hasData(int index)
hasData
in interface DataArray
true
if this array has data at the given index. Otherwise, false
.
ArrayIndexOutOfBoundsException
- if the index is out of range.public int getLength(int index)
getLength
in interface DataArray
-1 is returned.
public byte[] get(int index)
get
in interface DataArray
index
- the array index
ArrayIndexOutOfBoundsException
- if the index is out of range.public int get(int index, byte[] data)
get
in interface DataArray
index
- the array indexdata
- the byte array to fill in
ArrayIndexOutOfBoundsException
- if the index is out of range
or if the byte array does not have enough space to hold the read data.public int get(int index, byte[] data, int offset)
get
in interface DataArray
index
- the array indexdata
- the byte array to fill inoffset
- the offset of the byte array where data is filled in
ArrayIndexOutOfBoundsException
- if the index is out of range
or if the byte array does not have enough space to hold the read data.public int transferTo(int index, WritableByteChannel channel)
transferTo
in interface DataArray
index
- the array indexchannel
- channel to transfer data to
ArrayIndexOutOfBoundsException
- if the index is out of range.public void set(int index, byte[] data, long scn) throws Exception
set
in interface DataArray
index
- the array indexdata
- the data (byte array).
If null
, the data at the given index will be removed.scn
- the global scn indicating the sequence of this change
ArrayIndexOutOfBoundsException
- if the index is out of range.
Exception
public void set(int index, byte[] data, int offset, int length, long scn) throws Exception
set
in interface DataArray
index
- the array indexdata
- the data (byte array)
If null
, the data at the given index will be removed.offset
- the offset of byte array where data is readlength
- the length of data to read from the byte arrayscn
- the global scn indicating the sequence of this change
ArrayIndexOutOfBoundsException
- if the index is out of range
or if the offset and length is not properly specified.
Exception
public boolean hasIndex(int index)
hasIndex
in interface Array
public int length()
length
in interface Array
public long getHWMark()
Persistable
getHWMark
in interface Persistable
public long getLWMark()
Persistable
getLWMark
in interface Persistable
public void saveHWMark(long endOfPeriod) throws Exception
Persistable
saveHWMark
in interface Persistable
Exception
public void sync() throws IOException
Persistable
sync
in interface Persistable
IOException
public void persist() throws IOException
Persistable
persist
in interface Persistable
IOException
public void clear()
Array
clear
in interface Array
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |