com.github.netty.protocol.servlet.websocket.WebSocketHandlerEndpoint Maven / Gradle / Ivy
The newest version!
package com.github.netty.protocol.servlet.websocket;
import com.github.netty.core.util.LoggerFactoryX;
import com.github.netty.core.util.LoggerX;
import io.netty.util.internal.PlatformDependent;
import javax.websocket.*;
import java.nio.ByteBuffer;
import java.util.Objects;
public class WebSocketHandlerEndpoint extends Endpoint {
private static final LoggerX logger = LoggerFactoryX.getLogger(WebSocketHandlerEndpoint.class);
private final WebSocketHandler handler;
public WebSocketHandlerEndpoint(WebSocketHandler handler) {
this.handler = Objects.requireNonNull(handler, "WebSocketHandler");
}
public static void tryCloseWithError(Session session, Throwable exception) {
if (logger.isWarnEnabled()) {
logger.warn("Closing session due to exception for " + session, exception);
}
if (session.isOpen()) {
try {
session.close(new CloseReason(CloseReason.CloseCodes.UNEXPECTED_CONDITION, null));
} catch (Throwable e) {
// ignore
}
}
}
@Override
public void onOpen(Session session, EndpointConfig endpointConfig) {
session.addMessageHandler(new MessageHandler.Partial