<commit_before>package com.ofg.infrastructure.discovery

import com.ofg.config.BasicProfiles
import groovy.transform.CompileStatic
import org.apache.curator.framework.CuratorFramework
import org.apache.curator.framework.CuratorFrameworkFactory
import org.apache.curator.retry.RetryNTimes
import org.apache.curator.test.TestingServer
import org.apache.curator.x.discovery.ServiceDiscovery
import org.apache.curator.x.discovery.ServiceDiscoveryBuilder
import org.apache.curator.x.discovery.ServiceInstance
import org.apache.curator.x.discovery.UriSpec
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Conditional
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import

import static com.ofg.infrastructure.discovery.ServiceConfigurationProperties.PATH

/**
 * Class holding configuration to Zookeeper server, Zookeeper service instance and to Curator framework.
 *
 * All the beans are available only in the {@link BasicProfiles#PRODUCTION} profile.
 * 
 * @see CuratorFramework
 * @see ServiceInstance
 * @see ServiceDiscovery
 */
@CompileStatic
@Import(ConsumerDrivenContractConfiguration)
@Configuration
class ServiceDiscoveryInfrastructureConfiguration {

    @Bean(initMethod = 'start', destroyMethod = 'close')
    CuratorFramework curatorFramework(ZookeeperConnector zookeeperConnector,
                                      @Value('${service.resolver.connection.retry.times:5}') int numberOfRetries,
                                      @Value('${service.resolver.connection.retry.wait:1000}') int sleepMsBetweenRetries) {
        return CuratorFrameworkFactory.newClient(zookeeperConnector.serviceResolverUrl, new RetryNTimes(numberOfRetries, sleepMsBetweenRetries))
    }<commit_msg>[#250] unify curator client retry policies<commit_after>package com.ofg.infrastructure.discovery

import com.ofg.config.BasicProfiles
import groovy.transform.CompileStatic
import org.apache.curator.RetryPolicy
import org.apache.curator.framework.CuratorFramework
import org.apache.curator.framework.CuratorFrameworkFactory
import org.apache.curator.retry.ExponentialBackoffRetry
import org.apache.curator.test.TestingServer
import org.apache.curator.x.discovery.ServiceDiscovery
import org.apache.curator.x.discovery.ServiceDiscoveryBuilder
import org.apache.curator.x.discovery.ServiceInstance
import org.apache.curator.x.discovery.UriSpec
import org.springframework.beans.factory.annotation.Value
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Conditional
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import

import static com.ofg.infrastructure.discovery.ServiceConfigurationProperties.PATH

/**
 * Class holding configuration to Zookeeper server, Zookeeper service instance and to Curator framework.
 *
 * All the beans are available only in the {@link BasicProfiles#PRODUCTION} profile.
 *
 * @see CuratorFramework
 * @see RetryPolicy
 * @see ServiceInstance
 * @see ServiceDiscovery
 */
@CompileStatic
@Import(ConsumerDrivenContractConfiguration)
@Configuration
class ServiceDiscoveryInfrastructureConfiguration {

    @Bean
    RetryPolicy exponentialBackoffRetry(@Value('${service.resolver.connection.retry.baseSleepMs:50}') int numberOfRetries,
                                         @Value('${service.resolver.connection.retry.maxRetries:20}') int maxRetries,
                                         @Value('${service.resolver.connection.retry.maxSleepMs:500}') int maxSleepMs) {
        return new ExponentialBackoffRetry(50, 20, 500)
    }

    @Bean(initMethod = 'start', destroyMethod = 'close')
    CuratorFramework curatorFramework(ZookeeperConnector zookeeperConnector, RetryPolicy retryPolicy) {
        return CuratorFrameworkFactory.newClient(zookeeperConnector.serviceResolverUrl, retryPolicy)
    }
{'fraction_non_alphanumeric': 0.08270676691729323, 'fraction_numerical': 0.005513784461152882, 'mean_word_length': 5.187596899224806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7065895', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1028, 'n_words': 195}