Class MetricContext

  • All Implemented Interfaces:
    Iterable<BaseContext>

    public final class MetricContext
    extends BaseContext
    Child context that supplies instructions to the runtime actions about timers to start and stop to measure performance.
    • Constructor Detail

      • MetricContext

        public MetricContext()
        Constructor.
    • Method Detail

      • addTimer

        @Nonnull
        public MetricContext addTimer​(@Nonnull @NotEmpty
                                      String timerName,
                                      @Nonnull @NotEmpty
                                      String startId,
                                      @Nonnull @NotEmpty
                                      String stopId)
        Add an object/timer mapping.
        Parameters:
        timerName - name of timer
        startId - ID of object to start timer with
        stopId - ID of object to stop timer
        Returns:
        this context
      • getTimerMappings

        @Nonnull
        @NonnullElements
        @Live
        public Collection<Pair<String,​String>> getTimerMappings​(@Nonnull @NotEmpty
                                                                      String objectId)
        Get a modifiable collection of timer name / stop object pairs for the supplied start object ID.
        Parameters:
        objectId - the object ID input
        Returns:
        the collection of associated mappings
      • addCounter

        @Nonnull
        public MetricContext addCounter​(@Nonnull @NotEmpty
                                        String counterName,
                                        @Nonnull @NotEmpty
                                        String objectId)
        Add an object/counter mapping.
        Parameters:
        counterName - name of counter
        objectId - object ID
        Returns:
        this context
      • getCounterMappings

        @Nonnull
        @NonnullElements
        @Live
        public Map<String,​String> getCounterMappings()
        Get a modifiable map of object/counter associations.
        Returns:
        map of counters
      • start

        public void start​(@Nonnull @NotEmpty
                          String objectId)
        Conditionally starts one or more timers based on the supplied object identifier.

        The configured state of the context is used to determine whether, and which, timers to start, further influenced by the runtime state of the system with regard to enabling of metrics.

        Parameters:
        objectId - ID of the object being timed
      • stop

        public void stop​(@Nonnull @NotEmpty
                         String objectId)
        Stops any timers associated with the supplied object identifier and removes them from the tracking map.
        Parameters:
        objectId - ID of the object being timed
      • inc

        public void inc​(@Nonnull @NotEmpty
                        String objectId)
        Increment a counter associated with an object, if any.
        Parameters:
        objectId - ID of object
      • dec

        public void dec​(@Nonnull @NotEmpty
                        String objectId)
        Decrement a counter associated with an object, if any.
        Parameters:
        objectId - ID of object