2 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.restconf.nb.rfc8040.streams;
10 import static java.util.Objects.requireNonNull;
14 import javax.servlet.http.HttpServlet;
15 import javax.ws.rs.core.Application;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.aaa.web.servlet.ServletSupport;
18 import org.opendaylight.restconf.api.query.PrettyPrintParam;
19 import org.opendaylight.restconf.nb.rfc8040.ErrorTagMapping;
20 import org.opendaylight.restconf.server.spi.RestconfStream;
21 import org.osgi.service.component.annotations.Activate;
22 import org.osgi.service.component.annotations.Component;
23 import org.osgi.service.component.annotations.Deactivate;
24 import org.osgi.service.component.annotations.Reference;
27 * Auxiliary interface for instantiating JAX-RS streams.
29 * @deprecated This componet exists only to support SSE/Websocket delivery. It will be removed when support for
30 * WebSockets is removed.
32 @Component(factory = DefaultRestconfStreamServletFactory.FACTORY_NAME, service = RestconfStreamServletFactory.class)
33 @Deprecated(since = "7.0.0", forRemoval = true)
34 public final class DefaultRestconfStreamServletFactory implements RestconfStreamServletFactory, AutoCloseable {
35 public static final String FACTORY_NAME =
36 "org.opendaylight.restconf.nb.rfc8040.streams.RestconfStreamServletFactory";
38 private static final String PROP_NAME_PREFIX = ".namePrefix";
39 private static final String PROP_CORE_POOL_SIZE = ".corePoolSize";
40 private static final String PROP_STREAMS_CONFIGURATION = ".streamsConfiguration";
41 private static final String PROP_RESTCONF = ".restconf";
42 private static final String PROP_PRETTY_PRINT = ".prettyPrint";
43 private static final String PROP_ERROR_TAG_MAPPING = ".errorTagMapping";
45 private final @NonNull String restconf;
46 private final @NonNull ErrorTagMapping errorTagMapping;
47 private final @NonNull PrettyPrintParam prettyPrint;
48 private final RestconfStream.Registry streamRegistry;
49 private final ServletSupport servletSupport;
51 private final DefaultPingExecutor pingExecutor;
52 private final StreamsConfiguration streamsConfiguration;
54 public DefaultRestconfStreamServletFactory(final ServletSupport servletSupport, final String restconf,
55 final RestconfStream.Registry streamRegistry, final StreamsConfiguration streamsConfiguration,
56 final ErrorTagMapping errorTagMapping, final PrettyPrintParam prettyPrint, final String namePrefix,
57 final int corePoolSize) {
58 this.servletSupport = requireNonNull(servletSupport);
59 this.restconf = requireNonNull(restconf);
60 if (restconf.endsWith("/")) {
61 throw new IllegalArgumentException("{+restconf} value ends with /");
63 this.streamRegistry = requireNonNull(streamRegistry);
64 this.streamsConfiguration = requireNonNull(streamsConfiguration);
65 this.errorTagMapping = requireNonNull(errorTagMapping);
66 this.prettyPrint = requireNonNull(prettyPrint);
67 pingExecutor = new DefaultPingExecutor(namePrefix, corePoolSize);
71 public DefaultRestconfStreamServletFactory(@Reference final ServletSupport servletSupport,
72 @Reference final RestconfStream.Registry streamRegistry, final Map<String, ?> props) {
73 this(servletSupport, (String) props.get(PROP_RESTCONF), streamRegistry,
74 (StreamsConfiguration) props.get(PROP_STREAMS_CONFIGURATION),
75 (ErrorTagMapping) props.get(PROP_ERROR_TAG_MAPPING),
76 (PrettyPrintParam) props.get(PROP_PRETTY_PRINT),
77 (String) props.get(PROP_NAME_PREFIX), (int) requireNonNull(props.get(PROP_CORE_POOL_SIZE)));
81 public String restconf() {
86 public HttpServlet newStreamServlet() {
87 return servletSupport.createHttpServletBuilder(
90 public Set<Object> getSingletons() {
91 return Set.of(new SSEStreamService(streamRegistry, pingExecutor, streamsConfiguration));
97 public PrettyPrintParam prettyPrint() {
102 public ErrorTagMapping errorTagMapping() {
103 return errorTagMapping;
108 public void close() {
109 pingExecutor.close();
112 public static Map<String, ?> props(final String restconf, final ErrorTagMapping errorTagMapping,
113 final PrettyPrintParam prettyPrint, final StreamsConfiguration streamsConfiguration,
114 final String namePrefix, final int corePoolSize) {
116 PROP_RESTCONF, restconf,
117 PROP_ERROR_TAG_MAPPING, errorTagMapping,
118 PROP_PRETTY_PRINT, prettyPrint,
119 PROP_STREAMS_CONFIGURATION, streamsConfiguration,
120 PROP_NAME_PREFIX, namePrefix,
121 PROP_CORE_POOL_SIZE, corePoolSize);