Interface CounterManager


  • public interface CounterManager
    The 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:
    CounterConfiguration
    • Method Detail

      • defineCounter

        boolean defineCounter​(java.lang.String name,
                              CounterConfiguration configuration)
        Defines a counter with the specific name and CounterConfiguration.

        It does not overwrite existing configurations.

        Parameters:
        name - the counter name.
        configuration - the counter configuration
        Returns:
        true if successfully defined or false if the counter exists or fails to defined.
      • undefineCounter

        void undefineCounter​(java.lang.String name)
        It removes the counter and its configuration from the cluster.
        Parameters:
        name - The counter's name to remove
      • isDefined

        boolean isDefined​(java.lang.String name)
        Parameters:
        name - the counter name.
        Returns:
        true if the counter is defined or false if the counter is not defined or fails to check.
      • getConfiguration

        CounterConfiguration getConfiguration​(java.lang.String counterName)
        Parameters:
        counterName - the counter name.
        Returns:
        the counter's CounterConfiguration or null if the counter is not defined.
      • remove

        void remove​(java.lang.String counterName)
        It removes the counter from the cluster.

        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.

        Parameters:
        counterName - The counter's name to remove.
      • getCounterNames

        java.util.Collection<java.lang.String> getCounterNames()
        Returns a Collection of defined counter names.
        Returns:
        a Collection of defined counter names.