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();
}
});
}
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);
}
}
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;
}
}
Aggregations