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
FieldsModifier and TypeFieldDescriptionprotected io.netty.channel.ChannelHandlerContextprotected final ScheduledExecutorServiceprotected org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkDataThe link data of the paired remote partner.protected final Objectprotected org.bidib.jbidibc.messages.message.BidibResponseFactoryprotected final org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkDataThe link data of the server partner (ourself). -
Constructor Summary
ConstructorsConstructorDescriptionNetBidibServerHandler(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 TypeMethodDescriptionvoidaddRemoteConnectionListener(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 booleanbooleanReturns true if currently an active connection exists.protected voidprotected 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, channelReadMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelWritabilityChanged, userEventTriggeredMethods 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 org.bidib.jbidibc.messages.BidibMessagePublisher
publishBidibMessageMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Field Details
-
responseFactory
protected org.bidib.jbidibc.messages.message.BidibResponseFactory responseFactory -
pairedPartnerLock
-
pairedPartner
protected org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData pairedPartnerThe link data of the paired remote partner. -
serverLinkData
protected final org.bidib.jbidibc.messages.message.netbidib.NetBidibLinkData serverLinkDataThe link data of the server partner (ourself). -
ctx
protected io.netty.channel.ChannelHandlerContext ctx -
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 adapterbackendPortName- the port identifier of the backend, e.g. COM8serverLinkData- 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
-
performLazyInitialization
protected void performLazyInitialization() -
channelRegistered
- Specified by:
channelRegisteredin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelRegisteredin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelUnregistered
- 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.ProtocolException Process 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
- 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
-