001package org.javasimon.callback.quantiles; 002 003import org.javasimon.Stopwatch; 004import org.javasimon.clock.SimonClock; 005 006/** 007 * Callback which stores data in buckets to compute quantiles. 008 * Buckets are create using constant configuration. 009 * 010 * @author gquintana 011 */ 012public class FixedQuantilesCallback extends QuantilesCallback { 013 014 /** Buckets lower bound in milliseconds. */ 015 private final long min; 016 /** Buckets upper bound in milliseconds. */ 017 private final long max; 018 /** Number of buckets. */ 019 private final int bucketNb; 020 021 /** Main constructor. */ 022 public FixedQuantilesCallback(long min, long max, int bucketNb) { 023 this.min = min; 024 this.max = max; 025 this.bucketNb = bucketNb; 026 } 027 028 /** 029 * Constructor with all configuration 030 * 031 * @param bucketsType Linear or exponential 032 * @param min Min 033 * @param max Max 034 * @param bucketNb Number of buckets 035 */ 036 public FixedQuantilesCallback(BucketsType bucketsType, long min, long max, int bucketNb) { 037 super(bucketsType); 038 this.min = min; 039 this.max = max; 040 this.bucketNb = bucketNb; 041 } 042 043 /** 044 * Create buckets using callback attributes 045 * 046 * @param stopwatch Target stopwatch 047 * @return Created buckets 048 */ 049 @Override 050 protected Buckets createBuckets(Stopwatch stopwatch) { 051 return createBuckets(stopwatch, min * SimonClock.NANOS_IN_MILLIS, max * SimonClock.NANOS_IN_MILLIS, bucketNb); 052 } 053 054 public long getMin() { 055 return min; 056 } 057 058 public long getMax() { 059 return max; 060 } 061 062 public int getBucketNb() { 063 return bucketNb; 064 } 065}