Skip to content

Commit b8dc30b

Browse files
committed
HSEARCH-5464 Push client specific settings to client modules
1 parent b07b70a commit b8dc30b

File tree

11 files changed

+405
-214
lines changed

11 files changed

+405
-214
lines changed

backend/elasticsearch-client/common/src/main/java/org/hibernate/search/backend/elasticsearch/client/common/cfg/ElasticsearchBackendClientCommonSettings.java

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -88,94 +88,6 @@ private ElasticsearchBackendClientCommonSettings() {
8888
*/
8989
public static final String PASSWORD = "password";
9090

91-
/**
92-
* The timeout when executing a request to an Elasticsearch server.
93-
* <p>
94-
* This includes the time needed to establish a connection, send the request and read the response.
95-
* <p>
96-
* Expects a positive Integer value in milliseconds, such as 60000,
97-
* or a String that can be parsed into such Integer value.
98-
* <p>
99-
* Defaults to no request timeout.
100-
*/
101-
public static final String REQUEST_TIMEOUT = "request_timeout";
102-
103-
/**
104-
* The timeout when reading responses from an Elasticsearch server.
105-
* <p>
106-
* Expects a positive Integer value in milliseconds, such as {@code 60000},
107-
* or a String that can be parsed into such Integer value.
108-
* <p>
109-
* Defaults to {@link Defaults#READ_TIMEOUT}.
110-
*/
111-
public static final String READ_TIMEOUT = "read_timeout";
112-
113-
/**
114-
* The timeout when establishing a connection to an Elasticsearch server.
115-
* <p>
116-
* Expects a positive Integer value in milliseconds, such as {@code 3000},
117-
* or a String that can be parsed into such Integer value.
118-
* <p>
119-
* Defaults to {@link Defaults#CONNECTION_TIMEOUT}.
120-
*/
121-
public static final String CONNECTION_TIMEOUT = "connection_timeout";
122-
123-
/**
124-
* The maximum number of simultaneous connections to the Elasticsearch cluster,
125-
* all hosts taken together.
126-
* <p>
127-
* Expects a positive Integer value, such as {@code 40},
128-
* or a String that can be parsed into such Integer value.
129-
* <p>
130-
* Defaults to {@link Defaults#MAX_CONNECTIONS}.
131-
*/
132-
public static final String MAX_CONNECTIONS = "max_connections";
133-
134-
/**
135-
* The maximum number of simultaneous connections to each host of the Elasticsearch cluster.
136-
* <p>
137-
* Expects a positive Integer value, such as {@code 20},
138-
* or a String that can be parsed into such Integer value.
139-
* <p>
140-
* Defaults to {@link Defaults#MAX_CONNECTIONS_PER_ROUTE}.
141-
*/
142-
public static final String MAX_CONNECTIONS_PER_ROUTE = "max_connections_per_route";
143-
144-
/**
145-
* Whether automatic discovery of nodes in the Elasticsearch cluster is enabled.
146-
* <p>
147-
* Expects a Boolean value such as {@code true} or {@code false},
148-
* or a string that can be parsed into a Boolean value.
149-
* <p>
150-
* Defaults to {@link Defaults#DISCOVERY_ENABLED}.
151-
*/
152-
public static final String DISCOVERY_ENABLED = "discovery.enabled";
153-
154-
/**
155-
* The time interval between two executions of the automatic discovery, if enabled.
156-
* <p>
157-
* Expects a positive Integer value in seconds, such as {@code 2},
158-
* or a String that can be parsed into such Integer value.
159-
* <p>
160-
* Defaults to {@link Defaults#DISCOVERY_REFRESH_INTERVAL}.
161-
*/
162-
public static final String DISCOVERY_REFRESH_INTERVAL = "discovery.refresh_interval";
163-
164-
/**
165-
* How long connections to the Elasticsearch cluster can be kept idle.
166-
* <p>
167-
* Expects a positive Long value of milliseconds, such as 60000,
168-
* or a String that can be parsed into such Integer value.
169-
* <p>
170-
* If the response from an Elasticsearch cluster contains a {@code Keep-Alive} header,
171-
* then the effective max idle time will be whichever is lower:
172-
* the duration from the {@code Keep-Alive} header or the value of this property (if set).
173-
* <p>
174-
* If this property is not set, only the {@code Keep-Alive} header is considered,
175-
* and if it's absent, idle connections will be kept forever.
176-
*/
177-
public static final String MAX_KEEP_ALIVE = "max_keep_alive";
178-
17991
/**
18092
* Default values for the different settings if no values are given.
18193
*/
@@ -187,11 +99,5 @@ private Defaults() {
18799
public static final List<String> HOSTS = Collections.singletonList( "localhost:9200" );
188100
public static final String PROTOCOL = "http";
189101
public static final String PATH_PREFIX = "";
190-
public static final int READ_TIMEOUT = 30000;
191-
public static final int CONNECTION_TIMEOUT = 1000;
192-
public static final int MAX_CONNECTIONS = 40;
193-
public static final int MAX_CONNECTIONS_PER_ROUTE = 20;
194-
public static final boolean DISCOVERY_ENABLED = false;
195-
public static final int DISCOVERY_REFRESH_INTERVAL = 10;
196102
}
197103
}

backend/elasticsearch-client/elasticsearch-java-client/src/main/java/org/hibernate/search/backend/elasticsearch/client/java/cfg/ClientJavaElasticsearchBackendClientSettings.java

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,99 @@ public final class ClientJavaElasticsearchBackendClientSettings {
2020
private ClientJavaElasticsearchBackendClientSettings() {
2121
}
2222

23+
/**
24+
* The timeout when executing a request to an Elasticsearch server.
25+
* <p>
26+
* This includes the time needed to establish a connection, send the request and read the response.
27+
* <p>
28+
* Expects a positive Integer value in milliseconds, such as 60000,
29+
* or a String that can be parsed into such Integer value.
30+
* <p>
31+
* Defaults to no request timeout.
32+
*/
33+
public static final String REQUEST_TIMEOUT = "request_timeout";
34+
35+
/**
36+
* The timeout when reading responses from an Elasticsearch server.
37+
* <p>
38+
* Expects a positive Integer value in milliseconds, such as {@code 60000},
39+
* or a String that can be parsed into such Integer value.
40+
* <p>
41+
* Defaults to {@link Defaults#READ_TIMEOUT}.
42+
*/
43+
public static final String READ_TIMEOUT = "read_timeout";
44+
45+
/**
46+
* The timeout when establishing a connection to an Elasticsearch server.
47+
* <p>
48+
* Expects a positive Integer value in milliseconds, such as {@code 3000},
49+
* or a String that can be parsed into such Integer value.
50+
* <p>
51+
* Defaults to {@link Defaults#CONNECTION_TIMEOUT}.
52+
*/
53+
public static final String CONNECTION_TIMEOUT = "connection_timeout";
54+
55+
/**
56+
* The maximum number of simultaneous connections to the Elasticsearch cluster,
57+
* all hosts taken together.
58+
* <p>
59+
* Expects a positive Integer value, such as {@code 40},
60+
* or a String that can be parsed into such Integer value.
61+
* <p>
62+
* Defaults to {@link Defaults#MAX_CONNECTIONS}.
63+
*/
64+
public static final String MAX_CONNECTIONS = "max_connections";
65+
66+
/**
67+
* The maximum number of simultaneous connections to each host of the Elasticsearch cluster.
68+
* <p>
69+
* Expects a positive Integer value, such as {@code 20},
70+
* or a String that can be parsed into such Integer value.
71+
* <p>
72+
* Defaults to {@link Defaults#MAX_CONNECTIONS_PER_ROUTE}.
73+
*/
74+
public static final String MAX_CONNECTIONS_PER_ROUTE = "max_connections_per_route";
75+
76+
/**
77+
* Whether automatic discovery of nodes in the Elasticsearch cluster is enabled.
78+
* <p>
79+
* Expects a Boolean value such as {@code true} or {@code false},
80+
* or a string that can be parsed into a Boolean value.
81+
* <p>
82+
* Defaults to {@link Defaults#DISCOVERY_ENABLED}.
83+
*/
84+
public static final String DISCOVERY_ENABLED = "discovery.enabled";
85+
86+
/**
87+
* The time interval between two executions of the automatic discovery, if enabled.
88+
* <p>
89+
* Expects a positive Integer value in seconds, such as {@code 2},
90+
* or a String that can be parsed into such Integer value.
91+
* <p>
92+
* Defaults to {@link Defaults#DISCOVERY_REFRESH_INTERVAL}.
93+
*/
94+
public static final String DISCOVERY_REFRESH_INTERVAL = "discovery.refresh_interval";
95+
96+
/**
97+
* How long connections to the Elasticsearch cluster can be kept idle.
98+
* <p>
99+
* Expects a positive Long value of milliseconds, such as 60000,
100+
* or a String that can be parsed into such Integer value.
101+
* <p>
102+
* If the response from an Elasticsearch cluster contains a {@code Keep-Alive} header,
103+
* then the effective max idle time will be whichever is lower:
104+
* the duration from the {@code Keep-Alive} header or the value of this property (if set).
105+
* <p>
106+
* If this property is not set, only the {@code Keep-Alive} header is considered,
107+
* and if it's absent, idle connections will be kept forever.
108+
*/
109+
public static final String MAX_KEEP_ALIVE = "max_keep_alive";
110+
23111
/**
24112
* A {@link ElasticsearchHttpClientConfigurer} that defines custom HTTP client configuration.
25113
* <p>
26114
* It can be used for example to tune the SSL context to accept self-signed certificates.
27-
* It allows overriding other HTTP client settings, such as {@link ElasticsearchBackendClientCommonSettings#USERNAME} or {@link ElasticsearchBackendClientCommonSettings#MAX_CONNECTIONS_PER_ROUTE}.
115+
* It allows overriding other HTTP client settings, such as {@link ElasticsearchBackendClientCommonSettings#USERNAME} or {@link #MAX_CONNECTIONS_PER_ROUTE}.
28116
* <p>
29117
* Expects a reference to a bean of type {@link ElasticsearchHttpClientConfigurer}.
30118
* <p>
@@ -39,5 +127,12 @@ public static final class Defaults {
39127

40128
private Defaults() {
41129
}
130+
131+
public static final int READ_TIMEOUT = 30000;
132+
public static final int CONNECTION_TIMEOUT = 1000;
133+
public static final int MAX_CONNECTIONS = 40;
134+
public static final int MAX_CONNECTIONS_PER_ROUTE = 20;
135+
public static final boolean DISCOVERY_ENABLED = false;
136+
public static final int DISCOVERY_REFRESH_INTERVAL = 10;
42137
}
43138
}

backend/elasticsearch-client/elasticsearch-java-client/src/main/java/org/hibernate/search/backend/elasticsearch/client/java/impl/ClientJavaElasticsearchClientFactory.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,44 +90,44 @@ public class ClientJavaElasticsearchClientFactory implements ElasticsearchClient
9090
.build();
9191

9292
private static final OptionalConfigurationProperty<Integer> REQUEST_TIMEOUT =
93-
ConfigurationProperty.forKey( ElasticsearchBackendClientCommonSettings.REQUEST_TIMEOUT )
93+
ConfigurationProperty.forKey( ClientJavaElasticsearchBackendClientSettings.REQUEST_TIMEOUT )
9494
.asIntegerStrictlyPositive()
9595
.build();
9696

9797
private static final ConfigurationProperty<Integer> READ_TIMEOUT =
98-
ConfigurationProperty.forKey( ElasticsearchBackendClientCommonSettings.READ_TIMEOUT )
98+
ConfigurationProperty.forKey( ClientJavaElasticsearchBackendClientSettings.READ_TIMEOUT )
9999
.asIntegerPositiveOrZeroOrNegative()
100-
.withDefault( ElasticsearchBackendClientCommonSettings.Defaults.READ_TIMEOUT )
100+
.withDefault( ClientJavaElasticsearchBackendClientSettings.Defaults.READ_TIMEOUT )
101101
.build();
102102

103103
private static final ConfigurationProperty<Integer> CONNECTION_TIMEOUT =
104-
ConfigurationProperty.forKey( ElasticsearchBackendClientCommonSettings.CONNECTION_TIMEOUT )
104+
ConfigurationProperty.forKey( ClientJavaElasticsearchBackendClientSettings.CONNECTION_TIMEOUT )
105105
.asIntegerPositiveOrZeroOrNegative()
106-
.withDefault( ElasticsearchBackendClientCommonSettings.Defaults.CONNECTION_TIMEOUT )
106+
.withDefault( ClientJavaElasticsearchBackendClientSettings.Defaults.CONNECTION_TIMEOUT )
107107
.build();
108108

109109
private static final ConfigurationProperty<Integer> MAX_TOTAL_CONNECTION =
110-
ConfigurationProperty.forKey( ElasticsearchBackendClientCommonSettings.MAX_CONNECTIONS )
110+
ConfigurationProperty.forKey( ClientJavaElasticsearchBackendClientSettings.MAX_CONNECTIONS )
111111
.asIntegerStrictlyPositive()
112-
.withDefault( ElasticsearchBackendClientCommonSettings.Defaults.MAX_CONNECTIONS )
112+
.withDefault( ClientJavaElasticsearchBackendClientSettings.Defaults.MAX_CONNECTIONS )
113113
.build();
114114

115115
private static final ConfigurationProperty<Integer> MAX_TOTAL_CONNECTION_PER_ROUTE =
116-
ConfigurationProperty.forKey( ElasticsearchBackendClientCommonSettings.MAX_CONNECTIONS_PER_ROUTE )
116+
ConfigurationProperty.forKey( ClientJavaElasticsearchBackendClientSettings.MAX_CONNECTIONS_PER_ROUTE )
117117
.asIntegerStrictlyPositive()
118-
.withDefault( ElasticsearchBackendClientCommonSettings.Defaults.MAX_CONNECTIONS_PER_ROUTE )
118+
.withDefault( ClientJavaElasticsearchBackendClientSettings.Defaults.MAX_CONNECTIONS_PER_ROUTE )
119119
.build();
120120

121121
private static final ConfigurationProperty<Boolean> DISCOVERY_ENABLED =
122-
ConfigurationProperty.forKey( ElasticsearchBackendClientCommonSettings.DISCOVERY_ENABLED )
122+
ConfigurationProperty.forKey( ClientJavaElasticsearchBackendClientSettings.DISCOVERY_ENABLED )
123123
.asBoolean()
124-
.withDefault( ElasticsearchBackendClientCommonSettings.Defaults.DISCOVERY_ENABLED )
124+
.withDefault( ClientJavaElasticsearchBackendClientSettings.Defaults.DISCOVERY_ENABLED )
125125
.build();
126126

127127
private static final ConfigurationProperty<Integer> DISCOVERY_REFRESH_INTERVAL =
128-
ConfigurationProperty.forKey( ElasticsearchBackendClientCommonSettings.DISCOVERY_REFRESH_INTERVAL )
128+
ConfigurationProperty.forKey( ClientJavaElasticsearchBackendClientSettings.DISCOVERY_REFRESH_INTERVAL )
129129
.asIntegerStrictlyPositive()
130-
.withDefault( ElasticsearchBackendClientCommonSettings.Defaults.DISCOVERY_REFRESH_INTERVAL )
130+
.withDefault( ClientJavaElasticsearchBackendClientSettings.Defaults.DISCOVERY_REFRESH_INTERVAL )
131131
.build();
132132

133133
private static final OptionalConfigurationProperty<
@@ -137,7 +137,7 @@ public class ClientJavaElasticsearchClientFactory implements ElasticsearchClient
137137
.build();
138138

139139
private static final OptionalConfigurationProperty<Long> MAX_KEEP_ALIVE =
140-
ConfigurationProperty.forKey( ElasticsearchBackendClientCommonSettings.MAX_KEEP_ALIVE )
140+
ConfigurationProperty.forKey( ClientJavaElasticsearchBackendClientSettings.MAX_KEEP_ALIVE )
141141
.asLongStrictlyPositive()
142142
.build();
143143

0 commit comments

Comments
 (0)