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".

    Pedro Ruivo
    See Also:
    • 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.

        name - the counter name.
        configuration - the counter configuration
        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.
        name - The counter's name to remove
      • isDefined

        boolean isDefined​(java.lang.String name)
        name - the counter name.
        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)
        counterName - the counter name.
        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.

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

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