Class BootWebSocketHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.websocketx.WebSocketFrame>
org.summerboot.jexpress.nio.server.BootWebSocketHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler
public abstract class BootWebSocketHandler
extends io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.websocketx.WebSocketFrame>
usage example:
add to cfg_nio.properties: nio.WebSocketHandler=/mywebsocket/demo
@ChannelHandler.Sharable
@Singleton
@Service(binding = ChannelHandler.class, named = "/mywebsocket/demo")
public class MyHandler extends BootWebSocketHandler {
@Override
protected Caller auth(String token) {
return new User(0, token);
}
}
- Version:
- 2.0
- Author:
- Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final io.netty.channel.group.ChannelGroupprotected static final io.netty.util.AttributeKeyprotected org.apache.logging.log4j.Loggerprotected static final io.netty.handler.codec.http.websocketx.TextWebSocketFrame -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract CallervoidchannelActive(io.netty.channel.ChannelHandlerContext ctx) protected voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame msg) protected voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame msg) protected voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.TextWebSocketFrame msg) protected voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.WebSocketFrame msg) voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx) voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx) protected abstract StringonCallerConnected(io.netty.channel.ChannelHandlerContext ctx, Caller caller) protected abstract Stringprotected abstract Stringstatic voidsendToAllChannels(byte[] data, boolean auth) static voidsendToAllChannels(io.netty.handler.codec.http.websocketx.WebSocketFrame message, boolean auth) static voidsendToAllChannels(String text, boolean auth) static voidsendToChannel(io.netty.channel.ChannelHandlerContext ctx, byte[] data) static voidsendToChannel(io.netty.channel.ChannelHandlerContext ctx, String message) Methods inherited from class io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelReadMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Field Details
-
log
protected org.apache.logging.log4j.Logger log -
MSG_AUTH_FAILED
protected static final io.netty.handler.codec.http.websocketx.TextWebSocketFrame MSG_AUTH_FAILED -
clients
protected static final io.netty.channel.group.ChannelGroup clients -
KEY_CALLER
protected static final io.netty.util.AttributeKey KEY_CALLER
-
-
Constructor Details
-
BootWebSocketHandler
public BootWebSocketHandler()
-
-
Method Details
-
channelRead0
protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.WebSocketFrame msg) throws Exception - Specified by:
channelRead0in classio.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.websocketx.WebSocketFrame>- Throws:
Exception
-
channelRead0
protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame msg) throws Exception - Throws:
Exception
-
channelRead0
protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.TextWebSocketFrame msg) throws Exception - Throws:
Exception
-
channelRead0
protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame msg) throws Exception - Throws:
Exception
-
auth
-
onCallerConnected
-
onMessage
protected abstract String onMessage(io.netty.channel.ChannelHandlerContext ctx, Caller caller, String txt) - Parameters:
ctx-caller-txt-- Returns:
- non-null string will send back to peer
-
onMessage
-
sendToChannel
-
sendToChannel
public static void sendToChannel(io.netty.channel.ChannelHandlerContext ctx, byte[] data) -
sendToAllChannels
-
sendToAllChannels
public static void sendToAllChannels(byte[] data, boolean auth) -
sendToAllChannels
public static void sendToAllChannels(io.netty.handler.codec.http.websocketx.WebSocketFrame message, boolean auth) -
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) - Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter
-
channelActive
- Specified by:
channelActivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelActivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) - Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.netty.channel.ChannelHandlerAdapter
-
exceptionCaught
public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception - Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelHandler- Specified by:
exceptionCaughtin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
exceptionCaughtin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-