corda / net.corda.client.rpc.ext / MultiRPCClient

MultiRPCClient

class MultiRPCClient<I : RPCOps> : AutoCloseable

An RPC client connects to the specified server and allows to make calls using specified remote interface to the server that perform various useful tasks. Please see the Client RPC section of Corda Documentation to learn more about how this API works. Only a brief description is provided here.

Calling start returns an RPCConnection containing a proxy that allows making RPCs calls to the server. This is a blocking communication, and if the server throws an exception then it will be rethrown on the client. Proxies are thread safe and may be used to invoke multiple RPCs in parallel.

RPC sends and receives are logged on the net.corda.rpc logger.

In case of loss of connection to the server, the client will try to reconnect using the settings provided via CordaRPCClientConfiguration. If the client was created using a list of hosts via haAddressPool, automatic failover will occur (the servers have to be started in HA mode). While attempting failover, current and future RPC calls will throw RPCException.

It is also possible to add RPCConnectionListeners event before connection is started to be notified about connection lifecycle. Please see documentation on RPCConnectionListener for more details.

Parameters

hostAndPort - The network address to connect to.

haAddressPool - A list of NetworkHostAndPort representing the addresses of servers in HA mode. The client will attempt to connect to a live server by trying each address in the list. If the servers are not in HA mode, the client will round-robin from the beginning of the list and try all servers.

rpcOpsClass - Class instance of the RPCOps remote interface that will be used for communication.

username - The username to authenticate with.

password - The password to authenticate with.

configuration - An optional configuration used to tweak client behaviour.

sslConfiguration - An optional ClientRpcSslOptions used to enable secure communication with the server.

classLoader - a classloader, which will be used (if provided) to discover available SerializationCustomSerializers and SerializationWhitelists. If no classloader is provided, the classloader of the current class will be used by default for the aforementioned discovery process.

customSerializers - a set of SerializationCustomSerializers to be used. If this parameter is specified, then no classpath scanning will be performed for custom serializers, the provided ones will be used instead. This parameter serves as a more user-friendly option to specify your serializers and disable the classpath scanning (e.g. for performance reasons).

externalTrace - external Trace for correlation.

impersonatedActor - the actor on behalf of which all the invocations will be made.

targetLegalIdentity - in case of multi-identity RPC endpoint specific legal identity to which the calls must be addressed.

Constructors

<init>

MultiRPCClient(hostAndPort: NetworkHostAndPort, rpcOpsClass: Class<I>, username: String, password: String, configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT)
MultiRPCClient(hostAndPort: NetworkHostAndPort, rpcOpsClass: Class<I>, username: String, password: String, classLoader: ClassLoader, configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT)
MultiRPCClient(hostAndPort: NetworkHostAndPort, rpcOpsClass: Class<I>, username: String, password: String, sslConfiguration: ClientRpcSslOptions? = null, classLoader: ClassLoader? = null)
MultiRPCClient(hostAndPort: NetworkHostAndPort, rpcOpsClass: Class<I>, username: String, password: String, configuration: CordaRPCClientConfiguration, sslConfiguration: ClientRpcSslOptions?, classLoader: ClassLoader? = null)
MultiRPCClient(haAddressPool: List<NetworkHostAndPort>, rpcOpsClass: Class<I>, username: String, password: String, configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT, sslConfiguration: ClientRpcSslOptions? = null, classLoader: ClassLoader? = null)
MultiRPCClient(hostAndPort: NetworkHostAndPort, rpcOpsClass: Class<I>, username: String, password: String, customSerializers: Set<SerializationCustomSerializer<*, *>>?, configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT, sslConfiguration: ClientRpcSslOptions? = null, classLoader: ClassLoader? = null, externalTrace: Trace? = null, impersonatedActor: Actor? = null, targetLegalIdentity: CordaX500Name? = null)
MultiRPCClient(haAddressPool: List<NetworkHostAndPort>, rpcOpsClass: Class<I>, username: String, password: String, customSerializers: Set<SerializationCustomSerializer<*, *>>?, configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT, sslConfiguration: ClientRpcSslOptions? = null, classLoader: ClassLoader? = null, externalTrace: Trace? = null, impersonatedActor: Actor? = null, targetLegalIdentity: CordaX500Name? = null)

Functions

addConnectionListener

Adds RPCConnectionListener to this MultiRPCClient to be informed about important connectivity events.

fun addConnectionListener(listener: RPCConnectionListener<I>): Boolean

close

fun close(): Unit

removeConnectionListener

Removes RPCConnectionListener from this MultiRPCClient.

fun removeConnectionListener(listener: RPCConnectionListener<I>): Boolean

start

Logs in to the target server and returns an active connection.

fun start(): CompletableFuture<RPCConnection<I>>

stop

Stops the client and closes RPCConnection if it has been previously established

fun stop(): Unit