Introduce restconf.server.{api,spi,mdsal}
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / JaxRsNorthbound.java
index 5bce185ad7afa9cc1fd957bdd4dbb6c5988a8438..363a4257676b6d691d6f7966effc5a55ce54cd9f 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.restconf.nb.rfc8040;
 
 import com.google.common.annotations.Beta;
 import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
 import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
 import org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter;
 import org.opendaylight.aaa.web.FilterDetails;
@@ -18,8 +17,6 @@ import org.opendaylight.aaa.web.WebContext;
 import org.opendaylight.aaa.web.WebContextSecurer;
 import org.opendaylight.aaa.web.WebServer;
 import org.opendaylight.aaa.web.servlet.ServletSupport;
-import org.opendaylight.controller.config.threadpool.util.NamingThreadPoolFactory;
-import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;
 import org.opendaylight.mdsal.dom.api.DOMActionService;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
@@ -28,43 +25,19 @@ 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.streams.ListenersBroker;
-import org.opendaylight.restconf.nb.rfc8040.streams.StreamsConfiguration;
-import org.opendaylight.restconf.nb.rfc8040.streams.WebSocketInitializer;
+import org.opendaylight.restconf.nb.rfc8040.streams.RestconfStreamServletFactory;
 import org.opendaylight.yangtools.concepts.Registration;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
 import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.metatype.annotations.AttributeDefinition;
-import org.osgi.service.metatype.annotations.Designate;
-import org.osgi.service.metatype.annotations.ObjectClassDefinition;
 
 /**
  * Main entrypoint into RFC8040 northbound. Take care of wiring up all applications activating them through JAX-RS.
  */
 @Beta
-@Component(service = { }, configurationPid = "org.opendaylight.restconf.nb.rfc8040")
-@Designate(ocd = JaxRsNorthbound.Configuration.class)
+@Component(service = { })
 public final class JaxRsNorthbound implements AutoCloseable {
-    @ObjectClassDefinition
-    public @interface Configuration {
-        @AttributeDefinition(min = "0", max = "" + StreamsConfiguration.MAXIMUM_FRAGMENT_LENGTH_LIMIT)
-        int maximum$_$fragment$_$length() default 0;
-        @AttributeDefinition(min = "0")
-        int heartbeat$_$interval() default 10000;
-        @AttributeDefinition(min = "1")
-        int idle$_$timeout() default 30000;
-        @AttributeDefinition(min = "1")
-        String ping$_$executor$_$name$_$prefix() default "ping-executor";
-        // FIXME: this is a misnomer: it specifies the core pool size, i.e. minimum thread count, the maximum is set to
-        //        Integer.MAX_VALUE, which is not what we want
-        @AttributeDefinition(min = "0")
-        int max$_$thread$_$count() default 1;
-        @AttributeDefinition
-        boolean use$_$sse() default true;
-    }
-
     private final Registration discoveryReg;
     private final Registration restconfReg;
 
@@ -76,36 +49,8 @@ public final class JaxRsNorthbound implements AutoCloseable {
             @Reference final DOMMountPointService mountPointService,
             @Reference final DOMNotificationService notificationService, @Reference final DOMRpcService rpcService,
             @Reference final DOMSchemaService schemaService, @Reference final DatabindProvider databindProvider,
-            @Reference final MdsalRestconfServer server, final Configuration configuration) throws ServletException {
-        this(webServer, webContextSecurer, servletSupport, filterAdapterConfiguration, actionService, dataBroker,
-            mountPointService, notificationService, rpcService, schemaService, databindProvider, server,
-            configuration.ping$_$executor$_$name$_$prefix(), configuration.max$_$thread$_$count(),
-            new StreamsConfiguration(configuration.maximum$_$fragment$_$length(),
-                configuration.idle$_$timeout(), configuration.heartbeat$_$interval(), configuration.use$_$sse()));
-    }
-
-    public JaxRsNorthbound(final WebServer webServer, final WebContextSecurer webContextSecurer,
-            final ServletSupport servletSupport, final CustomFilterAdapterConfiguration filterAdapterConfiguration,
-            final DOMActionService actionService, final DOMDataBroker dataBroker,
-            final DOMMountPointService mountPointService, final DOMNotificationService notificationService,
-            final DOMRpcService rpcService, final DOMSchemaService schemaService,
-            final DatabindProvider databindProvider, final MdsalRestconfServer server, final String pingNamePrefix,
-            final int pingMaxThreadCount, final StreamsConfiguration streamsConfiguration) throws ServletException {
-        final var scheduledThreadPool = new ScheduledThreadPoolWrapper(pingMaxThreadCount,
-            new NamingThreadPoolFactory(pingNamePrefix));
-
-        final ListenersBroker listenersBroker;
-        final HttpServlet streamServlet;
-        if (streamsConfiguration.useSSE()) {
-            listenersBroker = new ListenersBroker.ServerSentEvents(dataBroker, notificationService, mountPointService);
-            streamServlet = servletSupport.createHttpServletBuilder(
-                new ServerSentEventsApplication(scheduledThreadPool, listenersBroker, streamsConfiguration))
-                .build();
-        } else {
-            listenersBroker = new ListenersBroker.WebSockets(dataBroker, notificationService, mountPointService);
-            streamServlet = new WebSocketInitializer(scheduledThreadPool, listenersBroker, streamsConfiguration);
-        }
-
+            @Reference final MdsalRestconfServer server, @Reference final RestconfStreamServletFactory servletFactory)
+                throws ServletException {
         final var restconfBuilder = WebContext.builder()
             .name("RFC8040 RESTCONF")
             .contextPath("/" + URLConstants.BASE_PATH)
@@ -114,13 +59,13 @@ public final class JaxRsNorthbound implements AutoCloseable {
                 .addUrlPattern("/*")
                 .servlet(servletSupport.createHttpServletBuilder(
                     new RestconfApplication(databindProvider, server, mountPointService, dataBroker, actionService,
-                        notificationService, schemaService, listenersBroker))
+                        notificationService, schemaService))
                     .build())
                 .asyncSupported(true)
                 .build())
             .addServlet(ServletDetails.builder()
                 .addUrlPattern("/" + URLConstants.STREAMS_SUBPATH + "/*")
-                .servlet(streamServlet)
+                .servlet(servletFactory.newStreamServlet())
                 .name("notificationServlet")
                 .asyncSupported(true)
                 .build())