From f148765c57b286b47904a423e70a5595c83c095a Mon Sep 17 00:00:00 2001 From: Ross Nicoll Date: Wed, 31 May 2017 01:23:06 +0100 Subject: [PATCH] Add RPC registration diagnostics Add diagnostic information if attempting to use an RPC interface with duplicate method names, rather than throwing a collection error. --- .../net/corda/node/services/messaging/RPCServer.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/node/src/main/kotlin/net/corda/node/services/messaging/RPCServer.kt b/node/src/main/kotlin/net/corda/node/services/messaging/RPCServer.kt index 81935366a9..e001d4a248 100644 --- a/node/src/main/kotlin/net/corda/node/services/messaging/RPCServer.kt +++ b/node/src/main/kotlin/net/corda/node/services/messaging/RPCServer.kt @@ -40,6 +40,7 @@ import rx.Observable import rx.Subscriber import rx.Subscription import java.lang.reflect.InvocationTargetException +import java.lang.reflect.Method import java.time.Duration import java.util.* import java.util.concurrent.* @@ -92,7 +93,7 @@ class RPCServer( } private val lifeCycle = LifeCycle(State.UNSTARTED) // The methodname->Method map to use for dispatching. - private val methodTable = ops.javaClass.declaredMethods.groupBy { it.name }.mapValues { it.value.single() } + private val methodTable: Map // The observable subscription mapping. private val observableMap = createObservableSubscriptionMap() // A mapping from client addresses to IDs of associated Observables @@ -114,6 +115,16 @@ class RPCServer( private var clientBindingRemovalConsumer: ClientConsumer? = null private var serverControl: ActiveMQServerControl? = null + init { + val groupedMethods = ops.javaClass.declaredMethods.groupBy { it.name } + groupedMethods.forEach { name, methods -> + if (methods.size > 1) { + throw IllegalArgumentException("Encountered more than one method called ${name} on ${ops.javaClass.name}") + } + } + methodTable = groupedMethods.mapValues { it.value.single() } + } + private fun createObservableSubscriptionMap(): ObservableSubscriptionMap { val onObservableRemove = RemovalListener { log.debug { "Unsubscribing from Observable with id ${it.key} because of ${it.cause}" }