com.apple.foundationdb

## Class LocalityUtil

- java.lang.Object
- - com.apple.foundationdb.LocalityUtil

    public class LocalityUtil
    extends java.lang.Object

The FoundationDB API comes with a set of functions for discovering the storage locations of keys within your cluster. This information can be useful for advanced users who wish to take into account the location of keys in the design of applications or processes.

### Method Summary

All Methods Static Methods Concrete Methods
`static java.util.concurrent.CompletableFuture<java.lang.String[]>` `getAddressesForKey(Transaction tr, byte[] key)` Returns a list of public network addresses as strings, one for each of the storage servers responsible for storing `key` and its associated value.
`static CloseableAsyncIterator<byte[]>` `getBoundaryKeys(Database db, byte[] begin, byte[] end)` Returns a `CloseableAsyncIterator` of keys `k` such that `begin <= k < end` and `k` is located at the start of a contiguous range stored on a single server. This method is not transactional.
`static CloseableAsyncIterator<byte[]>` `getBoundaryKeys(Transaction tr, byte[] begin, byte[] end)` Returns a `CloseableAsyncIterator` of keys `k` such that `begin <= k < end` and `k` is located at the start of a contiguous range stored on a single server. This method is not transactional.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### getBoundaryKeys

    public static CloseableAsyncIterator<byte[]> getBoundaryKeys(Database db,
                                                                 byte[] begin,
                                                                 byte[] end)

Returns a `CloseableAsyncIterator` of keys `k` such that `begin <= k < end` and `k` is located at the start of a contiguous range stored on a single server.
This method is not transactional. The returned boundaries are an estimate and may not represent the exact boundary locations at any database version.

Parameters:
  `db` - the database to query
  `begin` - the inclusive start of the range
  `end` - the exclusive end of the range
Returns:
  an sequence of keys denoting the start of single-server ranges

#### getBoundaryKeys

    public static CloseableAsyncIterator<byte[]> getBoundaryKeys(Transaction tr,
                                                                 byte[] begin,
                                                                 byte[] end)

Returns a `CloseableAsyncIterator` of keys `k` such that `begin <= k < end` and `k` is located at the start of a contiguous range stored on a single server.
This method is not transactional. The returned boundaries are an estimate and may not represent the exact boundary locations at any database version. The passed `Transaction` is not used for reads directly, instead it is used to get access to associated `Database`. As a result, options (such as retry limit) set on the passed `Transaction` will not be applied. If, however, the passed `Transaction` has already gotten a read version there is some latency advantage to using this form of the method. Also, if the database is unavailable prior to the function call, any timeout set on the passed `Transaction` will still trigger.

Parameters:
  `tr` - the transaction on which to base the query
  `begin` - the inclusive start of the range
  `end` - the exclusive end of the range
Returns:
  an sequence of keys denoting the start of single-server ranges

#### getAddressesForKey

    public static java.util.concurrent.CompletableFuture<java.lang.String[]> getAddressesForKey(Transaction tr,
                                                                                                byte[] key)

Returns a list of public network addresses as strings, one for each of the storage servers responsible for storing `key` and its associated value. If locality information is not available, the returned future will carry a `FDBException` locality_information_unavailable.

Parameters:
  `tr` - the transaction in which to gather location information
  `key` - the key for which to gather location information
Returns:
  a list of addresses in string form