Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Swirlds is a software platform designed to build fully-distributed applications that harness the power of the cloud without servers. Now you can develop applications with fairness in decision making, speed, trust and reliability, at a fraction of the cost of traditional server-based platforms.
/*
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC
*
* 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.swirlds.common.metrics;
import static com.swirlds.metrics.api.Metric.ValueType.MAX;
import static com.swirlds.metrics.api.Metric.ValueType.MIN;
import static com.swirlds.metrics.api.Metric.ValueType.STD_DEV;
import static com.swirlds.metrics.api.Metric.ValueType.VALUE;
import com.swirlds.base.utility.ToStringBuilder;
import com.swirlds.common.metrics.statistics.StatsBuffered;
import com.swirlds.metrics.api.FloatFormats;
import com.swirlds.metrics.api.Metric;
import com.swirlds.metrics.api.MetricType;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import java.util.EnumSet;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* A very flexible implementation of Metric which behavior is mostly passed to it via lambdas.
*
* @deprecated This class will be removed. Use one of the specialized {@link Metric}-implementations instead.
*/
@Deprecated(forRemoval = true)
public interface StatEntry extends Metric {
/**
* {@inheritDoc}
*/
@NonNull
@Override
default MetricType getMetricType() {
return MetricType.STAT_ENTRY;
}
/**
* {@inheritDoc}
*/
@NonNull
@Override
default EnumSet getValueTypes() {
return getBuffered() == null ? EnumSet.of(VALUE) : EnumSet.of(VALUE, MAX, MIN, STD_DEV);
}
/**
* {@inheritDoc}
*/
@NonNull
@Override
default Object get(@NonNull final ValueType valueType) {
Objects.requireNonNull(valueType, "valueType must not be null");
if (getBuffered() == null) {
if (valueType == VALUE) {
return getStatsStringSupplier().get();
}
throw new IllegalArgumentException("Unsupported ValueType: " + valueType);
} else {
return switch (valueType) {
case VALUE -> getStatsStringSupplier().get();
case MAX -> getBuffered().getMax();
case MIN -> getBuffered().getMin();
case STD_DEV -> getBuffered().getStdDev();
default -> throw new IllegalArgumentException("Unsupported ValueType: " + valueType);
};
}
}
/**
* Getter for {@code buffered}
*
* @return the {@link StatsBuffered}, if available, otherwise {@code null}
*/
@Nullable
StatsBuffered getBuffered();
/**
* Getter for {@code reset}, a lambda that resets the metric, using the given half life
*
* @return the reset-lambda, if available, otherwise {@code null}
*/
@Nullable
Consumer getReset();
/**
* Getter for {@code statsStringSupplier}, a lambda that returns the metric value
*
* @return the lambda
*/
@NonNull
Supplier