krati.core.segment
Class MappedSegment

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

public class MappedSegment
extends AbstractSegment

MappedSegment

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
MappedSegment(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()
           
 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

MappedSegment

public MappedSegment(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

getAppendPosition

public long getAppendPosition()

setAppendPosition

public void setAppendPosition(long newPosition)

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)

readLong

public long readLong(int pos)

readShort

public short readShort(int pos)

read

public void read(int pos,
                 byte[] dst)

read

public void read(int pos,
                 byte[] dst,
                 int offset,
                 int length)

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()

close

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

reinit

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

Throws:
IOException
UnsupportedOperationException

isRecyclable

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

canReadFromBuffer

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

canAppendToBuffer

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


Copyright © 2011. All Rights Reserved.