Make SSEStreamService class public
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / streams / WebSocketInitializer.java
1 /*
2  * Copyright © 2019 FRINX s.r.o. 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.streams;
9
10 import java.io.IOException;
11 import java.io.NotSerializableException;
12 import java.io.ObjectInputStream;
13 import java.io.ObjectOutputStream;
14 import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
15 import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
16 import org.opendaylight.restconf.server.spi.RestconfStream;
17
18 /**
19  * Web-socket servlet listening on ws or wss schemas for created data-change-event or notification streams.
20  */
21 @Deprecated(since = "7.0.0", forRemoval = true)
22 final class WebSocketInitializer extends WebSocketServlet {
23     @java.io.Serial
24     private static final long serialVersionUID = 1L;
25
26     private final transient WebSocketFactory creator;
27     private final int idleTimeoutMillis;
28
29     WebSocketInitializer(final String restconf, final RestconfStream.Registry streamRegistry,
30             final PingExecutor pingExecutor, final StreamsConfiguration configuration) {
31         creator = new WebSocketFactory(restconf, streamRegistry, pingExecutor,
32             configuration.maximumFragmentLength(), configuration.heartbeatInterval());
33         idleTimeoutMillis = configuration.idleTimeout();
34     }
35
36     /**
37      * Configuration of the web-socket factory - idle timeout and specified factory object.
38      *
39      * @param factory Configurable web-socket factory.
40      */
41     @Override
42     public void configure(final WebSocketServletFactory factory) {
43         factory.getPolicy().setIdleTimeout(idleTimeoutMillis);
44         factory.setCreator(creator);
45     }
46
47     @java.io.Serial
48     @SuppressWarnings("static-method")
49     private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
50         throwNSE();
51     }
52
53     @java.io.Serial
54     @SuppressWarnings("static-method")
55     private void writeObject(final ObjectOutputStream out) throws IOException {
56         throwNSE();
57     }
58
59     private static void throwNSE() throws NotSerializableException {
60         throw new NotSerializableException(WebSocketInitializer.class.getName());
61     }
62 }