net.opentsdb.uid
Interface UniqueIdInterface

All Known Implementing Classes:
UniqueId

public interface UniqueIdInterface

Represents a table of Unique IDs, manages the lookup and creation of IDs. For efficiency, various kinds of "names" need to be mapped to small, unique IDs. For instance, we give a unique ID to each metric name, to each tag name, to each tag value.

An instance of this class handles the unique IDs for one kind of ID. For example:

   UniqueId metric_names = ...;
   byte[] id = metric_names.get("sys.net.rx_bytes");
   
IDs are looked up in HBase and cached forever in memory (since they're immutable). IDs are encoded on a fixed number of bytes, which is implementation dependent.


Method Summary
 byte[] getId(String name)
          Finds the ID associated with a given name.
 String getName(byte[] id)
          Finds the name associated with a given ID.
 byte[] getOrCreateId(String name)
          Finds the ID associated with a given name or creates it.
 String kind()
          Returns what kind of Unique ID is served by this instance.
 short width()
          Returns the number of bytes on which each Unique ID is encoded.
 

Method Detail

kind

String kind()
Returns what kind of Unique ID is served by this instance.


width

short width()
Returns the number of bytes on which each Unique ID is encoded.


getName

String getName(byte[] id)
               throws NoSuchUniqueId,
                      org.hbase.async.HBaseException
Finds the name associated with a given ID.

Parameters:
id - The ID associated with that name.
Throws:
NoSuchUniqueId - if the given ID is not assigned.
org.hbase.async.HBaseException - if there is a problem communicating with HBase.
IllegalArgumentException - if the ID given in argument is encoded on the wrong number of bytes.
See Also:
getId(String), getOrCreateId(String)

getId

byte[] getId(String name)
             throws NoSuchUniqueName,
                    org.hbase.async.HBaseException
Finds the ID associated with a given name.

The length of the byte array is fixed in advance by the implementation.

Parameters:
name - The name to lookup in the table.
Returns:
A non-null, non-empty byte[] array.
Throws:
NoSuchUniqueName - if the name requested doesn't have an ID assigned.
org.hbase.async.HBaseException - if there is a problem communicating with HBase.
IllegalStateException - if the ID found in HBase is encoded on the wrong number of bytes.
See Also:
getName(byte[])

getOrCreateId

byte[] getOrCreateId(String name)
                     throws org.hbase.async.HBaseException,
                            IllegalStateException
Finds the ID associated with a given name or creates it.

The length of the byte array is fixed in advance by the implementation.

Parameters:
name - The name to lookup in the table or to assign an ID to.
Throws:
org.hbase.async.HBaseException - if there is a problem communicating with HBase.
IllegalStateException - if all possible IDs are already assigned.
IllegalStateException - if the ID found in HBase is encoded on the wrong number of bytes.