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

org.apache.rocketmq.shaded.io.opentelemetry.context.ContextStorageWrappers Maven / Gradle / Ivy

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

package org.apache.rocketmq.shaded.io.opentelemetry.context;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Holder of functions to wrap the used {@link ContextStorage}. Separate class from {@link
 * LazyStorage} to allow registering wrappers before initializing storage.
 */
final class ContextStorageWrappers {

  private static final Logger log = Logger.getLogger(ContextStorageWrappers.class.getName());

  private static boolean storageInitialized;

  private static final List> wrappers =
      new ArrayList<>();

  private static final Object mutex = new Object();

  static void addWrapper(Function wrapper) {
    synchronized (mutex) {
      if (storageInitialized) {
        log.log(
            Level.FINE,
            "ContextStorage has already been initialized, ignoring call to add wrapper.",
            new Throwable());
        return;
      }
      wrappers.add(wrapper);
    }
  }

  static List> getWrappers() {
    synchronized (mutex) {
      return wrappers;
    }
  }

  static void setStorageInitialized() {
    synchronized (mutex) {
      storageInitialized = true;
    }
  }

  private ContextStorageWrappers() {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy