mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
Retire findTokenizableService. (#2036)
This commit is contained in:
@ -377,12 +377,6 @@ abstract class AbstractNode(val configuration: NodeConfiguration,
|
|||||||
return service
|
return service
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : Any> findTokenizableService(clazz: Class<T>): T? {
|
|
||||||
return tokenizableServices.firstOrNull { clazz.isAssignableFrom(it.javaClass) }?.let { uncheckedCast(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <reified T : Any> findTokenizableService() = findTokenizableService(T::class.java)
|
|
||||||
|
|
||||||
private fun handleCustomNotaryService(service: NotaryService) {
|
private fun handleCustomNotaryService(service: NotaryService) {
|
||||||
runOnStop += service::stop
|
runOnStop += service::stop
|
||||||
service.start()
|
service.start()
|
||||||
@ -614,7 +608,7 @@ abstract class AbstractNode(val configuration: NodeConfiguration,
|
|||||||
|
|
||||||
protected open fun makeBFTCluster(notaryKey: PublicKey, bftSMaRtConfig: BFTSMaRtConfiguration): BFTSMaRt.Cluster {
|
protected open fun makeBFTCluster(notaryKey: PublicKey, bftSMaRtConfig: BFTSMaRtConfiguration): BFTSMaRt.Cluster {
|
||||||
return object : BFTSMaRt.Cluster {
|
return object : BFTSMaRt.Cluster {
|
||||||
override fun waitUntilAllReplicasHaveInitialized() {
|
override fun waitUntilAllReplicasHaveInitialized(notaryService: BFTNonValidatingNotaryService) {
|
||||||
log.warn("A BFT replica may still be initializing, in which case the upcoming consensus change may cause it to spin.")
|
log.warn("A BFT replica may still be initializing, in which case the upcoming consensus change may cause it to spin.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ class BFTNonValidatingNotaryService(override val services: ServiceHubInternal,
|
|||||||
log.info("BFT SMaRt replica $replicaId is running.")
|
log.info("BFT SMaRt replica $replicaId is running.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BFTSMaRt.Client(it, replicaId, cluster)
|
BFTSMaRt.Client(it, replicaId, cluster, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,10 +72,10 @@ object BFTSMaRt {
|
|||||||
|
|
||||||
interface Cluster {
|
interface Cluster {
|
||||||
/** Avoid bug where a replica fails to start due to a consensus change during the BFT startup sequence. */
|
/** Avoid bug where a replica fails to start due to a consensus change during the BFT startup sequence. */
|
||||||
fun waitUntilAllReplicasHaveInitialized()
|
fun waitUntilAllReplicasHaveInitialized(notaryService: BFTNonValidatingNotaryService)
|
||||||
}
|
}
|
||||||
|
|
||||||
class Client(config: BFTSMaRtConfig, private val clientId: Int, private val cluster: Cluster) : SingletonSerializeAsToken() {
|
class Client(config: BFTSMaRtConfig, private val clientId: Int, private val cluster: Cluster, private val notaryService: BFTNonValidatingNotaryService) : SingletonSerializeAsToken() {
|
||||||
companion object {
|
companion object {
|
||||||
private val log = loggerFor<Client>()
|
private val log = loggerFor<Client>()
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ object BFTSMaRt {
|
|||||||
fun commitTransaction(transaction: Any, otherSide: Party): ClusterResponse {
|
fun commitTransaction(transaction: Any, otherSide: Party): ClusterResponse {
|
||||||
require(transaction is FilteredTransaction || transaction is SignedTransaction) { "Unsupported transaction type: ${transaction.javaClass.name}" }
|
require(transaction is FilteredTransaction || transaction is SignedTransaction) { "Unsupported transaction type: ${transaction.javaClass.name}" }
|
||||||
awaitClientConnectionToCluster()
|
awaitClientConnectionToCluster()
|
||||||
cluster.waitUntilAllReplicasHaveInitialized()
|
cluster.waitUntilAllReplicasHaveInitialized(notaryService)
|
||||||
val requestBytes = CommitRequest(transaction, otherSide).serialize().bytes
|
val requestBytes = CommitRequest(transaction, otherSide).serialize().bytes
|
||||||
val responseBytes = proxy.invokeOrdered(requestBytes)
|
val responseBytes = proxy.invokeOrdered(requestBytes)
|
||||||
return responseBytes.deserialize<ClusterResponse>()
|
return responseBytes.deserialize<ClusterResponse>()
|
||||||
|
@ -210,7 +210,7 @@ class NodeInterestRatesTest {
|
|||||||
internals.registerInitiatedFlow(NodeInterestRates.FixQueryHandler::class.java)
|
internals.registerInitiatedFlow(NodeInterestRates.FixQueryHandler::class.java)
|
||||||
internals.registerInitiatedFlow(NodeInterestRates.FixSignHandler::class.java)
|
internals.registerInitiatedFlow(NodeInterestRates.FixSignHandler::class.java)
|
||||||
database.transaction {
|
database.transaction {
|
||||||
internals.findTokenizableService(NodeInterestRates.Oracle::class.java)!!.knownFixes = TEST_DATA
|
services.cordaService(NodeInterestRates.Oracle::class.java).knownFixes = TEST_DATA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val tx = makePartialTX()
|
val tx = makePartialTX()
|
||||||
|
@ -60,7 +60,7 @@ abstract class Simulation(val networkSendManuallyPumped: Boolean,
|
|||||||
registerInitiatedFlow(NodeInterestRates.FixSignHandler::class.java)
|
registerInitiatedFlow(NodeInterestRates.FixSignHandler::class.java)
|
||||||
javaClass.classLoader.getResourceAsStream("net/corda/irs/simulation/example.rates.txt").use {
|
javaClass.classLoader.getResourceAsStream("net/corda/irs/simulation/example.rates.txt").use {
|
||||||
database.transaction {
|
database.transaction {
|
||||||
findTokenizableService(NodeInterestRates.Oracle::class.java)!!.uploadFixes(it.reader().readText())
|
services.cordaService(NodeInterestRates.Oracle::class.java).uploadFixes(it.reader().readText())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,13 +323,12 @@ class MockNetwork(defaultParameters: MockNetworkParameters = MockNetworkParamete
|
|||||||
|
|
||||||
override fun makeBFTCluster(notaryKey: PublicKey, bftSMaRtConfig: BFTSMaRtConfiguration): BFTSMaRt.Cluster {
|
override fun makeBFTCluster(notaryKey: PublicKey, bftSMaRtConfig: BFTSMaRtConfiguration): BFTSMaRt.Cluster {
|
||||||
return object : BFTSMaRt.Cluster {
|
return object : BFTSMaRt.Cluster {
|
||||||
override fun waitUntilAllReplicasHaveInitialized() {
|
override fun waitUntilAllReplicasHaveInitialized(notaryService: BFTNonValidatingNotaryService) {
|
||||||
val clusterNodes = mockNet.nodes.filter { notaryKey in it.started!!.info.legalIdentities.map { it.owningKey } }
|
val clusterNodes = mockNet.nodes.filter { notaryKey in it.started!!.info.legalIdentities.map { it.owningKey } }
|
||||||
if (clusterNodes.size != bftSMaRtConfig.clusterAddresses.size) {
|
if (clusterNodes.size != bftSMaRtConfig.clusterAddresses.size) {
|
||||||
throw IllegalStateException("Unable to enumerate all nodes in BFT cluster.")
|
throw IllegalStateException("Unable to enumerate all nodes in BFT cluster.")
|
||||||
}
|
}
|
||||||
clusterNodes.forEach {
|
clusterNodes.forEach {
|
||||||
val notaryService = it.findTokenizableService(BFTNonValidatingNotaryService::class.java)!!
|
|
||||||
notaryService.waitUntilReplicaHasInitialized()
|
notaryService.waitUntilReplicaHasInitialized()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user