mirror of
https://github.com/corda/corda.git
synced 2025-01-01 02:36:44 +00:00
Switch to using CompositeKey inside network map cache
Switch to using CompositeKey inside network map cache, so that look up of node info from keys can be done in a more sensible manner.
This commit is contained in:
parent
12de4f46b1
commit
8cb27f1052
@ -54,10 +54,10 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
||||
override val mapServiceRegistered: ListenableFuture<Unit> get() = _registrationFuture
|
||||
|
||||
private var registeredForPush = false
|
||||
protected var registeredNodes: MutableMap<Party, NodeInfo> = Collections.synchronizedMap(HashMap<Party, NodeInfo>())
|
||||
protected var registeredNodes: MutableMap<CompositeKey, NodeInfo> = Collections.synchronizedMap(HashMap())
|
||||
|
||||
override fun getPartyInfo(party: Party): PartyInfo? {
|
||||
val node = registeredNodes[party]
|
||||
val node = registeredNodes[party.owningKey]
|
||||
if (node != null) {
|
||||
return PartyInfo.Node(node)
|
||||
}
|
||||
@ -71,7 +71,7 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getNodeByLegalIdentityKey(compositeKey: CompositeKey): NodeInfo? = registeredNodes[Party("", compositeKey)]
|
||||
override fun getNodeByLegalIdentityKey(compositeKey: CompositeKey): NodeInfo? = registeredNodes[compositeKey]
|
||||
|
||||
override fun track(): Pair<List<NodeInfo>, Observable<MapChange>> {
|
||||
synchronized(_changed) {
|
||||
@ -113,7 +113,7 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
||||
|
||||
override fun addNode(node: NodeInfo) {
|
||||
synchronized(_changed) {
|
||||
val previousNode = registeredNodes.put(node.legalIdentity, node)
|
||||
val previousNode = registeredNodes.put(node.legalIdentity.owningKey, node)
|
||||
if (previousNode == null) {
|
||||
changePublisher.onNext(MapChange.Added(node))
|
||||
} else if (previousNode != node) {
|
||||
@ -124,7 +124,7 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
||||
|
||||
override fun removeNode(node: NodeInfo) {
|
||||
synchronized(_changed) {
|
||||
registeredNodes.remove(node.legalIdentity)
|
||||
registeredNodes.remove(node.legalIdentity.owningKey)
|
||||
changePublisher.onNext(MapChange.Removed(node))
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ class MockNetworkMapCache() : InMemoryNetworkMapCache() {
|
||||
init {
|
||||
val mockNodeA = NodeInfo(MockAddress("bankC:8080"), Party("Bank C", DummyPublicKey("Bank C")))
|
||||
val mockNodeB = NodeInfo(MockAddress("bankD:8080"), Party("Bank D", DummyPublicKey("Bank D")))
|
||||
registeredNodes[mockNodeA.legalIdentity] = mockNodeA
|
||||
registeredNodes[mockNodeB.legalIdentity] = mockNodeB
|
||||
registeredNodes[mockNodeA.legalIdentity.owningKey] = mockNodeA
|
||||
registeredNodes[mockNodeB.legalIdentity.owningKey] = mockNodeB
|
||||
runWithoutMapService()
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ class MockNetworkMapCache() : InMemoryNetworkMapCache() {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
fun addRegistration(node: NodeInfo) {
|
||||
registeredNodes[node.legalIdentity] = node
|
||||
registeredNodes[node.legalIdentity.owningKey] = node
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,6 +41,6 @@ class MockNetworkMapCache() : InMemoryNetworkMapCache() {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
fun deleteRegistration(legalIdentity: Party) : Boolean {
|
||||
return registeredNodes.remove(legalIdentity) != null
|
||||
return registeredNodes.remove(legalIdentity.owningKey) != null
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user