Class WeakCounterImpl
- All Implemented Interfaces:
org.infinispan.counter.api.WeakCounter,CounterEventGenerator,TopologyChangeListener,InternalCounterAdmin
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
ConstructorsConstructorDescriptionWeakCounterImpl(String counterName, org.infinispan.AdvancedCache<WeakCounterKey, CounterValue> cache, org.infinispan.counter.api.CounterConfiguration configuration, CounterManagerNotificationManager notificationManager) -
Method Summary
Modifier and TypeMethodDescriptionadd(long delta) <T extends org.infinispan.counter.api.CounterListener>
org.infinispan.counter.api.Handle<T>addListener(T listener) org.infinispan.counter.api.WeakCounterdestroy()Destroys the counter.org.infinispan.counter.api.CounterEventgenerate(CounterKey key, CounterValue value) It generates theCounterEvent.org.infinispan.counter.api.CounterConfigurationgetKeys()Debug only!getName()Debug only!longgetValue()init()Initializes the key set.booleanChecks if the counter is aWeakCounter.remove()static CompletionStage<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.reset()Resets the counter to its initial value.org.infinispan.counter.api.SyncWeakCountersync()voidIt notifies the cache topology change.toString()value()Returns the counter's value.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.infinispan.counter.impl.manager.InternalCounterAdmin
asStrongCounterMethods inherited from interface org.infinispan.counter.api.WeakCounter
decrement, increment
-
Constructor Details
-
WeakCounterImpl
public WeakCounterImpl(String counterName, org.infinispan.AdvancedCache<WeakCounterKey, CounterValue> cache, org.infinispan.counter.api.CounterConfiguration configuration, CounterManagerNotificationManager notificationManager)
-
-
Method Details
-
removeWeakCounter
public static CompletionStage<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
Initializes the key set.Only one key will have the initial value and the remaining is zero.
-
getName
- Specified by:
getNamein interfaceorg.infinispan.counter.api.WeakCounter
-
getValue
public long getValue()- Specified by:
getValuein interfaceorg.infinispan.counter.api.WeakCounter
-
add
- Specified by:
addin interfaceorg.infinispan.counter.api.WeakCounter
-
asWeakCounter
public org.infinispan.counter.api.WeakCounter asWeakCounter()- Specified by:
asWeakCounterin interfaceInternalCounterAdmin- Returns:
- The
WeakCounterinstance or throws anCounterExceptionif the counter is not aWeakCounter.
-
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.
-
reset
Description copied from interface:InternalCounterAdminResets the counter to its initial value.- Specified by:
resetin interfaceInternalCounterAdmin- Specified by:
resetin interfaceorg.infinispan.counter.api.WeakCounter- 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.
-
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
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.WeakCounter
-
sync
public org.infinispan.counter.api.SyncWeakCounter sync()- Specified by:
syncin interfaceorg.infinispan.counter.api.WeakCounter
-
topologyChanged
public void topologyChanged()Description copied from interface:TopologyChangeListenerIt notifies the cache topology change.- Specified by:
topologyChangedin interfaceTopologyChangeListener
-
getPreferredKeys
Debug only! -
getKeys
Debug only! -
toString
-