Refactor restconf-nb blueprint
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / JaxRsNorthbound.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.nb.rfc8040;
9
10 import com.google.common.annotations.Beta;
11 import javax.servlet.ServletException;
12 import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
13 import org.opendaylight.aaa.web.WebContextSecurer;
14 import org.opendaylight.aaa.web.WebServer;
15 import org.opendaylight.aaa.web.servlet.ServletSupport;
16 import org.opendaylight.controller.config.threadpool.util.NamingThreadPoolFactory;
17 import org.opendaylight.controller.config.threadpool.util.ScheduledThreadPoolWrapper;
18 import org.opendaylight.mdsal.dom.api.DOMActionService;
19 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
20 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
21 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
22 import org.opendaylight.mdsal.dom.api.DOMRpcService;
23 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
24 import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
25 import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.RestconfDataStreamServiceImpl;
26 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
27 import org.opendaylight.restconf.nb.rfc8040.streams.WebSocketInitializer;
28 import org.opendaylight.restconf.nb.rfc8040.web.WebInitializer;
29
30 /**
31  * Main entrypoint into RFC8040 northbound. Take care of wiring up all applications activating them through JAX-RS.
32  */
33 @Beta
34 public final class JaxRsNorthbound implements AutoCloseable {
35     private final WebInitializer webInitializer;
36
37     public JaxRsNorthbound(final WebServer webServer, final WebContextSecurer webContextSecurer,
38             final ServletSupport servletSupport, final CustomFilterAdapterConfiguration filterAdapterConfiguration,
39             final DOMActionService actionService, final DOMDataBroker dataBroker,
40             final DOMMountPointService mountPointService, final DOMNotificationService notificationService,
41             final DOMRpcService rpcService, final DOMSchemaService schemaService,
42             final DatabindProvider databindProvider,
43             final String pingNamePrefix, final int pingMaxThreadCount, final int maximumFragmentLength,
44             final int heartbeatInterval, final int idleTimeout, final boolean useSSE) throws ServletException {
45         final var configuration = new Configuration(maximumFragmentLength, idleTimeout, heartbeatInterval, useSSE);
46         final var scheduledThreadPool = new ScheduledThreadPoolWrapper(pingMaxThreadCount,
47             new NamingThreadPoolFactory(pingNamePrefix));
48
49         webInitializer = new WebInitializer(webServer, webContextSecurer, servletSupport,
50             new RestconfApplication(databindProvider, mountPointService, dataBroker, rpcService, actionService,
51                 notificationService, schemaService, configuration),
52             new DataStreamApplication(databindProvider, mountPointService,
53                 new RestconfDataStreamServiceImpl(scheduledThreadPool, configuration)),
54             filterAdapterConfiguration,
55             new WebSocketInitializer(scheduledThreadPool, configuration));
56     }
57
58     @Override
59     public void close() {
60         webInitializer.close();
61     }
62 }