Interface CounterManager
-
- All Known Implementing Classes:
RemoteCounterManager
public interface CounterManager
TheCounterManager
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)
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 boolean
defineCounter(String name, CounterConfiguration configuration)
Defines a counter with the specificname
andCounterConfiguration
.CounterConfiguration
getConfiguration(String counterName)
Collection<String>
getCounterNames()
Returns aCollection
of defined counter names.StrongCounter
getStrongCounter(String name)
Returns theStrongCounter
with that specific name.WeakCounter
getWeakCounter(String name)
Returns theWeakCounter
with that specific name.boolean
isDefined(String name)
void
remove(String counterName)
It removes the counter from the cluster.
-
-
-
Method Detail
-
getStrongCounter
StrongCounter getStrongCounter(String name)
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
WeakCounter getWeakCounter(String name)
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
boolean defineCounter(String name, CounterConfiguration configuration)
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.
-
isDefined
boolean isDefined(String name)
- Parameters:
name
- the counter name.- Returns:
true
if the counter is defined orfalse
if the counter is not defined or fails to check.
-
getConfiguration
CounterConfiguration getConfiguration(String counterName)
- Parameters:
counterName
- the counter name.- Returns:
- the counter's
CounterConfiguration
ornull
if 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 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.
-
-