io.quarkus.websockets.next.CloseReason Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-websockets-next Show documentation
Show all versions of quarkus-websockets-next Show documentation
Implementation of the WebSocket API with enhanced efficiency and usability
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