From 21d06a8aa9620fd619d9c87394ffe3f49b74bd05 Mon Sep 17 00:00:00 2001 From: Viktor Kolomeyko Date: Mon, 25 Jun 2018 14:13:21 +0100 Subject: [PATCH] ENT-2132 Introduce a boolean flag which controls whether we should re-try RPC connection. (#3433) In case of initial logon - it will not be re-tried to cater for invalid endpoint and/or credentials. However, if connection been successfully established once, re-try logic is getting activated. --- .../client/jfx/model/NodeMonitorModel.kt | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/client/jfx/src/main/kotlin/net/corda/client/jfx/model/NodeMonitorModel.kt b/client/jfx/src/main/kotlin/net/corda/client/jfx/model/NodeMonitorModel.kt index 0194edb110..ec66c85988 100644 --- a/client/jfx/src/main/kotlin/net/corda/client/jfx/model/NodeMonitorModel.kt +++ b/client/jfx/src/main/kotlin/net/corda/client/jfx/model/NodeMonitorModel.kt @@ -6,7 +6,6 @@ import javafx.beans.property.SimpleObjectProperty import net.corda.client.rpc.CordaRPCClient import net.corda.client.rpc.CordaRPCClientConfiguration import net.corda.client.rpc.CordaRPCConnection -import net.corda.client.rpc.RPCException import net.corda.core.contracts.ContractState import net.corda.core.flows.StateMachineRunId import net.corda.core.identity.Party @@ -22,7 +21,6 @@ import net.corda.core.transactions.SignedTransaction import net.corda.core.utilities.NetworkHostAndPort import net.corda.core.utilities.contextLogger import net.corda.core.utilities.seconds -import org.apache.activemq.artemis.api.core.ActiveMQException import rx.Observable import rx.Subscription import rx.subjects.PublishSubject @@ -125,7 +123,7 @@ class NodeMonitorModel { } } - val stateMachines = performRpcReconnect(nodeHostAndPort, username, password) + val stateMachines = performRpcReconnect(nodeHostAndPort, username, password, shouldRetry = false) // Extract the flow tracking stream // TODO is there a nicer way of doing this? Stream of streams in general results in code like this... @@ -146,9 +144,9 @@ class NodeMonitorModel { futureProgressTrackerUpdates.startWith(currentProgressTrackerUpdates).flatMap { it }.retry().subscribe(progressTrackingSubject) } - private fun performRpcReconnect(nodeHostAndPort: NetworkHostAndPort, username: String, password: String): List { + private fun performRpcReconnect(nodeHostAndPort: NetworkHostAndPort, username: String, password: String, shouldRetry: Boolean): List { - val connection = establishConnectionWithRetry(nodeHostAndPort, username, password) + val connection = establishConnectionWithRetry(nodeHostAndPort, username, password, shouldRetry) val proxy = connection.proxy val (stateMachineInfos, stateMachineUpdatesRaw) = proxy.stateMachinesFeed() @@ -166,7 +164,7 @@ class NodeMonitorModel { // force closing the connection to avoid propagation of notification to the server side. connection.forceClose() // Perform re-connect. - performRpcReconnect(nodeHostAndPort, username, password) + performRpcReconnect(nodeHostAndPort, username, password, shouldRetry = true) }) retryableStateMachineUpdatesSubscription.set(subscription) @@ -176,7 +174,7 @@ class NodeMonitorModel { return stateMachineInfos } - private fun establishConnectionWithRetry(nodeHostAndPort: NetworkHostAndPort, username: String, password: String): CordaRPCConnection { + private fun establishConnectionWithRetry(nodeHostAndPort: NetworkHostAndPort, username: String, password: String, shouldRetry: Boolean): CordaRPCConnection { val retryInterval = 5.seconds @@ -195,21 +193,15 @@ class NodeMonitorModel { require(nodeInfo.legalIdentitiesAndCerts.isNotEmpty()) _connection } catch (throwable: Throwable) { - when (throwable) { - is ActiveMQException, is RPCException -> { - // Happens when: - // * incorrect credentials provided; - // * incorrect endpoint specified; - // - no point to retry connecting. - throw throwable - } - else -> { - // Deliberately not logging full stack trace as it will be full of internal stacktraces. - logger.info("Exception upon establishing connection: " + throwable.message) - null - } + if (shouldRetry) { + // Deliberately not logging full stack trace as it will be full of internal stacktraces. + logger.info("Exception upon establishing connection: " + throwable.message) + null + } else { + throw throwable } } + if (connection != null) { logger.info("Connection successfully established with: $nodeHostAndPort") return connection