Class ElasticsearchHttpClientFactory

java.lang.Object
org.alfresco.repo.search.impl.elasticsearch.client.ElasticsearchHttpClientFactory

public class ElasticsearchHttpClientFactory extends Object
Singleton factory for Elasticsearch Http Client. This class is providing an Elastic RestHighLevelClient instance, that maintains a pool of RestLowLevelClient instances.
  • Field Details

  • Constructor Details

    • ElasticsearchHttpClientFactory

      public ElasticsearchHttpClientFactory()
  • Method Details

    • init

      public void init()
      Initialize SSL Truststore for https connections using "encryption.ssl.truststore.*" properties
    • destroy

      public void destroy()
      Releases resources held by the Elasticsearch client transport, including the HTTP connection pool and IO reactor threads.
    • getSecureComms

      protected String getSecureComms()
    • getHost

      protected String getHost()
    • getBaseUrl

      protected String getBaseUrl()
    • getPort

      protected int getPort()
    • getSslEncryptionParameters

      protected org.alfresco.encryption.ssl.SSLEncryptionParameters getSslEncryptionParameters()
    • getKeyResourceLoader

      protected org.alfresco.encryption.KeyResourceLoader getKeyResourceLoader()
    • getSslTrustStore

      protected org.alfresco.encryption.AlfrescoKeyStore getSslTrustStore()
    • isHostNameVerification

      protected boolean isHostNameVerification()
    • getUser

      protected String getUser()
    • getMaxTotalConnections

      protected int getMaxTotalConnections()
    • getMaxHostConnections

      protected int getMaxHostConnections()
    • getThreadCount

      protected int getThreadCount()
    • getConnectionTimeout

      protected int getConnectionTimeout()
    • getSocketTimeout

      protected int getSocketTimeout()
    • getResponseTimeout

      protected int getResponseTimeout()
    • getClient

      protected org.opensearch.client.opensearch.OpenSearchClient getClient()
    • getElasticsearchClient

      public org.opensearch.client.opensearch.OpenSearchClient getElasticsearchClient()
      Singleton method returning the Elasticsearch client. The client is only built if it's not already created.
      Returns:
      Elasticsearch client
    • getElasticsearchServerUrl

      public String getElasticsearchServerUrl()
      Gets Elasticsearch server URL
      Returns:
      Elasticsearch server URL
    • getElasticsearchClient

      protected org.opensearch.client.opensearch.OpenSearchClient getElasticsearchClient(String protocol, int port)
      Creates an Elasticsearch client applying parameters from properties file
      Parameters:
      protocol - Http protocol: http or https
      port - Port number
      Returns:
      Elasticsearch client ready to be used
    • buildRequestConfig

      protected org.apache.hc.client5.http.config.RequestConfig buildRequestConfig()
      Builds and caches the RequestConfig with the configured response timeout.
    • getHttpAsyncClientBuilder

      protected org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder getHttpAsyncClientBuilder(org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder httpClientBuilder)
      Apply pooling options, credentials and SSL settings to Elasticsearch client
      Parameters:
      httpClientBuilder - Existing HttpClientBuilder instance
      Returns:
      httpClientBuilder including required settings
    • getCredentialsProvider

      protected org.apache.hc.client5.http.auth.CredentialsProvider getCredentialsProvider()
      Build CredentialsProvider instance with user and password values from properties file
      Returns:
      CredentialsProvider instance
    • getSSLContext

      protected SSLContext getSSLContext()
      Build SSLContext instance with truststore that must include Elasticsearch server public certificate in order to be trusted for this https connection.
      Returns:
      SSLContext instance
    • setHost

      public void setHost(String host)
    • setBaseUrl

      public void setBaseUrl(String baseUrl)
    • setPort

      public void setPort(int port)
    • setSecureComms

      public void setSecureComms(String secureComms)
    • setUser

      public void setUser(String user)
    • setPassword

      public void setPassword(String password)
    • setMaxTotalConnections

      public void setMaxTotalConnections(int maxTotalConnections)
    • setMaxHostConnections

      public void setMaxHostConnections(int maxHostConnections)
    • setConnectionTimeout

      public void setConnectionTimeout(int connectionTimeout)
    • setSocketTimeout

      public void setSocketTimeout(int socketTimeout)
    • setResponseTimeout

      public void setResponseTimeout(int responseTimeout)
    • setClient

      protected void setClient(org.opensearch.client.opensearch.OpenSearchClient client)
    • setSslEncryptionParameters

      public void setSslEncryptionParameters(org.alfresco.encryption.ssl.SSLEncryptionParameters sslEncryptionParameters)
    • setKeyResourceLoader

      public void setKeyResourceLoader(org.alfresco.encryption.KeyResourceLoader keyResourceLoader)
    • setHostNameVerification

      public void setHostNameVerification(boolean hostNameVerification)
    • setIndexName

      public void setIndexName(String indexName)
    • setArchiveIndexName

      public void setArchiveIndexName(String archiveIndexName)
    • getArchiveIndexName

      public String getArchiveIndexName()
    • getIndexName

      public String getIndexName()
    • setThreadCount

      public void setThreadCount(int threadCount)