Convert JaxRsNorthbound into a Component
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / rfc8040 / streams / StreamsConfiguration.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 static com.google.common.base.Preconditions.checkArgument;
11
12 /**
13  * RESTCONF configuration holder and verifier.
14  *
15  * @param maximumFragmentLength Maximum web-socket fragment length in number of Unicode code units (characters)
16  *                              (exceeded message length leads to fragmentation of messages).
17  * @param idleTimeout           Maximum idle time of web-socket session before the session is closed (milliseconds).
18  * @param heartbeatInterval     Interval in milliseconds between sending of ping control frames.
19  * @param useSSE                when is {@code true} use SSE else use WS
20  */
21 public record StreamsConfiguration(int maximumFragmentLength, int idleTimeout, int heartbeatInterval, boolean useSSE) {
22     // FIXME: can this be 64KiB exactly? if so, maximumFragmentLength should become a Uint16 and validation should be
23     //        pushed out to users
24     public static final int MAXIMUM_FRAGMENT_LENGTH_LIMIT = 65534;
25
26     public StreamsConfiguration {
27         checkArgument(maximumFragmentLength >= 0 && maximumFragmentLength <= MAXIMUM_FRAGMENT_LENGTH_LIMIT,
28             "Maximum fragment length must be disabled (0) or specified by positive value less than 64KiB");
29         checkArgument(idleTimeout > 0, "Idle timeout must be specified by positive value.");
30         checkArgument(heartbeatInterval >= 0,
31             "Heartbeat ping interval must be disabled (0) or specified by positive value.");
32     }
33 }