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
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassNested classes/interfaces inherited from interface org.apache.jena.sparql.core.Transactional
org.apache.jena.sparql.core.Transactional.Promote -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.jena.rdfconnection.SparqlQueryConnectionThe currently active connectionprotected ExceptionTrue indicates that a recovery process was started which eventually failedprotected Callable<org.apache.jena.rdfconnection.SparqlQueryConnection>protected Supplier<org.aksw.commons.util.healthcheck.HealthcheckRunner.Builder<?>>protected org.apache.jena.query.Queryprotected Callable<org.apache.jena.rdfconnection.SparqlQueryConnection>protected intNumber of times the healthcheck runner was invoked in an attempt to reconnect. -
Constructor Summary
ConstructorsConstructorDescriptionSparqlQueryConnectionWithReconnect(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 Summary
Modifier and TypeMethodDescriptionprotected voidvoidclose()Immediately obtain a connection from the supplierprotected voidorg.apache.jena.sparql.core.TransactionalThis method needs to be overridden for transaction supportintprotected voidhandleConnectionProblem(Exception e, int timestamp) booleanprotected booleanorg.apache.jena.query.QueryExecutionBuildernewQuery()org.apache.jena.query.QueryExecutionquery(org.apache.jena.query.Query query) Setup a SPARQL query execution.protected voidtestForConnectionProblem(Exception e, int timestamp) protected voidThis method is run by the healthcheck runner until there is no more exceptionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.aksw.jenax.dataaccess.sparql.connection.query.SparqlQueryConnectionTmp
parse, query, queryAsk, queryAsk, queryConstruct, queryConstruct, queryDescribe, queryDescribe, queryResultSet, queryResultSet, querySelect, querySelectMethods inherited from interface org.apache.jena.sparql.core.Transactional
begin, calc, calculate, calculateRead, calculateWrite, exec, execute, executeRead, executeWrite, promoteMethods inherited from interface org.aksw.jenax.dataaccess.sparql.common.TransactionalWrapper
abort, begin, begin, commit, end, getTransactionalDelegate, isInTransaction, promote, transactionMode, transactionType
-
Field Details
-
dataConnectionSupplier
-
probeConnectionSupplier
-
healthCheckQuery
protected org.apache.jena.query.Query healthCheckQuery -
healthCheckBuilder
protected Supplier<org.aksw.commons.util.healthcheck.HealthcheckRunner.Builder<?>> healthCheckBuilder -
connectionLostCause
True indicates that a recovery process was started which eventually failed -
reconnectAttemptCount
protected transient int reconnectAttemptCountNumber 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 activeDelegateThe 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
-
isConnectionLost
public boolean isConnectionLost() -
getReconnectAttemptCount
public int getReconnectAttemptCount() -
create
public static SparqlQueryConnectionWithReconnect create(Callable<org.apache.jena.rdfconnection.SparqlQueryConnection> connectionSupplier) throws Exception Immediately obtain a connection from the supplier- Throws:
Exception
-
getDelegate
public org.apache.jena.sparql.core.Transactional getDelegate()Description copied from interface:TransactionalWrapperThis method needs to be overridden for transaction support- Specified by:
getDelegatein interfaceTransactionalWrapper
-
checkForConnectionLoss
protected void checkForConnectionLoss() -
query
public org.apache.jena.query.QueryExecution query(org.apache.jena.query.Query query) Description copied from interface:SparqlQueryConnectionTmpSetup a SPARQL query execution. See alsoSparqlQueryConnectionTmp.querySelect(Query, Consumer),SparqlQueryConnectionTmp.queryConstruct(Query),SparqlQueryConnectionTmp.queryDescribe(Query),SparqlQueryConnectionTmp.queryAsk(Query)for ways to execute queries for of a specific form.- Specified by:
queryin interfaceorg.apache.jena.rdfconnection.SparqlQueryConnection- Specified by:
queryin interfaceSparqlQueryConnectionTmp- Returns:
- QueryExecution
-
isConnectionProblemException
-
forceCloseActiveConn
protected void forceCloseActiveConn() -
tryRecovery
This method is run by the healthcheck runner until there is no more exception- Throws:
Exception
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceorg.apache.jena.rdfconnection.SparqlQueryConnection
-
testForConnectionProblem
-
handleConnectionProblem
-
newQuery
public org.apache.jena.query.QueryExecutionBuilder newQuery()- Specified by:
newQueryin interfaceorg.apache.jena.rdfconnection.SparqlQueryConnection- Specified by:
newQueryin interfaceSparqlQueryConnectionTmp
-