Search in sources :

Example 1 with XmlFrameDecoder

use of io.netty.handler.codec.xml.XmlFrameDecoder in project opennms by OpenNMS.

the class TcpListener method start.

public void start() throws InterruptedException {
    bossGroup = new NioEventLoopGroup();
    workerGroup = new NioEventLoopGroup();
    final ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast(new LoggingHandler());
            ch.pipeline().addLast(new XmlFrameDecoder(2147483647));
            ch.pipeline().addLast(new XmlEventProcessor(eventIpcManager));
        }
    });
    // Bind and start to accept incoming connections.
    future = b.bind(config.getTCPIpAddress(), config.getTCPPort()).sync().await();
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) XmlFrameDecoder(io.netty.handler.codec.xml.XmlFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Example 2 with XmlFrameDecoder

use of io.netty.handler.codec.xml.XmlFrameDecoder in project opennms by OpenNMS.

the class UdpListener method start.

public void start() throws InterruptedException {
    bossGroup = new NioEventLoopGroup();
    final Bootstrap b = new Bootstrap().group(bossGroup).channel(NioDatagramChannel.class).option(ChannelOption.SO_REUSEADDR, true).option(ChannelOption.SO_RCVBUF, Integer.MAX_VALUE).handler(new ChannelInitializer<DatagramChannel>() {

        @Override
        protected void initChannel(DatagramChannel ch) throws Exception {
            ch.pipeline().addLast(new LoggingHandler());
            ch.pipeline().addLast(new MessageToMessageDecoder<DatagramPacket>() {

                @Override
                protected void decode(ChannelHandlerContext ctx, DatagramPacket msg, List<Object> out) throws Exception {
                    msg.retain();
                    out.add(msg.content());
                }
            });
            ch.pipeline().addLast(new XmlFrameDecoder(2147483647));
            ch.pipeline().addLast(new XmlEventProcessor(eventIpcManager));
        }
    });
    future = b.bind(config.getUDPIpAddress(), config.getUDPPort()).await();
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) NioDatagramChannel(io.netty.channel.socket.nio.NioDatagramChannel) DatagramChannel(io.netty.channel.socket.DatagramChannel) NioDatagramChannel(io.netty.channel.socket.nio.NioDatagramChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) XmlFrameDecoder(io.netty.handler.codec.xml.XmlFrameDecoder) MessageToMessageDecoder(io.netty.handler.codec.MessageToMessageDecoder) DatagramPacket(io.netty.channel.socket.DatagramPacket) Bootstrap(io.netty.bootstrap.Bootstrap) List(java.util.List) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 XmlFrameDecoder (io.netty.handler.codec.xml.XmlFrameDecoder)2 LoggingHandler (io.netty.handler.logging.LoggingHandler)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 DatagramChannel (io.netty.channel.socket.DatagramChannel)1 DatagramPacket (io.netty.channel.socket.DatagramPacket)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioDatagramChannel (io.netty.channel.socket.nio.NioDatagramChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 MessageToMessageDecoder (io.netty.handler.codec.MessageToMessageDecoder)1 List (java.util.List)1