Search in sources :

Example 1 with Plc4xServerAdapter

use of org.apache.plc4x.java.tools.plc4xserver.protocol.Plc4xServerAdapter in project plc4x by apache.

the class Plc4xServer method start.

public void start() throws PlcException {
    if (loopGroup != null) {
        return;
    }
    try {
        loopGroup = new NioEventLoopGroup();
        workerGroup = new NioEventLoopGroup();
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(loopGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

            @Override
            public void initChannel(SocketChannel channel) {
                ChannelPipeline pipeline = channel.pipeline();
                pipeline.addLast(new GeneratedProtocolMessageCodec<>(Plc4xMessage.class, Plc4xMessage::staticParse, ByteOrder.BIG_ENDIAN, null, new ByteLengthEstimator(), null));
                pipeline.addLast(new Plc4xServerAdapter());
            }
        }).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
        bootstrap.bind(Plc4xConstants.PLC4XTCPDEFAULTPORT).sync();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new PlcException(e);
    }
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) Plc4xMessage(org.apache.plc4x.java.plc4x.readwrite.Plc4xMessage) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) GeneratedProtocolMessageCodec(org.apache.plc4x.java.spi.connection.GeneratedProtocolMessageCodec) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) PlcException(org.apache.plc4x.java.api.exceptions.PlcException) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Plc4xServerAdapter(org.apache.plc4x.java.tools.plc4xserver.protocol.Plc4xServerAdapter)

Aggregations

ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)1 PlcException (org.apache.plc4x.java.api.exceptions.PlcException)1 Plc4xMessage (org.apache.plc4x.java.plc4x.readwrite.Plc4xMessage)1 GeneratedProtocolMessageCodec (org.apache.plc4x.java.spi.connection.GeneratedProtocolMessageCodec)1 Plc4xServerAdapter (org.apache.plc4x.java.tools.plc4xserver.protocol.Plc4xServerAdapter)1