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
9 package org.opendaylight.restconf.nb.rfc8040.streams.websockets;
11 import com.google.common.base.Preconditions;
14 * Web-socket configuration holder and verifier.
16 public class WebSocketConfiguration {
18 private static final int MAX_FRAGMENT_LENGTH = 65535;
20 private final int maximumFragmentLength;
21 private final int idleTimeout;
22 private final int heartbeatInterval;
25 * Creation of the web-socket configuration holder with verification of input parameters.
27 * @param maximumFragmentLength Maximum web-socket fragment length in number of Unicode code units (characters)
28 * (exceeded message length leads to fragmentation of messages).
29 * @param idleTimeout Maximum idle time of web-socket session before the session is closed (milliseconds).
30 * @param heartbeatInterval Interval in milliseconds between sending of ping control frames.
32 public WebSocketConfiguration(int maximumFragmentLength, int idleTimeout, int heartbeatInterval) {
33 Preconditions.checkArgument(idleTimeout > 0, "Idle timeout must be specified by positive value.");
34 Preconditions.checkArgument(maximumFragmentLength >= 0 && maximumFragmentLength < MAX_FRAGMENT_LENGTH,
35 "Maximum fragment length must be disabled (0) or specified by positive value "
36 + "less than 64 KB.");
37 Preconditions.checkArgument(heartbeatInterval >= 0, "Heartbeat ping interval must be "
38 + "disabled (0) or specified by positive value.");
40 this.maximumFragmentLength = maximumFragmentLength;
41 this.idleTimeout = idleTimeout;
42 this.heartbeatInterval = heartbeatInterval;
45 public int getMaximumFragmentLength() {
46 return maximumFragmentLength;
49 public int getIdleTimeout() {
53 public int getHeartbeatInterval() {
54 return heartbeatInterval;