001package org.avaje.metric.statistics; 002 003/** 004 * Can be used by {@link org.avaje.metric.MetricSupplier} when adapting metrics from an external source. 005 * <p> 006 * By default this is a non-bucket timed metric. 007 * </p> 008 */ 009public class TimedAdapter implements TimedStatistics { 010 011 private final String name; 012 private final long startTime; 013 private final long count; 014 private final long total; 015 private final long max; 016 017 /** 018 * Create with the metric name and values. 019 */ 020 public TimedAdapter(String name, long startTime, long count, long total, long max) { 021 this.name = name; 022 this.startTime = startTime; 023 this.count = count; 024 this.total = total; 025 this.max = max; 026 } 027 028 @Override 029 public boolean isBucket() { 030 return false; 031 } 032 033 @Override 034 public String getBucketRange() { 035 return null; 036 } 037 038 @Override 039 public long getStartTime() { 040 return startTime; 041 } 042 043 @Override 044 public long getCount() { 045 return count; 046 } 047 048 @Override 049 public long getTotal() { 050 return total; 051 } 052 053 @Override 054 public long getMax() { 055 return max; 056 } 057 058 @Override 059 public long getMean() { 060 return (count < 1) ? 0L : Math.round((double) (total / count)); 061 } 062 063 @Override 064 public String getName() { 065 return name; 066 } 067 068 @Override 069 public void visit(MetricStatisticsVisitor visitor) { 070 visitor.visit(this); 071 } 072}