Search in sources :

Example 1 with BackgroundTupleResult

use of org.eclipse.rdf4j.query.resultio.helpers.BackgroundTupleResult in project rdf4j by eclipse.

the class BackgroundResultExecutor method parse.

public TupleQueryResult parse(TupleQueryResultParser parser, InputStream in) {
    BackgroundTupleResult result = new BackgroundTupleResult(parser, in);
    autoCloseRunnable(result, result);
    return result;
}
Also used : BackgroundTupleResult(org.eclipse.rdf4j.query.resultio.helpers.BackgroundTupleResult)

Example 2 with BackgroundTupleResult

use of org.eclipse.rdf4j.query.resultio.helpers.BackgroundTupleResult in project rdf4j by eclipse.

the class QueryResultIO method parseTupleInternal.

private static TupleQueryResult parseTupleInternal(InputStream in, QueryResultFormat format, boolean parseOnBackgroundThread) throws IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException {
    TupleQueryResultParser parser = createTupleParser(format);
    if (parseOnBackgroundThread) {
        BackgroundTupleResult result = new BackgroundTupleResult(new QueueCursor<>(new LinkedBlockingQueue<>(1)), parser, in);
        // Start a new thread in the background, which will be completed
        // when the BackgroundTupleResult is either closed or interrupted
        boolean allGood = false;
        try {
            ForkJoinPool.commonPool().submit(result);
            allGood = true;
        } finally {
            if (!allGood) {
                result.close();
            }
        }
        return result;
    } else {
        TupleQueryResultBuilder qrBuilder = new TupleQueryResultBuilder();
        try {
            parser.setQueryResultHandler(qrBuilder).parseQueryResult(in);
        } catch (QueryResultHandlerException e) {
            if (e instanceof TupleQueryResultHandlerException) {
                throw (TupleQueryResultHandlerException) e;
            } else {
                throw new TupleQueryResultHandlerException(e);
            }
        }
        return qrBuilder.getQueryResult();
    }
}
Also used : TupleQueryResultBuilder(org.eclipse.rdf4j.query.impl.TupleQueryResultBuilder) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) BackgroundTupleResult(org.eclipse.rdf4j.query.resultio.helpers.BackgroundTupleResult) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException)

Aggregations

BackgroundTupleResult (org.eclipse.rdf4j.query.resultio.helpers.BackgroundTupleResult)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 QueryResultHandlerException (org.eclipse.rdf4j.query.QueryResultHandlerException)1 TupleQueryResultHandlerException (org.eclipse.rdf4j.query.TupleQueryResultHandlerException)1 TupleQueryResultBuilder (org.eclipse.rdf4j.query.impl.TupleQueryResultBuilder)1