blob: b8307891bf127680cb83d27f53124025f80eaf54 [file] [log] [blame]
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.alibaba.jstorm.common.metric;
import java.util.concurrent.atomic.AtomicLong;
import com.alibaba.jstorm.common.metric.operator.convert.Convertor;
import com.alibaba.jstorm.common.metric.operator.merger.AvgMerger2;
import com.alibaba.jstorm.common.metric.operator.updater.AvgUpdater2;
import com.alibaba.jstorm.common.metric.window.Metric;
import com.alibaba.jstorm.utils.Pair;
import com.google.common.util.concurrent.AtomicDouble;
/**
* Meter is used to compute tps
*
* Attention: 1.
*
* @author zhongyan.feng
*
*/
public class Histogram extends Metric<Double, Pair<AtomicDouble, AtomicLong>> {
private static final long serialVersionUID = -1362345159511508074L;
public Histogram() {
defaultValue =
new Pair<AtomicDouble, AtomicLong>(new AtomicDouble(0.0),
new AtomicLong(0));
updater = new AvgUpdater2();
merger = new AvgMerger2();
convertor = new HistogramConvertor();
init();
}
public static class HistogramConvertor implements
Convertor<Pair<AtomicDouble, AtomicLong>, Double> {
private static final long serialVersionUID = -1569170826785657226L;
@Override
public Double convert(Pair<AtomicDouble, AtomicLong> from) {
// TODO Auto-generated method stub
if (from == null) {
return 0.0d;
}
if (from.getSecond().get() == 0) {
return 0.0d;
} else {
return from.getFirst().get() / from.getSecond().get();
}
}
}
}