Search in sources :

Example 6 with CommandDecoder

use of io.pravega.shared.protocol.netty.CommandDecoder 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 CommandDecoder

use of io.pravega.shared.protocol.netty.CommandDecoder 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)

Example 8 with CommandDecoder

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

the class ConnectionPoolingTest method setUp.

@Before
public void setUp() throws Exception {
    // Configure SSL.
    port = TestUtils.getAvailableListenPort();
    final SslContext sslCtx;
    if (ssl) {
        try {
            sslCtx = SslContextBuilder.forServer(new File(SecurityConfigDefaults.TLS_SERVER_CERT_PATH), new File(SecurityConfigDefaults.TLS_SERVER_PRIVATE_KEY_PATH)).build();
        } catch (SSLException e) {
            throw new RuntimeException(e);
        }
    } else {
        sslCtx = null;
    }
    boolean nio = false;
    EventLoopGroup bossGroup;
    EventLoopGroup workerGroup;
    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());
                SSLEngine sslEngine = handler.engine();
                SSLParameters sslParameters = sslEngine.getSSLParameters();
                sslParameters.setEndpointIdentificationAlgorithm("LDAPS");
                sslEngine.setSSLParameters(sslParameters);
                p.addLast(handler);
            }
            p.addLast(new CommandEncoder(null, NO_OP_METRIC_NOTIFIER), new LengthFieldBasedFrameDecoder(MAX_WIRECOMMAND_SIZE, 4, 4), new CommandDecoder(), new EchoServerHandler());
        }
    });
    // Start the server.
    serverChannel = b.bind("localhost", port).awaitUninterruptibly().channel();
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) EpollServerSocketChannel(io.netty.channel.epoll.EpollServerSocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) SSLEngine(javax.net.ssl.SSLEngine) CommandEncoder(io.pravega.shared.protocol.netty.CommandEncoder) SSLException(javax.net.ssl.SSLException) SSLParameters(javax.net.ssl.SSLParameters) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) SslContext(io.netty.handler.ssl.SslContext) CommandDecoder(io.pravega.shared.protocol.netty.CommandDecoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) SSLException(javax.net.ssl.SSLException) ConnectionFailedException(io.pravega.shared.protocol.netty.ConnectionFailedException) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) EventLoopGroup(io.netty.channel.EventLoopGroup) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) File(java.io.File) Before(org.junit.Before)

Aggregations

LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)8 CommandDecoder (io.pravega.shared.protocol.netty.CommandDecoder)8 CommandEncoder (io.pravega.shared.protocol.netty.CommandEncoder)8 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)3 SocketChannel (io.netty.channel.socket.SocketChannel)3 SslContext (io.netty.handler.ssl.SslContext)3 SslHandler (io.netty.handler.ssl.SslHandler)3 File (java.io.File)3 SSLException (javax.net.ssl.SSLException)3 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)2 EpollServerSocketChannel (io.netty.channel.epoll.EpollServerSocketChannel)2 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)2 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)2 LoggingHandler (io.netty.handler.logging.LoggingHandler)2 ConnectionFailedException (io.pravega.shared.protocol.netty.ConnectionFailedException)2