import { IReservoir , ReservoirType } from '../Reservoir' ; import { MetricType } from '../MetricType' ; import { BucketCounter } from './BucketCounter' ; import { UniformReservoir } from '../reservoir/UniformReservoir' ; import { ExponentiallyDecayingReservoir } from '../reservoir/ExponentiallyDecayingReservoir' ; import { BucketReservoir } from '../reservoir/BucketReservoir' ; import { Counting , Metric , Sampling , Snapshot } from '../domain' ; see export interface IHistogram extends Metric , Sampling , Counting { param value update ( value ) ; } export class BaseHistogram implements IHistogram { reservoir : IReservoir ; type = MetricType . HISTOGRAM ; count : BucketCounter ; constructor ( type = ReservoirType . EXPONENTIALLY_DECAYING , interval = 10 , numberOfBucket = 10 ) { this . count = new BucketCounter ( interval , numberOfBucket ) ; if ( typeof type === 'object' ) { this . reservoir = type ; } else { switch ( type ) { case ReservoirType . EXPONENTIALLY_DECAYING : this . reservoir = new ExponentiallyDecayingReservoir ( ) ; break ; case ReservoirType . UNIFORM : this . reservoir = new UniformReservoir ( 1024 ) ; break ; case ReservoirType . BUCKET : this . reservoir = new BucketReservoir ( interval , numberOfBucket , this . count ) ; break ; default : this . reservoir = new ExponentiallyDecayingReservoir ( ) ; } } } update ( value ) { this . count . update ( ) ; this . reservoir . update ( value ) ; } getCount ( ) { return this . count . getCount ( ) ; } getSnapshot ( ) { return this . reservoir . getSnapshot ( ) ; } }