heesung-sn commented on code in PR #23903:
URL: https://github.com/apache/pulsar/pull/23903#discussion_r1932612827
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/util/RangeCache.java:
##########
@@ -106,7 +106,39 @@ K getKey() {
return localKey;
}
+ /**
+ * Get the value associated with the key. Returns null if the key does
not match the key.
+ *
+ * @param key the key to match
+ * @return the value associated with the key, or null if the value has
already been recycled or the key does not
+ * match
+ */
V getValue(K key) {
+ return getValueInternal(key, false);
+ }
+
+ /**
+ * Get the value associated with the Map.Entry's key and value. Exact
instance of the key is required to match.
+ * @param entry the entry which contains the key and {@link
EntryWrapper} value to get the value from
+ * @return the value associated with the key, or null if the value has
already been recycled or the key does not
+ * exactly match the same instance
+ */
+ static <K, V> V getValueMatchingMapEntry(Map.Entry<K, EntryWrapper<K,
V>> entry) {
+ return entry.getValue().getValueInternal(entry.getKey(), true);
+ }
+
+ /**
+ * Get the value associated with the key. Returns null if the key does
not match the key associated with the
+ * value.
+ *
+ * @param key the key to match
+ * @param requireSameKeyInstance when true, the matching will be
restricted to exactly the same instance of the
+ * key as the one stored in the wrapper.
This is used to avoid any races
+ * when retrieving or removing the
entries from the cache when the key and value
+ * instances are available.
+ * @return the value associated with the key, or null if the key does
not match
+ */
+ private V getValueInternal(K key, boolean requireSameKeyInstance) {
Review Comment:
@BewareMyPower I remember you argued that pulsar should stop abusing this
object pooling pattern. Wdyt?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]