public class ThreadedSPARQL extends SPARQL
SPARQL.sparql(String) will block, if server doesn't respond. Here, you can set a maximum time limit.
This is achieved by wrapping underlying SPARQL in a Thread, which then has a maximum execution time.
| Modifier and Type | Field | Description |
|---|---|---|
(package private) ExecutorService |
executor |
|
private org.slf4j.Logger |
log |
|
private int |
timeoutInSeconds |
| Constructor | Description |
|---|---|
ThreadedSPARQL() |
#ENDPOINT_DBPEDIA_ORG as endpoint used. |
ThreadedSPARQL(int timeoutInSeconds,
String endpoint) |
|
ThreadedSPARQL(String endpoint) |
Default timeout : 10 seconds
|
| Modifier and Type | Method | Description |
|---|---|---|
void |
destroy() |
Call this to close the underlying thread pool.
|
int |
getTimeoutInSeconds() |
|
static void |
main(String[] args) |
|
void |
setTimeoutInSeconds(int timeoutInSeconds) |
|
Set<org.apache.jena.rdf.model.RDFNode> |
sparql(String query) |
Fire a sparql query against endpoint defined in constructor.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitextractAnswerStrings, getCacheTimeToLive, isValidSparqlQuery, setCacheTimeToLiveprivate int timeoutInSeconds
private final org.slf4j.Logger log
ExecutorService executor
public ThreadedSPARQL()
#ENDPOINT_DBPEDIA_ORG as endpoint used.
Default timeout : 10 seconds
public ThreadedSPARQL(String endpoint)
public ThreadedSPARQL(int timeoutInSeconds,
String endpoint)
timeoutInSeconds - - set a maximum time limit for the execution of one query. Only set if >0 otherwise ignored (default=10s)endpoint - - A sparql endpoint, e.g. SPARQLEndpoints.DBPEDIA_ORGpublic Set<org.apache.jena.rdf.model.RDFNode> sparql(String query) throws ExecutionException
This will break operation after timeoutInSeconds has been reached. in this case, null is returned.
For string representation of answers, see SPARQL.extractAnswerStrings(Set)
sparql in class SPARQLquery - - a sparql queryExecutionExceptionpublic int getTimeoutInSeconds()
public void setTimeoutInSeconds(int timeoutInSeconds)
timeoutInSeconds - - the time after a query times out.public void destroy()
public static void main(String[] args) throws InterruptedException, ExecutionException
Copyright © 2016–2018 Pivotal Software, Inc.. All rights reserved.