All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.opentelemetry.javaagent.tooling.util.ClassLoaderValue Maven / Gradle / Ivy

There is a newer version: 2.12.0-alpha
Show newest version
/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.opentelemetry.javaagent.tooling.util;

import java.util.function.Supplier;

/**
 * Associate value with a class loader. Added value will behave as if it was stored in a field in
 * the class loader object, meaning that the value can be garbage collected once the class loader is
 * garbage collected and referencing the class loader from the value will not prevent garbage
 * collector from collecting the class loader.
 */
public final class ClassLoaderValue {

  @SuppressWarnings("unchecked")
  public T get(ClassLoader classLoader) {
    return (T) ClassLoaderMap.get(classLoader, this);
  }

  public void put(ClassLoader classLoader, T value) {
    ClassLoaderMap.put(classLoader, this, value);
  }

  @SuppressWarnings("unchecked")
  public T computeIfAbsent(ClassLoader classLoader, Supplier value) {
    return (T) ClassLoaderMap.computeIfAbsent(classLoader, this, value);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy