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>
-
-
Field Summary
Fields Modifier and Type Field Description protected io.netty.channel.ChannelHandlerContextctxprotected ScheduledExecutorServicelocalNodeDataWorkersprotected org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkDatapairedPartnerThe link data of the paired remote partner.protected ObjectpairedPartnerLockprotected org.bidib.jbidibc.messages.message.BidibResponseFactoryresponseFactoryprotected org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkDataserverLinkDataThe 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRemoteConnectionListener(org.bidib.jbidibc.messages.ConnectionListener remoteConnectionListener)voidchannelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in)voidchannelReadComplete(io.netty.channel.ChannelHandlerContext ctx)voidchannelRegistered(io.netty.channel.ChannelHandlerContext ctx)voidchannelUnregistered(io.netty.channel.ChannelHandlerContext ctx)voidexceptionCaught(io.netty.channel.ChannelHandlerContext ctx, Throwable cause)protected booleanhandleLocalBidibUpResponse()booleanhasActiveConnection()Returns true if currently an active connection exists.protected voidperformLazyInitialization()protected booleanprocessLocalBidibUpResponseFromBackend(org.bidib.jbidibc.messages.message.LocalBidibUpResponse localBidibUpResponse)Process theLocalBidibUpResponseand publishLocalLinkMessagemessages to the connected partner.protected voidpublishPairedStatus(io.netty.channel.ChannelHandlerContext ctx, int descriptor)voidremoveRemoteConnectionListener(org.bidib.jbidibc.messages.ConnectionListener remoteConnectionListener)voidsetPairingCallback(BiFunction<org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData,Integer,Boolean> pairingCallback)voidsetPairingStore(PairingStore pairingStore)-
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
-
-
-
-
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
-
localNodeDataWorkers
protected final ScheduledExecutorService localNodeDataWorkers
-
-
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 adapterbackendPortName- the port identifier of the backend, e.g. COM8serverLinkData- 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:
channelRegisteredin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelRegisteredin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelUnregistered
public void channelUnregistered(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelUnregisteredin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelUnregisteredin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelRead0
public void channelRead0(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in)- Specified by:
channelRead0in classio.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.ProtocolExceptionProcess theLocalBidibUpResponseand publishLocalLinkMessagemessages 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:
channelReadCompletein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadCompletein classio.netty.channel.ChannelInboundHandlerAdapter- 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
-
hasActiveConnection
public boolean hasActiveConnection()
Returns true if currently an active connection exists.- Returns:
- channel group has an active connection
-
-