Interface CounterManager
-
public interface CounterManagerTheCounterManagercreates, defines and returns counters.It is thread-safe in the way that multiples threads can retrieve/create counters concurrently. If it is the first time a counter is created, other concurrent threads may block until it is properly initialized.
A counter can be defined using
defineCounter(String, CounterConfiguration)andisDefined(String)returns if the counter is defined or not.The counter can be retrieved/created using the
getStrongCounter(String)orgetWeakCounter(String)to return an (un)bounded strong counter or weak counter. The operation will fail if the counter is defined with a different type. For example, define a strong counter"test"and try to retrieve using thegetWeakCounter("test".- Since:
- 9.0
- Author:
- Pedro Ruivo
- See Also:
CounterConfiguration
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleandefineCounter(String name, CounterConfiguration configuration)Defines a counter with the specificnameandCounterConfiguration.CounterConfigurationgetConfiguration(String counterName)Collection<String>getCounterNames()Returns aCollectionof defined counter names.StrongCountergetStrongCounter(String name)Returns theStrongCounterwith that specific name.WeakCountergetWeakCounter(String name)Returns theWeakCounterwith that specific name.booleanisDefined(String name)voidremove(String counterName)It removes the counter from the cluster.
-
-
-
Method Detail
-
getStrongCounter
StrongCounter getStrongCounter(String name)
Returns theStrongCounterwith that specific name.If the
StrongCounterdoes not exists, it is created based on theCounterConfiguration.Note that the counter must be defined prior to this method invocation using
defineCounter(String, CounterConfiguration)or via global configuration. This method only supportsCounterType.BOUNDED_STRONGandCounterType.UNBOUNDED_STRONGcounters.- Parameters:
name- the counter name.- Returns:
- the
StrongCounterinstance. - Throws:
CounterException- if unable to retrieve the counter.CounterConfigurationException- if the counter configuration is not valid or it does not exists.
-
getWeakCounter
WeakCounter getWeakCounter(String name)
Returns theWeakCounterwith that specific name.If the
WeakCounterdoes not exists, it is created based on theCounterConfiguration.Note that the counter must be defined prior to this method invocation using
defineCounter(String, CounterConfiguration)or via global configuration. This method only supportsCounterType.WEAKcounters.- Parameters:
name- the counter name.- Returns:
- the
WeakCounterinstance. - Throws:
CounterException- if unable to retrieve the counter.CounterConfigurationException- if the counter configuration is not valid or it does not exists.
-
defineCounter
boolean defineCounter(String name, CounterConfiguration configuration)
Defines a counter with the specificnameandCounterConfiguration.It does not overwrite existing configurations.
- Parameters:
name- the counter name.configuration- the counter configuration- Returns:
trueif successfully defined orfalseif the counter exists or fails to defined.
-
isDefined
boolean isDefined(String name)
- Parameters:
name- the counter name.- Returns:
trueif the counter is defined orfalseif the counter is not defined or fails to check.
-
getConfiguration
CounterConfiguration getConfiguration(String counterName)
- Parameters:
counterName- the counter name.- Returns:
- the counter's
CounterConfigurationornullif the counter is not defined.
-
remove
void remove(String counterName)
It removes the counter from the cluster.All instances returned by
getWeakCounter(String)orgetStrongCounter(String)are destroyed and they shouldn't be used anymore. Also, the registeredCounterListeners are removed and they aren't invoked anymore.- Parameters:
counterName- The counter's name to remove.
-
getCounterNames
Collection<String> getCounterNames()
Returns aCollectionof defined counter names.- Returns:
- a
Collectionof defined counter names.
-
-