org.apache.kafka.common.record
Class MemoryRecords

java.lang.Object
  extended by org.apache.kafka.common.record.MemoryRecords
All Implemented Interfaces:
java.lang.Iterable<LogEntry>, Records

public class MemoryRecords
extends java.lang.Object
implements Records

A Records implementation backed by a ByteBuffer.


Nested Class Summary
static class MemoryRecords.RecordsIterator
           
 
Field Summary
 
Fields inherited from interface org.apache.kafka.common.record.Records
LOG_OVERHEAD, OFFSET_LENGTH, SIZE_LENGTH
 
Method Summary
 void append(long offset, byte[] key, byte[] value)
          Append a new record and offset to the buffer
 void append(long offset, Record record)
          Append the given record and offset to the buffer
 java.nio.ByteBuffer buffer()
          Get the byte buffer that backs this records instance
 int capacity()
          Return the capacity of the buffer
 void close()
          Close this batch for no more appends
 double compressionRate()
          The compression rate of this record set
static MemoryRecords emptyRecords(java.nio.ByteBuffer buffer, CompressionType type)
           
static MemoryRecords emptyRecords(java.nio.ByteBuffer buffer, CompressionType type, int capacity)
           
 boolean hasRoomFor(byte[] key, byte[] value)
          Check if we have room for a new record containing the given key/value pair Note that the return value is based on the estimate of the bytes written to the compressor, which may not be accurate if compression is really used.
 boolean isFull()
           
static MemoryRecords iterableRecords(java.nio.ByteBuffer buffer)
           
 java.util.Iterator<LogEntry> iterator()
           
 int sizeInBytes()
          The size of this record set
 int writeTo(java.nio.channels.GatheringByteChannel channel)
          Write the records in this set to the given channel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

emptyRecords

public static MemoryRecords emptyRecords(java.nio.ByteBuffer buffer,
                                         CompressionType type,
                                         int capacity)

emptyRecords

public static MemoryRecords emptyRecords(java.nio.ByteBuffer buffer,
                                         CompressionType type)

iterableRecords

public static MemoryRecords iterableRecords(java.nio.ByteBuffer buffer)

append

public void append(long offset,
                   Record record)
Append the given record and offset to the buffer


append

public void append(long offset,
                   byte[] key,
                   byte[] value)
Append a new record and offset to the buffer


hasRoomFor

public boolean hasRoomFor(byte[] key,
                          byte[] value)
Check if we have room for a new record containing the given key/value pair Note that the return value is based on the estimate of the bytes written to the compressor, which may not be accurate if compression is really used. When this happens, the following append may cause dynamic buffer re-allocation in the underlying byte buffer stream. Also note that besides the records' capacity, there is also a size limit for the batch. This size limit may be smaller than the capacity (e.g. when appending a single message whose size is larger than the batch size, the capacity will be the message size, but the size limit will still be the batch size), and when the records' size has exceed this limit we also mark this record as full.


isFull

public boolean isFull()

close

public void close()
Close this batch for no more appends


writeTo

public int writeTo(java.nio.channels.GatheringByteChannel channel)
            throws java.io.IOException
Write the records in this set to the given channel

Specified by:
writeTo in interface Records
Parameters:
channel - The channel to write to
Returns:
The number of bytes written
Throws:
java.io.IOException - If the write fails.

sizeInBytes

public int sizeInBytes()
The size of this record set

Specified by:
sizeInBytes in interface Records

compressionRate

public double compressionRate()
The compression rate of this record set


capacity

public int capacity()
Return the capacity of the buffer


buffer

public java.nio.ByteBuffer buffer()
Get the byte buffer that backs this records instance


iterator

public java.util.Iterator<LogEntry> iterator()
Specified by:
iterator in interface java.lang.Iterable<LogEntry>