Package com.orbitz.consul.cache
Class ConsulCache<K,V>
- java.lang.Object
-
- com.orbitz.consul.cache.ConsulCache<K,V>
-
- Type Parameters:
V-
- All Implemented Interfaces:
java.lang.AutoCloseable
- Direct Known Subclasses:
HealthCheckCache,KVCache,NodesCatalogCache,ServiceCatalogCache,ServiceHealthCache
public class ConsulCache<K,V> extends java.lang.Object implements java.lang.AutoCloseableA cache structure that can provide an up-to-date read-only map backed by consul data
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interfaceConsulCache.CallbackConsumer<V>passed in by creators to vary the content of the cached valuesstatic interfaceConsulCache.Listener<K,V>Implementers can register a listener to receive a new map when it changesprotected static classConsulCache.Scheduler
-
Constructor Summary
Constructors Modifier Constructor Description protectedConsulCache(java.util.function.Function<V,K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor)protectedConsulCache(java.util.function.Function<V,K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor, ConsulCache.Scheduler callbackScheduler)protectedConsulCache(java.util.function.Function<V,K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor, java.util.concurrent.ScheduledExecutorService callbackScheduleExecutorService)
-
Method Summary
Modifier and Type Method Description booleanaddListener(ConsulCache.Listener<K,V> listener)booleanawaitInitialized(long timeout, java.util.concurrent.TimeUnit unit)voidclose()protected static ConsulCache.SchedulercreateDefault()protected static ConsulCache.SchedulercreateExternal(java.util.concurrent.ScheduledExecutorService executor)java.util.List<ConsulCache.Listener<K,V>>getListeners()com.google.common.collect.ImmutableMap<K,V>getMap()ConsulResponse<com.google.common.collect.ImmutableMap<K,V>>getMapWithMetadata()protected com.orbitz.consul.cache.ConsulCache.StategetState()booleanremoveListener(ConsulCache.Listener<K,V> listener)voidstart()voidstop()protected static QueryOptionswatchParams(java.math.BigInteger index, int blockSeconds, QueryOptions queryOptions)
-
-
-
Constructor Detail
-
ConsulCache
protected ConsulCache(java.util.function.Function<V,K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor)
-
ConsulCache
protected ConsulCache(java.util.function.Function<V,K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor, java.util.concurrent.ScheduledExecutorService callbackScheduleExecutorService)
-
ConsulCache
protected ConsulCache(java.util.function.Function<V,K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor, ConsulCache.Scheduler callbackScheduler)
-
-
Method Detail
-
start
public void start()
-
stop
public void stop()
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable
-
awaitInitialized
public boolean awaitInitialized(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
getMapWithMetadata
public ConsulResponse<com.google.common.collect.ImmutableMap<K,V>> getMapWithMetadata()
-
watchParams
protected static QueryOptions watchParams(java.math.BigInteger index, int blockSeconds, QueryOptions queryOptions)
-
createDefault
protected static ConsulCache.Scheduler createDefault()
-
createExternal
protected static ConsulCache.Scheduler createExternal(java.util.concurrent.ScheduledExecutorService executor)
-
addListener
public boolean addListener(ConsulCache.Listener<K,V> listener)
-
getListeners
public java.util.List<ConsulCache.Listener<K,V>> getListeners()
-
removeListener
public boolean removeListener(ConsulCache.Listener<K,V> listener)
-
getState
protected com.orbitz.consul.cache.ConsulCache.State getState()
-
-