class GridQueryCancel {
    /** */
    private final List<QueryCancellable> cancelActions = new ArrayList<>(3);

    /** */
    private boolean canceled;

    /**
     * Adds a cancel action.
     *
     * @param clo Clo.
     */
    public synchronized void add(QueryCancellable clo) throws QueryCancelledException {
        assert clo != null;

        if (canceled)
            throw new QueryCancelledException();

        cancelActions.add(clo);
    }

    /**
     * Executes cancel closure.
     */
    public synchronized void cancel() {<FILL_FUNCTION_BODY>}

    /**
     * Stops query execution if a user requested cancel.
     */
    public synchronized void checkCancelled() throws QueryCancelledException {
        if (canceled)
            throw new QueryCancelledException();
    }

    /** */
    public synchronized boolean isCanceled() {
        return canceled;
    }
}

        if (canceled)
            return;

        canceled = true;

        IgniteException ex = null;

        // Run actions in the reverse order.
        for (int i = cancelActions.size() - 1; i >= 0; i--) {
            try {
                QueryCancellable act = cancelActions.get(i);

                act.doCancel();
            }
            catch (Exception e) {
                if (ex == null)
                    ex = new IgniteException(e);
                else
                    ex.addSuppressed(e);
            }
        }

        if (ex != null)
            throw ex;
    
<no_super_class>