org.opensearch.common.util.concurrent.ThreadContextAccess Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensearch Show documentation
Show all versions of opensearch Show documentation
OpenSearch subproject :server
/*
* 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;
});
}
}