diff options
author | 2020-11-19 16:30:01 +0100 | |
---|---|---|
committer | 2020-11-25 13:24:31 +0100 | |
commit | c610bf0763522c2de5b68c9a7670a9bd269ad262 (patch) | |
tree | 7aabf350a4ab273abf143aa84e8e94706e9b46d5 /rest-services/cbs-client/src/main/java | |
parent | 3752a9df5643ba8b57a567a42eabe84db8b48975 (diff) |
Fix CbsClientFactory to allow retry on Mono from createCbsClient
Issue-ID: DCAEGEN2-2516
Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
Change-Id: Id6e58625f3c6bd4aa7dcb1bb167839e0ed31ef93
Diffstat (limited to 'rest-services/cbs-client/src/main/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())); + } } |