Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
  *
  * Copyright 2013 Netflix, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
 package com.netflix.stats.distribution;
 
 import java.util.Date;


A DataAccumulator that also publishes statistics about the "previous" buffer. This implements DataDistributionMBean and so can be registered as an MBean and accessed via JMX if desired.

Author(s):
netflixoss
Version:
$Revision: $
 
 public class DataDistribution extends DataAccumulator implements DataDistributionMBean {
 
     private long numValues = 0L;
     private double mean = 0.0;
     private double variance = 0.0;
     private double stddev = 0.0;
     private double min = 0.0;
     private double max = 0.0;
     private long ts = 0L;
     private long interval = 0L;
     private int size = 0;
     private final double[] percents;
     private final double[] percentiles;

    
Creates a new DataDistribution with no data summarized.

Parameters:
bufferSize the size of each buffer held by the DataAccumulator
percents array of percentile values to calculate when buffers are swapped and new data is published. The array values must be in the range [0 .. 100].
 
     @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "EI_EXPOSE_REP2")
     public DataDistribution(int bufferSizedouble[] percents) {
         super(bufferSize);
         assert percentsOK(percents);
         this. = percents;
         this. = new double[percents.length];
     }
 
     private static boolean percentsOK(double[] percents) {
         if (percents == null) {
             return false;
         }
         for (int i = 0; i < percents.lengthi++) {
             if (percents[i] < 0.0 || percents[i] > 100.0) { // SUPPRESS CHECKSTYLE MagicNumber
                 return false;
             }
         }
         return true;
     }

    
 
     protected void publish(DataBuffer buf) {
          = System.currentTimeMillis();
          = buf.getNumValues();
          = buf.getMean();
          = buf.getVariance();
          = buf.getStdDev();
          = buf.getMinimum();
          = buf.getMaximum();
          = buf.getSampleIntervalMillis();
          = buf.getSampleSize();
         buf.getPercentiles();
     }
 
     /*
      * DataDistributionMBean protocol
      */

    
 
     public void clear() {
          = 0L;
          = 0.0;
          = 0.0;
          = 0.0;
          = 0.0;
          = 0.0;
          = 0L;
         = 0L;
         = 0;
        for (int i = 0; i < .i++) {
            [i] = 0.0;
        }
    }

    
    public long getNumValues() {
        return ;
    }

    
    public double getMean() {
        return ;
    }

    
    public double getVariance() {
        return ;
    }

    
    public double getStdDev() {
        return ;
    }

    
    public double getMinimum() {
        return ;
    }

    
    public double getMaximum() {
        return ;
    }

    
    public String getTimestamp() {
        return new Date(getTimestampMillis()).toString();
    }

    
    public long getTimestampMillis() {
        return ;
    }

    
    public long getSampleIntervalMillis() {
        return ;
    }

    
    public int getSampleSize() {
        return ;
    }

    
    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "EI_EXPOSE_REP")
    public double[] getPercents() {
        return ;
    }

    
    @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "EI_EXPOSE_REP")
    public double[] getPercentiles() {
        return ;
    }
// DataDistribution
New to GrepCode? Check out our FAQ X