Class SparqlQueryConnectionWithReconnect

java.lang.Object
org.aksw.jenax.dataaccess.sparql.connection.reconnect.SparqlQueryConnectionWithReconnect
All Implemented Interfaces:
AutoCloseable, TransactionalWrapper, SparqlQueryConnectionTmp, org.apache.jena.rdfconnection.SparqlQueryConnection, org.apache.jena.sparql.core.Transactional

public class SparqlQueryConnectionWithReconnect extends Object implements SparqlQueryConnectionTmp
A connection wrapper that tries to recover from loss of the underlying connection. Neither replays transactions nor individual queries. If a query fails due to a connection loss then attempts are made to establish a new connection. If an attempt is successful then a ConnectionReestablishedException is raised which indicates that the query failed but the connection would be ready to accept workloads again. The main benefit of this class that it removes the need of passing a java.sql.DataSource-like object to client methods that operate on a single connection. It also takes care of the resource management such as closing the connections used for probing. The client methods can catch the ConnectionReestablishedException and ConnectionLostException and act accordingly such as by replaying some queries or moving on the the next workload. This class is thread safe: In case of a connection problem, the health check runner is started by one of the threads that requested a query execution. All other threads are blocked while the health check is running and fire the appropriate exception once it finishes.
Author:
raven
  • Field Details

    • dataConnectionSupplier

      protected Callable<org.apache.jena.rdfconnection.SparqlQueryConnection> dataConnectionSupplier
    • probeConnectionSupplier

      protected Callable<org.apache.jena.rdfconnection.SparqlQueryConnection> probeConnectionSupplier
    • healthCheckQuery

      protected org.apache.jena.query.Query healthCheckQuery
    • healthCheckBuilder

      protected Supplier<org.aksw.commons.util.healthcheck.HealthcheckRunner.Builder<?>> healthCheckBuilder
    • connectionLostCause

      protected transient Exception connectionLostCause
      True indicates that a recovery process was started which eventually failed
    • reconnectAttemptCount

      protected transient int reconnectAttemptCount
      Number of times the healthcheck runner was invoked in an attempt to reconnect. Not to be confused with the number of reconnect attempts made by a single healthcheck run. This value is used as 'timestamp' when multiple requests are waiting for the connection to become available again
    • activeDelegate

      protected org.apache.jena.rdfconnection.SparqlQueryConnection activeDelegate
      The currently active connection
  • Constructor Details

    • SparqlQueryConnectionWithReconnect

      public SparqlQueryConnectionWithReconnect(Callable<org.apache.jena.rdfconnection.SparqlQueryConnection> dataConnectionSupplier, Callable<org.apache.jena.rdfconnection.SparqlQueryConnection> probeConnectionSupplier, Supplier<org.aksw.commons.util.healthcheck.HealthcheckRunner.Builder<?>> healthCheckBuilder, org.apache.jena.rdfconnection.SparqlQueryConnection activeDelegate)
  • Method Details