Search in sources :

Example 6 with QueryCancelledException

use of org.apache.jena.query.QueryCancelledException in project jena by apache.

the class TestQueryIterSort method setup.

@Before
public void setup() {
    random = new Random();
    Var[] vars = new Var[] { Var.alloc("1"), Var.alloc("2"), Var.alloc("3"), Var.alloc("4"), Var.alloc("5"), Var.alloc("6"), Var.alloc("7"), Var.alloc("8"), Var.alloc("9"), Var.alloc("0") };
    unsorted = new ArrayList<>();
    for (int i = 0; i < 500; i++) {
        unsorted.add(randomBinding(vars));
    }
    List<SortCondition> conditions = new ArrayList<>();
    conditions.add(new SortCondition(new ExprVar("8"), Query.ORDER_ASCENDING));
    comparator = new BindingComparator(conditions);
    iterator = new CallbackIterator(unsorted.iterator(), 25, null);
    iterator.setCallback(new Callback() {

        @Override
        public void call() {
            throw new QueryCancelledException();
        }
    });
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) SortCondition(org.apache.jena.query.SortCondition) BindingComparator(org.apache.jena.sparql.engine.binding.BindingComparator) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) ArrayList(java.util.ArrayList) Random(java.util.Random) QueryCancelledException(org.apache.jena.query.QueryCancelledException) Before(org.junit.Before)

Example 7 with QueryCancelledException

use of org.apache.jena.query.QueryCancelledException in project jena by apache.

the class ActionBase method doCommon.

/**
     * Common framework for handling HTTP requests.
     * @param request
     * @param response
     */
protected void doCommon(HttpServletRequest request, HttpServletResponse response) {
    try {
        long id = allocRequestId(request, response);
        // Lifecycle
        HttpAction action = allocHttpAction(id, request, response);
        printRequest(action);
        action.setStartTime();
        // The response may be changed to a HttpServletResponseTracker
        response = action.response;
        initResponse(request, response);
        Context cxt = ARQ.getContext();
        try {
            execCommonWorker(action);
        } catch (QueryCancelledException ex) {
            // To put in the action timeout, need (1) global, (2) dataset and (3) protocol settings.
            // See
            //    global -- cxt.get(ARQ.queryTimeout) 
            //    dataset -- dataset.getContect(ARQ.queryTimeout)
            //    protocol -- SPARQL_Query.setAnyTimeouts
            String message = String.format("Query timed out");
            // Possibility :: response.setHeader("Retry-after", "600") ;    // 5 minutes
            ServletOps.responseSendError(response, HttpSC.SERVICE_UNAVAILABLE_503, message);
        } catch (ActionErrorException ex) {
            if (ex.getCause() != null)
                ex.getCause().printStackTrace(System.err);
            // Log message done by printResponse in a moment.
            if (ex.getMessage() != null)
                ServletOps.responseSendError(response, ex.getRC(), ex.getMessage());
            else
                ServletOps.responseSendError(response, ex.getRC());
        } catch (RuntimeIOException ex) {
            log.warn(format("[%d] Runtime IO Exception (client left?) RC = %d : %s", id, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage()), ex);
            ServletOps.responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage());
        } catch (Throwable ex) {
            // This should not happen.
            //ex.printStackTrace(System.err) ;
            log.warn(format("[%d] RC = %d : %s", id, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage()), ex);
            ServletOps.responseSendError(response, HttpSC.INTERNAL_SERVER_ERROR_500, ex.getMessage());
        }
        action.setFinishTime();
        printResponse(action);
        archiveHttpAction(action);
    } catch (Throwable th) {
        log.error("Internal error", th);
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) RuntimeIOException(org.apache.jena.atlas.RuntimeIOException) QueryCancelledException(org.apache.jena.query.QueryCancelledException)

Example 8 with QueryCancelledException

use of org.apache.jena.query.QueryCancelledException in project jena by apache.

the class QueryIteratorBase method nextBinding.

/** final - subclasses implement moveToNextBinding() */
@Override
public final Binding nextBinding() {
    try {
        // Need to make sure to only read this once per iteration
        boolean shouldCancel = requestingCancel;
        if (shouldCancel && abortIterator) {
            // Try to close first to release resources (in case the user
            // doesn't have a close() call in a finally block)
            close();
            throw new QueryCancelledException();
        }
        if (finished)
            throw new NoSuchElementException(Lib.className(this));
        if (!hasNextBinding())
            throw new NoSuchElementException(Lib.className(this));
        Binding obj = moveToNextBinding();
        if (obj == null)
            throw new NoSuchElementException(Lib.className(this));
        if (shouldCancel && !finished) {
            // But .cancel sets both requestingCancel and abortIterator
            // This only happens with a continuing iterator.
            close();
        }
        return obj;
    } catch (QueryFatalException ex) {
        Log.error(this, "QueryFatalException", ex);
        throw ex;
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryFatalException(org.apache.jena.query.QueryFatalException) QueryCancelledException(org.apache.jena.query.QueryCancelledException) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

QueryCancelledException (org.apache.jena.query.QueryCancelledException)8 Context (org.apache.jena.sparql.util.Context)4 RuntimeIOException (org.apache.jena.atlas.RuntimeIOException)2 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2 QueryIterSort (org.apache.jena.sparql.engine.iterator.QueryIterSort)2 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NoSuchElementException (java.util.NoSuchElementException)1 Random (java.util.Random)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 IteratorDelayedInitialization (org.apache.jena.atlas.iterator.IteratorDelayedInitialization)1 QueryFatalException (org.apache.jena.query.QueryFatalException)1 SortCondition (org.apache.jena.query.SortCondition)1 Var (org.apache.jena.sparql.core.Var)1 BindingComparator (org.apache.jena.sparql.engine.binding.BindingComparator)1 ExprVar (org.apache.jena.sparql.expr.ExprVar)1 Before (org.junit.Before)1