Class NetBidibServerHandler<T>

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.SimpleChannelInboundHandler<io.netty.buffer.ByteBuf>
org.bidib.jbidibc.netbidib.server.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
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected io.netty.channel.ChannelHandlerContext
     
    protected final ScheduledExecutorService
     
    protected org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData
    The link data of the paired remote partner.
    protected final Object
     
    protected org.bidib.jbidibc.messages.message.BidibResponseFactory
     
    protected final org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData
    The link data of the server partner (ourself).
  • 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
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addRemoteConnectionListener(org.bidib.jbidibc.messages.ConnectionListener remoteConnectionListener)
     
    void
    channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in)
     
    void
    channelReadComplete(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    channelRegistered(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    channelUnregistered(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    exceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)
     
    protected boolean
     
    boolean
    Returns true if currently an active connection exists.
    protected void
     
    protected boolean
    processLocalBidibUpResponseFromBackend(org.bidib.jbidibc.messages.message.LocalBidibUpResponse localBidibUpResponse)
    Process the LocalBidibUpResponse and publish LocalLinkMessage messages to the connected partner.
    protected void
    publishPairedStatus(io.netty.channel.ChannelHandlerContext ctx, int descriptor)
     
    void
    removeRemoteConnectionListener(org.bidib.jbidibc.messages.ConnectionListener remoteConnectionListener)
     
    void
    setPairingCallback(BiFunction<org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData,Integer,Boolean> pairingCallback)
     
    void
     

    Methods inherited from class io.netty.channel.SimpleChannelInboundHandler

    acceptInboundMessage, channelRead

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelInactive, 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 org.bidib.jbidibc.messages.BidibMessagePublisher

    publishBidibMessage

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Field Details

    • 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
    • localNodeDataWorkers

      protected final ScheduledExecutorService localNodeDataWorkers
  • Constructor Details

    • 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 Details

    • 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