
org.apache.dubbo.metrics.model.container.LongContainer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dubbo Show documentation
Show all versions of dubbo Show documentation
The all in one project of dubbo
/*
* 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 org.apache.dubbo.metrics.model.container;
import org.apache.dubbo.metrics.model.Metric;
import org.apache.dubbo.metrics.model.key.MetricsKey;
import org.apache.dubbo.metrics.model.key.MetricsKeyWrapper;
import org.apache.dubbo.metrics.model.sample.GaugeMetricSample;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* Long type data container
* @param
*/
public class LongContainer extends ConcurrentHashMap {
/**
* Provide the metric type name
*/
private final transient MetricsKeyWrapper metricsKeyWrapper;
/**
* The initial value corresponding to the key is generally 0 of different data types
*/
private final transient Function initFunc;
/**
* Statistical data calculation function, which can be self-increment, self-decrement, or more complex avg function
*/
private final transient BiConsumer consumerFunc;
/**
* Data output function required by {@link GaugeMetricSample GaugeMetricSample}
*/
private transient Function valueSupplier;
public LongContainer(MetricsKeyWrapper metricsKeyWrapper, Supplier initFunc, BiConsumer consumerFunc) {
super(128, 0.5f);
this.metricsKeyWrapper = metricsKeyWrapper;
this.initFunc = s -> initFunc.get();
this.consumerFunc = consumerFunc;
this.valueSupplier = k -> this.get(k).longValue();
}
public boolean specifyType(String type) {
return type.equals(getMetricsKeyWrapper().getType());
}
public MetricsKeyWrapper getMetricsKeyWrapper() {
return metricsKeyWrapper;
}
public boolean isKeyWrapper(MetricsKey metricsKey, String registryOpType) {
return metricsKeyWrapper.isKey(metricsKey, registryOpType);
}
public Function getInitFunc() {
return initFunc;
}
public BiConsumer getConsumerFunc() {
return consumerFunc;
}
public Function getValueSupplier() {
return valueSupplier;
}
public void setValueSupplier(Function valueSupplier) {
this.valueSupplier = valueSupplier;
}
@Override
public String toString() {
return "LongContainer{" + "metricsKeyWrapper=" + metricsKeyWrapper + '}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
LongContainer> that = (LongContainer>) o;
return metricsKeyWrapper.equals(that.metricsKeyWrapper);
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + metricsKeyWrapper.hashCode();
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy