Skip to content

Commit 6136ece

Browse files
committed
HSEARCH-5464 Move out client common classes
1 parent 925daac commit 6136ece

File tree

102 files changed

+421
-217
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+421
-217
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
SPDX-License-Identifier: Apache-2.0
4+
Copyright Red Hat Inc. and Hibernate Authors
5+
-->
6+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
8+
<modelVersion>4.0.0</modelVersion>
9+
<parent>
10+
<groupId>org.hibernate.search</groupId>
11+
<artifactId>hibernate-search-parent-public</artifactId>
12+
<version>8.2.0-SNAPSHOT</version>
13+
<relativePath>../../../build/parents/public</relativePath>
14+
</parent>
15+
<artifactId>hibernate-search-backend-elasticsearch-client-common</artifactId>
16+
17+
<name>Hibernate Search Backend - Elasticsearch Client SPI</name>
18+
<description>Rest client SPI for the Elasticsearch backend</description>
19+
20+
<properties>
21+
<!-- This is a publicly distributed module that should be published: -->
22+
<deploy.skip>false</deploy.skip>
23+
<java.module.name>org.hibernate.search.backend.elasticsearch.client.common</java.module.name>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.hibernate.search</groupId>
29+
<artifactId>hibernate-search-engine</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.jboss.logging</groupId>
33+
<artifactId>jboss-logging</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.jboss.logging</groupId>
37+
<artifactId>jboss-logging-annotations</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>com.google.code.gson</groupId>
41+
<artifactId>gson</artifactId>
42+
</dependency>
43+
</dependencies>
44+
45+
<build>
46+
<plugins>
47+
<plugin>
48+
<groupId>org.moditect</groupId>
49+
<artifactId>moditect-maven-plugin</artifactId>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
</project>

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/gson/spi/GsonProvider.java renamed to backend/elasticsearch-client/common/src/main/java/org/hibernate/search/backend/elasticsearch/client/common/gson/spi/GsonProvider.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.search.backend.elasticsearch.gson.spi;
5+
package org.hibernate.search.backend.elasticsearch.client.common.gson.spi;
66

77
import java.util.Set;
88
import java.util.function.Supplier;
99

10-
import org.hibernate.search.backend.elasticsearch.lowlevel.index.mapping.impl.RootTypeMapping;
11-
import org.hibernate.search.backend.elasticsearch.lowlevel.index.settings.impl.IndexSettings;
12-
import org.hibernate.search.util.common.impl.CollectionHelper;
13-
1410
import com.google.gson.Gson;
1511
import com.google.gson.GsonBuilder;
1612
import com.google.gson.reflect.TypeToken;
@@ -21,24 +17,18 @@
2117
public final class GsonProvider {
2218

2319
/*
24-
* See https://github.com/google/gson/issues/764.
25-
*
26-
* Only composite type adapters (referring to another type adapter)
27-
* should be affected by this bug, so we'll list the corresponding types here.
28-
* Maybe it's even narrower, and only type adapters that indirectly refer to themselves are affected,
29-
* but I'm not entirely sure about that.
30-
*
31-
* Note we only need to list "root" types:
32-
* all types they refer to will also have their type adapter initialized.
20+
* https://github.com/google/gson/issues/764 is supposedly fixed.
21+
* Hence, we may not need the workaround anymore.
22+
* This version will be used in the test so we'll notice if things are still broken, for the main code
23+
* the workaround is in place through the GsonProviderHelper.
3324
*/
34-
private static final Set<TypeToken<?>> TYPES_CAUSING_GSON_CONCURRENT_INITIALIZATION_BUG =
35-
CollectionHelper.asImmutableSet(
36-
TypeToken.get( IndexSettings.class ),
37-
TypeToken.get( RootTypeMapping.class )
38-
);
39-
4025
public static GsonProvider create(Supplier<GsonBuilder> builderBaseSupplier, boolean logPrettyPrinting) {
41-
return new GsonProvider( builderBaseSupplier, logPrettyPrinting );
26+
return create( builderBaseSupplier, logPrettyPrinting, Set.of() );
27+
}
28+
29+
public static GsonProvider create(Supplier<GsonBuilder> builderBaseSupplier, boolean logPrettyPrinting,
30+
Set<TypeToken<?>> typeTokensToInit) {
31+
return new GsonProvider( builderBaseSupplier, logPrettyPrinting, typeTokensToInit );
4232
}
4333

4434
private final Gson gson;
@@ -47,16 +37,17 @@ public static GsonProvider create(Supplier<GsonBuilder> builderBaseSupplier, boo
4737

4838
private final JsonLogHelper logHelper;
4939

50-
private GsonProvider(Supplier<GsonBuilder> builderBaseSupplier, boolean logPrettyPrinting) {
40+
private GsonProvider(Supplier<GsonBuilder> builderBaseSupplier, boolean logPrettyPrinting,
41+
Set<TypeToken<?>> typeTokensToInit) {
5142
// Null serialization needs to be enabled to index null fields
5243
gson = builderBaseSupplier.get()
5344
.serializeNulls()
5445
.create();
55-
initializeTypeAdapters( gson );
46+
initializeTypeAdapters( gson, typeTokensToInit );
5647

5748
gsonNoSerializeNulls = builderBaseSupplier.get()
5849
.create();
59-
initializeTypeAdapters( gsonNoSerializeNulls );
50+
initializeTypeAdapters( gsonNoSerializeNulls, typeTokensToInit );
6051

6152
logHelper = JsonLogHelper.create( builderBaseSupplier.get(), logPrettyPrinting );
6253
}
@@ -81,8 +72,8 @@ public JsonLogHelper getLogHelper() {
8172
* We just initialize every adapter known to cause problems before we make the Gson object
8273
* available to multiple threads.
8374
*/
84-
private static void initializeTypeAdapters(Gson gson) {
85-
for ( TypeToken<?> typeToken : TYPES_CAUSING_GSON_CONCURRENT_INITIALIZATION_BUG ) {
75+
private static void initializeTypeAdapters(Gson gson, Set<TypeToken<?>> typeTokensToInit) {
76+
for ( TypeToken<?> typeToken : typeTokensToInit ) {
8677
gson.getAdapter( typeToken );
8778
}
8879
}

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/gson/spi/JsonLogHelper.java renamed to backend/elasticsearch-client/common/src/main/java/org/hibernate/search/backend/elasticsearch/client/common/gson/spi/JsonLogHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.search.backend.elasticsearch.gson.spi;
5+
package org.hibernate.search.backend.elasticsearch.client.common.gson.spi;
66

77
import java.io.PrintWriter;
88
import java.io.StringWriter;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package org.hibernate.search.backend.elasticsearch.client.common;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.search.backend.elasticsearch.client.spi;
5+
package org.hibernate.search.backend.elasticsearch.client.common.spi;
66

77
import java.util.concurrent.CompletableFuture;
88

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.search.backend.elasticsearch.client.spi;
5+
package org.hibernate.search.backend.elasticsearch.client.common.spi;
66

7-
import java.util.Optional;
8-
9-
import org.hibernate.search.backend.elasticsearch.ElasticsearchVersion;
10-
import org.hibernate.search.backend.elasticsearch.gson.spi.GsonProvider;
7+
import org.hibernate.search.backend.elasticsearch.client.common.gson.spi.GsonProvider;
118
import org.hibernate.search.engine.cfg.ConfigurationPropertySource;
129
import org.hibernate.search.engine.common.execution.spi.SimpleScheduledExecutor;
1310
import org.hibernate.search.engine.environment.bean.BeanResolver;
1411
import org.hibernate.search.engine.environment.thread.spi.ThreadProvider;
1512

1613
/**
1714
* Creates the Elasticsearch client.
18-
*
1915
*/
2016
public interface ElasticsearchClientFactory {
2117

22-
ElasticsearchClientImplementor create(BeanResolver beanResolver, ConfigurationPropertySource propertySource,
18+
ElasticsearchClientImplementor create(BeanResolver beanResolver,
19+
ConfigurationPropertySource propertySource,
2320
ThreadProvider threadProvider, String threadNamePrefix,
2421
SimpleScheduledExecutor timeoutExecutorService,
25-
GsonProvider gsonProvider,
26-
Optional<ElasticsearchVersion> configuredVersion);
22+
GsonProvider gsonProvider);
2723

2824
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.search.backend.elasticsearch.client.spi;
5+
package org.hibernate.search.backend.elasticsearch.client.common.spi;
66

77
/**
88
* An interface allowing to close an {@link ElasticsearchClient}.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.search.backend.elasticsearch.client.spi;
5+
package org.hibernate.search.backend.elasticsearch.client.common.spi;
66

77
import java.util.ArrayList;
88
import java.util.Collection;
@@ -12,7 +12,7 @@
1212
import java.util.Map;
1313
import java.util.StringJoiner;
1414

15-
import org.hibernate.search.backend.elasticsearch.util.spi.URLEncodedString;
15+
import org.hibernate.search.backend.elasticsearch.client.common.util.spi.URLEncodedString;
1616
import org.hibernate.search.engine.common.timing.Deadline;
1717

1818
import com.google.gson.JsonObject;
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.search.backend.elasticsearch.client.spi;
6-
7-
import java.util.Objects;
5+
package org.hibernate.search.backend.elasticsearch.client.common.spi;
86

97
import com.google.gson.JsonObject;
108

backend/elasticsearch/src/main/java/org/hibernate/search/backend/elasticsearch/util/spi/URLEncodedString.java renamed to backend/elasticsearch-client/common/src/main/java/org/hibernate/search/backend/elasticsearch/client/common/util/spi/URLEncodedString.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-License-Identifier: Apache-2.0
33
* Copyright Red Hat Inc. and Hibernate Authors
44
*/
5-
package org.hibernate.search.backend.elasticsearch.util.spi;
5+
package org.hibernate.search.backend.elasticsearch.client.common.util.spi;
66

77
import java.io.UnsupportedEncodingException;
88
import java.net.URLEncoder;

0 commit comments

Comments
 (0)