Make SSEStreamService class public
[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  */
20 public record StreamsConfiguration(int maximumFragmentLength, int idleTimeout, int heartbeatInterval) {
21     // FIXME: can this be 64KiB exactly? if so, maximumFragmentLength should become a Uint16 and validation should be
22     //        pushed out to users
23     public static final int MAXIMUM_FRAGMENT_LENGTH_LIMIT = 65534;
24
25     public StreamsConfiguration {
26         checkArgument(maximumFragmentLength >= 0 && maximumFragmentLength <= MAXIMUM_FRAGMENT_LENGTH_LIMIT,
27             "Maximum fragment length must be disabled (0) or specified by positive value less than 64KiB");
28         checkArgument(idleTimeout > 0, "Idle timeout must be specified by positive value.");
29         checkArgument(heartbeatInterval >= 0,
30             "Heartbeat ping interval must be disabled (0) or specified by positive value.");
31         // we need at least one heartbeat before we time out the socket
32         checkArgument(idleTimeout > heartbeatInterval, "Idle timeout must be greater than heartbeat ping interval.");
33     }
34 }