Class SharedHttpClientSessionManager
- All Implemented Interfaces:
HttpClientDependent
,HttpClientSessionManager
HttpClient
to manage HTTP connections.- Author:
- James Leigh
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
HTTP connection request timeout in milliseconds for general use.static final String
Configurable system propertyorg.eclipse.rdf4j.client.http.connectionRequestTimeout
for specifying the HTTP connection request timeout in milliseconds for general use.static final int
HTTP connection timeout in milliseconds for general use.static final String
Configurable system propertyorg.eclipse.rdf4j.client.http.connectionTimeout
for specifying the HTTP connection timeout in milliseconds for general use.static final int
Core pool size for the executor service, as read from system properties or defaults.static final String
Configurable system propertyorg.eclipse.rdf4j.client.executors.corePoolSize
for specifying the background executor core thread pool size.static final int
Default HTTP connection request timeout in milliseconds for general use.static final int
Default HTTP connection timeout in milliseconds for general use.static final int
Default core pool size for the executor service.static final int
Default maximum number of connections per route (per host).static final int
Default maximum total number of connections.static final int
Default HTTP socket timeout in milliseconds for general use.static final int
Default HTTP connection request timeout in milliseconds for SPARQL SERVICE calls.static final int
Default HTTP connection timeout in milliseconds for SPARQL SERVICE calls.static final int
Default HTTP socket timeout in milliseconds for SPARQL SERVICE calls.static final int
Maximum number of connections per route (per host), as read from system properties or defaults.static final String
Configurable system propertyorg.eclipse.rdf4j.client.http.maxConnPerRoute
for specifying the maximum number of connections per route (per host).static final int
Maximum total number of connections, as read from system properties or defaults.static final String
Configurable system propertyorg.eclipse.rdf4j.client.http.maxConnTotal
for specifying the maximum total number of connections.static final int
HTTP socket timeout in milliseconds for general use.static final String
Configurable system propertyorg.eclipse.rdf4j.client.http.socketTimeout
for specifying the HTTP socket timeout in milliseconds for general use.static final int
HTTP connection request timeout in milliseconds for SPARQL SERVICE calls.static final String
Configurable system propertyorg.eclipse.rdf4j.client.sparql.http.connectionRequestTimeout
for specifying the HTTP connection request timeout in milliseconds when used in SPARQL SERVICE calls.static final int
HTTP connection timeout in milliseconds for SPARQL SERVICE calls.static final String
Configurable system propertyorg.eclipse.rdf4j.client.sparql.http.connectionTimeout
for specifying the HTTP connection timeout in milliseconds when used in SPARQL SERVICE calls.static final int
HTTP socket timeout in milliseconds for SPARQL SERVICE calls.static final String
Configurable system propertyorg.eclipse.rdf4j.client.sparql.http.socketTimeout
for specifying the HTTP socket timeout in milliseconds when used in SPARQL SERVICE calls. -
Constructor Summary
ConstructorDescriptionSharedHttpClientSessionManager
(org.apache.http.impl.client.CloseableHttpClient dependentClient, ScheduledExecutorService dependentExecutorService) -
Method Summary
Modifier and TypeMethodDescriptioncreateRDF4JProtocolSession
(String serverURL) Creates a new session to the remote RDF4J REST API.createSPARQLProtocolSession
(String queryEndpointUrl, String updateEndpointUrl) Creates a new SPARQL Protocol session to the remote SPARQL endpoint.org.apache.http.client.config.RequestConfig
Returns the defaultRequestConfig
using the currently set timeout values.protected final ExecutorService
Get theExecutorService
used by this session manager.org.apache.http.client.HttpClient
HttpClient
that has been assigned or has been used by this object.void
Deprecated.Create a new instance instead of trying to reactivate an old instance.void
Switches the current timeout settings to use the SPARQL-specific timeouts.void
Resets the current timeout settings to the general timeouts.void
setHttpClient
(org.apache.http.client.HttpClient httpClient) Assign anHttpClient
that this object should use.void
setHttpClientBuilder
(org.apache.http.impl.client.HttpClientBuilder httpClientBuilder) Set an optionalHttpClientBuilder
to create the innerhttpClient
(if the latter is not provided externally as dependent client).void
shutDown()
Closes any remaining connections and threads used by the sessions created by this object.
-
Field Details
-
CORE_POOL_SIZE_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.executors.corePoolSize
for specifying the background executor core thread pool size.- See Also:
-
MAX_CONN_PER_ROUTE_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.http.maxConnPerRoute
for specifying the maximum number of connections per route (per host). Default is 25.This property determines the maximum number of concurrent connections to a single host (route). Adjusting this value can improve performance when communicating with a server that supports multiple concurrent connections.
- See Also:
-
MAX_CONN_TOTAL_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.http.maxConnTotal
for specifying the maximum total number of connections. Default is 50.This property sets the maximum total number of concurrent connections that can be open at the same time. Increasing this value allows more simultaneous connections to different hosts, which can improve throughput in multi-threaded environments.
- See Also:
-
CONNECTION_TIMEOUT_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.http.connectionTimeout
for specifying the HTTP connection timeout in milliseconds for general use. Default is 30 seconds.The connection timeout determines the maximum time the client will wait to establish a TCP connection to the server. A default of 30 seconds is set to allow for potential network delays without causing unnecessary timeouts.
- See Also:
-
CONNECTION_REQUEST_TIMEOUT_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.http.connectionRequestTimeout
for specifying the HTTP connection request timeout in milliseconds for general use. Default is 1 hour.The connection request timeout defines how long the client will wait for a connection from the connection pool.
- See Also:
-
SOCKET_TIMEOUT_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.http.socketTimeout
for specifying the HTTP socket timeout in milliseconds for general use. Default is 10 days.The socket timeout controls the maximum period of inactivity between data packets during data transfer. A longer timeout is appropriate for large data transfers, ensuring that operations are not interrupted prematurely.
- See Also:
-
SPARQL_CONNECTION_TIMEOUT_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.sparql.http.connectionTimeout
for specifying the HTTP connection timeout in milliseconds when used in SPARQL SERVICE calls. Default is 5 seconds.A shorter connection timeout is set for SPARQL SERVICE calls to quickly detect unresponsive endpoints in federated queries, improving overall query performance by avoiding long waits for unreachable servers.
- See Also:
-
SPARQL_CONNECTION_REQUEST_TIMEOUT_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.sparql.http.connectionRequestTimeout
for specifying the HTTP connection request timeout in milliseconds when used in SPARQL SERVICE calls. Default is 10 minutes.This timeout controls how long the client waits for a connection from the pool when making SPARQL SERVICE calls. A shorter timeout than general use ensures that queries fail fast if resources are constrained, maintaining responsiveness.
- See Also:
-
SPARQL_SOCKET_TIMEOUT_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.sparql.http.socketTimeout
for specifying the HTTP socket timeout in milliseconds when used in SPARQL SERVICE calls. Default is 1 hour.The socket timeout for SPARQL SERVICE calls is set to a shorter duration to detect unresponsive servers during data transfer, ensuring that the client does not wait indefinitely for data that may never arrive.
- See Also:
-
DEFAULT_CORE_POOL_SIZE
public static final int DEFAULT_CORE_POOL_SIZEDefault core pool size for the executor service. Set to 5.This value determines the number of threads to keep in the pool, even if they are idle. Adjusting this value can help manage resource utilization in high-load scenarios.
- See Also:
-
DEFAULT_MAX_CONN_PER_ROUTE
public static final int DEFAULT_MAX_CONN_PER_ROUTEDefault maximum number of connections per route (per host). Set to 25.This value limits the number of concurrent connections to a single host. Increasing it can improve performance when communicating with a server that can handle multiple connections.
- See Also:
-
DEFAULT_MAX_CONN_TOTAL
public static final int DEFAULT_MAX_CONN_TOTALDefault maximum total number of connections. Set to 50.This value limits the total number of concurrent connections that can be open at the same time. Increasing it allows for more simultaneous connections to different hosts.
- See Also:
-
DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUTDefault HTTP connection timeout in milliseconds for general use. Set to 30 seconds.The connection timeout determines the maximum time the client will wait to establish a TCP connection to the server.
- See Also:
-
DEFAULT_CONNECTION_REQUEST_TIMEOUT
public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUTDefault HTTP connection request timeout in milliseconds for general use. Set to 1 hour.The connection request timeout defines how long the client will wait for a connection from the connection pool.
- See Also:
-
DEFAULT_SOCKET_TIMEOUT
public static final int DEFAULT_SOCKET_TIMEOUTDefault HTTP socket timeout in milliseconds for general use. Set to 10 days.The socket timeout controls the maximum period of inactivity between data packets during data transfer. A longer timeout is appropriate for large data transfers.
- See Also:
-
DEFAULT_SPARQL_CONNECTION_TIMEOUT
public static final int DEFAULT_SPARQL_CONNECTION_TIMEOUTDefault HTTP connection timeout in milliseconds for SPARQL SERVICE calls. Set to 5 seconds.A shorter connection timeout is set for SPARQL SERVICE calls to quickly detect unresponsive endpoints in federated queries.
- See Also:
-
DEFAULT_SPARQL_CONNECTION_REQUEST_TIMEOUT
public static final int DEFAULT_SPARQL_CONNECTION_REQUEST_TIMEOUTDefault HTTP connection request timeout in milliseconds for SPARQL SERVICE calls. Set to 10 minutes.This timeout controls how long the client waits for a connection from the pool when making SPARQL SERVICE calls.
- See Also:
-
DEFAULT_SPARQL_SOCKET_TIMEOUT
public static final int DEFAULT_SPARQL_SOCKET_TIMEOUTDefault HTTP socket timeout in milliseconds for SPARQL SERVICE calls. Set to 1 hour.The socket timeout for SPARQL SERVICE calls is set to a shorter duration to detect unresponsive servers during data transfer.
- See Also:
-
CORE_POOL_SIZE
public static final int CORE_POOL_SIZECore pool size for the executor service, as read from system properties or defaults. -
MAX_CONN_PER_ROUTE
public static final int MAX_CONN_PER_ROUTEMaximum number of connections per route (per host), as read from system properties or defaults. -
MAX_CONN_TOTAL
public static final int MAX_CONN_TOTALMaximum total number of connections, as read from system properties or defaults. -
CONNECTION_TIMEOUT
public static final int CONNECTION_TIMEOUTHTTP connection timeout in milliseconds for general use. -
CONNECTION_REQUEST_TIMEOUT
public static final int CONNECTION_REQUEST_TIMEOUTHTTP connection request timeout in milliseconds for general use. -
SOCKET_TIMEOUT
public static final int SOCKET_TIMEOUTHTTP socket timeout in milliseconds for general use. -
SPARQL_CONNECTION_TIMEOUT
public static final int SPARQL_CONNECTION_TIMEOUTHTTP connection timeout in milliseconds for SPARQL SERVICE calls. -
SPARQL_CONNECTION_REQUEST_TIMEOUT
public static final int SPARQL_CONNECTION_REQUEST_TIMEOUTHTTP connection request timeout in milliseconds for SPARQL SERVICE calls. -
SPARQL_SOCKET_TIMEOUT
public static final int SPARQL_SOCKET_TIMEOUTHTTP socket timeout in milliseconds for SPARQL SERVICE calls.
-
-
Constructor Details
-
SharedHttpClientSessionManager
public SharedHttpClientSessionManager() -
SharedHttpClientSessionManager
public SharedHttpClientSessionManager(org.apache.http.impl.client.CloseableHttpClient dependentClient, ScheduledExecutorService dependentExecutorService)
-
-
Method Details
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient()Description copied from interface:HttpClientDependent
HttpClient
that has been assigned or has been used by this object. The life cycle might not be or might be tied to this object, depending on whetherHttpClient
was passed to or created by this object respectively.- Specified by:
getHttpClient
in interfaceHttpClientDependent
- Specified by:
getHttpClient
in interfaceHttpClientSessionManager
- Returns:
- Returns the httpClient.
-
setHttpClient
public void setHttpClient(org.apache.http.client.HttpClient httpClient) Description copied from interface:HttpClientDependent
Assign anHttpClient
that this object should use. The life cycle of the givenHttpClient
is independent of this object. Closing or shutting down this object does not have any impact on the given client. Callers must ensure that the given client is properly closed elsewhere.- Specified by:
setHttpClient
in interfaceHttpClientDependent
- Parameters:
httpClient
- The httpClient to use for remote/service calls.
-
setHttpClientBuilder
public void setHttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder httpClientBuilder) Set an optionalHttpClientBuilder
to create the innerhttpClient
(if the latter is not provided externally as dependent client).- Parameters:
httpClientBuilder
- the builder for the managed HttpClient- See Also:
-
createSPARQLProtocolSession
public SPARQLProtocolSession createSPARQLProtocolSession(String queryEndpointUrl, String updateEndpointUrl) Description copied from interface:HttpClientSessionManager
Creates a new SPARQL Protocol session to the remote SPARQL endpoint.- Specified by:
createSPARQLProtocolSession
in interfaceHttpClientSessionManager
-
createRDF4JProtocolSession
Description copied from interface:HttpClientSessionManager
Creates a new session to the remote RDF4J REST API.- Specified by:
createRDF4JProtocolSession
in interfaceHttpClientSessionManager
-
shutDown
public void shutDown()Description copied from interface:HttpClientSessionManager
Closes any remaining connections and threads used by the sessions created by this object.- Specified by:
shutDown
in interfaceHttpClientSessionManager
-
initialize
Deprecated.Create a new instance instead of trying to reactivate an old instance.No-op -
getExecutorService
Get theExecutorService
used by this session manager.- Returns:
- a
ExecutorService
used by allSPARQLProtocolSession
andRDF4JProtocolSession
instances created by this session manager.
-
getDefaultRequestConfig
public org.apache.http.client.config.RequestConfig getDefaultRequestConfig()Returns the defaultRequestConfig
using the currently set timeout values.- Returns:
- a configured
RequestConfig
with the current timeouts.
-
setDefaultSparqlServiceTimeouts
public void setDefaultSparqlServiceTimeouts()Switches the current timeout settings to use the SPARQL-specific timeouts. This method should be called when making SPARQL SERVICE calls to apply shorter timeout values.The SPARQL-specific timeouts are shorter to ensure that unresponsive or slow SPARQL endpoints do not cause long delays in federated query processing. Quick detection of such issues improves the responsiveness and reliability of SPARQL queries.
-
setDefaultTimeouts
public void setDefaultTimeouts()Resets the current timeout settings to the general timeouts. This method should be called to revert any changes made bysetDefaultSparqlServiceTimeouts()
and apply the general timeout values.The general timeouts are longer to accommodate operations that may take more time, such as large data transfers or extensive processing, without causing premature timeouts.
-