<commit_before>package com.avairebot.orion.contracts.async;

import com.avairebot.orion.requests.Response;
import net.dv8tion.jda.core.utils.SimpleLog;

import java.util.function.Consumer;

public abstract class Future {

    /**
     * The default success consumer that should be used if no success consumer is given.
     */
    private Consumer<Response> DEFAULT_SUCCESS = (Response) -> {
    };

    /**
     * The default failure consumer that should be used if no failure consumer is given.
     */
    private Consumer<Throwable> DEFAULT_FAILURE = (Exception) -> {
        SimpleLog.getLog(Future.class).fatal(String.format(
            "Future Consumer returned failure: [%s] %s", Exception.getClass().getSimpleName(), Exception.getMessage()
        ));
    };

    /**
     * Sends the future request with no consumers.
     */
    public void send() {
        this.send(null, null);
    }

    /**
     * Sends the future request, on success the given success consumer will be
     * invoked with the content of the request, if the future request fails
     * the default failure consumer will be invoked.
     *
     * @param success The consumer that should be invoked on success.
     */
    public void send(Consumer success) {
        this.send(success, null);
    }

    /**
     * Sends the future request, on success the given success consumer will be
     * invoked with the content of the reuqest, if the future request fails
     * the failure consumer will be invoked instead.
     *
     * @param success The consumer that should be invoked on success.
     * @param failure The consumer that should be invoked on failure.
     */
    public void send(final Consumer success, final Consumer<Throwable> failure) {
        new Thread(() -> {
            handle(
                success == null ? DEFAULT_SUCCESS : success,
                failure == null ? DEFAULT_FAILURE : failure

            );
        }).start();
    }

    /**
     * Handles the future request.
     *
     * @param success Never-null success consumer.
     * @param failure Never-null failure consumer.
     */
    protected abstract void handle(Consumer success, Consumer<Throwable> failure);
}
<commit_msg>Change future requests from creating new threads to using a pool<commit_after>package com.avairebot.orion.contracts.async;

import com.avairebot.orion.requests.Response;
import net.dv8tion.jda.core.utils.SimpleLog;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Consumer;

public abstract class Future {

    /**
     * The thread executor service provider, all future requests will be added to the pool of threads.
     */
    private static final ExecutorService SERVICE = Executors.newFixedThreadPool(3);

    /**
     * The default success consumer that should be used if no success consumer is given.
     */
    private Consumer<Response> DEFAULT_SUCCESS = (Response) -> {
    };

    /**
     * The default failure consumer that should be used if no failure consumer is given.
     */
    private Consumer<Throwable> DEFAULT_FAILURE = (Exception) -> {
        SimpleLog.getLog(Future.class).fatal(String.format(
            "Future Consumer returned failure: [%s] %s", Exception.getClass().getSimpleName(), Exception.getMessage()
        ));
    };

    /**
     * Sends the future request with no consumers.
     */
    public void send() {
        this.send(null, null);
    }

    /**
     * Sends the future request, on success the given success consumer will be
     * invoked with the content of the request, if the future request fails
     * the default failure consumer will be invoked.
     *
     * @param success The consumer that should be invoked on success.
     */
    public void send(Consumer success) {
        this.send(success, null);
    }

    /**
     * Sends the future request, on success the given success consumer will be
     * invoked with the content of the reuqest, if the future request fails
     * the failure consumer will be invoked instead.
     *
     * @param success The consumer that should be invoked on success.
     * @param failure The consumer that should be invoked on failure.
     */
    public void send(final Consumer success, final Consumer<Throwable> failure) {
        SERVICE.submit(() -> handle(
            success == null ? DEFAULT_SUCCESS : success,
            failure == null ? DEFAULT_FAILURE : failure

        ));
    }

    /**
     * Handles the future request.
     *
     * @param success Never-null success consumer.
     * @param failure Never-null failure consumer.
     */
    protected abstract void handle(Consumer success, Consumer<Throwable> failure);
}

{'fraction_non_alphanumeric': 0.087972800679983, 'fraction_numerical': 0.0006374840628984276, 'mean_word_length': 2.623556581986143, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '7058150', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1185, 'n_words': 450}