@Test public void testChannelRead0() throws Exception { ChannelHandlerContext ctx = getContext(); List<SxpDomain> domains = new ArrayList<>(); when(sxpNode.getDomains()).thenReturn(domains); domains.add(getDomain(null)); decoder.channelRead0(ctx, mock(ByteBuf.class)); verify(ctx).fireChannelRead(any(ByteBuf.class)); when(sxpNode.getConnection(any(SocketAddress.class))).thenReturn(mock(SxpConnection.class)); decoder.channelRead0(ctx, mock(ByteBuf.class)); verify(ctx, times(2)).fireChannelRead(any(ByteBuf.class)); }
@Override public void channelRead0(ChannelHandlerContext ctx, ByteBuf message) throws ErrorCodeDataLengthException, AttributeLengthException, TlvNotFoundException, AddressLengthException, UnknownNodeIdException, ErrorMessageException, UnknownSxpMessageTypeException, AttributeVariantException, UnknownHostException, UnknownPrefixException { InetSocketAddress address = getAddress(ctx); final SxpConnection connection = owner.getConnection(address); final SxpDomain domain = getTemplateDomain(address); if (address != null && connection == null && domain != null) { final SxpConnectionTemplateFields template = domain.getTemplate(address); Notification notification = MessageFactory.parse(null, message); Version version = getVersion(notification); ConnectionMode mode = getMode(notification); if ((template.getTemplateMode() == null || template.getTemplateMode().equals(mode)) && ( template.getTemplateVersion() == null || template.getTemplateVersion().equals(version))) { LOG.info("{} Adding new SxpConnection from template {}", owner, template); addConnection(domain.getName(), new ConnectionBuilder().setMode(invertMode(mode)) .setTcpPort(template.getTemplateTcpPort()) .setPeerAddress(IpAddressBuilder.getDefaultInstance(address.getAddress().getHostAddress())) .setPassword(template.getTemplatePassword()) .setSecurityType(template.getTemplateSecurityType()) .setDescription("AutoGenerated connection.") .setState(ConnectionState.Off) .setConnectionTimers(new ConnectionTimersBuilder().build()) .setVersion(version) .setCapabilities(Configuration.getCapabilities(version)) .build()); } ctx.close(); } else { ReferenceCountUtil.retain(message); ctx.fireChannelRead(message); } }
ConnectionDecoder extends SimpleChannelInboundHandler<ByteBuf> { @Override public void channelRead0(ChannelHandlerContext ctx, ByteBuf message) throws ErrorCodeDataLengthException, AttributeLengthException, TlvNotFoundException, AddressLengthException, UnknownNodeIdException, ErrorMessageException, UnknownSxpMessageTypeException, AttributeVariantException, UnknownHostException, UnknownPrefixException { InetSocketAddress address = getAddress(ctx); final SxpConnection connection = owner.getConnection(address); final SxpDomain domain = getTemplateDomain(address); if (address != null && connection == null && domain != null) { final SxpConnectionTemplateFields template = domain.getTemplate(address); Notification notification = MessageFactory.parse(null, message); Version version = getVersion(notification); ConnectionMode mode = getMode(notification); if ((template.getTemplateMode() == null || template.getTemplateMode().equals(mode)) && ( template.getTemplateVersion() == null || template.getTemplateVersion().equals(version))) { LOG.info("{} Adding new SxpConnection from template {}", owner, template); addConnection(domain.getName(), new ConnectionBuilder().setMode(invertMode(mode)) .setTcpPort(template.getTemplateTcpPort()) .setPeerAddress(IpAddressBuilder.getDefaultInstance(address.getAddress().getHostAddress())) .setPassword(template.getTemplatePassword()) .setSecurityType(template.getTemplateSecurityType()) .setDescription("AutoGenerated connection.") .setState(ConnectionState.Off) .setConnectionTimers(new ConnectionTimersBuilder().build()) .setVersion(version) .setCapabilities(Configuration.getCapabilities(version)) .build()); } ctx.close(); } else { ReferenceCountUtil.retain(message); ctx.fireChannelRead(message); } } }
ConnectionDecoder extends SimpleChannelInboundHandler<ByteBuf> { @Override public void channelRead0(ChannelHandlerContext ctx, ByteBuf message) throws ErrorCodeDataLengthException, AttributeLengthException, TlvNotFoundException, AddressLengthException, UnknownNodeIdException, ErrorMessageException, UnknownSxpMessageTypeException, AttributeVariantException, UnknownHostException, UnknownPrefixException { InetSocketAddress address = getAddress(ctx); final SxpConnection connection = owner.getConnection(address); final SxpDomain domain = getTemplateDomain(address); if (address != null && connection == null && domain != null) { final SxpConnectionTemplateFields template = domain.getTemplate(address); Notification notification = MessageFactory.parse(null, message); Version version = getVersion(notification); ConnectionMode mode = getMode(notification); if ((template.getTemplateMode() == null || template.getTemplateMode().equals(mode)) && ( template.getTemplateVersion() == null || template.getTemplateVersion().equals(version))) { LOG.info("{} Adding new SxpConnection from template {}", owner, template); addConnection(domain.getName(), new ConnectionBuilder().setMode(invertMode(mode)) .setTcpPort(template.getTemplateTcpPort()) .setPeerAddress(IpAddressBuilder.getDefaultInstance(address.getAddress().getHostAddress())) .setPassword(template.getTemplatePassword()) .setSecurityType(template.getTemplateSecurityType()) .setDescription("AutoGenerated connection.") .setState(ConnectionState.Off) .setConnectionTimers(new ConnectionTimersBuilder().build()) .setVersion(version) .setCapabilities(Configuration.getCapabilities(version)) .build()); } ctx.close(); } else { ReferenceCountUtil.retain(message); ctx.fireChannelRead(message); } } ConnectionDecoder(SxpNode owner); }
ConnectionDecoder extends SimpleChannelInboundHandler<ByteBuf> { @Override public void channelRead0(ChannelHandlerContext ctx, ByteBuf message) throws ErrorCodeDataLengthException, AttributeLengthException, TlvNotFoundException, AddressLengthException, UnknownNodeIdException, ErrorMessageException, UnknownSxpMessageTypeException, AttributeVariantException, UnknownHostException, UnknownPrefixException { InetSocketAddress address = getAddress(ctx); final SxpConnection connection = owner.getConnection(address); final SxpDomain domain = getTemplateDomain(address); if (address != null && connection == null && domain != null) { final SxpConnectionTemplateFields template = domain.getTemplate(address); Notification notification = MessageFactory.parse(null, message); Version version = getVersion(notification); ConnectionMode mode = getMode(notification); if ((template.getTemplateMode() == null || template.getTemplateMode().equals(mode)) && ( template.getTemplateVersion() == null || template.getTemplateVersion().equals(version))) { LOG.info("{} Adding new SxpConnection from template {}", owner, template); addConnection(domain.getName(), new ConnectionBuilder().setMode(invertMode(mode)) .setTcpPort(template.getTemplateTcpPort()) .setPeerAddress(IpAddressBuilder.getDefaultInstance(address.getAddress().getHostAddress())) .setPassword(template.getTemplatePassword()) .setSecurityType(template.getTemplateSecurityType()) .setDescription("AutoGenerated connection.") .setState(ConnectionState.Off) .setConnectionTimers(new ConnectionTimersBuilder().build()) .setVersion(version) .setCapabilities(Configuration.getCapabilities(version)) .build()); } ctx.close(); } else { ReferenceCountUtil.retain(message); ctx.fireChannelRead(message); } } ConnectionDecoder(SxpNode owner); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelRead0(ChannelHandlerContext ctx, ByteBuf message); }
ConnectionDecoder extends SimpleChannelInboundHandler<ByteBuf> { @Override public void channelRead0(ChannelHandlerContext ctx, ByteBuf message) throws ErrorCodeDataLengthException, AttributeLengthException, TlvNotFoundException, AddressLengthException, UnknownNodeIdException, ErrorMessageException, UnknownSxpMessageTypeException, AttributeVariantException, UnknownHostException, UnknownPrefixException { InetSocketAddress address = getAddress(ctx); final SxpConnection connection = owner.getConnection(address); final SxpDomain domain = getTemplateDomain(address); if (address != null && connection == null && domain != null) { final SxpConnectionTemplateFields template = domain.getTemplate(address); Notification notification = MessageFactory.parse(null, message); Version version = getVersion(notification); ConnectionMode mode = getMode(notification); if ((template.getTemplateMode() == null || template.getTemplateMode().equals(mode)) && ( template.getTemplateVersion() == null || template.getTemplateVersion().equals(version))) { LOG.info("{} Adding new SxpConnection from template {}", owner, template); addConnection(domain.getName(), new ConnectionBuilder().setMode(invertMode(mode)) .setTcpPort(template.getTemplateTcpPort()) .setPeerAddress(IpAddressBuilder.getDefaultInstance(address.getAddress().getHostAddress())) .setPassword(template.getTemplatePassword()) .setSecurityType(template.getTemplateSecurityType()) .setDescription("AutoGenerated connection.") .setState(ConnectionState.Off) .setConnectionTimers(new ConnectionTimersBuilder().build()) .setVersion(version) .setCapabilities(Configuration.getCapabilities(version)) .build()); } ctx.close(); } else { ReferenceCountUtil.retain(message); ctx.fireChannelRead(message); } } ConnectionDecoder(SxpNode owner); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelRead0(ChannelHandlerContext ctx, ByteBuf message);  }