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.
/*
* Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
*
* 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.hazelcast.internal.metrics.impl;
import com.hazelcast.internal.metrics.DoubleProbeFunction;
import com.hazelcast.internal.metrics.LongProbeFunction;
import com.hazelcast.internal.metrics.MetricDescriptor;
import com.hazelcast.internal.metrics.Probe;
import com.hazelcast.internal.metrics.ProbeFunction;
import com.hazelcast.internal.util.ExceptionUtil;
import com.hazelcast.internal.util.counters.Counter;
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodHandles.Lookup;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.Semaphore;
import java.util.function.Function;
import java.util.function.Supplier;
import static com.hazelcast.internal.metrics.impl.ProbeType.getType;
import static java.lang.String.format;
/**
* A {@link MethodProbe} is a {@link ProbeFunction} that invokes a method that is annotated with {@link Probe}.
*
* Internally accesses the method using reflection via one of these mechanisms (as a pose to a simple {@link Method#invoke} for
* performance reasons):
*
*
{@link #methodHandle}
*
{@link #staticAccessor}
*
{@link #nonStaticAccessor}
*
*/
abstract class MethodProbe implements ProbeFunction {
private static final Lookup LOOKUP = MethodHandles.lookup();
/**
* {@link MethodHandle} used to access primitives to avoid boxing, specifically to reduce redundant object creation.
*
* E.G. for a method that returns {@link long}, when typically invoked via reflection, an {@link Object} would instead be
* returned. The {@link long} would be boxed to {@link Long}, and then immediately unboxed again back to a {@link long} for
* returning from {@link LongProbeFunction#get(S)}.
*
* Faster than basic reflection, but slower than a {@link LambdaMetafactory} generated accessor.
*/
final MethodHandle methodHandle;
/**
* A {@link Supplier} used to access static methods returning objects (reference types).
*
* Generated via a {@link LambdaMetafactory}, bound to a {@link MethodHandle} derived from {@link #methodHandle}.
*
* Faster than basic reflection and {@link MethodHandle#invokeExact()}, but only applicable for reference types.
*
* @see Further reading
*/
final Supplier> staticAccessor;
/**
* A {@link Function} used to access instance methods returning objects (reference types)
*
* {@link Function#apply(T)}'s parameter is the instance to retrieve the value from.
*
* @see #staticAccessor
*/
final Function