org.hbase.async
Class KeyValue

java.lang.Object
  extended by org.hbase.async.KeyValue
All Implemented Interfaces:
Comparable<KeyValue>

public final class KeyValue
extends Object
implements Comparable<KeyValue>

A "cell" in an HBase table.

This represents one unit of HBase data, one "record".

A note byte arrays

This class will never copy any byte[] that's given to it, neither will it create a copy before returning one to you. Changing a byte array get from or pass to this class will have unpredictable consequences. In particular, multiple KeyValue instances may share the same byte arrays, so changing one instance may also unexpectedly affect others.


Field Summary
static long TIMESTAMP_NOW
          Timestamp value to let the server set the timestamp at processing time.
 
Constructor Summary
KeyValue(byte[] key, byte[] family, byte[] qualifier, byte[] value)
          Constructor.
KeyValue(byte[] key, byte[] family, byte[] qualifier, long timestamp, byte[] value)
          Constructor.
 
Method Summary
 int compareTo(KeyValue other)
           
 boolean equals(Object other)
           
 byte[] family()
          Returns the column family.
static KeyValue fromBuffer(ChannelBuffer buf, KeyValue prev)
          De-serializes KeyValue from a buffer.
 int hashCode()
           
 byte[] key()
          Returns the row key.
 byte[] qualifier()
          Returns the column qualifier.
 long timestamp()
          Returns the timestamp stored in this KeyValue.
 String toString()
           
 byte[] value()
          Returns the value, the contents of the cell.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TIMESTAMP_NOW

public static final long TIMESTAMP_NOW
Timestamp value to let the server set the timestamp at processing time. When this value is used as a timestamp on a KeyValue, the server will substitute a real timestamp at the time it processes it. HBase uses current UNIX time in milliseconds.

See Also:
Constant Field Values
Constructor Detail

KeyValue

public KeyValue(byte[] key,
                byte[] family,
                byte[] qualifier,
                long timestamp,
                byte[] value)
Constructor.

Parameters:
key - The row key. Length must fit in 16 bits.
family - The column family. Length must fit in 8 bits.
qualifier - The column qualifier.
timestamp - Timestamp on the value. This timestamp can be set to guarantee ordering of values or operations. It is strongly advised to use a UNIX timestamp in milliseconds, e.g. from a source such as System.currentTimeMillis(). This value must be strictly positive.
value - The value, the contents of the cell.
Throws:
IllegalArgumentException - if any argument is invalid (e.g. array size is too long) or if the timestamp is negative.
Since:
1.2

KeyValue

public KeyValue(byte[] key,
                byte[] family,
                byte[] qualifier,
                byte[] value)
Constructor.

This KeyValue will be timestamped by the server at the time the server processes it.

Parameters:
key - The row key. Length must fit in 16 bits.
family - The column family. Length must fit in 8 bits.
qualifier - The column qualifier.
value - The value, the contents of the cell.
Throws:
IllegalArgumentException - if any argument is invalid (e.g. array size is too long).
See Also:
TIMESTAMP_NOW
Method Detail

key

public byte[] key()
Returns the row key.


family

public byte[] family()
Returns the column family.


qualifier

public byte[] qualifier()
Returns the column qualifier.


timestamp

public long timestamp()
Returns the timestamp stored in this KeyValue.

See Also:
TIMESTAMP_NOW

value

public byte[] value()
Returns the value, the contents of the cell.


compareTo

public int compareTo(KeyValue other)
Specified by:
compareTo in interface Comparable<KeyValue>

equals

public boolean equals(Object other)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

fromBuffer

public static KeyValue fromBuffer(ChannelBuffer buf,
                                  KeyValue prev)
De-serializes KeyValue from a buffer.

Parameters:
buf - The buffer to de-serialize from.
prev - Another KeyValue previously de-serialized from the same buffer. Can be null. The idea here is that KeyValues often come in a sorted batch, and often share a number of byte arrays (e.g. they all have the same row key and/or same family...). When you specify another KeyValue, its byte arrays will be re-used in order to avoid having too much duplicate data in memory. This costs a little bit of CPU time to compare the arrays but saves memory (which in turns saves CPU time later).
Returns:
a new instance (guaranteed non-null).
Throws:
IllegalArgumentException - if the buffer seems to contain a malformed KeyValue.