CptBartender commented on code in PR #2911:
URL: https://github.com/apache/karaf/pull/2911#discussion_r4172922938
##########
util/src/main/java/org/apache/karaf/util/tracker/BaseActivator.java:
##########
@@ -320,40 +328,39 @@ public void run() {
* Called in {@link #doOpen()}.
*
* @param clazz The service interface to track.
+ * @param <T> Generic type of the service to track
* @throws InvalidSyntaxException If the tracker syntax is not correct.
*/
- protected void trackService(Class<?> clazz) throws InvalidSyntaxException {
- if (!trackers.containsKey(clazz.getName())) {
- SingleServiceTracker tracker = new
SingleServiceTracker<>(bundleContext, clazz, (u, v) -> reconfigure());
- tracker.open();
- trackers.put(clazz.getName(), tracker);
- }
+ protected <T> void trackService(Class<T> clazz) throws
InvalidSyntaxException {
+ trackService(clazz, null);
}
/**
* Called in {@link #doOpen()}.
*
* @param clazz The service interface to track.
* @param filter The filter to use to select the services to track.
+ * @param <T> Generic type of the service to track
* @throws InvalidSyntaxException If the tracker syntax is not correct (in
the filter especially).
*/
- protected void trackService(Class<?> clazz, String filter) throws
InvalidSyntaxException {
- if (!trackers.containsKey(clazz.getName())) {
+ protected <T> void trackService(Class<T> clazz, String filter) throws
InvalidSyntaxException {
+ if (!trackers.containsKey(clazz)) {
if (filter != null && filter.isEmpty()) {
filter = null;
}
- SingleServiceTracker tracker = new
SingleServiceTracker<>(bundleContext, clazz, filter, (u, v) -> reconfigure());
+ SingleServiceTracker<T> tracker = new
SingleServiceTracker<>(bundleContext, clazz, filter, (u, v) -> reconfigure());
tracker.open();
- trackers.put(clazz.getName(), tracker);
+ trackers.put(clazz, tracker);
}
}
protected void trackService(String className, String filter) throws
InvalidSyntaxException {
- if (!trackers.containsKey(className)) {
- SingleServiceTracker tracker = new
SingleServiceTracker<>(bundleContext, className, filter, (u, v) ->
reconfigure());
- tracker.open();
- trackers.put(className, tracker);
- }
+ try {
+ Class<?> clazz = Class.forName(className);
Review Comment:
Reworked
--
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]