Package org.kiwiproject.consul.cache
Class ConsulCache<K,V>
java.lang.Object
org.kiwiproject.consul.cache.ConsulCache<K,V>
- Type Parameters:
K- the type of keys this cache containsV- the type of values this cache contains
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
HealthCheckCache,KVCache,NodesCatalogCache,ServiceCatalogCache,ServiceHealthCache
A cache structure that can provide an up-to-date read-only
map backed by consul data
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfacepassed in by creators to vary the content of the cached valuesstatic interfaceImplementers can register a listener to receive a new map when it changesprotected static classstatic enumRepresents the possible states of a ConsulCache. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConsulCache(Function<V, K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor) protectedConsulCache(Function<V, K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor, ScheduledExecutorService callbackScheduleExecutorService) protectedConsulCache(Function<V, K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor, ConsulCache.Scheduler callbackScheduler) -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddListener(ConsulCache.Listener<K, V> listener) Add a new listener.booleanawaitInitialized(long timeout, TimeUnit unit) protected static voidcheckWatch(int networkReadMillis, int cacheWatchSeconds) voidclose()protected static ConsulCache.Schedulerprotected static ConsulCache.SchedulercreateExternal(ScheduledExecutorService executor) getMap()ConsulResponse<com.google.common.collect.ImmutableMap<K,V>> getState()booleanremoveListener(ConsulCache.Listener<K, V> listener) voidstart()voidstop()protected static QueryOptionswatchParams(BigInteger index, int blockSeconds, QueryOptions queryOptions)
-
Constructor Details
-
ConsulCache
protected ConsulCache(Function<V, K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor) -
ConsulCache
protected ConsulCache(Function<V, K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor, ScheduledExecutorService callbackScheduleExecutorService) -
ConsulCache
protected ConsulCache(Function<V, K> keyConversion, ConsulCache.CallbackConsumer<V> callbackConsumer, CacheConfig cacheConfig, ClientEventHandler eventHandler, CacheDescriptor cacheDescriptor, ConsulCache.Scheduler callbackScheduler)
-
-
Method Details
-
start
public void start() -
stop
public void stop() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
awaitInitialized
- Throws:
InterruptedException
-
getMap
-
getMapWithMetadata
-
watchParams
protected static QueryOptions watchParams(BigInteger index, int blockSeconds, QueryOptions queryOptions) -
createDefault
-
createExternal
-
addListener
Add a new listener.- Parameters:
listener- the listener to add- Returns:
- true to indicate the listener was added
- Implementation Note:
- This always returns true because
CopyOnWriteArrayListis used to store the listeners, and itsCopyOnWriteArrayList.add(Object)method always returns true
-
getListeners
-
removeListener
-
getState
-
checkWatch
protected static void checkWatch(int networkReadMillis, int cacheWatchSeconds)
-