adoroszlai commented on code in PR #4798:
URL: https://github.com/apache/ozone/pull/4798#discussion_r1271287033
##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/conf/OzoneConfiguration.java:
##########
@@ -335,4 +336,16 @@ private static void addDeprecatedKeys() {
OZONE_CONTAINER_COPY_WORKDIR)
});
}
+
+ @Override
+ public synchronized <T> T getSingletonObject(Class<T> configurationClass) {
+ if (singletons.containsKey(configurationClass)) {
+ return (T) singletons.get(configurationClass);
+ }
+
+ T singletonObject = getObject(configurationClass);
+ singletons.put(configurationClass, singletonObject);
+ return singletonObject;
+ }
Review Comment:
This can be implemented more simply:
```suggestion
public <T> T getSingletonObject(Class<T> configurationClass) {
return (T) singletons.computeIfAbsent(configurationClass,
c -> getObject(configurationClass));
}
```
##########
hadoop-hdds/config/src/main/java/org/apache/hadoop/hdds/conf/ConfigurationSource.java:
##########
@@ -183,6 +183,20 @@ default <T> T getObject(Class<T> configurationClass) {
}
+ /**
+ * Returns a singleton instance of the given configuration class.
+ * If an instance of the class has already been created,
+ * it will be returned; otherwise, a new instance will be created,
+ * stored in a map for future retrieval.
+ *
+ * @param configurationClass The class for which a singleton
+ * instance is required
+ * @return a singleton instance of the given class
+ */
+ default <T> T getSingletonObject(Class<T> configurationClass) {
+ return getObject(configurationClass);
+ }
+
Review Comment:
I don't think this should be added to the `ConfigurationSource` interface,
since it does not offer the "singleton" functionality.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]