Add comments to ClassLoader scoped weak map
@@ -4,12 +4,17 @@ import datadog.trace.bootstrap.WeakMap;
import java.util.HashMap;
import java.util.Map;
+/** A registry which is scoped per-classloader able to hold key-value pairs with weak keys. */
public class ClassLoaderScopedWeakMap {
public static final ClassLoaderScopedWeakMap INSTANCE = new ClassLoaderScopedWeakMap();
private final WeakMap<ClassLoader, Map<Object, Object>> map = WeakMap.Supplier.DEFAULT.get();
+ /**
+ * Gets the element registered at the specified key or register as new one retrieved by the
+ * provided supplier.
+ */
public synchronized Object getOrCreate(
ClassLoader classLoader, Object key, Supplier valueSupplier) {
Map<Object, Object> classLoaderMap = map.get(classLoader);
@@ -27,6 +32,10 @@ public class ClassLoaderScopedWeakMap {
return value;
}
+ /**
+ * Supplies the value to be stored and it is called only when a value does not exists yet in the
+ * registry.
+ */
public interface Supplier {
Object get();
}
