Search in sources :

Example 6 with ExceptionLoggingHandler

use of io.pravega.shared.protocol.netty.ExceptionLoggingHandler in project pravega by pravega.

the class PravegaConnectionListener method startListening.

// endregion
public void startListening() {
    // Configure SSL.
    final SslContext sslCtx;
    if (ssl) {
        try {
            sslCtx = SslContextBuilder.forServer(new File(this.certFile), new File(this.keyFile)).build();
        } catch (SSLException e) {
            throw new RuntimeException(e);
        }
    } else {
        sslCtx = null;
    }
    boolean nio = false;
    try {
        bossGroup = new EpollEventLoopGroup(1);
        workerGroup = new EpollEventLoopGroup();
    } catch (ExceptionInInitializerError | UnsatisfiedLinkError | NoClassDefFoundError e) {
        nio = true;
        bossGroup = new NioEventLoopGroup(1);
        workerGroup = new NioEventLoopGroup();
    }
    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup).channel(nio ? NioServerSocketChannel.class : EpollServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            if (sslCtx != null) {
                SslHandler handler = sslCtx.newHandler(ch.alloc());
                p.addLast(handler);
            }
            ServerConnectionInboundHandler lsh = new ServerConnectionInboundHandler();
            // p.addLast(new LoggingHandler(LogLevel.INFO));
            p.addLast(new ExceptionLoggingHandler(ch.remoteAddress().toString()), new CommandEncoder(null), new LengthFieldBasedFrameDecoder(MAX_WIRECOMMAND_SIZE, 4, 4), new CommandDecoder(), new AppendDecoder(), lsh);
            lsh.setRequestProcessor(new AppendProcessor(store, lsh, new PravegaRequestProcessor(store, lsh, statsRecorder, tokenVerifier), statsRecorder, tokenVerifier));
        }
    });
    // Start the server.
    serverChannel = b.bind(host, port).awaitUninterruptibly().channel();
}
Also used : EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) ExceptionLoggingHandler(io.pravega.shared.protocol.netty.ExceptionLoggingHandler) CommandEncoder(io.pravega.shared.protocol.netty.CommandEncoder) SSLException(javax.net.ssl.SSLException) ExceptionLoggingHandler(io.pravega.shared.protocol.netty.ExceptionLoggingHandler) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) SslContext(io.netty.handler.ssl.SslContext) AppendDecoder(io.pravega.shared.protocol.netty.AppendDecoder) CommandDecoder(io.pravega.shared.protocol.netty.CommandDecoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) SSLException(javax.net.ssl.SSLException) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) File(java.io.File)

Example 7 with ExceptionLoggingHandler

use of io.pravega.shared.protocol.netty.ExceptionLoggingHandler in project pravega by pravega.

the class AdminConnectionListenerTest method testCreateEncodingStack.

@Test
public void testCreateEncodingStack() {
    @Cleanup AdminConnectionListener listener = new AdminConnectionListener(false, false, "localhost", 6622, mock(StreamSegmentStore.class), mock(TableStore.class), new PassingTokenVerifier(), null, null, SecurityConfigDefaults.TLS_PROTOCOL_VERSION);
    List<ChannelHandler> stack = listener.createEncodingStack("connection");
    // Check that the order of encoders is the right one.
    Assert.assertTrue(stack.get(0) instanceof ExceptionLoggingHandler);
    Assert.assertTrue(stack.get(1) instanceof CommandEncoder);
    Assert.assertTrue(stack.get(2) instanceof LengthFieldBasedFrameDecoder);
    Assert.assertTrue(stack.get(3) instanceof CommandDecoder);
}
Also used : StreamSegmentStore(io.pravega.segmentstore.contracts.StreamSegmentStore) CommandDecoder(io.pravega.shared.protocol.netty.CommandDecoder) ExceptionLoggingHandler(io.pravega.shared.protocol.netty.ExceptionLoggingHandler) PassingTokenVerifier(io.pravega.segmentstore.server.host.delegationtoken.PassingTokenVerifier) ChannelHandler(io.netty.channel.ChannelHandler) CommandEncoder(io.pravega.shared.protocol.netty.CommandEncoder) Cleanup(lombok.Cleanup) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) TableStore(io.pravega.segmentstore.contracts.tables.TableStore) Test(org.junit.Test)

Aggregations

LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)7 CommandDecoder (io.pravega.shared.protocol.netty.CommandDecoder)7 CommandEncoder (io.pravega.shared.protocol.netty.CommandEncoder)7 ExceptionLoggingHandler (io.pravega.shared.protocol.netty.ExceptionLoggingHandler)7 AppendDecoder (io.pravega.shared.protocol.netty.AppendDecoder)4 ChannelHandler (io.netty.channel.ChannelHandler)3 ChannelPipeline (io.netty.channel.ChannelPipeline)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 SocketChannel (io.netty.channel.socket.SocketChannel)2 SslContext (io.netty.handler.ssl.SslContext)2 SslHandler (io.netty.handler.ssl.SslHandler)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 SSLException (javax.net.ssl.SSLException)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 Channel (io.netty.channel.Channel)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)1