Class P2PFileTransferServerHandler

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

    @Sharable
    public class P2PFileTransferServerHandler
    extends io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.FullHttpRequest>
    The server-side Netty handler to process requests for P2P file transfer. It's shareable among multiple requests since it doesn't maintain states.
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

        io.netty.channel.ChannelHandler.Sharable
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void channelActive​(io.netty.channel.ChannelHandlerContext ctx)  
      protected void channelRead0​(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.FullHttpRequest httpRequest)
      This method is called with the request that is received from the client.
      void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx, java.lang.Throwable cause)  
      void userEventTriggered​(io.netty.channel.ChannelHandlerContext ctx, java.lang.Object event)
      Netty calls this function when events that we have registered for, occur (in this case we are specifically waiting for IdleStateEvent so that we close connections that have been idle too long - maybe due to client failure)
      • Methods inherited from class io.netty.channel.SimpleChannelInboundHandler

        acceptInboundMessage, channelRead
      • Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

        channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged
      • 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
    • Constructor Detail

      • P2PFileTransferServerHandler

        public P2PFileTransferServerHandler​(java.lang.String baseDir)
    • Method Detail

      • channelActive

        public void channelActive​(io.netty.channel.ChannelHandlerContext ctx)
        Specified by:
        channelActive in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelActive in class io.netty.channel.ChannelInboundHandlerAdapter
      • channelRead0

        protected void channelRead0​(io.netty.channel.ChannelHandlerContext ctx,
                                    io.netty.handler.codec.http.FullHttpRequest httpRequest)
                             throws java.lang.Exception
        This method is called with the request that is received from the client. It validates the incoming request, and currently it only supports GET
        Specified by:
        channelRead0 in class io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.FullHttpRequest>
        Parameters:
        ctx - the ChannelHandlerContext which this SimpleChannelInboundHandler belongs to
        httpRequest - the message to handle
        Throws:
        java.lang.Exception
      • userEventTriggered

        public void userEventTriggered​(io.netty.channel.ChannelHandlerContext ctx,
                                       java.lang.Object event)
                                throws java.lang.Exception
        Netty calls this function when events that we have registered for, occur (in this case we are specifically waiting for IdleStateEvent so that we close connections that have been idle too long - maybe due to client failure)
        Specified by:
        userEventTriggered in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        userEventTriggered in class io.netty.channel.ChannelInboundHandlerAdapter
        Parameters:
        ctx - The ChannelHandlerContext that can be used to perform operations on the channel.
        event - The event that occurred.
        Throws:
        java.lang.Exception
      • exceptionCaught

        public void exceptionCaught​(io.netty.channel.ChannelHandlerContext ctx,
                                    java.lang.Throwable cause)
                             throws java.lang.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:
        java.lang.Exception