Eliminate AbstractRestconfApplication 11/108811/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Nov 2023 18:06:42 +0000 (19:06 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 1 Nov 2023 18:13:04 +0000 (19:13 +0100)
AbstractRestconfApplication is really needed only to support
RestconfDocumentedException, which we are no longer using.

Rename DataStreamApplication to ServerSentEventsApplication, hidden from
outside world and make it a plain Application.

Also merge AbstractRestconfApplication into RestconfApplication and hide
it as well.

JIRA: NETCONF-1102
Change-Id: I91135f716c46a6aa34c98c4f89ddcd42d344082a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/AbstractRestconfApplication.java [deleted file]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/DataStreamApplication.java [deleted file]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/JaxRsNorthbound.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/ServerSentEventsApplication.java [new file with mode: 0644]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java

diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/AbstractRestconfApplication.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/AbstractRestconfApplication.java
deleted file mode 100644 (file)
index dd031b2..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2020 Lumina Networks, Inc. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.collect.ImmutableSet;
-import java.util.List;
-import java.util.Set;
-import javax.ws.rs.core.Application;
-import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonPatchStatusBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlPatchStatusBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.YangSchemaExportBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.YinSchemaExportBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors.RestconfDocumentedExceptionMapper;
-
-/**
- * Abstract Restconf Application.
- */
-abstract class AbstractRestconfApplication extends Application {
-    private final DatabindProvider databindProvider;
-    private final List<Object> services;
-
-    AbstractRestconfApplication(final DatabindProvider databindProvider, final List<Object> services) {
-        this.databindProvider = requireNonNull(databindProvider);
-        this.services = requireNonNull(services);
-    }
-
-    @Override
-    public final Set<Class<?>> getClasses() {
-        return Set.of(
-            JsonNormalizedNodeBodyWriter.class, XmlNormalizedNodeBodyWriter.class,
-            YinSchemaExportBodyWriter.class, YangSchemaExportBodyWriter.class,
-            JsonPatchStatusBodyWriter.class, XmlPatchStatusBodyWriter.class);
-    }
-
-    @Override
-    public final Set<Object> getSingletons() {
-        return ImmutableSet.<Object>builderWithExpectedSize(services.size() + 1)
-            .addAll(services)
-            .add(new RestconfDocumentedExceptionMapper(databindProvider))
-            .build();
-    }
-}
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/DataStreamApplication.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/DataStreamApplication.java
deleted file mode 100644 (file)
index e18302d..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2020 Lumina Networks, Inc. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040;
-
-import java.util.List;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataStreamServiceImpl;
-
-/**
- * Restconf Application extends {@link AbstractRestconfApplication}. Is used for sending SSE.
- */
-@Singleton
-public class DataStreamApplication extends AbstractRestconfApplication {
-    @Inject
-    public DataStreamApplication(final DatabindProvider databindProvider,
-            final RestconfDataStreamServiceImpl dataStreamService) {
-        super(databindProvider, List.of(dataStreamService));
-    }
-}
index 07154433d10c7902a411a2479479816dc083d170..359906f97f4476af6fedc80a84fbc9c47ef791fe 100644 (file)
@@ -27,7 +27,6 @@ import org.opendaylight.mdsal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.MdsalRestconfServer;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataStreamServiceImpl;
 import org.opendaylight.restconf.nb.rfc8040.streams.ListenersBroker;
 import org.opendaylight.restconf.nb.rfc8040.streams.RestconfStreamsConstants;
 import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
@@ -102,8 +101,7 @@ public final class JaxRsNorthbound implements AutoCloseable {
             streamServlet = ServletDetails.builder()
                 .addUrlPattern("/" + URLConstants.SSE_SUBPATH + "/*")
                 .servlet(servletSupport.createHttpServletBuilder(
-                    new DataStreamApplication(databindProvider,
-                        new RestconfDataStreamServiceImpl(scheduledThreadPool, listenersBroker, streamsConfiguration)))
+                    new ServerSentEventsApplication(scheduledThreadPool, listenersBroker, streamsConfiguration))
                     .build())
                 .name("notificationServlet")
                 .asyncSupported(true)
index 8ca4e6502a06bf30d20a4405dced040e01ba003d..366dc4700c3c63453c2814ea0b646d6c51295b56 100644 (file)
@@ -7,15 +7,21 @@
  */
 package org.opendaylight.restconf.nb.rfc8040;
 
-import java.util.List;
-import javax.inject.Inject;
-import javax.inject.Singleton;
+import java.util.Set;
+import javax.ws.rs.core.Application;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyWriter;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonPatchStatusBodyWriter;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyWriter;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlPatchStatusBodyWriter;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.YangSchemaExportBodyWriter;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.YinSchemaExportBodyWriter;
+import org.opendaylight.restconf.nb.rfc8040.jersey.providers.errors.RestconfDocumentedExceptionMapper;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.MdsalRestconfServer;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataServiceImpl;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfImpl;
@@ -25,14 +31,15 @@ import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfSchemaSe
 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfStreamsSubscriptionServiceImpl;
 import org.opendaylight.restconf.nb.rfc8040.streams.ListenersBroker;
 
-@Singleton
-public class RestconfApplication extends AbstractRestconfApplication {
-    @Inject
-    public RestconfApplication(final DatabindProvider databindProvider, final MdsalRestconfServer server,
+final class RestconfApplication extends Application {
+    private final Set<Object> singletons;
+
+    RestconfApplication(final DatabindProvider databindProvider, final MdsalRestconfServer server,
             final DOMMountPointService mountPointService, final DOMDataBroker dataBroker,
             final DOMActionService actionService, final DOMNotificationService notificationService,
             final DOMSchemaService domSchemaService, final ListenersBroker listenersBroker) {
-        super(databindProvider, List.of(
+        singletons = Set.of(
+            new RestconfDocumentedExceptionMapper(databindProvider),
             // FIXME: NETCONF:1102: do not instantiate this service
             new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider,
                 listenersBroker),
@@ -40,6 +47,19 @@ public class RestconfApplication extends AbstractRestconfApplication {
             new RestconfInvokeOperationsServiceImpl(databindProvider, server, mountPointService, listenersBroker),
             new RestconfOperationsServiceImpl(databindProvider, server),
             new RestconfSchemaServiceImpl(domSchemaService, mountPointService),
-            new RestconfImpl(databindProvider)));
+            new RestconfImpl(databindProvider));
+    }
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        return Set.of(
+            JsonNormalizedNodeBodyWriter.class, XmlNormalizedNodeBodyWriter.class,
+            YinSchemaExportBodyWriter.class, YangSchemaExportBodyWriter.class,
+            JsonPatchStatusBodyWriter.class, XmlPatchStatusBodyWriter.class);
+    }
+
+    @Override
+    public Set<Object> getSingletons() {
+        return singletons;
     }
 }
diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/ServerSentEventsApplication.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/ServerSentEventsApplication.java
new file mode 100644 (file)
index 0000000..2188038
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2020 Lumina Networks, Inc. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.nb.rfc8040;
+
+import java.util.Set;
+import javax.ws.rs.core.Application;
+import org.opendaylight.controller.config.threadpool.ScheduledThreadPool;
+import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataStreamServiceImpl;
+import org.opendaylight.restconf.nb.rfc8040.streams.ListenersBroker;
+import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
+
+/**
+ * JAX-RS binding for Server-Sent Events.
+ */
+final class ServerSentEventsApplication extends Application {
+    private final RestconfDataStreamServiceImpl singleton;
+
+    ServerSentEventsApplication(final ScheduledThreadPool scheduledThreadPool, final ListenersBroker listenersBroker,
+            final StreamsConfiguration configuration) {
+        singleton = new RestconfDataStreamServiceImpl(scheduledThreadPool, listenersBroker, configuration);
+    }
+
+    @Override
+    public Set<Object> getSingletons() {
+        return Set.of(singleton);
+    }
+}
index 81b94bd961a3147323ea542991dc24ba15499d5e..ab89cfecfdcbaee3a302b364b50afb8e116ebe3b 100644 (file)
@@ -10,8 +10,6 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 import static java.util.Objects.requireNonNull;
 
 import java.util.concurrent.ScheduledExecutorService;
-import javax.inject.Inject;
-import javax.inject.Singleton;
 import javax.ws.rs.Encoded;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
@@ -34,7 +32,6 @@ import org.slf4j.LoggerFactory;
  * Access to notification streams via Server-Sent Events.
  */
 @Path("/")
-@Singleton
 public final class RestconfDataStreamServiceImpl {
     private static final Logger LOG = LoggerFactory.getLogger(RestconfDataStreamServiceImpl.class);
 
@@ -43,7 +40,6 @@ public final class RestconfDataStreamServiceImpl {
     private final int maximumFragmentLength;
     private final int heartbeatInterval;
 
-    @Inject
     public RestconfDataStreamServiceImpl(final ScheduledThreadPool scheduledThreadPool,
             final ListenersBroker listenersBroker, final StreamsConfiguration configuration) {
         executorService = scheduledThreadPool.getExecutor();