public final class QueryIndex<T> extends Object
Id against a set of
queries that are known in advance. The index is thread safe for queries. Updates to the
index should be done from a single thread at a time.| Modifier and Type | Class and Description |
|---|---|
static interface |
QueryIndex.CacheSupplier<V>
Supplier to create a new instance of a cache used for other checks.
|
static class |
QueryIndex.DefaultCacheSupplier<V>
Default supplier based on a simple LFU cache.
|
| Modifier and Type | Method and Description |
|---|---|
QueryIndex<T> |
add(Query query,
T value)
Add a value that should match for the specified query.
|
List<T> |
findMatches(Function<String,String> tags)
Find all values where the corresponding queries match the specified tags.
|
List<T> |
findMatches(com.netflix.spectator.api.Id id)
Find all values where the corresponding queries match the specified id.
|
void |
forEachMatch(Function<String,String> tags,
Consumer<T> consumer)
Invoke the consumer for all values where the corresponding queries match the specified tags.
|
void |
forEachMatch(com.netflix.spectator.api.Id id,
Consumer<T> consumer)
Invoke the consumer for all values where the corresponding queries match the specified id.
|
boolean |
isEmpty()
Returns true if this index is empty and wouldn't match any ids.
|
static <V> QueryIndex<V> |
newInstance(QueryIndex.CacheSupplier<V> cacheSupplier)
Return a new instance of an index that is empty.
|
static <V> QueryIndex<V> |
newInstance(com.netflix.spectator.api.Registry registry)
Return a new instance of an index that is empty.
|
boolean |
remove(Query query,
T value)
Remove the specified value associated with a specific query from the index.
|
String |
toString() |
public static <V> QueryIndex<V> newInstance(com.netflix.spectator.api.Registry registry)
public static <V> QueryIndex<V> newInstance(QueryIndex.CacheSupplier<V> cacheSupplier)
public QueryIndex<T> add(Query query, T value)
query - Query that corresponds to the value.value - Value to return for ids that match the query.public boolean remove(Query query, T value)
public boolean isEmpty()
public List<T> findMatches(com.netflix.spectator.api.Id id)
id - Id to check against the queries.public void forEachMatch(com.netflix.spectator.api.Id id,
Consumer<T> consumer)
id - Id to check against the queries.consumer - Function to invoke for values associated with a query that matches the id.public List<T> findMatches(Function<String,String> tags)
tags - Function to look up the value for a given tag key. The function should return
null if there is no value for the key.public void forEachMatch(Function<String,String> tags, Consumer<T> consumer)
tags - Function to look up the value for a given tag key. The function should return
null if there is no value for the key.consumer - Function to invoke for values associated with a query that matches the id.