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

    Fields
    Modifier and Type
    Field
    Description
    protected static final io.netty.channel.group.ChannelGroup
     
    protected static final io.netty.util.AttributeKey
     
    protected org.apache.logging.log4j.Logger
     
    protected static final io.netty.handler.codec.http.websocketx.TextWebSocketFrame
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract Caller
    auth(String token)
     
    void
    channelActive(io.netty.channel.ChannelHandlerContext ctx)
     
    protected void
    channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame msg)
     
    protected void
    channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame msg)
     
    protected void
    channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.TextWebSocketFrame msg)
     
    protected void
    channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.websocketx.WebSocketFrame msg)
     
    void
    exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
     
    void
    handlerAdded(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
     
    protected abstract String
    onCallerConnected(io.netty.channel.ChannelHandlerContext ctx, Caller caller)
     
    protected abstract String
    onMessage(io.netty.channel.ChannelHandlerContext ctx, Caller caller, byte[] data)
     
    protected abstract String
    onMessage(io.netty.channel.ChannelHandlerContext ctx, Caller caller, String txt)
     
    static void
    sendToAllChannels(byte[] data, boolean auth)
     
    static void
    sendToAllChannels(io.netty.handler.codec.http.websocketx.WebSocketFrame message, boolean auth)
     
    static void
    sendToAllChannels(String text, boolean auth)
     
    static void
    sendToChannel(io.netty.channel.ChannelHandlerContext ctx, byte[] data)
     
    static void
    sendToChannel(io.netty.channel.ChannelHandlerContext ctx, String message)
     

    Methods inherited from class io.netty.channel.SimpleChannelInboundHandler

    acceptInboundMessage, channelRead

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
      channelRead0 in class io.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

      protected abstract Caller auth(String token)
    • onCallerConnected

      protected abstract String onCallerConnected(io.netty.channel.ChannelHandlerContext ctx, Caller caller)
    • 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

      protected abstract String onMessage(io.netty.channel.ChannelHandlerContext ctx, Caller caller, byte[] data)
    • sendToChannel

      public static void sendToChannel(io.netty.channel.ChannelHandlerContext ctx, String message)
    • sendToChannel

      public static void sendToChannel(io.netty.channel.ChannelHandlerContext ctx, byte[] data)
    • sendToAllChannels

      public static void sendToAllChannels(String text, boolean auth)
    • 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:
      handlerAdded in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerAdded in class io.netty.channel.ChannelHandlerAdapter
    • channelActive

      public void channelActive(io.netty.channel.ChannelHandlerContext ctx) throws Exception
      Specified by:
      channelActive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception
    • handlerRemoved

      public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx)
      Specified by:
      handlerRemoved in interface io.netty.channel.ChannelHandler
      Overrides:
      handlerRemoved in class io.netty.channel.ChannelHandlerAdapter
    • exceptionCaught

      public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) throws Exception
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelHandler
      Specified by:
      exceptionCaught in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      exceptionCaught in class io.netty.channel.ChannelInboundHandlerAdapter
      Throws:
      Exception