Class AbstractStrongCounter
- java.lang.Object
-
- org.infinispan.counter.impl.strong.AbstractStrongCounter
-
- All Implemented Interfaces:
org.infinispan.counter.api.StrongCounter,CounterEventGenerator
- Direct Known Subclasses:
BoundedStrongCounter,UnboundedStrongCounter
public abstract class AbstractStrongCounter extends Object implements org.infinispan.counter.api.StrongCounter, CounterEventGenerator
A base strong consistent counter implementation.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
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Long>addAndGet(long delta)<T extends org.infinispan.counter.api.CounterListener>
org.infinispan.counter.api.Handle<T>addListener(T listener)CompletableFuture<Long>compareAndSwap(long expect, long update)voiddestroyAndRemove()org.infinispan.counter.api.CounterEventgenerate(CounterKey key, CounterValue value)It generates theCounterEvent.org.infinispan.counter.api.CounterConfigurationgetConfiguration()StringgetName()CompletableFuture<Long>getValue()protected abstract longhandleAddResult(CounterValue counterValue)Extracts and validates the value after a read.protected abstract LonghandleCASResult(Object state)voidinit()CompletableFuture<Void>remove()static voidremoveStrongCounter(org.infinispan.Cache<StrongCounterKey,CounterValue> cache, String counterName)It removes a strong counter from thecache, identified by thecounterName.CompletableFuture<Void>reset()org.infinispan.counter.api.SyncStrongCountersync()
-
-
-
Method Detail
-
removeStrongCounter
public static 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
public final void init()
-
getName
public final String getName()
- Specified by:
getNamein interfaceorg.infinispan.counter.api.StrongCounter
-
getValue
public final CompletableFuture<Long> getValue()
- Specified by:
getValuein interfaceorg.infinispan.counter.api.StrongCounter
-
addAndGet
public final CompletableFuture<Long> addAndGet(long delta)
- Specified by:
addAndGetin interfaceorg.infinispan.counter.api.StrongCounter
-
reset
public final CompletableFuture<Void> reset()
- Specified by:
resetin interfaceorg.infinispan.counter.api.StrongCounter
-
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
public CompletableFuture<Long> compareAndSwap(long expect, long update)
- Specified by:
compareAndSwapin interfaceorg.infinispan.counter.api.StrongCounter
-
generate
public org.infinispan.counter.api.CounterEvent generate(CounterKey key, CounterValue value)
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
public CompletableFuture<Void> 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
-
destroyAndRemove
public void destroyAndRemove()
-
handleAddResult
protected abstract long handleAddResult(CounterValue counterValue)
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.
-
-