Class SharedHttpClientSessionManager
- java.lang.Object
-
- org.eclipse.rdf4j.http.client.SharedHttpClientSessionManager
-
- All Implemented Interfaces:
HttpClientDependent
,HttpClientSessionManager
public class SharedHttpClientSessionManager extends Object implements HttpClientSessionManager, HttpClientDependent
A Manager for HTTP sessions that uses a sharedHttpClient
to manage HTTP connections.- Author:
- James Leigh
-
-
Field Summary
Fields Modifier and Type Field Description static int
CONNECTION_REQUEST_TIMEOUT
HTTP connection request timeout in milliseconds for general use.static String
CONNECTION_REQUEST_TIMEOUT_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.http.connectionRequestTimeout
for specifying the HTTP connection request timeout in milliseconds for general use.static int
CONNECTION_TIMEOUT
HTTP connection timeout in milliseconds for general use.static String
CONNECTION_TIMEOUT_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.http.connectionTimeout
for specifying the HTTP connection timeout in milliseconds for general use.static int
CORE_POOL_SIZE
Core pool size for the executor service, as read from system properties or defaults.static String
CORE_POOL_SIZE_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.executors.corePoolSize
for specifying the background executor core thread pool size.static int
DEFAULT_CONNECTION_REQUEST_TIMEOUT
Default HTTP connection request timeout in milliseconds for general use.static int
DEFAULT_CONNECTION_TIMEOUT
Default HTTP connection timeout in milliseconds for general use.static int
DEFAULT_CORE_POOL_SIZE
Default core pool size for the executor service.static int
DEFAULT_MAX_CONN_PER_ROUTE
Default maximum number of connections per route (per host).static int
DEFAULT_MAX_CONN_TOTAL
Default maximum total number of connections.static int
DEFAULT_SOCKET_TIMEOUT
Default HTTP socket timeout in milliseconds for general use.static int
DEFAULT_SPARQL_CONNECTION_REQUEST_TIMEOUT
Default HTTP connection request timeout in milliseconds for SPARQL SERVICE calls.static int
DEFAULT_SPARQL_CONNECTION_TIMEOUT
Default HTTP connection timeout in milliseconds for SPARQL SERVICE calls.static int
DEFAULT_SPARQL_SOCKET_TIMEOUT
Default HTTP socket timeout in milliseconds for SPARQL SERVICE calls.static int
MAX_CONN_PER_ROUTE
Maximum number of connections per route (per host), as read from system properties or defaults.static String
MAX_CONN_PER_ROUTE_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.http.maxConnPerRoute
for specifying the maximum number of connections per route (per host).static int
MAX_CONN_TOTAL
Maximum total number of connections, as read from system properties or defaults.static String
MAX_CONN_TOTAL_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.http.maxConnTotal
for specifying the maximum total number of connections.static int
SOCKET_TIMEOUT
HTTP socket timeout in milliseconds for general use.static String
SOCKET_TIMEOUT_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.http.socketTimeout
for specifying the HTTP socket timeout in milliseconds for general use.static int
SPARQL_CONNECTION_REQUEST_TIMEOUT
HTTP connection request timeout in milliseconds for SPARQL SERVICE calls.static String
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.static int
SPARQL_CONNECTION_TIMEOUT
HTTP connection timeout in milliseconds for SPARQL SERVICE calls.static String
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.static int
SPARQL_SOCKET_TIMEOUT
HTTP socket timeout in milliseconds for SPARQL SERVICE calls.static String
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.
-
Constructor Summary
Constructors Constructor Description SharedHttpClientSessionManager()
SharedHttpClientSessionManager(org.apache.http.impl.client.CloseableHttpClient dependentClient, ScheduledExecutorService dependentExecutorService)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description RDF4JProtocolSession
createRDF4JProtocolSession(String serverURL)
Creates a new session to the remote RDF4J REST API.SPARQLProtocolSession
createSPARQLProtocolSession(String queryEndpointUrl, String updateEndpointUrl)
Creates a new SPARQL Protocol session to the remote SPARQL endpoint.org.apache.http.client.config.RequestConfig
getDefaultRequestConfig()
Returns the defaultRequestConfig
using the currently set timeout values.protected ExecutorService
getExecutorService()
Get theExecutorService
used by this session manager.org.apache.http.client.HttpClient
getHttpClient()
HttpClient
that has been assigned or has been used by this object.void
initialize()
Deprecated.Create a new instance instead of trying to reactivate an old instance.void
setDefaultSparqlServiceTimeouts()
Switches the current timeout settings to use the SPARQL-specific timeouts.void
setDefaultTimeouts()
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 Detail
-
CORE_POOL_SIZE_PROPERTY
public static final String CORE_POOL_SIZE_PROPERTY
Configurable system propertyorg.eclipse.rdf4j.client.executors.corePoolSize
for specifying the background executor core thread pool size.- See Also:
- Constant Field Values
-
MAX_CONN_PER_ROUTE_PROPERTY
public static final String 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:
- Constant Field Values
-
MAX_CONN_TOTAL_PROPERTY
public static final String 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:
- Constant Field Values
-
CONNECTION_TIMEOUT_PROPERTY
public static final String 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:
- Constant Field Values
-
CONNECTION_REQUEST_TIMEOUT_PROPERTY
public static final String 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:
- Constant Field Values
-
SOCKET_TIMEOUT_PROPERTY
public static final String 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:
- Constant Field Values
-
SPARQL_CONNECTION_TIMEOUT_PROPERTY
public static final String 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:
- Constant Field Values
-
SPARQL_CONNECTION_REQUEST_TIMEOUT_PROPERTY
public static final String 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:
- Constant Field Values
-
SPARQL_SOCKET_TIMEOUT_PROPERTY
public static final String 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:
- Constant Field Values
-
DEFAULT_CORE_POOL_SIZE
public static final int DEFAULT_CORE_POOL_SIZE
Default 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:
- Constant Field Values
-
DEFAULT_MAX_CONN_PER_ROUTE
public static final int DEFAULT_MAX_CONN_PER_ROUTE
Default 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:
- Constant Field Values
-
DEFAULT_MAX_CONN_TOTAL
public static final int DEFAULT_MAX_CONN_TOTAL
Default 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:
- Constant Field Values
-
DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_CONNECTION_TIMEOUT
Default 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:
- Constant Field Values
-
DEFAULT_CONNECTION_REQUEST_TIMEOUT
public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT
Default 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:
- Constant Field Values
-
DEFAULT_SOCKET_TIMEOUT
public static final int DEFAULT_SOCKET_TIMEOUT
Default 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:
- Constant Field Values
-
DEFAULT_SPARQL_CONNECTION_TIMEOUT
public static final int DEFAULT_SPARQL_CONNECTION_TIMEOUT
Default 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:
- Constant Field Values
-
DEFAULT_SPARQL_CONNECTION_REQUEST_TIMEOUT
public static final int DEFAULT_SPARQL_CONNECTION_REQUEST_TIMEOUT
Default 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:
- Constant Field Values
-
DEFAULT_SPARQL_SOCKET_TIMEOUT
public static final int DEFAULT_SPARQL_SOCKET_TIMEOUT
Default 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:
- Constant Field Values
-
CORE_POOL_SIZE
public static final int CORE_POOL_SIZE
Core pool size for the executor service, as read from system properties or defaults.
-
MAX_CONN_PER_ROUTE
public static final int MAX_CONN_PER_ROUTE
Maximum number of connections per route (per host), as read from system properties or defaults.
-
MAX_CONN_TOTAL
public static final int MAX_CONN_TOTAL
Maximum total number of connections, as read from system properties or defaults.
-
CONNECTION_TIMEOUT
public static final int CONNECTION_TIMEOUT
HTTP connection timeout in milliseconds for general use.
-
CONNECTION_REQUEST_TIMEOUT
public static final int CONNECTION_REQUEST_TIMEOUT
HTTP connection request timeout in milliseconds for general use.
-
SOCKET_TIMEOUT
public static final int SOCKET_TIMEOUT
HTTP socket timeout in milliseconds for general use.
-
SPARQL_CONNECTION_TIMEOUT
public static final int SPARQL_CONNECTION_TIMEOUT
HTTP connection timeout in milliseconds for SPARQL SERVICE calls.
-
SPARQL_CONNECTION_REQUEST_TIMEOUT
public static final int SPARQL_CONNECTION_REQUEST_TIMEOUT
HTTP connection request timeout in milliseconds for SPARQL SERVICE calls.
-
SPARQL_SOCKET_TIMEOUT
public static final int SPARQL_SOCKET_TIMEOUT
HTTP socket timeout in milliseconds for SPARQL SERVICE calls.
-
-
Constructor Detail
-
SharedHttpClientSessionManager
public SharedHttpClientSessionManager()
-
SharedHttpClientSessionManager
public SharedHttpClientSessionManager(org.apache.http.impl.client.CloseableHttpClient dependentClient, ScheduledExecutorService dependentExecutorService)
-
-
Method Detail
-
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:
HttpClientBuilders
-
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
public RDF4JProtocolSession createRDF4JProtocolSession(String serverURL)
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 public void initialize()
Deprecated.Create a new instance instead of trying to reactivate an old instance.No-op
-
getExecutorService
protected final ExecutorService 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.
-
-