mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +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
|
override val mapServiceRegistered: ListenableFuture<Unit> get() = _registrationFuture
|
||||||
|
|
||||||
private var registeredForPush = false
|
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? {
|
override fun getPartyInfo(party: Party): PartyInfo? {
|
||||||
val node = registeredNodes[party]
|
val node = registeredNodes[party.owningKey]
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
return PartyInfo.Node(node)
|
return PartyInfo.Node(node)
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
|||||||
return null
|
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>> {
|
override fun track(): Pair<List<NodeInfo>, Observable<MapChange>> {
|
||||||
synchronized(_changed) {
|
synchronized(_changed) {
|
||||||
@ -113,7 +113,7 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
|||||||
|
|
||||||
override fun addNode(node: NodeInfo) {
|
override fun addNode(node: NodeInfo) {
|
||||||
synchronized(_changed) {
|
synchronized(_changed) {
|
||||||
val previousNode = registeredNodes.put(node.legalIdentity, node)
|
val previousNode = registeredNodes.put(node.legalIdentity.owningKey, node)
|
||||||
if (previousNode == null) {
|
if (previousNode == null) {
|
||||||
changePublisher.onNext(MapChange.Added(node))
|
changePublisher.onNext(MapChange.Added(node))
|
||||||
} else if (previousNode != node) {
|
} else if (previousNode != node) {
|
||||||
@ -124,7 +124,7 @@ open class InMemoryNetworkMapCache : SingletonSerializeAsToken(), NetworkMapCach
|
|||||||
|
|
||||||
override fun removeNode(node: NodeInfo) {
|
override fun removeNode(node: NodeInfo) {
|
||||||
synchronized(_changed) {
|
synchronized(_changed) {
|
||||||
registeredNodes.remove(node.legalIdentity)
|
registeredNodes.remove(node.legalIdentity.owningKey)
|
||||||
changePublisher.onNext(MapChange.Removed(node))
|
changePublisher.onNext(MapChange.Removed(node))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@ class MockNetworkMapCache() : InMemoryNetworkMapCache() {
|
|||||||
init {
|
init {
|
||||||
val mockNodeA = NodeInfo(MockAddress("bankC:8080"), Party("Bank C", DummyPublicKey("Bank C")))
|
val mockNodeA = NodeInfo(MockAddress("bankC:8080"), Party("Bank C", DummyPublicKey("Bank C")))
|
||||||
val mockNodeB = NodeInfo(MockAddress("bankD:8080"), Party("Bank D", DummyPublicKey("Bank D")))
|
val mockNodeB = NodeInfo(MockAddress("bankD:8080"), Party("Bank D", DummyPublicKey("Bank D")))
|
||||||
registeredNodes[mockNodeA.legalIdentity] = mockNodeA
|
registeredNodes[mockNodeA.legalIdentity.owningKey] = mockNodeA
|
||||||
registeredNodes[mockNodeB.legalIdentity] = mockNodeB
|
registeredNodes[mockNodeB.legalIdentity.owningKey] = mockNodeB
|
||||||
runWithoutMapService()
|
runWithoutMapService()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ class MockNetworkMapCache() : InMemoryNetworkMapCache() {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
fun addRegistration(node: NodeInfo) {
|
fun addRegistration(node: NodeInfo) {
|
||||||
registeredNodes[node.legalIdentity] = node
|
registeredNodes[node.legalIdentity.owningKey] = node
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,6 +41,6 @@ class MockNetworkMapCache() : InMemoryNetworkMapCache() {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
fun deleteRegistration(legalIdentity: Party) : Boolean {
|
fun deleteRegistration(legalIdentity: Party) : Boolean {
|
||||||
return registeredNodes.remove(legalIdentity) != null
|
return registeredNodes.remove(legalIdentity.owningKey) != null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user