2 * Copyright © 2019 FRINX s.r.o. 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 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;
19 * Web-socket servlet listening on ws or wss schemas for created data-change-event or notification streams.
21 final class WebSocketInitializer extends WebSocketServlet {
23 private static final long serialVersionUID = 1L;
25 private final transient WebSocketFactory creator;
26 private final int idleTimeoutMillis;
28 WebSocketInitializer(final RestconfStream.Registry streamRegistry, final PingExecutor pingExecutor,
29 final StreamsConfiguration configuration) {
30 creator = new WebSocketFactory(streamRegistry, pingExecutor,
31 configuration.maximumFragmentLength(), configuration.heartbeatInterval());
32 idleTimeoutMillis = configuration.idleTimeout();
36 * Configuration of the web-socket factory - idle timeout and specified factory object.
38 * @param factory Configurable web-socket factory.
41 public void configure(final WebSocketServletFactory factory) {
42 factory.getPolicy().setIdleTimeout(idleTimeoutMillis);
43 factory.setCreator(creator);
47 @SuppressWarnings("static-method")
48 private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException {
53 @SuppressWarnings("static-method")
54 private void writeObject(final ObjectOutputStream out) throws IOException {
58 private static void throwNSE() throws NotSerializableException {
59 throw new NotSerializableException(WebSocketInitializer.class.getName());