diff options
Diffstat (limited to 'rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java')
-rw-r--r-- | rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java index 00aad603..7e625182 100644 --- a/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java +++ b/rest-services/cbs-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/cbs/client/api/CbsClientFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * DCAEGEN2-SERVICES-SDK * ================================================================================ - * Copyright (C) 2019 Nokia. All rights reserved. + * Copyright (C) 2019-2020 Nokia. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,12 +54,9 @@ public class CbsClientFactory { * @since 1.1.2 */ public static @NotNull Mono<CbsClient> createCbsClient(CbsClientConfiguration configuration) { - return Mono.defer(() -> { - final RxHttpClient httpClient = buildHttpClient(configuration.trustStoreKeys()); - final CbsLookup cbsLookup = new CbsLookup(); - return cbsLookup.lookup(configuration) - .map(addr -> new CbsClientImpl(httpClient, configuration.appName(), addr, configuration.protocol())); - }); + return Mono.fromCallable(() -> buildHttpClient(configuration.trustStoreKeys())) + .cache() + .flatMap(httpClient -> createCbsClientMono(httpClient, configuration)); } private static RxHttpClient buildHttpClient(TrustStoreKeys trustStoreKeys) { @@ -67,4 +64,10 @@ public class CbsClientFactory { ? RxHttpClientFactory.create(trustStoreKeys) : RxHttpClientFactory.create(); } + + private static Mono<CbsClient> createCbsClientMono(RxHttpClient httpClient, + CbsClientConfiguration configuration) { + return new CbsLookup().lookup(configuration) + .map(addr -> new CbsClientImpl(httpClient, configuration.appName(), addr, configuration.protocol())); + } } |