Skip to content

Package: ElasticsearchClientProvider

ElasticsearchClientProvider

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.service.elasticsearch.client;
14:
15: import org.eclipse.kapua.service.elasticsearch.client.configuration.ElasticsearchClientConfiguration;
16: import org.eclipse.kapua.service.elasticsearch.client.exception.ClientClosingException;
17: import org.eclipse.kapua.service.elasticsearch.client.exception.ClientProviderInitException;
18: import org.eclipse.kapua.service.elasticsearch.client.exception.ClientUnavailableException;
19:
20: /**
21: * {@link ElasticsearchClient} wrapper definition.
22: *
23: * @param <C> {@link ElasticsearchClient} type.
24: * @since 1.0.0
25: */
26: public interface ElasticsearchClientProvider<C extends ElasticsearchClient> extends AutoCloseable {
27:
28: /**
29: * Initializes the {@link ElasticsearchClientProvider}.
30: * <p>
31: * The init methods can be called more than once in order to reinitialize the underlying datastore connection.
32: * It the datastore was already initialized this method close the old one before initializing the new one.
33: *
34: * @return Itself, to chain invocations.
35: * @throws ClientProviderInitException in case of error while initializing {@link ElasticsearchClientProvider}
36: * @since 1.3.0
37: */
38: ElasticsearchClientProvider<C> init() throws ClientProviderInitException;
39:
40: /**
41: * Closes the {@link ElasticsearchClientProvider} and all {@link ElasticsearchClient}s
42: *
43: * @throws ClientClosingException in case of error while closing the client.
44: * @since 1.0.0
45: */
46: @Override
47: void close() throws ClientClosingException;
48:
49: /**
50: * Sets the {@link ElasticsearchClientConfiguration} to use to instantiate and manage the {@link ElasticsearchClient}.
51: *
52: * @param elasticsearchClientConfiguration The {@link ElasticsearchClientConfiguration}.
53: * @return Itself, to chain invocations.
54: * @since 1.3.0
55: */
56: ElasticsearchClientProvider<C> withClientConfiguration(ElasticsearchClientConfiguration elasticsearchClientConfiguration);
57:
58: /**
59: * Sets the {@link ModelContext} to use in the {@link ElasticsearchClient}.
60: *
61: * @param modelContext The {@link ElasticsearchClientConfiguration}.
62: * @return Itself, to chain invocations.
63: * @since 1.3.0
64: */
65: ElasticsearchClientProvider<C> withModelContext(ModelContext modelContext);
66:
67: /**
68: * Sets the {@link QueryConverter} to use in the {@link ElasticsearchClient}/
69: *
70: * @param queryConverter The {@link QueryConverter}.
71: * @return Itself, to chain invocations.
72: * @since 1.3.0
73: */
74: ElasticsearchClientProvider<C> withModelConverter(QueryConverter queryConverter);
75:
76:
77: /**
78: * Gets an initialized {@link ElasticsearchClient} instance.
79: *
80: * @return An initialized {@link ElasticsearchClient} instance.
81: * @throws ClientUnavailableException if the client has not being initialized.
82: * @since 1.0.0
83: */
84: C getElasticsearchClient() throws ClientUnavailableException;
85: }