All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.ipe.ble.irp.handler.configuration.DestinationConfig Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
package com.sap.ipe.ble.irp.handler.configuration;

import com.sap.cloud.sdk.cloudplatform.connectivity.*;
import com.sap.cloud.sdk.cloudplatform.resilience.CacheExpirationStrategy;
import com.sap.cloud.sdk.cloudplatform.resilience.ResilienceConfiguration;
import com.sap.ipe.ble.irp.handler.GenericHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.time.Duration;

/***
 * DestinationConfig is used to set the Resilience and DestinationService related information
 *
 */
@Configuration
public class DestinationConfig {

    /***
     *This method is used to define the bean for resilience configuration needed
     * @return resilience configurations maintained
     */
    @Bean(name="resilience")
    public ResilienceConfiguration resilienceConfiguration() {
        return ResilienceConfiguration.of(GenericHandler.class)
                .retryConfiguration(ResilienceConfiguration.RetryConfiguration.of(3, Duration.ofSeconds(1L)))
                .circuitBreakerConfiguration(
                        ResilienceConfiguration.CircuitBreakerConfiguration.of()
                                .waitDuration(Duration.ofSeconds(30)))
                .bulkheadConfiguration(
                        ResilienceConfiguration.BulkheadConfiguration.of()
                                .maxConcurrentCalls(1000));
    }

    /**
     * This method is used to define the bean for destination services
     * Here we specify the retrievalStrategy and token exchange strategy
     * @return destination options for retrieval and token exchange
     */
    @Bean(name="destOptions")
    public DestinationOptions destinationOptions() {
        return DestinationOptions.builder()
                .augmentBuilder(
                        DestinationServiceOptionsAugmenter.augmenter()
                                .retrievalStrategy(
                                        DestinationServiceRetrievalStrategy
                                                .CURRENT_TENANT)
                                .tokenExchangeStrategy(
                                        DestinationServiceTokenExchangeStrategy.LOOKUP_THEN_EXCHANGE))
                .build();
    }

    /***
     * This method is used to define the bean for destinationService
     * Here we define the cache expiration time and change detection
     * @return destination service for caching
     */
    @Bean(name="destLoader")
    public DestinationService scpCfDestinationLoader() {
        DestinationService.Cache.setExpiration(
                Duration.ofHours(1L), CacheExpirationStrategy.WHEN_CREATED);
        DestinationService.Cache.enableChangeDetection();
        return new DestinationService();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy