<commit_before>package io.quarkus.rest.runtime.jaxrs;

import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.TimeoutHandler;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;

import io.quarkus.rest.runtime.core.QuarkusRestRequestContext;

public class QuarkusRestAsyncResponse implements AsyncResponse {

    private final QuarkusRestRequestContext context;
    private volatile boolean suspended;
    private volatile boolean cancelled;

    public QuarkusRestAsyncResponse(QuarkusRestRequestContext context) {
        this.context = context;
        suspended = true;
    }

    @Override
    public boolean resume(Object response) {
        if (!suspended) {
            return false;
        } else {
            suspended = false;
        }
        context.setResult(response);
        context.resume();
        return true;
    }

    @Override
    public boolean resume(Throwable response) {
        if (!suspended) {
            return false;
        } else {
            suspended = false;
        }
        context.setThrowable(response);
        context.resume();
        return true;
    }

    @Override
    public boolean cancel() {
        if (!suspended) {
            return false;
        }
        suspended = false;
        cancelled = true;

        context.setThrowable(new WebApplicationException(Response.status(503).build()));
        context.resume();
        return true;
    }

    @Override
    public boolean cancel(int retryAfter) {
        if (!suspended) {
            return false;
        }
        suspended = false;
        cancelled = true;
        context.setThrowable(new WebApplicationException(Response.status(503)
                .header(HttpHeaders.RETRY_AFTER, retryAfter).build()));
        context.resume();
        return true;
    }

    @Override
    public boolean cancel(Date retryAfter) {
        return cancel((int) ((retryAfter.getTime() - System.currentTimeMillis()) / 1000));
    }

    @Override
    public boolean isSuspended() {
        return suspended;
    }

    @Override
    public boolean isCancelled() {
        return cancelled;
    }
<commit_msg>Fixes to AsyncResponse.cancel<commit_after>package io.quarkus.rest.runtime.jaxrs;

import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.TimeoutHandler;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;

import io.quarkus.rest.runtime.core.QuarkusRestRequestContext;

public class QuarkusRestAsyncResponse implements AsyncResponse {

    private final QuarkusRestRequestContext context;
    private volatile boolean suspended;
    private volatile boolean cancelled;

    public QuarkusRestAsyncResponse(QuarkusRestRequestContext context) {
        this.context = context;
        suspended = true;
    }

    @Override
    public boolean resume(Object response) {
        if (!suspended) {
            return false;
        } else {
            suspended = false;
        }
        context.setResult(response);
        context.resume();
        return true;
    }

    @Override
    public boolean resume(Throwable response) {
        if (!suspended) {
            return false;
        } else {
            suspended = false;
        }
        context.setThrowable(response);
        context.resume();
        return true;
    }

    @Override
    public boolean cancel() {
        if (cancelled) {
            return true;
        }
        if (!suspended) {
            return false;
        }
        suspended = false;
        cancelled = true;

        context.setThrowable(new WebApplicationException(Response.status(503).build()));
        context.resume();
        return true;
    }

    @Override
    public boolean cancel(int retryAfter) {
        return internalCancel(retryAfter);
    }

    private boolean internalCancel(Object retryAfter) {
        if (cancelled) {
            return true;
        }
        if (!suspended) {
            return false;
        }
        suspended = false;
        cancelled = true;
        context.setThrowable(new WebApplicationException(Response.status(503)
                .header(HttpHeaders.RETRY_AFTER, retryAfter).build()));
        context.resume();
        return true;
    }

    @Override
    public boolean cancel(Date retryAfter) {
        return internalCancel(retryAfter);
    }

    @Override
    public boolean isSuspended() {
        return suspended;
    }

    @Override
    public boolean isCancelled() {
        return cancelled;
    }

{'fraction_non_alphanumeric': 0.09004149377593361, 'fraction_numerical': 0.0033195020746887966, 'mean_word_length': 2.302054794520548, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '425386', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1285, 'n_words': 287}