<commit_before>package jenkins.security;

import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.ChannelClosedException;
import org.jenkinsci.remoting.RoleChecker;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

import javax.annotation.Nonnull;


/**
 * Convenient {@link Callable} meant to be run on agent.
 *
 * @author <NAME>
 * @since 1.587 / 1.580.1
 */
public abstract class MasterToSlaveCallable<V, T extends Throwable> implements Callable<V,T> {

    private static final long serialVersionUID = 1L;

    @Override
    public void checkRoles(RoleChecker checker) throws SecurityException {
        checker.check(this,Roles.SLAVE);
    }

    //TODO: replace by Callable#getChannelOrFail() once Minimal supported Remoting version is 3.15 or above
    @Restricted(NoExternalUse.class)
    protected static Channel _getChannelOrFail() throws ChannelClosedException {
        final Channel ch = Channel.current();
        if (ch == null) {
            throw new ChannelClosedException("No channel associated with the thread", null);
        }
        return ch;
    }

    //TODO: replace by Callable#getOpenChannelOrFail() once Minimal supported Remoting version is 3.15 or above
    @Restricted(NoExternalUse.class)
    protected static Channel _getOpenChannelOrFail() throws ChannelClosedException {
        final Channel ch = _getChannelOrFail();
        if (ch.isClosingOrClosed()) { // TODO: Since Remoting 2.33, we still need to explicitly declare minimal Remoting version
            throw new ChannelClosedException("The associated channel " + ch + " is closing down or has closed down", ch.getCloseRequestCause());
        }
        return ch;
    }
}<commit_msg>[JENKINS-48761] - Use pre-Remoting 3.0 ChannelClosedException APIs<commit_after>package jenkins.security;

import hudson.remoting.Callable;
import hudson.remoting.Channel;
import hudson.remoting.ChannelClosedException;
import org.jenkinsci.remoting.RoleChecker;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

import javax.annotation.Nonnull;


/**
 * Convenient {@link Callable} meant to be run on agent.
 *
 * @author <NAME>
 * @since 1.587 / 1.580.1
 */
public abstract class MasterToSlaveCallable<V, T extends Throwable> implements Callable<V,T> {

    private static final long serialVersionUID = 1L;

    @Override
    public void checkRoles(RoleChecker checker) throws SecurityException {
        checker.check(this,Roles.SLAVE);
    }

    //TODO: replace by Callable#getChannelOrFail() once Minimal supported Remoting version is 3.15 or above
    @Restricted(NoExternalUse.class)
    protected static Channel _getChannelOrFail() throws ChannelClosedException {
        final Channel ch = Channel.current();
        if (ch == null) {
            throw new ChannelClosedException(new IllegalStateException("No channel associated with the thread"));
        }
        return ch;
    }

    //TODO: replace by Callable#getOpenChannelOrFail() once Minimal supported Remoting version is 3.15 or above
    @Restricted(NoExternalUse.class)
    protected static Channel _getOpenChannelOrFail() throws ChannelClosedException {
        final Channel ch = _getChannelOrFail();
        if (ch.isClosingOrClosed()) { // TODO: Since Remoting 2.33, we still need to explicitly declare minimal Remoting version
            throw new ChannelClosedException(new IllegalStateException("The associated channel " + ch + " is closing down or has closed down", ch.getCloseRequestCause()));
        }
        return ch;
    }
}
{'fraction_non_alphanumeric': 0.08557186374965384, 'fraction_numerical': 0.012461921905289393, 'mean_word_length': 3.7777777777777777, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1563370', 'n_tokens_mistral': 1068, 'n_tokens_neox': 999, 'n_words': 298}