Search in sources :

Example 1 with SimpleCodecContext

use of org.lanternpowered.server.network.message.codec.SimpleCodecContext in project LanternServer by LanternPowered.

the class NetworkManager method init0.

@Override
protected ChannelFuture init0(SocketAddress address, boolean epoll) {
    this.bootstrap = new ServerBootstrap();
    // Take advantage of the fast thread local threads,
    // this is also provided by the default thread factory
    final ThreadFactory threadFactory = ThreadHelper.newFastThreadLocalThreadFactory(() -> "netty-" + threadCounter.getAndIncrement());
    this.bossGroup = createEventLoopGroup(epoll, threadFactory);
    this.workerGroup = createEventLoopGroup(epoll, threadFactory);
    this.socketAddress = address;
    return this.bootstrap.group(this.bossGroup, this.workerGroup).channel(getServerSocketChannelClass(epoll)).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            final ChannelPipeline pipeline = ch.pipeline();
            final NetworkSession networkSession = new NetworkSession(ch, server, NetworkManager.this);
            final CodecContext codecContext = new SimpleCodecContext(new LanternByteBufferAllocator(ch.alloc()), ch, networkSession);
            pipeline.addLast(new ReadTimeoutHandler(NetworkSession.READ_TIMEOUT_SECONDS)).addLast(NetworkSession.LEGACY_PING, new LegacyProtocolHandler(networkSession)).addLast(NetworkSession.ENCRYPTION, NoopHandler.INSTANCE).addLast(NetworkSession.FRAMING, new MessageFramingHandler()).addLast(NetworkSession.COMPRESSION, NoopHandler.INSTANCE).addLast(NetworkSession.CODECS, new MessageCodecHandler(codecContext)).addLast(NetworkSession.PROCESSOR, new MessageProcessorHandler(codecContext)).addLast(NetworkSession.HANDLER, networkSession);
        }
    }).childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_KEEPALIVE, true).bind(address);
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) SocketChannel(io.netty.channel.socket.SocketChannel) SimpleCodecContext(org.lanternpowered.server.network.message.codec.SimpleCodecContext) CodecContext(org.lanternpowered.server.network.message.codec.CodecContext) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) LegacyProtocolHandler(org.lanternpowered.server.network.pipeline.LegacyProtocolHandler) LanternByteBufferAllocator(org.lanternpowered.server.network.buffer.LanternByteBufferAllocator) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) MessageFramingHandler(org.lanternpowered.server.network.pipeline.MessageFramingHandler) SimpleCodecContext(org.lanternpowered.server.network.message.codec.SimpleCodecContext) MessageProcessorHandler(org.lanternpowered.server.network.pipeline.MessageProcessorHandler) MessageCodecHandler(org.lanternpowered.server.network.pipeline.MessageCodecHandler)

Aggregations

ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ChannelPipeline (io.netty.channel.ChannelPipeline)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 ReadTimeoutHandler (io.netty.handler.timeout.ReadTimeoutHandler)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 LanternByteBufferAllocator (org.lanternpowered.server.network.buffer.LanternByteBufferAllocator)1 CodecContext (org.lanternpowered.server.network.message.codec.CodecContext)1 SimpleCodecContext (org.lanternpowered.server.network.message.codec.SimpleCodecContext)1 LegacyProtocolHandler (org.lanternpowered.server.network.pipeline.LegacyProtocolHandler)1 MessageCodecHandler (org.lanternpowered.server.network.pipeline.MessageCodecHandler)1 MessageFramingHandler (org.lanternpowered.server.network.pipeline.MessageFramingHandler)1 MessageProcessorHandler (org.lanternpowered.server.network.pipeline.MessageProcessorHandler)1