Class AbstractStrongCounter
- All Implemented Interfaces:
org.infinispan.counter.api.StrongCounter,CounterEventGenerator,InternalCounterAdmin
- Direct Known Subclasses:
BoundedStrongCounter,UnboundedStrongCounter
Implementation: The value is stored in a single key and it uses the Infinispan's concurrency control and distribution to apply the write and reads. It uses the functional API.
Writes: The writes are performed by the functional API in order. The single key approach allows us to provide atomic properties for the counter value.
Reads: The reads read the value from the cache and it can go remotely.
Weak Reads: This implementation supports weak cached reads. It uses clustered listeners to receive the notifications of the actual value to store it locally.
- Since:
- 9.0
- Author:
- Pedro Ruivo
-
Method Summary
Modifier and TypeMethodDescriptionfinal CompletableFuture<Long> addAndGet(long delta) final <T extends org.infinispan.counter.api.CounterListener>
org.infinispan.counter.api.Handle<T> addListener(T listener) org.infinispan.counter.api.StrongCountercompareAndSwap(long expect, long update) destroy()Destroys the counter.org.infinispan.counter.api.CounterEventgenerate(CounterKey key, CounterValue value) It generates theCounterEvent.final org.infinispan.counter.api.CounterConfigurationfinal StringgetName()final CompletableFuture<Long> getValue()protected abstract longhandleAddResult(CounterValue counterValue) Extracts and validates the value after a read.protected abstract LonghandleCASResult(Object state) init()booleanChecks if the counter is aWeakCounter.remove()static CompletionStage<Void> removeStrongCounter(org.infinispan.Cache<StrongCounterKey, CounterValue> cache, String counterName) It removes a strong counter from thecache, identified by thecounterName.final CompletableFuture<Void> reset()Resets the counter to its initial value.org.infinispan.counter.api.SyncStrongCountersync()value()Returns the counter's value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.infinispan.counter.impl.manager.InternalCounterAdmin
asWeakCounterMethods inherited from interface org.infinispan.counter.api.StrongCounter
compareAndSet, decrementAndGet, incrementAndGet
-
Method Details
-
removeStrongCounter
public static CompletionStage<Void> removeStrongCounter(org.infinispan.Cache<StrongCounterKey, CounterValue> cache, String counterName) It removes a strong counter from thecache, identified by thecounterName.- Parameters:
cache- TheCacheto remove the counter from.counterName- The counter's name.
-
init
-
asStrongCounter
public org.infinispan.counter.api.StrongCounter asStrongCounter()- Specified by:
asStrongCounterin interfaceInternalCounterAdmin- Returns:
- The
StrongCounterinstance or throws anCounterExceptionif the counter is not aStrongCounter.
-
destroy
Description copied from interface:InternalCounterAdminDestroys the counter.It drops the counter's value and all listeners registered.
- Specified by:
destroyin interfaceInternalCounterAdmin- Returns:
- A
CompletionStageinstance which is completed when the operation finishes.
-
value
Description copied from interface:InternalCounterAdminReturns the counter's value.- Specified by:
valuein interfaceInternalCounterAdmin- Returns:
- A
CompletionStageinstance which is completed when the operation finishes.
-
isWeakCounter
public boolean isWeakCounter()Description copied from interface:InternalCounterAdminChecks if the counter is aWeakCounter.If
true, ensuresInternalCounterAdmin.asWeakCounter()never throws anCounterException. Otherwise, it ensuresInternalCounterAdmin.asStrongCounter()never throws anCounterException.- Specified by:
isWeakCounterin interfaceInternalCounterAdmin- Returns:
trueif the counter isWeakCounter.
-
getName
- Specified by:
getNamein interfaceorg.infinispan.counter.api.StrongCounter
-
getValue
- Specified by:
getValuein interfaceorg.infinispan.counter.api.StrongCounter
-
addAndGet
- Specified by:
addAndGetin interfaceorg.infinispan.counter.api.StrongCounter
-
reset
Description copied from interface:InternalCounterAdminResets the counter to its initial value.- Specified by:
resetin interfaceInternalCounterAdmin- Specified by:
resetin interfaceorg.infinispan.counter.api.StrongCounter- Returns:
- A
CompletionStageinstance which is completed when the operation finishes.
-
addListener
public final <T extends org.infinispan.counter.api.CounterListener> org.infinispan.counter.api.Handle<T> addListener(T listener) - Specified by:
addListenerin interfaceorg.infinispan.counter.api.StrongCounter
-
compareAndSwap
- Specified by:
compareAndSwapin interfaceorg.infinispan.counter.api.StrongCounter
-
generate
Description copied from interface:CounterEventGeneratorIt generates theCounterEvent.The
valueis the new value ofCounterEvent.- Specified by:
generatein interfaceCounterEventGenerator- Parameters:
key- The counter's key.value- The counter's most recentCounterValue.- Returns:
- The
CounterEventwith the updated value.
-
remove
- Specified by:
removein interfaceorg.infinispan.counter.api.StrongCounter
-
getConfiguration
public final org.infinispan.counter.api.CounterConfiguration getConfiguration()- Specified by:
getConfigurationin interfaceorg.infinispan.counter.api.StrongCounter
-
sync
public org.infinispan.counter.api.SyncStrongCounter sync()- Specified by:
syncin interfaceorg.infinispan.counter.api.StrongCounter
-
handleCASResult
-
handleAddResult
Extracts and validates the value after a read.Any exception should be thrown using
CompletionException.- Parameters:
counterValue- The newCounterValue.- Returns:
- The new value stored in
CounterValue.
-