krati.core.segment
Class MemorySegment

java.lang.Object
  extended by krati.core.segment.AbstractSegment
      extended by krati.core.segment.MemorySegment
All Implemented Interfaces:
Segment

public class MemorySegment
extends AbstractSegment

MemorySegment

Author:
jwu

Nested Class Summary
 
Nested classes/interfaces inherited from interface krati.core.segment.Segment
Segment.Mode
 
Field Summary
 
Fields inherited from class krati.core.segment.AbstractSegment
_channel, _initSizeBytes, _initSizeMB, _lastForcedTime, _raf, _segFile, _segId, _segMode, _storageVersion
 
Fields inherited from interface krati.core.segment.Segment
dataStartPosition, defaultSegmentCompactFactor, defaultSegmentFileSizeMB, maxSegmentFileSizeMB, minSegmentFileSizeMB, posLastForcedTime, posStorageVersion, STORAGE_VERSION
 
Constructor Summary
MemorySegment(int segmentId, File segmentFile, int initialSizeMB, Segment.Mode mode)
           
 
Method Summary
 int append(byte[] data)
           
 int append(byte[] data, int offset, int length)
           
 int appendInt(int value)
           
 int appendLong(long value)
           
 int appendShort(short value)
           
 void asReadOnly()
           
 boolean canAppendToBuffer()
           
 boolean canReadFromBuffer()
           
 void close(boolean force)
           
 void force()
           
 long getAppendPosition()
           
protected  void init()
           
protected  ByteBuffer initByteBuffer()
           
 boolean isRecyclable()
           
 void read(int pos, byte[] dst)
           
 void read(int pos, byte[] dst, int offset, int length)
           
 int readInt(int pos)
           
 long readLong(int pos)
           
 short readShort(int pos)
           
 void reinit()
          Re-initialize this Segment for read and write.
 void setAppendPosition(long newPosition)
           
 int transferTo(int pos, int length, Segment targetSegment)
           
 int transferTo(int pos, int length, WritableByteChannel targetChannel)
           
 
Methods inherited from class krati.core.segment.AbstractSegment
decrLoadSize, getChannelPosition, getHeader, getInitialSize, getInitialSizeMB, getLastForcedTime, getLoadFactor, getLoadSize, getMode, getSegmentFile, getSegmentId, getStatus, getStorageVersion, incrLoadSize, initHeader, isReadOnly, loadHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemorySegment

public MemorySegment(int segmentId,
                     File segmentFile,
                     int initialSizeMB,
                     Segment.Mode mode)
              throws IOException
Throws:
IOException
Method Detail

init

protected void init()
             throws IOException
Specified by:
init in class AbstractSegment
Throws:
IOException

initByteBuffer

protected ByteBuffer initByteBuffer()

getAppendPosition

public long getAppendPosition()
                       throws IOException
Throws:
IOException

setAppendPosition

public void setAppendPosition(long newPosition)
                       throws IOException
Throws:
IOException

appendInt

public int appendInt(int value)
              throws IOException,
                     SegmentOverflowException,
                     SegmentReadOnlyException
Throws:
IOException
SegmentOverflowException
SegmentReadOnlyException

appendLong

public int appendLong(long value)
               throws IOException,
                      SegmentOverflowException,
                      SegmentReadOnlyException
Throws:
IOException
SegmentOverflowException
SegmentReadOnlyException

appendShort

public int appendShort(short value)
                throws IOException,
                       SegmentOverflowException,
                       SegmentReadOnlyException
Throws:
IOException
SegmentOverflowException
SegmentReadOnlyException

append

public int append(byte[] data)
           throws IOException,
                  SegmentOverflowException,
                  SegmentReadOnlyException
Throws:
IOException
SegmentOverflowException
SegmentReadOnlyException

append

public int append(byte[] data,
                  int offset,
                  int length)
           throws IOException,
                  SegmentOverflowException,
                  SegmentReadOnlyException
Throws:
IOException
SegmentOverflowException
SegmentReadOnlyException

readInt

public int readInt(int pos)
            throws IOException
Throws:
IOException

readLong

public long readLong(int pos)
              throws IOException
Throws:
IOException

readShort

public short readShort(int pos)
                throws IOException
Throws:
IOException

read

public void read(int pos,
                 byte[] dst)
          throws IOException
Throws:
IOException

read

public void read(int pos,
                 byte[] dst,
                 int offset,
                 int length)
          throws IOException
Throws:
IOException

transferTo

public int transferTo(int pos,
                      int length,
                      Segment targetSegment)
               throws IOException
Throws:
IOException

transferTo

public int transferTo(int pos,
                      int length,
                      WritableByteChannel targetChannel)
               throws IOException
Throws:
IOException

asReadOnly

public void asReadOnly()
                throws IOException
Throws:
IOException

force

public void force()
           throws IOException
Throws:
IOException

close

public void close(boolean force)
           throws IOException
Throws:
IOException

reinit

public void reinit()
            throws IOException
Description copied from interface: Segment
Re-initialize this Segment for read and write.

Throws:
IOException

isRecyclable

public final boolean isRecyclable()
Returns:
whether this Segment is recyclable.

canReadFromBuffer

public final boolean canReadFromBuffer()
Returns:
whether this Segment can support reads from a buffer.

canAppendToBuffer

public final boolean canAppendToBuffer()
Returns:
whether this Segment can support writes by appending to a buffer.


Copyright © 2011. All Rights Reserved.