optional warning when adding duplicated key to AppendOnlyPersistenMap (#1635)

* logging duplication warning is optional when adding to AppendOnlyPersistentMap
* suppress warnings in PersistentIdentityService
This commit is contained in:
szymonsztuka 2017-09-26 09:34:14 +01:00 committed by GitHub
parent 8bab2ae9a1
commit 3218fd513d
2 changed files with 7 additions and 7 deletions

View File

@ -102,11 +102,11 @@ class PersistentIdentityService(identities: Iterable<PartyAndCertificate> = empt
caCertStore = CertStore.getInstance("Collection", CollectionCertStoreParameters(caCertificatesWithRoot)) caCertStore = CertStore.getInstance("Collection", CollectionCertStoreParameters(caCertificatesWithRoot))
identities.forEach { identities.forEach {
val key = mapToKey(it) val key = mapToKey(it)
keyToParties.addWithDuplicatesAllowed(key, it) keyToParties.addWithDuplicatesAllowed(key, it, false)
principalToParties.addWithDuplicatesAllowed(it.name, key) principalToParties.addWithDuplicatesAllowed(it.name, key, false)
} }
confidentialIdentities.forEach { confidentialIdentities.forEach {
principalToParties.addWithDuplicatesAllowed(it.name, mapToKey(it)) principalToParties.addWithDuplicatesAllowed(it.name, mapToKey(it), false)
} }
} }
@ -129,7 +129,7 @@ class PersistentIdentityService(identities: Iterable<PartyAndCertificate> = empt
val key = mapToKey(identity) val key = mapToKey(identity)
keyToParties.addWithDuplicatesAllowed(key, identity) keyToParties.addWithDuplicatesAllowed(key, identity)
// Always keep the first party we registered, as that's the well known identity // Always keep the first party we registered, as that's the well known identity
principalToParties.addWithDuplicatesAllowed(identity.name, key) principalToParties.addWithDuplicatesAllowed(identity.name, key, false)
val parentId = mapToKey(identity.certPath.certificates[1].publicKey) val parentId = mapToKey(identity.certPath.certificates[1].publicKey)
return keyToParties[parentId] return keyToParties[parentId]
} }

View File

@ -48,7 +48,7 @@ class AppendOnlyPersistentMap<K, V, E, out EK> (
return result.map { x -> fromPersistentEntity(x) }.asSequence() return result.map { x -> fromPersistentEntity(x) }.asSequence()
} }
private tailrec fun set(key: K, value: V, logWarning: Boolean = true, store: (K,V) -> V?): Boolean { private tailrec fun set(key: K, value: V, logWarning: Boolean, store: (K,V) -> V?): Boolean {
var insertionAttempt = false var insertionAttempt = false
var isUnique = true var isUnique = true
val existingInCache = cache.get(key) { // Thread safe, if multiple threads may wait until the first one has loaded. val existingInCache = cache.get(key) { // Thread safe, if multiple threads may wait until the first one has loaded.
@ -95,8 +95,8 @@ class AppendOnlyPersistentMap<K, V, E, out EK> (
* If the map previously contained a mapping for the key, the old value is not replaced. * If the map previously contained a mapping for the key, the old value is not replaced.
* @return true if added key was unique, otherwise false * @return true if added key was unique, otherwise false
*/ */
fun addWithDuplicatesAllowed(key: K, value: V): Boolean = fun addWithDuplicatesAllowed(key: K, value: V, logWarning: Boolean = true): Boolean =
set(key, value) { set(key, value, logWarning) {
k, v -> k, v ->
val existingEntry = DatabaseTransactionManager.current().session.find(persistentEntityClass, toPersistentEntityKey(k)) val existingEntry = DatabaseTransactionManager.current().session.find(persistentEntityClass, toPersistentEntityKey(k))
if (existingEntry == null) { if (existingEntry == null) {