mirror of
https://github.com/corda/corda.git
synced 2024-12-19 21:17:58 +00:00
CORDA-3091: Move executor thread management into CordaRPCConnection (#5491)
This commit is contained in:
parent
be6824dac4
commit
6ca4b589e2
@ -1,8 +1,8 @@
|
|||||||
package net.corda.client.jfx.model
|
package net.corda.client.jfx.model
|
||||||
|
|
||||||
import javafx.beans.property.SimpleObjectProperty
|
import javafx.beans.property.SimpleObjectProperty
|
||||||
import net.corda.client.rpc.CordaRPCClientConfiguration
|
import net.corda.client.rpc.CordaRPCClient
|
||||||
import net.corda.client.rpc.internal.ReconnectingCordaRPCOps
|
import net.corda.client.rpc.CordaRPCConnection
|
||||||
import net.corda.core.contracts.ContractState
|
import net.corda.core.contracts.ContractState
|
||||||
import net.corda.core.flows.StateMachineRunId
|
import net.corda.core.flows.StateMachineRunId
|
||||||
import net.corda.core.identity.Party
|
import net.corda.core.identity.Party
|
||||||
@ -48,7 +48,7 @@ class NodeMonitorModel : AutoCloseable {
|
|||||||
val progressTracking: Observable<ProgressTrackingEvent> = progressTrackingSubject
|
val progressTracking: Observable<ProgressTrackingEvent> = progressTrackingSubject
|
||||||
val networkMap: Observable<MapChange> = networkMapSubject
|
val networkMap: Observable<MapChange> = networkMapSubject
|
||||||
|
|
||||||
private lateinit var rpc: CordaRPCOps
|
private lateinit var rpc: CordaRPCConnection
|
||||||
val proxyObservable = SimpleObjectProperty<CordaRPCOps>()
|
val proxyObservable = SimpleObjectProperty<CordaRPCOps>()
|
||||||
lateinit var notaryIdentities: List<Party>
|
lateinit var notaryIdentities: List<Party>
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ class NodeMonitorModel : AutoCloseable {
|
|||||||
*/
|
*/
|
||||||
override fun close() {
|
override fun close() {
|
||||||
try {
|
try {
|
||||||
(rpc as ReconnectingCordaRPCOps).close()
|
rpc.close()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.error("Error closing RPC connection to node", e)
|
logger.error("Error closing RPC connection to node", e)
|
||||||
}
|
}
|
||||||
@ -72,35 +72,42 @@ class NodeMonitorModel : AutoCloseable {
|
|||||||
* TODO provide an unsubscribe mechanism
|
* TODO provide an unsubscribe mechanism
|
||||||
*/
|
*/
|
||||||
fun register(nodeHostAndPort: NetworkHostAndPort, username: String, password: String) {
|
fun register(nodeHostAndPort: NetworkHostAndPort, username: String, password: String) {
|
||||||
rpc = ReconnectingCordaRPCOps(nodeHostAndPort, username, password, CordaRPCClientConfiguration.DEFAULT)
|
rpc = CordaRPCClient(nodeHostAndPort).start(username, password)
|
||||||
|
proxyObservable.value = rpc.proxy
|
||||||
proxyObservable.value = rpc
|
|
||||||
|
|
||||||
// Vault snapshot (force single page load with MAX_PAGE_SIZE) + updates
|
// Vault snapshot (force single page load with MAX_PAGE_SIZE) + updates
|
||||||
val (statesSnapshot, vaultUpdates) = rpc.vaultTrackBy<ContractState>(QueryCriteria.VaultQueryCriteria(Vault.StateStatus.ALL),
|
val (
|
||||||
PageSpecification(DEFAULT_PAGE_NUM, MAX_PAGE_SIZE))
|
statesSnapshot,
|
||||||
val unconsumedStates = statesSnapshot.states.filterIndexed { index, _ ->
|
vaultUpdates
|
||||||
statesSnapshot.statesMetadata[index].status == Vault.StateStatus.UNCONSUMED
|
) = rpc.proxy.vaultTrackBy<ContractState>(
|
||||||
|
QueryCriteria.VaultQueryCriteria(Vault.StateStatus.ALL),
|
||||||
|
PageSpecification(DEFAULT_PAGE_NUM, MAX_PAGE_SIZE)
|
||||||
|
)
|
||||||
|
val unconsumedStates =
|
||||||
|
statesSnapshot.states.filterIndexed { index, _ ->
|
||||||
|
statesSnapshot.statesMetadata[index].status == Vault.StateStatus.UNCONSUMED
|
||||||
}.toSet()
|
}.toSet()
|
||||||
val consumedStates = statesSnapshot.states.toSet() - unconsumedStates
|
val consumedStates = statesSnapshot.states.toSet() - unconsumedStates
|
||||||
val initialVaultUpdate = Vault.Update(consumedStates, unconsumedStates, references = emptySet())
|
val initialVaultUpdate = Vault.Update(consumedStates, unconsumedStates, references = emptySet())
|
||||||
vaultUpdates.startWith(initialVaultUpdate).subscribe(vaultUpdatesSubject::onNext)
|
vaultUpdates.startWith(initialVaultUpdate).subscribe(vaultUpdatesSubject::onNext)
|
||||||
|
|
||||||
// Transactions
|
// Transactions
|
||||||
val (transactions, newTransactions) = @Suppress("DEPRECATION") rpc.internalVerifiedTransactionsFeed()
|
val (transactions, newTransactions) =
|
||||||
|
@Suppress("DEPRECATION") rpc.proxy.internalVerifiedTransactionsFeed()
|
||||||
newTransactions.startWith(transactions).subscribe(transactionsSubject::onNext)
|
newTransactions.startWith(transactions).subscribe(transactionsSubject::onNext)
|
||||||
|
|
||||||
// SM -> TX mapping
|
// SM -> TX mapping
|
||||||
val (smTxMappings, futureSmTxMappings) = rpc.stateMachineRecordedTransactionMappingFeed()
|
val (smTxMappings, futureSmTxMappings) =
|
||||||
|
rpc.proxy.stateMachineRecordedTransactionMappingFeed()
|
||||||
futureSmTxMappings.startWith(smTxMappings).subscribe(stateMachineTransactionMappingSubject::onNext)
|
futureSmTxMappings.startWith(smTxMappings).subscribe(stateMachineTransactionMappingSubject::onNext)
|
||||||
|
|
||||||
// Parties on network
|
// Parties on network
|
||||||
val (parties, futurePartyUpdate) = rpc.networkMapFeed()
|
val (parties, futurePartyUpdate) = rpc.proxy.networkMapFeed()
|
||||||
futurePartyUpdate.startWith(parties.map(MapChange::Added)).subscribe(networkMapSubject::onNext)
|
futurePartyUpdate.startWith(parties.map(MapChange::Added)).subscribe(networkMapSubject::onNext)
|
||||||
|
|
||||||
val stateMachines = rpc.stateMachinesSnapshot()
|
val stateMachines = rpc.proxy.stateMachinesSnapshot()
|
||||||
|
|
||||||
notaryIdentities = rpc.notaryIdentities()
|
notaryIdentities = rpc.proxy.notaryIdentities()
|
||||||
|
|
||||||
// Extract the flow tracking stream
|
// Extract the flow tracking stream
|
||||||
// TODO is there a nicer way of doing this? Stream of streams in general results in code like this...
|
// TODO is there a nicer way of doing this? Stream of streams in general results in code like this...
|
||||||
|
@ -56,8 +56,8 @@ class CordaRPCClientReconnectionTest {
|
|||||||
maxReconnectAttempts = 5
|
maxReconnectAttempts = 5
|
||||||
))
|
))
|
||||||
|
|
||||||
(client.start(rpcUser.username, rpcUser.password, gracefulReconnect = gracefulReconnect).proxy as ReconnectingCordaRPCOps).use {
|
(client.start(rpcUser.username, rpcUser.password, gracefulReconnect = gracefulReconnect)).use {
|
||||||
val rpcOps = it
|
val rpcOps = it.proxy as ReconnectingCordaRPCOps
|
||||||
val networkParameters = rpcOps.networkParameters
|
val networkParameters = rpcOps.networkParameters
|
||||||
val cashStatesFeed = rpcOps.vaultTrack(Cash.State::class.java)
|
val cashStatesFeed = rpcOps.vaultTrack(Cash.State::class.java)
|
||||||
cashStatesFeed.updates.subscribe { latch.countDown() }
|
cashStatesFeed.updates.subscribe { latch.countDown() }
|
||||||
@ -96,8 +96,8 @@ class CordaRPCClientReconnectionTest {
|
|||||||
maxReconnectAttempts = 5
|
maxReconnectAttempts = 5
|
||||||
))
|
))
|
||||||
|
|
||||||
(client.start(rpcUser.username, rpcUser.password, gracefulReconnect = gracefulReconnect).proxy as ReconnectingCordaRPCOps).use {
|
(client.start(rpcUser.username, rpcUser.password, gracefulReconnect = gracefulReconnect)).use {
|
||||||
val rpcOps = it
|
val rpcOps = it.proxy as ReconnectingCordaRPCOps
|
||||||
val cashStatesFeed = rpcOps.vaultTrack(Cash.State::class.java)
|
val cashStatesFeed = rpcOps.vaultTrack(Cash.State::class.java)
|
||||||
val subscription = cashStatesFeed.updates.subscribe { latch.countDown() }
|
val subscription = cashStatesFeed.updates.subscribe { latch.countDown() }
|
||||||
rpcOps.startTrackedFlow(::CashIssueFlow, 10.DOLLARS, OpaqueBytes.of(0), defaultNotaryIdentity).returnValue.get()
|
rpcOps.startTrackedFlow(::CashIssueFlow, 10.DOLLARS, OpaqueBytes.of(0), defaultNotaryIdentity).returnValue.get()
|
||||||
@ -113,6 +113,7 @@ class CordaRPCClientReconnectionTest {
|
|||||||
latch.await(4, TimeUnit.SECONDS)
|
latch.await(4, TimeUnit.SECONDS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,8 +137,8 @@ class CordaRPCClientReconnectionTest {
|
|||||||
maxReconnectAttempts = 5
|
maxReconnectAttempts = 5
|
||||||
))
|
))
|
||||||
|
|
||||||
(client.start(rpcUser.username, rpcUser.password, gracefulReconnect = gracefulReconnect).proxy as ReconnectingCordaRPCOps).use {
|
(client.start(rpcUser.username, rpcUser.password, gracefulReconnect = gracefulReconnect)).use {
|
||||||
val rpcOps = it
|
val rpcOps = it.proxy as ReconnectingCordaRPCOps
|
||||||
val networkParameters = rpcOps.networkParameters
|
val networkParameters = rpcOps.networkParameters
|
||||||
val cashStatesFeed = rpcOps.vaultTrack(Cash.State::class.java)
|
val cashStatesFeed = rpcOps.vaultTrack(Cash.State::class.java)
|
||||||
cashStatesFeed.updates.subscribe { latch.countDown() }
|
cashStatesFeed.updates.subscribe { latch.countDown() }
|
||||||
|
@ -27,6 +27,9 @@ import net.corda.serialization.internal.amqp.SerializationFactoryCacheKey
|
|||||||
import net.corda.serialization.internal.amqp.SerializerFactory
|
import net.corda.serialization.internal.amqp.SerializerFactory
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import java.util.concurrent.ExecutorService
|
||||||
|
import java.util.concurrent.Executors
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is essentially just a wrapper for an RPCConnection<CordaRPCOps> and can be treated identically.
|
* This class is essentially just a wrapper for an RPCConnection<CordaRPCOps> and can be treated identically.
|
||||||
@ -35,9 +38,10 @@ import java.util.*
|
|||||||
*/
|
*/
|
||||||
class CordaRPCConnection private constructor(
|
class CordaRPCConnection private constructor(
|
||||||
private val oneTimeConnection: RPCConnection<CordaRPCOps>?,
|
private val oneTimeConnection: RPCConnection<CordaRPCOps>?,
|
||||||
|
private val observersPool: ExecutorService?,
|
||||||
private val reconnectingCordaRPCOps: ReconnectingCordaRPCOps?
|
private val reconnectingCordaRPCOps: ReconnectingCordaRPCOps?
|
||||||
) : RPCConnection<CordaRPCOps> {
|
) : RPCConnection<CordaRPCOps> {
|
||||||
internal constructor(connection: RPCConnection<CordaRPCOps>?) : this(connection, null)
|
internal constructor(connection: RPCConnection<CordaRPCOps>?) : this(connection, null, null)
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@CordaInternal
|
@CordaInternal
|
||||||
@ -46,14 +50,20 @@ class CordaRPCConnection private constructor(
|
|||||||
password: String,
|
password: String,
|
||||||
addresses: List<NetworkHostAndPort>,
|
addresses: List<NetworkHostAndPort>,
|
||||||
rpcConfiguration: CordaRPCClientConfiguration,
|
rpcConfiguration: CordaRPCClientConfiguration,
|
||||||
gracefulReconnect: GracefulReconnect
|
gracefulReconnect: GracefulReconnect,
|
||||||
|
sslConfiguration: ClientRpcSslOptions? = null,
|
||||||
|
classLoader: ClassLoader? = null
|
||||||
): CordaRPCConnection {
|
): CordaRPCConnection {
|
||||||
return CordaRPCConnection(null, ReconnectingCordaRPCOps(
|
val observersPool: ExecutorService = Executors.newCachedThreadPool()
|
||||||
|
return CordaRPCConnection(null, observersPool, ReconnectingCordaRPCOps(
|
||||||
addresses,
|
addresses,
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
rpcConfiguration,
|
rpcConfiguration,
|
||||||
gracefulReconnect
|
gracefulReconnect,
|
||||||
|
sslConfiguration,
|
||||||
|
classLoader,
|
||||||
|
observersPool
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +79,18 @@ class CordaRPCConnection private constructor(
|
|||||||
|
|
||||||
override fun forceClose() = actualConnection.forceClose()
|
override fun forceClose() = actualConnection.forceClose()
|
||||||
|
|
||||||
override fun close() = actualConnection.close()
|
override fun close() {
|
||||||
|
try {
|
||||||
|
actualConnection.close()
|
||||||
|
} finally {
|
||||||
|
observersPool?.apply {
|
||||||
|
shutdown()
|
||||||
|
if (!awaitTermination(@Suppress("MagicNumber")30, TimeUnit.SECONDS)) {
|
||||||
|
shutdownNow()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -322,19 +343,36 @@ class CordaRPCClient private constructor(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(hostAndPort: NetworkHostAndPort, configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT) : this(
|
constructor(
|
||||||
hostAndPort = hostAndPort, haAddressPool = emptyList(), configuration = configuration
|
hostAndPort: NetworkHostAndPort,
|
||||||
|
configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT
|
||||||
|
) : this(
|
||||||
|
hostAndPort = hostAndPort,
|
||||||
|
haAddressPool = emptyList(),
|
||||||
|
configuration = configuration
|
||||||
)
|
)
|
||||||
|
|
||||||
constructor(hostAndPort: NetworkHostAndPort,
|
constructor(
|
||||||
configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT,
|
hostAndPort: NetworkHostAndPort,
|
||||||
classLoader: ClassLoader): this(hostAndPort, configuration, null, classLoader = classLoader)
|
configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT,
|
||||||
|
classLoader: ClassLoader
|
||||||
|
): this(
|
||||||
|
hostAndPort,
|
||||||
|
configuration,
|
||||||
|
null,
|
||||||
|
classLoader = classLoader
|
||||||
|
)
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
hostAndPort: NetworkHostAndPort,
|
hostAndPort: NetworkHostAndPort,
|
||||||
sslConfiguration: ClientRpcSslOptions? = null,
|
sslConfiguration: ClientRpcSslOptions? = null,
|
||||||
classLoader: ClassLoader? = null
|
classLoader: ClassLoader? = null
|
||||||
) : this(hostAndPort = hostAndPort, haAddressPool = emptyList(), sslConfiguration = sslConfiguration, classLoader = classLoader)
|
) : this(
|
||||||
|
hostAndPort = hostAndPort,
|
||||||
|
haAddressPool = emptyList(),
|
||||||
|
sslConfiguration = sslConfiguration,
|
||||||
|
classLoader = classLoader
|
||||||
|
)
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(
|
constructor(
|
||||||
@ -342,7 +380,13 @@ class CordaRPCClient private constructor(
|
|||||||
configuration: CordaRPCClientConfiguration,
|
configuration: CordaRPCClientConfiguration,
|
||||||
sslConfiguration: ClientRpcSslOptions?,
|
sslConfiguration: ClientRpcSslOptions?,
|
||||||
classLoader: ClassLoader? = null
|
classLoader: ClassLoader? = null
|
||||||
) : this(hostAndPort = hostAndPort, haAddressPool = emptyList(), configuration = configuration, sslConfiguration = sslConfiguration, classLoader = classLoader)
|
) : this(
|
||||||
|
hostAndPort = hostAndPort,
|
||||||
|
haAddressPool = emptyList(),
|
||||||
|
configuration = configuration,
|
||||||
|
sslConfiguration = sslConfiguration,
|
||||||
|
classLoader = classLoader
|
||||||
|
)
|
||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
constructor(
|
constructor(
|
||||||
@ -350,7 +394,13 @@ class CordaRPCClient private constructor(
|
|||||||
configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT,
|
configuration: CordaRPCClientConfiguration = CordaRPCClientConfiguration.DEFAULT,
|
||||||
sslConfiguration: ClientRpcSslOptions? = null,
|
sslConfiguration: ClientRpcSslOptions? = null,
|
||||||
classLoader: ClassLoader? = null
|
classLoader: ClassLoader? = null
|
||||||
) : this(hostAndPort = null, haAddressPool = haAddressPool, configuration = configuration, sslConfiguration = sslConfiguration, classLoader = classLoader)
|
) : this(
|
||||||
|
hostAndPort = null,
|
||||||
|
haAddressPool = haAddressPool,
|
||||||
|
configuration = configuration,
|
||||||
|
sslConfiguration = sslConfiguration,
|
||||||
|
classLoader = classLoader
|
||||||
|
)
|
||||||
|
|
||||||
// Here to keep the keep ABI compatibility happy
|
// Here to keep the keep ABI compatibility happy
|
||||||
companion object {}
|
companion object {}
|
||||||
@ -362,11 +412,23 @@ class CordaRPCClient private constructor(
|
|||||||
try {
|
try {
|
||||||
val cache = Caffeine.newBuilder().maximumSize(128).build<SerializationFactoryCacheKey, SerializerFactory>().asMap()
|
val cache = Caffeine.newBuilder().maximumSize(128).build<SerializationFactoryCacheKey, SerializerFactory>().asMap()
|
||||||
|
|
||||||
// If the client has explicitly provided a classloader use this one to scan for custom serializers, otherwise use the current one.
|
// If the client has explicitly provided a classloader use this one to scan for custom serializers,
|
||||||
|
// otherwise use the current one.
|
||||||
val serializationClassLoader = this.classLoader ?: this.javaClass.classLoader
|
val serializationClassLoader = this.classLoader ?: this.javaClass.classLoader
|
||||||
val customSerializers = createInstancesOfClassesImplementing(serializationClassLoader, SerializationCustomSerializer::class.java)
|
val customSerializers = createInstancesOfClassesImplementing(
|
||||||
val serializationWhitelists = ServiceLoader.load(SerializationWhitelist::class.java, serializationClassLoader).toSet()
|
serializationClassLoader,
|
||||||
AMQPClientSerializationScheme.initialiseSerialization(serializationClassLoader, customSerializers, serializationWhitelists, cache)
|
SerializationCustomSerializer::class.java
|
||||||
|
)
|
||||||
|
val serializationWhitelists = ServiceLoader.load(
|
||||||
|
SerializationWhitelist::class.java,
|
||||||
|
serializationClassLoader
|
||||||
|
).toSet()
|
||||||
|
AMQPClientSerializationScheme.initialiseSerialization(
|
||||||
|
serializationClassLoader,
|
||||||
|
customSerializers,
|
||||||
|
serializationWhitelists,
|
||||||
|
cache
|
||||||
|
)
|
||||||
} catch (e: IllegalStateException) {
|
} catch (e: IllegalStateException) {
|
||||||
// Race e.g. two of these constructed in parallel, ignore.
|
// Race e.g. two of these constructed in parallel, ignore.
|
||||||
}
|
}
|
||||||
@ -401,7 +463,11 @@ class CordaRPCClient private constructor(
|
|||||||
* @throws RPCException if the server version is too low or if the server isn't reachable within a reasonable timeout.
|
* @throws RPCException if the server version is too low or if the server isn't reachable within a reasonable timeout.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun start(username: String, password: String, gracefulReconnect: GracefulReconnect? = null): CordaRPCConnection {
|
fun start(
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
gracefulReconnect: GracefulReconnect? = null
|
||||||
|
): CordaRPCConnection {
|
||||||
return start(username, password, null, null, gracefulReconnect)
|
return start(username, password, null, null, gracefulReconnect)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +484,12 @@ class CordaRPCClient private constructor(
|
|||||||
* @throws RPCException if the server version is too low or if the server isn't reachable within a reasonable timeout.
|
* @throws RPCException if the server version is too low or if the server isn't reachable within a reasonable timeout.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun start(username: String, password: String, targetLegalIdentity: CordaX500Name, gracefulReconnect: GracefulReconnect? = null): CordaRPCConnection {
|
fun start(
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
targetLegalIdentity: CordaX500Name,
|
||||||
|
gracefulReconnect: GracefulReconnect? = null
|
||||||
|
): CordaRPCConnection {
|
||||||
return start(username, password, null, null, targetLegalIdentity, gracefulReconnect)
|
return start(username, password, null, null, targetLegalIdentity, gracefulReconnect)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,7 +507,13 @@ class CordaRPCClient private constructor(
|
|||||||
* @throws RPCException if the server version is too low or if the server isn't reachable within a reasonable timeout.
|
* @throws RPCException if the server version is too low or if the server isn't reachable within a reasonable timeout.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun start(username: String, password: String, externalTrace: Trace?, impersonatedActor: Actor?, gracefulReconnect: GracefulReconnect? = null): CordaRPCConnection {
|
fun start(
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
externalTrace: Trace?,
|
||||||
|
impersonatedActor: Actor?,
|
||||||
|
gracefulReconnect: GracefulReconnect? = null
|
||||||
|
): CordaRPCConnection {
|
||||||
return start(username, password, externalTrace, impersonatedActor, null, gracefulReconnect)
|
return start(username, password, externalTrace, impersonatedActor, null, gracefulReconnect)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -457,7 +534,14 @@ class CordaRPCClient private constructor(
|
|||||||
* @throws RPCException if the server version is too low or if the server isn't reachable within a reasonable timeout.
|
* @throws RPCException if the server version is too low or if the server isn't reachable within a reasonable timeout.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun start(username: String, password: String, externalTrace: Trace?, impersonatedActor: Actor?, targetLegalIdentity: CordaX500Name?, gracefulReconnect: GracefulReconnect? = null): CordaRPCConnection {
|
fun start(
|
||||||
|
username: String,
|
||||||
|
password: String,
|
||||||
|
externalTrace: Trace?,
|
||||||
|
impersonatedActor: Actor?,
|
||||||
|
targetLegalIdentity: CordaX500Name?,
|
||||||
|
gracefulReconnect: GracefulReconnect? = null
|
||||||
|
): CordaRPCConnection {
|
||||||
val addresses = if (haAddressPool.isEmpty()) {
|
val addresses = if (haAddressPool.isEmpty()) {
|
||||||
listOf(hostAndPort!!)
|
listOf(hostAndPort!!)
|
||||||
} else {
|
} else {
|
||||||
@ -465,9 +549,23 @@ class CordaRPCClient private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return if (gracefulReconnect != null) {
|
return if (gracefulReconnect != null) {
|
||||||
CordaRPCConnection.createWithGracefulReconnection(username, password, addresses, configuration, gracefulReconnect)
|
CordaRPCConnection.createWithGracefulReconnection(
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
addresses,
|
||||||
|
configuration,
|
||||||
|
gracefulReconnect,
|
||||||
|
sslConfiguration
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
CordaRPCConnection(getRpcClient().start(InternalCordaRPCOps::class.java, username, password, externalTrace, impersonatedActor, targetLegalIdentity))
|
CordaRPCConnection(getRpcClient().start(
|
||||||
|
InternalCordaRPCOps::class.java,
|
||||||
|
username,
|
||||||
|
password,
|
||||||
|
externalTrace,
|
||||||
|
impersonatedActor,
|
||||||
|
targetLegalIdentity
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,37 +32,24 @@ import java.util.concurrent.TimeUnit
|
|||||||
/**
|
/**
|
||||||
* Wrapper over [CordaRPCOps] that handles exceptions when the node or the connection to the node fail.
|
* Wrapper over [CordaRPCOps] that handles exceptions when the node or the connection to the node fail.
|
||||||
*
|
*
|
||||||
* All operations are retried on failure, except flow start operations that die before receiving a valid [FlowHandle], in which case a [CouldNotStartFlowException] is thrown.
|
* All operations are retried on failure, except flow start operations that die before receiving a valid [FlowHandle], in which case a
|
||||||
|
* [CouldNotStartFlowException] is thrown.
|
||||||
*
|
*
|
||||||
* When calling methods that return a [DataFeed] like [CordaRPCOps.vaultTrackBy], the returned [DataFeed.updates] object will no longer
|
* When calling methods that return a [DataFeed] like [CordaRPCOps.vaultTrackBy], the returned [DataFeed.updates] object will no longer
|
||||||
* be a usable [rx.Observable] but an instance of [ReconnectingObservable].
|
* be a usable [rx.Observable] but an instance of [ReconnectingObservable].
|
||||||
* The caller has to explicitly cast to [ReconnectingObservable] and call [ReconnectingObservable.subscribe]. If used as an [rx.Observable] it will just fail.
|
* The caller has to explicitly cast to [ReconnectingObservable] and call [ReconnectingObservable.subscribe]. If used as an [rx.Observable]
|
||||||
|
* it will just fail.
|
||||||
* The returned [DataFeed.snapshot] is the snapshot as it was when the feed was first retrieved.
|
* The returned [DataFeed.snapshot] is the snapshot as it was when the feed was first retrieved.
|
||||||
*
|
*
|
||||||
* Note: There is no guarantee that observations will not be lost.
|
* Note: There is no guarantee that observations will not be lost.
|
||||||
*
|
*
|
||||||
* *This class is not a stable API. Any project that wants to use it, must copy and paste it.*
|
* *This class is not a stable API. Any project that wants to use it, must copy and paste it.*
|
||||||
*/
|
*/
|
||||||
// TODO The executor service is not needed. All we need is a single thread that deals with reconnecting and onto which ReconnectingObservables
|
// TODO The executor service is not needed. All we need is a single thread that deals with reconnecting and onto which
|
||||||
// and other things can attach themselves as listeners for reconnect events.
|
// ReconnectingObservables and other things can attach themselves as listeners for reconnect events.
|
||||||
class ReconnectingCordaRPCOps private constructor(
|
class ReconnectingCordaRPCOps private constructor(
|
||||||
val reconnectingRPCConnection: ReconnectingRPCConnection,
|
val reconnectingRPCConnection: ReconnectingRPCConnection
|
||||||
private val observersPool: ExecutorService,
|
) : InternalCordaRPCOps by proxy(reconnectingRPCConnection) {
|
||||||
private val userPool: Boolean
|
|
||||||
) : AutoCloseable, InternalCordaRPCOps by proxy(reconnectingRPCConnection, observersPool) {
|
|
||||||
// Constructors that mirror CordaRPCClient.
|
|
||||||
constructor(
|
|
||||||
nodeHostAndPort: NetworkHostAndPort,
|
|
||||||
username: String,
|
|
||||||
password: String,
|
|
||||||
rpcConfiguration: CordaRPCClientConfiguration,
|
|
||||||
sslConfiguration: ClientRpcSslOptions? = null,
|
|
||||||
classLoader: ClassLoader? = null,
|
|
||||||
observersPool: ExecutorService? = null
|
|
||||||
) : this(
|
|
||||||
ReconnectingRPCConnection(listOf(nodeHostAndPort), username, password, rpcConfiguration, sslConfiguration, classLoader),
|
|
||||||
observersPool ?: Executors.newCachedThreadPool(),
|
|
||||||
observersPool != null)
|
|
||||||
constructor(
|
constructor(
|
||||||
nodeHostAndPorts: List<NetworkHostAndPort>,
|
nodeHostAndPorts: List<NetworkHostAndPort>,
|
||||||
username: String,
|
username: String,
|
||||||
@ -71,18 +58,23 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
gracefulReconnect: GracefulReconnect? = null,
|
gracefulReconnect: GracefulReconnect? = null,
|
||||||
sslConfiguration: ClientRpcSslOptions? = null,
|
sslConfiguration: ClientRpcSslOptions? = null,
|
||||||
classLoader: ClassLoader? = null,
|
classLoader: ClassLoader? = null,
|
||||||
observersPool: ExecutorService? = null
|
observersPool: ExecutorService
|
||||||
) : this(
|
) : this(ReconnectingRPCConnection(
|
||||||
ReconnectingRPCConnection(nodeHostAndPorts, username, password, rpcConfiguration, sslConfiguration, classLoader, gracefulReconnect),
|
nodeHostAndPorts,
|
||||||
observersPool ?: Executors.newCachedThreadPool(),
|
username,
|
||||||
observersPool != null)
|
password,
|
||||||
|
rpcConfiguration,
|
||||||
|
sslConfiguration,
|
||||||
|
classLoader,
|
||||||
|
gracefulReconnect,
|
||||||
|
observersPool))
|
||||||
private companion object {
|
private companion object {
|
||||||
private val log = contextLogger()
|
private val log = contextLogger()
|
||||||
private fun proxy(reconnectingRPCConnection: ReconnectingRPCConnection, observersPool: ExecutorService): InternalCordaRPCOps {
|
private fun proxy(reconnectingRPCConnection: ReconnectingRPCConnection): InternalCordaRPCOps {
|
||||||
return Proxy.newProxyInstance(
|
return Proxy.newProxyInstance(
|
||||||
this::class.java.classLoader,
|
this::class.java.classLoader,
|
||||||
arrayOf(InternalCordaRPCOps::class.java),
|
arrayOf(InternalCordaRPCOps::class.java),
|
||||||
ErrorInterceptingHandler(reconnectingRPCConnection, observersPool)) as InternalCordaRPCOps
|
ErrorInterceptingHandler(reconnectingRPCConnection)) as InternalCordaRPCOps
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private val retryFlowsPool = Executors.newScheduledThreadPool(1)
|
private val retryFlowsPool = Executors.newScheduledThreadPool(1)
|
||||||
@ -125,7 +117,8 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
val rpcConfiguration: CordaRPCClientConfiguration,
|
val rpcConfiguration: CordaRPCClientConfiguration,
|
||||||
val sslConfiguration: ClientRpcSslOptions? = null,
|
val sslConfiguration: ClientRpcSslOptions? = null,
|
||||||
val classLoader: ClassLoader?,
|
val classLoader: ClassLoader?,
|
||||||
val gracefulReconnect: GracefulReconnect? = null
|
val gracefulReconnect: GracefulReconnect? = null,
|
||||||
|
val observersPool: ExecutorService
|
||||||
) : RPCConnection<CordaRPCOps> {
|
) : RPCConnection<CordaRPCOps> {
|
||||||
private var currentRPCConnection: CordaRPCConnection? = null
|
private var currentRPCConnection: CordaRPCConnection? = null
|
||||||
enum class CurrentState {
|
enum class CurrentState {
|
||||||
@ -178,12 +171,18 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
return currentRPCConnection!!
|
return currentRPCConnection!!
|
||||||
}
|
}
|
||||||
|
|
||||||
private tailrec fun establishConnectionWithRetry(retryInterval: Duration = 1.seconds, roundRobinIndex: Int = 0): CordaRPCConnection {
|
private tailrec fun establishConnectionWithRetry(
|
||||||
|
retryInterval: Duration = 1.seconds,
|
||||||
|
roundRobinIndex: Int = 0
|
||||||
|
): CordaRPCConnection {
|
||||||
val attemptedAddress = nodeHostAndPorts[roundRobinIndex]
|
val attemptedAddress = nodeHostAndPorts[roundRobinIndex]
|
||||||
log.info("Connecting to: $attemptedAddress")
|
log.info("Connecting to: $attemptedAddress")
|
||||||
try {
|
try {
|
||||||
return CordaRPCClient(
|
return CordaRPCClient(
|
||||||
attemptedAddress, rpcConfiguration.copy(connectionMaxRetryInterval = retryInterval, maxReconnectAttempts = 1), sslConfiguration, classLoader
|
attemptedAddress,
|
||||||
|
rpcConfiguration.copy(connectionMaxRetryInterval = retryInterval, maxReconnectAttempts = 1),
|
||||||
|
sslConfiguration,
|
||||||
|
classLoader
|
||||||
).start(username, password).also {
|
).start(username, password).also {
|
||||||
// Check connection is truly operational before returning it.
|
// Check connection is truly operational before returning it.
|
||||||
require(it.proxy.nodeInfo().legalIdentitiesAndCerts.isNotEmpty()) {
|
require(it.proxy.nodeInfo().legalIdentitiesAndCerts.isNotEmpty()) {
|
||||||
@ -240,7 +239,7 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
currentRPCConnection?.close()
|
currentRPCConnection?.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private class ErrorInterceptingHandler(val reconnectingRPCConnection: ReconnectingRPCConnection, val observersPool: ExecutorService) : InvocationHandler {
|
private class ErrorInterceptingHandler(val reconnectingRPCConnection: ReconnectingRPCConnection) : InvocationHandler {
|
||||||
private fun Method.isStartFlow() = name.startsWith("startFlow") || name.startsWith("startTrackedFlow")
|
private fun Method.isStartFlow() = name.startsWith("startFlow") || name.startsWith("startTrackedFlow")
|
||||||
|
|
||||||
private fun checkIfIsStartFlow(method: Method, e: InvocationTargetException) {
|
private fun checkIfIsStartFlow(method: Method, e: InvocationTargetException) {
|
||||||
@ -290,7 +289,7 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
DataFeed::class.java -> {
|
DataFeed::class.java -> {
|
||||||
// Intercept the data feed methods and return a ReconnectingObservable instance
|
// Intercept the data feed methods and return a ReconnectingObservable instance
|
||||||
val initialFeed: DataFeed<Any, Any?> = uncheckedCast(doInvoke(method, args))
|
val initialFeed: DataFeed<Any, Any?> = uncheckedCast(doInvoke(method, args))
|
||||||
val observable = ReconnectingObservable(reconnectingRPCConnection, observersPool, initialFeed) {
|
val observable = ReconnectingObservable(reconnectingRPCConnection, initialFeed) {
|
||||||
// This handles reconnecting and creates new feeds.
|
// This handles reconnecting and creates new feeds.
|
||||||
uncheckedCast(this.invoke(reconnectingRPCConnection.proxy, method, args))
|
uncheckedCast(this.invoke(reconnectingRPCConnection.proxy, method, args))
|
||||||
}
|
}
|
||||||
@ -302,8 +301,7 @@ class ReconnectingCordaRPCOps private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
fun close() {
|
||||||
if (!userPool) observersPool.shutdown()
|
|
||||||
retryFlowsPool.shutdown()
|
retryFlowsPool.shutdown()
|
||||||
reconnectingRPCConnection.forceClose()
|
reconnectingRPCConnection.forceClose()
|
||||||
}
|
}
|
||||||
|
@ -4,21 +4,18 @@ import net.corda.core.messaging.DataFeed
|
|||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.Subscriber
|
import rx.Subscriber
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
import java.util.concurrent.ExecutorService
|
|
||||||
import java.util.concurrent.atomic.AtomicReference
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
|
|
||||||
class ReconnectingObservable<T> private constructor(subscriber: ReconnectingSubscriber<T>) : Observable<T>(subscriber) {
|
class ReconnectingObservable<T> private constructor(subscriber: ReconnectingSubscriber<T>) : Observable<T>(subscriber) {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
reconnectingRPCConnection: ReconnectingCordaRPCOps.ReconnectingRPCConnection,
|
reconnectingRPCConnection: ReconnectingCordaRPCOps.ReconnectingRPCConnection,
|
||||||
executor: ExecutorService,
|
|
||||||
initialDataFeed: DataFeed<*, T>,
|
initialDataFeed: DataFeed<*, T>,
|
||||||
createDataFeed: () -> DataFeed<*, T>
|
createDataFeed: () -> DataFeed<*, T>
|
||||||
) : this(ReconnectingSubscriber(reconnectingRPCConnection, executor, initialDataFeed, createDataFeed))
|
) : this(ReconnectingSubscriber(reconnectingRPCConnection, initialDataFeed, createDataFeed))
|
||||||
|
|
||||||
private class ReconnectingSubscriber<T>(
|
private class ReconnectingSubscriber<T>(
|
||||||
private val reconnectingRPCConnection: ReconnectingCordaRPCOps.ReconnectingRPCConnection,
|
private val reconnectingRPCConnection: ReconnectingCordaRPCOps.ReconnectingRPCConnection,
|
||||||
private val executor: ExecutorService,
|
|
||||||
private val initialDataFeed: DataFeed<*, T>,
|
private val initialDataFeed: DataFeed<*, T>,
|
||||||
private val createDataFeed: () -> DataFeed<*, T>
|
private val createDataFeed: () -> DataFeed<*, T>
|
||||||
) : OnSubscribe<T>, Subscription {
|
) : OnSubscribe<T>, Subscription {
|
||||||
@ -59,7 +56,7 @@ class ReconnectingObservable<T> private constructor(subscriber: ReconnectingSubs
|
|||||||
|
|
||||||
private fun scheduleResubscribe(error: Throwable) {
|
private fun scheduleResubscribe(error: Throwable) {
|
||||||
if (unsubscribed) return
|
if (unsubscribed) return
|
||||||
executor.execute {
|
reconnectingRPCConnection.observersPool.execute {
|
||||||
if (unsubscribed) return@execute
|
if (unsubscribed) return@execute
|
||||||
reconnectingRPCConnection.reconnectOnError(error)
|
reconnectingRPCConnection.reconnectOnError(error)
|
||||||
val newDataFeed = createDataFeed()
|
val newDataFeed = createDataFeed()
|
||||||
|
File diff suppressed because one or more lines are too long
@ -133,7 +133,8 @@ class RpcReconnectTests {
|
|||||||
}
|
}
|
||||||
val reconnect = GracefulReconnect(onDisconnect = { numDisconnects++ }, onReconnect = onReconnect)
|
val reconnect = GracefulReconnect(onDisconnect = { numDisconnects++ }, onReconnect = onReconnect)
|
||||||
val client = CordaRPCClient(addressesForRpc)
|
val client = CordaRPCClient(addressesForRpc)
|
||||||
val bankAReconnectingRpc = client.start(demoUser.username, demoUser.password, gracefulReconnect = reconnect).proxy as ReconnectingCordaRPCOps
|
val bankAReconnectingRPCConnection = client.start(demoUser.username, demoUser.password, gracefulReconnect = reconnect)
|
||||||
|
val bankAReconnectingRpc = bankAReconnectingRPCConnection.proxy as ReconnectingCordaRPCOps
|
||||||
// DOCEND rpcReconnectingRPC
|
// DOCEND rpcReconnectingRPC
|
||||||
|
|
||||||
// Observe the vault and collect the observations.
|
// Observe the vault and collect the observations.
|
||||||
@ -330,7 +331,7 @@ class RpcReconnectTests {
|
|||||||
// Stop the observers.
|
// Stop the observers.
|
||||||
vaultSubscription.unsubscribe()
|
vaultSubscription.unsubscribe()
|
||||||
stateMachineSubscription.unsubscribe()
|
stateMachineSubscription.unsubscribe()
|
||||||
bankAReconnectingRpc.close()
|
bankAReconnectingRPCConnection.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy.close()
|
proxy.close()
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.corda.bank.api
|
package net.corda.bank.api
|
||||||
|
|
||||||
import net.corda.bank.api.BankOfCordaWebApi.IssueRequestParams
|
import net.corda.bank.api.BankOfCordaWebApi.IssueRequestParams
|
||||||
import net.corda.client.rpc.CordaRPCClientConfiguration
|
import net.corda.client.rpc.CordaRPCClient
|
||||||
import net.corda.client.rpc.internal.ReconnectingCordaRPCOps
|
import net.corda.client.rpc.GracefulReconnect
|
||||||
import net.corda.core.messaging.startFlow
|
import net.corda.core.messaging.startFlow
|
||||||
import net.corda.core.transactions.SignedTransaction
|
import net.corda.core.transactions.SignedTransaction
|
||||||
import net.corda.core.utilities.NetworkHostAndPort
|
import net.corda.core.utilities.NetworkHostAndPort
|
||||||
@ -35,7 +35,9 @@ object BankOfCordaClientApi {
|
|||||||
*
|
*
|
||||||
* @return a payment transaction (following successful issuance of cash to self).
|
* @return a payment transaction (following successful issuance of cash to self).
|
||||||
*/
|
*/
|
||||||
fun requestRPCIssue(rpcAddress: NetworkHostAndPort, params: IssueRequestParams): SignedTransaction = requestRPCIssueHA(listOf(rpcAddress), params)
|
fun requestRPCIssue(rpcAddress: NetworkHostAndPort, params: IssueRequestParams): SignedTransaction {
|
||||||
|
return requestRPCIssueHA(listOf(rpcAddress), params)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RPC API
|
* RPC API
|
||||||
@ -44,20 +46,28 @@ object BankOfCordaClientApi {
|
|||||||
*/
|
*/
|
||||||
fun requestRPCIssueHA(availableRpcServers: List<NetworkHostAndPort>, params: IssueRequestParams): SignedTransaction {
|
fun requestRPCIssueHA(availableRpcServers: List<NetworkHostAndPort>, params: IssueRequestParams): SignedTransaction {
|
||||||
// TODO: privileged security controls required
|
// TODO: privileged security controls required
|
||||||
ReconnectingCordaRPCOps(availableRpcServers, BOC_RPC_USER, BOC_RPC_PWD, CordaRPCClientConfiguration.DEFAULT).use { rpc->
|
CordaRPCClient(availableRpcServers)
|
||||||
rpc.waitUntilNetworkReady().getOrThrow()
|
.start(BOC_RPC_USER, BOC_RPC_PWD, gracefulReconnect = GracefulReconnect()).use { rpc->
|
||||||
|
rpc.proxy.waitUntilNetworkReady().getOrThrow()
|
||||||
|
|
||||||
// Resolve parties via RPC
|
// Resolve parties via RPC
|
||||||
val issueToParty = rpc.wellKnownPartyFromX500Name(params.issueToPartyName)
|
val issueToParty = rpc.proxy.wellKnownPartyFromX500Name(params.issueToPartyName)
|
||||||
?: throw IllegalStateException("Unable to locate ${params.issueToPartyName} in Network Map Service")
|
?: throw IllegalStateException("Unable to locate ${params.issueToPartyName} in Network Map Service")
|
||||||
val notaryLegalIdentity = rpc.notaryIdentities().firstOrNull { it.name == params.notaryName }
|
val notaryLegalIdentity = rpc.proxy.notaryIdentities().firstOrNull { it.name == params.notaryName }
|
||||||
?: throw IllegalStateException("Couldn't locate notary ${params.notaryName} in NetworkMapCache")
|
?: throw IllegalStateException("Couldn't locate notary ${params.notaryName} in NetworkMapCache")
|
||||||
|
|
||||||
val anonymous = true
|
val anonymous = true
|
||||||
val issuerBankPartyRef = OpaqueBytes.of(params.issuerBankPartyRef.toByte())
|
val issuerBankPartyRef = OpaqueBytes.of(params.issuerBankPartyRef.toByte())
|
||||||
|
|
||||||
logger.info("${rpc.nodeInfo()} issuing ${params.amount} to transfer to $issueToParty ...")
|
logger.info("${rpc.proxy.nodeInfo()} issuing ${params.amount} to transfer to $issueToParty ...")
|
||||||
return rpc.startFlow(::CashIssueAndPaymentFlow, params.amount, issuerBankPartyRef, issueToParty, anonymous, notaryLegalIdentity)
|
return rpc.proxy.startFlow(
|
||||||
|
::CashIssueAndPaymentFlow,
|
||||||
|
params.amount,
|
||||||
|
issuerBankPartyRef,
|
||||||
|
issueToParty,
|
||||||
|
anonymous,
|
||||||
|
notaryLegalIdentity
|
||||||
|
)
|
||||||
.returnValue.getOrThrow().stx
|
.returnValue.getOrThrow().stx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,9 @@ package net.corda.webserver.internal
|
|||||||
import com.google.common.html.HtmlEscapers.htmlEscaper
|
import com.google.common.html.HtmlEscapers.htmlEscaper
|
||||||
import io.netty.channel.unix.Errors
|
import io.netty.channel.unix.Errors
|
||||||
import net.corda.client.jackson.JacksonSupport
|
import net.corda.client.jackson.JacksonSupport
|
||||||
import net.corda.client.rpc.CordaRPCClientConfiguration
|
import net.corda.client.rpc.CordaRPCClient
|
||||||
import net.corda.client.rpc.internal.ReconnectingCordaRPCOps
|
import net.corda.client.rpc.CordaRPCConnection
|
||||||
|
import net.corda.client.rpc.GracefulReconnect
|
||||||
import net.corda.core.internal.errors.AddressBindingException
|
import net.corda.core.internal.errors.AddressBindingException
|
||||||
import net.corda.core.messaging.CordaRPCOps
|
import net.corda.core.messaging.CordaRPCOps
|
||||||
import net.corda.core.utilities.contextLogger
|
import net.corda.core.utilities.contextLogger
|
||||||
@ -46,8 +47,12 @@ class NodeWebServer(val config: WebServerConfig) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun run() {
|
fun run() {
|
||||||
while (server.isRunning) {
|
try {
|
||||||
Thread.sleep(100) // TODO: Redesign
|
while (server.isRunning) {
|
||||||
|
Thread.sleep(100) // TODO: Redesign
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
rpc.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +80,11 @@ class NodeWebServer(val config: WebServerConfig) {
|
|||||||
sslContextFactory.setIncludeProtocols("TLSv1.2")
|
sslContextFactory.setIncludeProtocols("TLSv1.2")
|
||||||
sslContextFactory.setExcludeCipherSuites(".*NULL.*", ".*RC4.*", ".*MD5.*", ".*DES.*", ".*DSS.*")
|
sslContextFactory.setExcludeCipherSuites(".*NULL.*", ".*RC4.*", ".*MD5.*", ".*DES.*", ".*DSS.*")
|
||||||
sslContextFactory.setIncludeCipherSuites(".*AES.*GCM.*")
|
sslContextFactory.setIncludeCipherSuites(".*AES.*GCM.*")
|
||||||
val sslConnector = ServerConnector(server, SslConnectionFactory(sslContextFactory, "http/1.1"), HttpConnectionFactory(httpsConfiguration))
|
val sslConnector = ServerConnector(
|
||||||
|
server,
|
||||||
|
SslConnectionFactory(sslContextFactory, "http/1.1"),
|
||||||
|
HttpConnectionFactory(httpsConfiguration)
|
||||||
|
)
|
||||||
sslConnector.port = address.port
|
sslConnector.port = address.port
|
||||||
sslConnector
|
sslConnector
|
||||||
} else {
|
} else {
|
||||||
@ -175,9 +184,21 @@ class NodeWebServer(val config: WebServerConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reconnectingCordaRPCOps() = ReconnectingCordaRPCOps(config.rpcAddress, config.runAs.username , config.runAs.password, CordaRPCClientConfiguration.DEFAULT, null, javaClass.classLoader)
|
private lateinit var rpc: CordaRPCConnection
|
||||||
|
private fun reconnectingCordaRPCOps(): CordaRPCOps {
|
||||||
|
rpc = CordaRPCClient(config.rpcAddress, null, javaClass.classLoader)
|
||||||
|
.start(
|
||||||
|
config.runAs.username,
|
||||||
|
config.runAs.password,
|
||||||
|
GracefulReconnect()
|
||||||
|
)
|
||||||
|
return rpc.proxy
|
||||||
|
}
|
||||||
|
|
||||||
/** Fetch WebServerPluginRegistry classes registered in META-INF/services/net.corda.webserver.services.WebServerPluginRegistry files that exist in the classpath */
|
/**
|
||||||
|
* Fetch WebServerPluginRegistry classes registered in META-INF/services/net.corda.webserver.services.WebServerPluginRegistry
|
||||||
|
* files that exist in the classpath
|
||||||
|
*/
|
||||||
val pluginRegistries: List<WebServerPluginRegistry> by lazy {
|
val pluginRegistries: List<WebServerPluginRegistry> by lazy {
|
||||||
ServiceLoader.load(WebServerPluginRegistry::class.java).toList()
|
ServiceLoader.load(WebServerPluginRegistry::class.java).toList()
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,8 @@ import net.corda.client.jackson.JacksonSupport
|
|||||||
import net.corda.client.jackson.StringToMethodCallParser
|
import net.corda.client.jackson.StringToMethodCallParser
|
||||||
import net.corda.client.rpc.CordaRPCClient
|
import net.corda.client.rpc.CordaRPCClient
|
||||||
import net.corda.client.rpc.CordaRPCClientConfiguration
|
import net.corda.client.rpc.CordaRPCClientConfiguration
|
||||||
|
import net.corda.client.rpc.GracefulReconnect
|
||||||
import net.corda.client.rpc.PermissionException
|
import net.corda.client.rpc.PermissionException
|
||||||
import net.corda.client.rpc.internal.ReconnectingCordaRPCOps
|
|
||||||
import net.corda.core.CordaException
|
import net.corda.core.CordaException
|
||||||
import net.corda.core.concurrent.CordaFuture
|
import net.corda.core.concurrent.CordaFuture
|
||||||
import net.corda.core.contracts.UniqueIdentifier
|
import net.corda.core.contracts.UniqueIdentifier
|
||||||
@ -22,7 +22,6 @@ import net.corda.core.internal.*
|
|||||||
import net.corda.core.internal.concurrent.doneFuture
|
import net.corda.core.internal.concurrent.doneFuture
|
||||||
import net.corda.core.internal.concurrent.openFuture
|
import net.corda.core.internal.concurrent.openFuture
|
||||||
import net.corda.core.internal.messaging.InternalCordaRPCOps
|
import net.corda.core.internal.messaging.InternalCordaRPCOps
|
||||||
import net.corda.core.internal.packageName_
|
|
||||||
import net.corda.core.messaging.*
|
import net.corda.core.messaging.*
|
||||||
import net.corda.tools.shell.utlities.ANSIProgressRenderer
|
import net.corda.tools.shell.utlities.ANSIProgressRenderer
|
||||||
import net.corda.tools.shell.utlities.StdoutANSIProgressRenderer
|
import net.corda.tools.shell.utlities.StdoutANSIProgressRenderer
|
||||||
@ -91,21 +90,24 @@ object InteractiveShell {
|
|||||||
|
|
||||||
fun startShell(configuration: ShellConfiguration, classLoader: ClassLoader? = null, standalone: Boolean = false) {
|
fun startShell(configuration: ShellConfiguration, classLoader: ClassLoader? = null, standalone: Boolean = false) {
|
||||||
rpcOps = { username: String, password: String ->
|
rpcOps = { username: String, password: String ->
|
||||||
if (standalone) {
|
val connection = if (standalone) {
|
||||||
ReconnectingCordaRPCOps(configuration.hostAndPort, username, password, CordaRPCClientConfiguration.DEFAULT, configuration.ssl, classLoader).also {
|
CordaRPCClient(
|
||||||
rpcConn = it
|
configuration.hostAndPort,
|
||||||
}
|
configuration.ssl,
|
||||||
|
classLoader
|
||||||
|
).start(username, password, gracefulReconnect = GracefulReconnect())
|
||||||
} else {
|
} else {
|
||||||
val client = CordaRPCClient(hostAndPort = configuration.hostAndPort,
|
CordaRPCClient(
|
||||||
|
hostAndPort = configuration.hostAndPort,
|
||||||
configuration = CordaRPCClientConfiguration.DEFAULT.copy(
|
configuration = CordaRPCClientConfiguration.DEFAULT.copy(
|
||||||
maxReconnectAttempts = 1
|
maxReconnectAttempts = 1
|
||||||
),
|
),
|
||||||
sslConfiguration = configuration.ssl,
|
sslConfiguration = configuration.ssl,
|
||||||
classLoader = classLoader)
|
classLoader = classLoader
|
||||||
val connection = client.start(username, password)
|
).start(username, password)
|
||||||
rpcConn = connection
|
|
||||||
connection.proxy as InternalCordaRPCOps
|
|
||||||
}
|
}
|
||||||
|
rpcConn = connection
|
||||||
|
connection.proxy as InternalCordaRPCOps
|
||||||
}
|
}
|
||||||
_startShell(configuration, classLoader)
|
_startShell(configuration, classLoader)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user