Add lazily-instantiated maps 88/89588/26
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 4 May 2020 12:34:27 +0000 (14:34 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 6 May 2020 22:08:41 +0000 (00:08 +0200)
commit98d1ba0a51e29b3009a0038e078a043a4aed688d
treefcb2b34645a2cfda3a636e60cac55a2f6a8eac5e
parent66d31028a61921c152ed46f46dd6dee3574af9f7
Add lazily-instantiated maps

Instantiating an ImmutableMap on each access is quite wasteful,
as there are a number of cases where we do not need the entire
mapping to be instantiated.

Typical uses touch the Map only once -- either to lookup a value
based on the key, or to iterate through the values. Others are
possible, but those two cover most of the patterns.

We add the prerequisite indirection and two implementations to
support each of the cases. The iterator part is optimized to
perform lazy object instantiation -- similar to LazyBindingList.

The lookup part works in a rather similar way, except it keeps
a lookup ConcurrentHashMap as the primary storage and values
are seen as expendable secondary storage. This makes iteration
order unstable, which might be seen as a violation of immutable
contract -- but our contract is a Map and mappings remain stable.

JIRA: MDSAL-539
Change-Id: I7c095065915f3c0d7b180d4aa1494e15d6374a11
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/BindingToNormalizedStreamWriter.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/CodecDataObject.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/KeyedListNodeCodecContext.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyBindingList.java
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyBindingMap.java [new file with mode: 0644]
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyBindingMapIterState.java [new file with mode: 0644]
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyBindingMapLookupState.java [new file with mode: 0644]
binding/mdsal-binding-dom-codec/src/test/java/org/opendaylight/mdsal/binding/dom/codec/impl/LazyBindingMapTest.java [new file with mode: 0644]