Interface MetricConsumer


  • public interface MetricConsumer

    This interface defines the consumer counterpart of the Metric interface. All Metric objects contain their own thread local instance of this interface, so most implementations will require a registry of sorts to manage the aggregation of state across MetricConsumers.

    An Application needs to bind a Provider of this interface to an implementation, or else all calls to the Metric objects become no-ops. An implementation will look similar to:

     private final MyMetricRegistry myMetricRegistry = new MyMetricRegistry();
     void createContainer() {
         ContainerBuilder builder = containerActivator.newContainerBuilder();
         builder.guice().install(new MyGuiceModule());
         (...)
     }
     class MyGuiceModule extends com.google.inject.AbstractModule {
         void configure() {
             bind(MetricConsumer.class).toProvider(myMetricRegistry);
             (...)
         }
     }
     class MyMetricRegistry implements com.google.inject.Provider<MetricConsumer> {
         (...)
     }
     
    Author:
    Simon Thoresen Hult
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void add​(java.lang.String key, java.lang.Number val, Metric.Context ctx)
      Consume a call to Metric.add(String, Number, Metric.Context).
      Metric.Context createContext​(java.util.Map<java.lang.String,​?> properties)
      Creates a Metric.Context object that encapsulates the given properties.
      void set​(java.lang.String key, java.lang.Number val, Metric.Context ctx)
      Consume a call to Metric.set(String, Number, Metric.Context).
    • Method Detail

      • set

        void set​(java.lang.String key,
                 java.lang.Number val,
                 Metric.Context ctx)

        Consume a call to Metric.set(String, Number, Metric.Context).

        Parameters:
        key - The name of the metric to modify.
        val - The value to assign to the named metric.
        ctx - The context to further describe this entry.
      • add

        void add​(java.lang.String key,
                 java.lang.Number val,
                 Metric.Context ctx)

        Consume a call to Metric.add(String, Number, Metric.Context).

        Parameters:
        key - The name of the metric to modify.
        val - The value to add to the named metric.
        ctx - The context to further describe this entry.
      • createContext

        Metric.Context createContext​(java.util.Map<java.lang.String,​?> properties)

        Creates a Metric.Context object that encapsulates the given properties. The returned Context object will be passed along every future call to set(String, Number, Metric.Context) and add(String, Number, Metric.Context) where the properties match those given here.

        Parameters:
        properties - The properties to incorporate in the context.
        Returns:
        The created context.