Interface CounterManager
- All Known Implementing Classes:
RemoteCounterManager
CounterManager creates, 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) and isDefined(String) returns if the counter is defined or not.
The counter can be retrieved/created using the getStrongCounter(String) or getWeakCounter(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 the getWeakCounter("test".
- Since:
- 9.0
- Author:
- Pedro Ruivo
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleandefineCounter(String name, CounterConfiguration configuration) Defines a counter with the specificnameandCounterConfiguration.getConfiguration(String counterName) Returns aCollectionof defined counter names.getStrongCounter(String name) Returns theStrongCounterwith that specific name.getWeakCounter(String name) Returns theWeakCounterwith that specific name.booleanvoidIt removes the counter from the cluster.voidundefineCounter(String name) It removes the counter and its configuration from the cluster.
-
Method Details
-
getStrongCounter
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
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
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.
-
undefineCounter
It removes the counter and its configuration from the cluster.- Parameters:
name- The counter's name to remove
-
isDefined
- Parameters:
name- the counter name.- Returns:
trueif the counter is defined orfalseif the counter is not defined or fails to check.
-
getConfiguration
- Parameters:
counterName- the counter name.- Returns:
- the counter's
CounterConfigurationornullif the counter is not defined.
-
remove
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.
-