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:
Ross Nicoll 2017-02-02 16:10:10 +00:00 committed by Chris Rankin
parent 12de4f46b1
commit 8cb27f1052
2 changed files with 9 additions and 9 deletions

View File

@ -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))
}
}

View File

@ -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
}
}