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

org.opensearch.common.util.concurrent.ThreadContextAccess Maven / Gradle / Ivy

There is a newer version: 2.18.0
Show newest version
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * The OpenSearch Contributors require contributions made to
 * this file be licensed under the Apache-2.0 license or a
 * compatible open source license.
 */

package org.opensearch.common.util.concurrent;

import org.opensearch.SpecialPermission;
import org.opensearch.common.annotation.InternalApi;

import java.security.AccessController;
import java.security.PrivilegedAction;

/**
 * This class wraps the {@link ThreadContext} operations requiring access in
 * {@link AccessController#doPrivileged(PrivilegedAction)} blocks.
 *
 * @opensearch.internal
 */
@SuppressWarnings("removal")
@InternalApi
public final class ThreadContextAccess {

    private ThreadContextAccess() {}

    public static  T doPrivileged(PrivilegedAction operation) {
        SpecialPermission.check();
        return AccessController.doPrivileged(operation);
    }

    public static void doPrivilegedVoid(Runnable action) {
        SpecialPermission.check();
        AccessController.doPrivileged((PrivilegedAction) () -> {
            action.run();
            return null;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy