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 TypeMethodDescriptionboolean
defineCounter
(String name, CounterConfiguration configuration) Defines a counter with the specificname
andCounterConfiguration
.getConfiguration
(String counterName) Returns aCollection
of defined counter names.getStrongCounter
(String name) Returns theStrongCounter
with that specific name.getWeakCounter
(String name) Returns theWeakCounter
with that specific name.boolean
void
It removes the counter from the cluster.void
undefineCounter
(String name) It removes the counter and its configuration from the cluster.
-
Method Details
-
getStrongCounter
Returns theStrongCounter
with that specific name.If the
StrongCounter
does 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_STRONG
andCounterType.UNBOUNDED_STRONG
counters.- Parameters:
name
- the counter name.- Returns:
- the
StrongCounter
instance. - Throws:
CounterException
- if unable to retrieve the counter.CounterConfigurationException
- if the counter configuration is not valid or it does not exists.
-
getWeakCounter
Returns theWeakCounter
with that specific name.If the
WeakCounter
does 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.WEAK
counters.- Parameters:
name
- the counter name.- Returns:
- the
WeakCounter
instance. - 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 specificname
andCounterConfiguration
.It does not overwrite existing configurations.
- Parameters:
name
- the counter name.configuration
- the counter configuration- Returns:
true
if successfully defined orfalse
if 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:
true
if the counter is defined orfalse
if the counter is not defined or fails to check.
-
getConfiguration
- Parameters:
counterName
- the counter name.- Returns:
- the counter's
CounterConfiguration
ornull
if 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 registeredCounterListener
s are removed and they aren't invoked anymore.- Parameters:
counterName
- The counter's name to remove.
-
getCounterNames
Collection<String> getCounterNames()Returns aCollection
of defined counter names.- Returns:
- a
Collection
of defined counter names.
-