Class MainHandler

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
com.cloud.serverpak.MainHandler
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

public class MainHandler extends io.netty.channel.ChannelInboundHandlerAdapter
The main listener of the Netty pipeline, extends ChannelInboundHandlerAdapter, the method of reading channelRead channelRead is essentially the main point connecting the Netty kernel and the program with all its actions that will be taken to process received message.
  • 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
    private AuthService
    Authorization service AuthService.
    private static List<io.netty.channel.Channel>
     
     
     
    A listener logger for processing incoming messages.
    private String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    MainHandler(AuthService authService)
    Receives a link to the authorization service when creating it.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
    Reads received message objects.
    void
    exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
    Called when errors occur, closes the channel context.
    static List<io.netty.channel.Channel>
     

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggered

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Field Details

  • Constructor Details

    • MainHandler

      public MainHandler(AuthService authService)
      Receives a link to the authorization service when creating it. Launches thread pool, file management service, and message listener logger.
      Parameters:
      authService - Authorization service.
      See Also:
  • Method Details

    • channelRead

      public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)
      Reads received message objects. Depending on the incoming class messages are taken from HandlerRegistry processing method and stores it in the function interface variable RequestHandler. Calls this method for execution by passing parameters to it:
      Specified by:
      channelRead in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelRead in class io.netty.channel.ChannelInboundHandlerAdapter
      Parameters:
      ctx - channel context.
      msg - the message object.
    • getChannels

      public static List<io.netty.channel.Channel> getChannels()
    • exceptionCaught

      public void exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
      Called when errors occur, closes the channel context.
      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
      Parameters:
      ctx - channel context.
      cause - a variable with an exception.