Class NetBidibServerHandler<T>

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, org.bidib.jbidibc.messages.BidibMessagePublisher<T>
    Direct Known Subclasses:
    NetBidibServerHandlerByteArray

    public abstract class NetBidibServerHandler<T>
    extends io.netty.channel.SimpleChannelInboundHandler<io.netty.buffer.ByteBuf>
    implements org.bidib.jbidibc.messages.BidibMessagePublisher<T>
    • Nested Class Summary

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

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

      Constructors 
      Constructor Description
      NetBidibServerHandler​(io.netty.channel.group.ChannelGroup channelGroup, org.bidib.jbidibc.messages.HostAdapter<T> hostAdapter, String backendPortName, org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData serverLinkData, Consumer<NetBidibServerHandler<T>> lazyInitializationCallback, Function<org.bidib.jbidibc.messages.message.BidibMessageInterface,​T> messageContentSupplier, RoleTypeEnum roleType, org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData pairedPartner)
      Constructor
    • Field Detail

      • responseFactory

        protected org.bidib.jbidibc.messages.message.BidibResponseFactory responseFactory
      • pairedPartnerLock

        protected final Object pairedPartnerLock
      • pairedPartner

        protected org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData pairedPartner
        The link data of the paired remote partner.
      • serverLinkData

        protected final org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData serverLinkData
        The link data of the server partner (ourself).
      • ctx

        protected io.netty.channel.ChannelHandlerContext ctx
    • Constructor Detail

      • NetBidibServerHandler

        public NetBidibServerHandler​(io.netty.channel.group.ChannelGroup channelGroup,
                                     org.bidib.jbidibc.messages.HostAdapter<T> hostAdapter,
                                     String backendPortName,
                                     org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData serverLinkData,
                                     Consumer<NetBidibServerHandler<T>> lazyInitializationCallback,
                                     Function<org.bidib.jbidibc.messages.message.BidibMessageInterface,​T> messageContentSupplier,
                                     RoleTypeEnum roleType,
                                     org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData pairedPartner)
        Constructor
        Parameters:
        channelGroup - the channel group to pool all TCP connections.
        hostAdapter - the host adapter
        backendPortName - the port identifier of the backend, e.g. COM8
        serverLinkData - the server link data instance to use
    • Method Detail

      • handleLocalBidibUpResponse

        protected boolean handleLocalBidibUpResponse()
      • addRemoteConnectionListener

        public void addRemoteConnectionListener​(org.bidib.jbidibc.messages.ConnectionListener remoteConnectionListener)
      • removeRemoteConnectionListener

        public void removeRemoteConnectionListener​(org.bidib.jbidibc.messages.ConnectionListener remoteConnectionListener)
      • setPairingStore

        public void setPairingStore​(PairingStore pairingStore)
      • performLazyInitialization

        protected void performLazyInitialization()
      • channelRegistered

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

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

        public void channelRead0​(io.netty.channel.ChannelHandlerContext ctx,
                                 io.netty.buffer.ByteBuf in)
        Specified by:
        channelRead0 in class io.netty.channel.SimpleChannelInboundHandler<io.netty.buffer.ByteBuf>
      • setPairingCallback

        public void setPairingCallback​(BiFunction<org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData,​Integer,​Boolean> pairingCallback)
      • publishPairedStatus

        protected void publishPairedStatus​(io.netty.channel.ChannelHandlerContext ctx,
                                           int descriptor)
                                    throws org.bidib.jbidibc.messages.exception.ProtocolException
        Throws:
        org.bidib.jbidibc.messages.exception.ProtocolException
      • processLocalBidibUpResponseFromBackend

        protected boolean processLocalBidibUpResponseFromBackend​(org.bidib.jbidibc.messages.message.LocalBidibUpResponse localBidibUpResponse)
                                                          throws org.bidib.jbidibc.messages.exception.ProtocolException
        Process the LocalBidibUpResponse and publish LocalLinkMessage messages to the connected partner.
        Parameters:
        localBidibUpResponse - the localBidibUpResponse message received from the backend
        Returns:
        true: send the pairing status to the connected partner, false: don't send the pairing status to the connected partner
        Throws:
        org.bidib.jbidibc.messages.exception.ProtocolException - thrown if illegal message content is detected or processing of message failed.
      • channelReadComplete

        public void channelReadComplete​(io.netty.channel.ChannelHandlerContext ctx)
                                 throws Exception
        Specified by:
        channelReadComplete in interface io.netty.channel.ChannelInboundHandler
        Overrides:
        channelReadComplete in class io.netty.channel.ChannelInboundHandlerAdapter
        Throws:
        Exception
      • 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
      • hasActiveConnection

        public boolean hasActiveConnection()
        Returns true if currently an active connection exists.
        Returns:
        channel group has an active connection