All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.websockets.next.CloseReason Maven / Gradle / Ivy

There is a newer version: 3.17.2
Show newest version
package io.quarkus.websockets.next;

import io.netty.handler.codec.http.websocketx.WebSocketCloseStatus;

/**
 * Indicates a reason for closing a connection. See also RFC-6455
 * section 5.5.1. The pre-defined status codes are
 * listed in section 7.4.1.
 *
 * @see WebSocketCloseStatus
 * @see WebSocketConnection#close(CloseReason)
 * @see WebSocketClientConnection#close(CloseReason)
 */
public class CloseReason {

    public static final CloseReason NORMAL = new CloseReason(WebSocketCloseStatus.NORMAL_CLOSURE.code());

    public static final CloseReason INTERNAL_SERVER_ERROR = new CloseReason(WebSocketCloseStatus.INTERNAL_SERVER_ERROR.code());

    private final int code;

    private final String message;

    /**
     *
     * @param code The status code must comply with RFC-6455
     */
    public CloseReason(int code) {
        this(code, null);
    }

    /**
     *
     * @param code The status code must comply with RFC-6455
     * @param message
     */
    public CloseReason(int code, String message) {
        if (!WebSocketCloseStatus.isValidStatusCode(code)) {
            throw new IllegalArgumentException("Invalid status code: " + code);
        }
        this.code = code;
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    @Override
    public String toString() {
        return "CloseReason [code=" + code + ", " + (message != null ? "message=" + message : "") + "]";
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy