@SuppressWarnings("unchecked") protected synchronized <T extends ContextAwareMetric> T getOrCreate(String name, ContextAwareMetricFactory<T> factory) { InnerMetric metric = this.contextAwareMetrics.get(name); if (metric != null) { if (factory.isInstance(metric)) { return (T) metric.getContextAwareMetric(); } throw new IllegalArgumentException(name + " is already used for a different type of metric"); } T newMetric = factory.newMetric(this.metricContext.get(), name); this.register(name, newMetric); return newMetric; }
@BeforeClass public void setUp() { this.context = MetricContext.builder(CONTEXT_NAME).build(); this.counter = ContextAwareMetricFactory.DEFAULT_CONTEXT_AWARE_COUNTER_FACTORY.newMetric( this.context, RECORDS_PROCESSED); this.meter = ContextAwareMetricFactory.DEFAULT_CONTEXT_AWARE_METER_FACTORY.newMetric( this.context, RECORD_PROCESS_RATE); this.histogram = ContextAwareMetricFactory.DEFAULT_CONTEXT_AWARE_HISTOGRAM_FACTORY.newMetric( this.context, RECORD_SIZE_DISTRIBUTION); this.timer = ContextAwareMetricFactory.DEFAULT_CONTEXT_AWARE_TIMER_FACTORY.newMetric( this.context, TOTAL_DURATION); }
@SuppressWarnings("unchecked") protected synchronized <T extends ContextAwareMetric> T getOrCreate( ContextAwareMetricFactory<T> factory, ContextAwareMetricFactoryArgs args) { String name = args.getName(); InnerMetric metric = this.contextAwareMetrics.get(name); if (metric != null) { if (factory.isInstance(metric)) { return (T) metric.getContextAwareMetric(); } throw new IllegalArgumentException(name + " is already used for a different type of metric"); } T newMetric = factory.newMetric(args); this.register(name, newMetric); return newMetric; }
@SuppressWarnings("unchecked") protected synchronized <T extends ContextAwareMetric> T getOrCreate(String name, ContextAwareMetricFactory<T> factory) { InnerMetric metric = this.contextAwareMetrics.get(name); if (metric != null) { if (factory.isInstance(metric)) { return (T) metric.getContextAwareMetric(); } throw new IllegalArgumentException(name + " is already used for a different type of metric"); } T newMetric = factory.newMetric(this.metricContext.get(), name); this.register(name, newMetric); return newMetric; }
@SuppressWarnings("unchecked") protected synchronized <T extends ContextAwareMetric> T getOrCreate( ContextAwareMetricFactory<T> factory, ContextAwareMetricFactoryArgs args) { String name = args.getName(); InnerMetric metric = this.contextAwareMetrics.get(name); if (metric != null) { if (factory.isInstance(metric)) { return (T) metric.getContextAwareMetric(); } throw new IllegalArgumentException(name + " is already used for a different type of metric"); } T newMetric = factory.newMetric(args); this.register(name, newMetric); return newMetric; }