1

I am trying to implement something like circuit breaker for my Sesame connections to the back-end database. When the database is absent I want to know this after 2 seconds, not to rely on the defaults of the client for timeouts. I can possibly overcome this with my own FutureTasks where I will execute the repository initialization and the connection obtaining. However in the logs I can see that sesame client uses o.a.h.i.c.PoolingClientConnectionManager - which is passed I bet ExecutorService and some default timeouts. This will make my FutureTask solution pretty messy. Is there an easier way to set timeouts for the sesame client.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
user3572788
  • 151
  • 2
  • 10

1 Answers1

1

You can set the query and update timeout, specifically, on the query/update object itself:

 RepositoryConnection conn = ....;

 ... 
 TupleQuery query = conn.prepareTupleQuery(QueryLangage.SPARQL, "SELECT ...");
 query.setMaxExecutionTime(2);

However, if you want to set a general timeout for all api calls over HTTP, the only way to currently do that is by obtaining a reference to the HttpClient object, and reconfigure it:

  HTTPRepository repo = ....;
  AbstractHttpClient httpClient = (AbstractHttpClient)((SesameClientImpl)repo.getSesameClient()).getHtttpClient();
  HttpParams params = httpClient.getParams();
  params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 2000);
  httpClient.setParams(params);

As you can see, this is rather brittle (lots of explicit casts), and uses an approach that is deprecated in Apache HttpClient 4.4. So I don't exactly recommend this as a stable solution, but it should provide a workaround in the short term.

In the longer term the Sesame dev team are working on more convenient access to the configuration of the httpclient.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Jeen Broekstra
  • 21,642
  • 4
  • 51
  • 73
  • 1
    Yes. Works. What I added was : **params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 2000);** . Of course setting httpclient's timeouts should be before **repo.initialize()** and **repo.getConnection()**. Thanks a lot! – user3572788 Apr 25 '15 at 11:17