Remove intermediate ServiceFactory 79/89379/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 25 Apr 2020 19:25:33 +0000 (21:25 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 25 Apr 2020 19:25:33 +0000 (21:25 +0200)
Since PaxWebServer implements nothing we can easily make it a
ServiceFactory, reducing one indirection and making things a bit
more clear.

Change-Id: I41385adec33fb4b0ea17f3f74140090d8642540a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
web/impl-osgi/src/main/java/org/opendaylight/aaa/web/osgi/PaxWebServer.java

index 09f8a1ecb9a7825349ab00e88b817c968324f19b..5e0ad366bdb56a8324e9be828914a245bd767bad 100644 (file)
@@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory;
  * @author Tom Pantelis - added ServiceFactory to solve possible class loading issues in web components
  */
 @Singleton
-public class PaxWebServer {
+public class PaxWebServer implements ServiceFactory<WebServer> {
 
     // TODO write an IT (using Pax Exam) which tests this, re-use JettyLauncherTest
 
@@ -57,19 +57,7 @@ public class PaxWebServer {
     @Inject
     public PaxWebServer(final @Reference WebContainer paxWebContainer, final BundleContext bundleContext) {
         this.paxWeb = paxWebContainer;
-
-        serviceRegistration = bundleContext.registerService(WebServer.class, new ServiceFactory<WebServer>() {
-                @Override
-                public WebServer getService(final Bundle bundle, final ServiceRegistration<WebServer> registration) {
-                    return newWebServer(bundle);
-                }
-
-                @Override
-                public void ungetService(final Bundle bundle, final ServiceRegistration<WebServer> registration,
-                        final WebServer service) {
-                }
-            }, null);
-
+        serviceRegistration = bundleContext.registerService(WebServer.class, this, null);
         LOG.info("PaxWebServer initialized & WebServer service factory registered");
     }
 
@@ -87,7 +75,8 @@ public class PaxWebServer {
         }
     }
 
-    WebServer newWebServer(final Bundle bundle) {
+    @Override
+    public WebServer getService(final Bundle bundle, final ServiceRegistration<WebServer> registration) {
         LOG.info("Creating WebServer instance for bundle {}", bundle);
 
         final BundleContext bundleContext = bundle.getBundleContext();
@@ -132,8 +121,13 @@ public class PaxWebServer {
         };
     }
 
-    private static class WebContextImpl implements WebContextRegistration {
+    @Override
+    public void ungetService(final Bundle bundle, final ServiceRegistration<WebServer> registration,
+            final WebServer service) {
+        // no-op
+    }
 
+    private static class WebContextImpl implements WebContextRegistration {
         private final String contextPath;
         private final WebContainer paxWeb;
         private final List<Servlet> registeredServlets = new ArrayList<>();