Class ThreadedSPARQL

java.lang.Object
org.aksw.qa.commons.sparql.SPARQL
org.aksw.qa.commons.sparql.ThreadedSPARQL

public class ThreadedSPARQL extends SPARQL
Fire a sparql query against an endpoint

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.

Author:
jhuth
  • Field Details

    • timeoutInSeconds

      private int timeoutInSeconds
    • log

      private final org.slf4j.Logger log
    • executor

      private ExecutorService executor
  • Constructor Details

    • ThreadedSPARQL

      public ThreadedSPARQL()
      #ENDPOINT_DBPEDIA_ORG as endpoint used.

      Default timeout : 10 seconds

    • ThreadedSPARQL

      public ThreadedSPARQL(String endpoint)
      Default timeout : 10 seconds
    • ThreadedSPARQL

      public ThreadedSPARQL(int timeoutInSeconds, String endpoint)
      Parameters:
      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_ORG
  • Method Details

    • sparql

      public Set<org.apache.jena.rdf.model.RDFNode> sparql(String query)
      Fire a sparql query against endpoint defined in constructor.

      This will break operation after timeoutInSeconds has been reached. in this case, null is returned.

      For string representation of answers, see SPARQL.extractAnswerStrings(Set)

      Overrides:
      sparql in class SPARQL
      Parameters:
      query - - a sparql query
      Returns:
    • getTimeoutInSeconds

      public int getTimeoutInSeconds()
      Returns:
      - the time after a query times out.
    • setTimeoutInSeconds

      public void setTimeoutInSeconds(int timeoutInSeconds)
      Parameters:
      timeoutInSeconds - - the time after a query times out.
    • destroy

      public void destroy()
      Call this to close the underlying thread pool.