Class P2PFileTransferServerHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.FullHttpRequest>
com.linkedin.davinci.blobtransfer.server.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 -
Constructor Summary
ConstructorsConstructorDescriptionP2PFileTransferServerHandler(String baseDir, int blobTransferMaxTimeoutInMin, BlobSnapshotManager blobSnapshotManager, int maxAllowedConcurrentSnapshotUsers) -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelInactive(io.netty.channel.ChannelHandlerContext ctx) This method is called when the channel is inactive.protected voidchannelRead0(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.voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause) voidsendMetadata(io.netty.channel.ChannelHandlerContext ctx, BlobTransferPartitionMetadata metadata) Send metadata for the given blob transfer requestvoiduserEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object event) Netty calls this function when events that we have registered for, occur (in this case we are specifically waiting forIdleStateEventso that we close connections that have been idle too long - maybe due to client failure)Methods inherited from class io.netty.channel.SimpleChannelInboundHandler
acceptInboundMessage, channelReadMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChangedMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Constructor Details
-
P2PFileTransferServerHandler
public P2PFileTransferServerHandler(String baseDir, int blobTransferMaxTimeoutInMin, BlobSnapshotManager blobSnapshotManager, int maxAllowedConcurrentSnapshotUsers)
-
-
Method Details
-
channelRead0
protected void channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.handler.codec.http.FullHttpRequest httpRequest) throws 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:
channelRead0in classio.netty.channel.SimpleChannelInboundHandler<io.netty.handler.codec.http.FullHttpRequest>- Parameters:
ctx- theChannelHandlerContextwhich thisSimpleChannelInboundHandlerbelongs tohttpRequest- the message to handle- Throws:
Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) This method is called when the channel is inactive. It is used to decrease the concurrent user count. Because the channel is inactive, we can assume that the transfer is complete. If we decrease the concurrent user at channelRead0, when the connection is break in half, we will not be able to decrease the count in server side- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Parameters:
ctx-
-
userEventTriggered
public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object event) throws Exception Netty calls this function when events that we have registered for, occur (in this case we are specifically waiting forIdleStateEventso that we close connections that have been idle too long - maybe due to client failure)- Specified by:
userEventTriggeredin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
userEventTriggeredin classio.netty.channel.ChannelInboundHandlerAdapter- Parameters:
ctx- TheChannelHandlerContextthat can be used to perform operations on the channel.event- The event that occurred.- Throws:
Exception
-
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
-
sendMetadata
public void sendMetadata(io.netty.channel.ChannelHandlerContext ctx, BlobTransferPartitionMetadata metadata) throws com.fasterxml.jackson.core.JsonProcessingException Send metadata for the given blob transfer request- Parameters:
ctx- the channel contextmetadata- the metadata to be sent- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-