Class WeakCounterImpl
- java.lang.Object
-
- org.infinispan.counter.impl.weak.WeakCounterImpl
-
- All Implemented Interfaces:
org.infinispan.counter.api.WeakCounter,CounterEventGenerator,TopologyChangeListener
public class WeakCounterImpl extends Object implements org.infinispan.counter.api.WeakCounter, CounterEventGenerator, TopologyChangeListener
A weak consistent counter implementation.Implementation: The counter is split in multiple keys and they are stored in the cache.
Write: A write operation will pick a key to update. If the node is a primary owner of one of the key, that key is chosen based on thread-id. This will take advantage of faster write operations. If the node is not a primary owner, one of the key in key set is chosen.
Read: A read operation needs to read all the key set (including the remote keys). This is slower than atomic counter.
Weak Read: A snapshot of all the keys values is kept locally and they are updated via cluster listeners.
Reset: The reset operation is not atomic and intermediate results may be observed.
- Since:
- 9.0
- Author:
- Pedro Ruivo
-
-
Constructor Summary
Constructors Constructor Description WeakCounterImpl(String counterName, org.infinispan.AdvancedCache<WeakCounterKey,CounterValue> cache, org.infinispan.counter.api.CounterConfiguration configuration, CounterManagerNotificationManager notificationManager)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompletableFuture<Void>add(long delta)<T extends org.infinispan.counter.api.CounterListener>
org.infinispan.counter.api.Handle<T>addListener(T listener)voiddestroyAndRemove()org.infinispan.counter.api.CounterEventgenerate(CounterKey key, CounterValue value)It generates theCounterEvent.org.infinispan.counter.api.CounterConfigurationgetConfiguration()WeakCounterKey[]getKeys()Debug only!StringgetName()WeakCounterKey[]getPreferredKeys()Debug only!longgetValue()voidinit()Initializes the key set.CompletableFuture<Void>remove()static voidremoveWeakCounter(org.infinispan.Cache<WeakCounterKey,CounterValue> cache, org.infinispan.counter.api.CounterConfiguration configuration, String counterName)It removes a weak counter from thecache, identified by thecounterName.CompletableFuture<Void>reset()org.infinispan.counter.api.SyncWeakCountersync()voidtopologyChanged()It notifies the cache topology change.StringtoString()
-
-
-
Constructor Detail
-
WeakCounterImpl
public WeakCounterImpl(String counterName, org.infinispan.AdvancedCache<WeakCounterKey,CounterValue> cache, org.infinispan.counter.api.CounterConfiguration configuration, CounterManagerNotificationManager notificationManager)
-
-
Method Detail
-
removeWeakCounter
public static void removeWeakCounter(org.infinispan.Cache<WeakCounterKey,CounterValue> cache, org.infinispan.counter.api.CounterConfiguration configuration, String counterName)
It removes a weak counter from thecache, identified by thecounterName.- Parameters:
cache- TheCacheto remove the counter from.configuration- The counter's configuration.counterName- The counter's name.
-
init
public void init()
Initializes the key set.Only one key will have the initial value and the remaining is zero.
-
getName
public String getName()
- Specified by:
getNamein interfaceorg.infinispan.counter.api.WeakCounter
-
getValue
public long getValue()
- Specified by:
getValuein interfaceorg.infinispan.counter.api.WeakCounter
-
add
public CompletableFuture<Void> add(long delta)
- Specified by:
addin interfaceorg.infinispan.counter.api.WeakCounter
-
reset
public CompletableFuture<Void> reset()
- Specified by:
resetin interfaceorg.infinispan.counter.api.WeakCounter
-
addListener
public <T extends org.infinispan.counter.api.CounterListener> org.infinispan.counter.api.Handle<T> addListener(T listener)
- Specified by:
addListenerin interfaceorg.infinispan.counter.api.WeakCounter
-
getConfiguration
public org.infinispan.counter.api.CounterConfiguration getConfiguration()
- Specified by:
getConfigurationin interfaceorg.infinispan.counter.api.WeakCounter
-
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.WeakCounter
-
sync
public org.infinispan.counter.api.SyncWeakCounter sync()
- Specified by:
syncin interfaceorg.infinispan.counter.api.WeakCounter
-
destroyAndRemove
public void destroyAndRemove()
-
topologyChanged
public void topologyChanged()
Description copied from interface:TopologyChangeListenerIt notifies the cache topology change.- Specified by:
topologyChangedin interfaceTopologyChangeListener
-
getPreferredKeys
public WeakCounterKey[] getPreferredKeys()
Debug only!
-
getKeys
public WeakCounterKey[] getKeys()
Debug only!
-
-