public interface CounterManager
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".
CounterConfiguration| Modifier and Type | Method and Description |
|---|---|
boolean |
defineCounter(String name,
CounterConfiguration configuration)
Defines a counter with the specific
name and CounterConfiguration. |
CounterConfiguration |
getConfiguration(String counterName) |
Collection<String> |
getCounterNames()
Returns a
Collection of defined counter names. |
StrongCounter |
getStrongCounter(String name)
Returns the
StrongCounter with that specific name. |
WeakCounter |
getWeakCounter(String name)
Returns the
WeakCounter with that specific name. |
boolean |
isDefined(String name) |
void |
remove(String counterName)
It removes the counter from the cluster.
|
StrongCounter getStrongCounter(String name)
StrongCounter with that specific name.
If the StrongCounter does not exists, it is created based on the CounterConfiguration.
Note that the counter must be defined prior to this method invocation using defineCounter(String, CounterConfiguration) or via global configuration. This method only supports
CounterType.BOUNDED_STRONG and CounterType.UNBOUNDED_STRONG counters.
name - the counter name.StrongCounter instance.CounterException - if unable to retrieve the counter.CounterConfigurationException - if the counter configuration is not valid
or it does not exists.WeakCounter getWeakCounter(String name)
WeakCounter with that specific name.
If the WeakCounter does not exists, it is created based on the CounterConfiguration.
Note that the counter must be defined prior to this method invocation using defineCounter(String, CounterConfiguration) or via global configuration. This method only supports
CounterType.WEAK counters.
name - the counter name.WeakCounter instance.CounterException - if unable to retrieve the counter.CounterConfigurationException - if the counter configuration is not valid
or it does not exists.boolean defineCounter(String name, CounterConfiguration configuration)
name and CounterConfiguration.
It does not overwrite existing configurations.
name - the counter name.configuration - the counter configurationtrue if successfully defined or false if the counter exists or fails to defined.boolean isDefined(String name)
name - the counter name.true if the counter is defined or false if the counter is not defined or fails to check.CounterConfiguration getConfiguration(String counterName)
counterName - the counter name.CounterConfiguration or null if the counter is not defined.void remove(String counterName)
All instances returned by getWeakCounter(String) or getStrongCounter(String) are destroyed and
they shouldn't be used anymore. Also, the registered CounterListeners are removed and they aren't invoked
anymore.
counterName - The counter's name to remove.Collection<String> getCounterNames()
Collection of defined counter names.Collection of defined counter names.Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.