Example usage for io.netty.channel.local LocalChannel pipeline

List of usage examples for io.netty.channel.local LocalChannel pipeline

Introduction

In this page you can find the example usage for io.netty.channel.local LocalChannel pipeline.

Prototype

@Override
    public ChannelPipeline pipeline() 

Source Link

Usage

From source file:com.twitter.http2.HttpHeaderCompressionTest.java

License:Apache License

private void testHeaderEcho(HttpHeaderBlockFrame frame) throws Throwable {
    final EchoHandler sh = new EchoHandler();
    final TestHandler ch = new TestHandler(frame);

    ServerBootstrap sb = new ServerBootstrap().group(new LocalEventLoopGroup())
            .channel(LocalServerChannel.class).childHandler(new ChannelInitializer<LocalChannel>() {
                @Override/*from  w  w w . jav  a 2  s.c o  m*/
                public void initChannel(LocalChannel channel) throws Exception {
                    channel.pipeline().addLast(new HttpConnectionHandler(true), sh);
                }
            });
    Bootstrap cb = new Bootstrap().group(new LocalEventLoopGroup()).channel(LocalChannel.class)
            .handler(new ChannelInitializer<LocalChannel>() {
                @Override
                public void initChannel(LocalChannel channel) throws Exception {
                    channel.pipeline().addLast(new HttpConnectionHandler(false), ch);
                }
            });

    LocalAddress localAddress = new LocalAddress("HttpHeaderCompressionTest");
    Channel sc = sb.bind(localAddress).sync().channel();
    ChannelFuture ccf = cb.connect(localAddress);
    assertTrue(ccf.awaitUninterruptibly().isSuccess());

    while (!ch.success) {
        if (sh.exception.get() != null) {
            break;
        }
        if (ch.exception.get() != null) {
            break;
        }

        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
            // Ignore.
        }
    }

    sc.close().awaitUninterruptibly();
    cb.group().shutdownGracefully();
    sb.group().shutdownGracefully();

    if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) {
        throw sh.exception.get();
    }
    if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) {
        throw ch.exception.get();
    }
    if (sh.exception.get() != null) {
        throw sh.exception.get();
    }
    if (ch.exception.get() != null) {
        throw ch.exception.get();
    }
}

From source file:org.opendaylight.controller.netconf.netty.EchoClient.java

License:Open Source License

public EchoClient(final ChannelHandler clientHandler) {
    channelInitializer = new ChannelInitializer<LocalChannel>() {
        @Override/*from www.  ja  va2 s  .  c  o m*/
        public void initChannel(LocalChannel ch) throws Exception {
            ch.pipeline().addLast(clientHandler);
        }
    };
}

From source file:org.opendaylight.controller.netconf.netty.EchoServer.java

License:Open Source License

public void run() {
    // Configure the server.
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {//w  w  w. j  a  v a2  s . co m
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(LocalServerChannel.class).option(ChannelOption.SO_BACKLOG, 100)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<LocalChannel>() {
                    @Override
                    public void initChannel(LocalChannel ch) throws Exception {
                        ch.pipeline().addLast(new EchoServerHandler());
                    }
                });

        // Start the server.
        LocalAddress localAddress = NetconfConfigUtil.getNetconfLocalAddress();
        ChannelFuture f = b.bind(localAddress).sync();

        // Wait until the server socket is closed.
        f.channel().closeFuture().sync();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        // Shut down all event loops to terminate all threads.
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}

From source file:org.opendaylight.controller.netconf.netty.ProxyServerHandler.java

License:Open Source License

@Override
public void channelActive(ChannelHandlerContext remoteCtx) {
    final ProxyClientHandler clientHandler = new ProxyClientHandler(remoteCtx);
    clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
        @Override/*from   w ww  .j  a v a2  s  .c o m*/
        public void initChannel(LocalChannel ch) throws Exception {
            ch.pipeline().addLast(clientHandler);
        }
    });
    ChannelFuture clientChannelFuture = clientBootstrap.connect(localAddress).awaitUninterruptibly();
    clientChannel = clientChannelFuture.channel();
    clientChannel.writeAndFlush(Unpooled.copiedBuffer("connected\n".getBytes()));
}

From source file:org.opendaylight.controller.netconf.ssh.RemoteNetconfCommand.java

License:Open Source License

@Override
public void start(final Environment env) throws IOException {
    LOG.trace("Establishing internal connection to netconf server for client: {}", getClientAddress());

    final Bootstrap clientBootstrap = new Bootstrap();
    clientBootstrap.group(clientEventGroup).channel(LocalChannel.class);

    clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
        @Override/*ww w .j a  va  2 s.  co m*/
        public void initChannel(final LocalChannel ch) throws Exception {
            ch.pipeline()
                    .addLast(new SshProxyClientHandler(in, out, netconfHelloMessageAdditionalHeader, callback));
        }
    });
    clientChannelFuture = clientBootstrap.connect(localAddress);
    clientChannelFuture.addListener(new GenericFutureListener<ChannelFuture>() {

        @Override
        public void operationComplete(final ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
                clientChannel = clientChannelFuture.channel();
            } else {
                LOG.warn("Unable to establish internal connection to netconf server for client: {}",
                        getClientAddress());
                Preconditions.checkNotNull(callback, "Exit callback must be set");
                callback.onExit(1, "Unable to establish internal connection to netconf server for client: "
                        + getClientAddress());
            }
        }
    });
}

From source file:org.opendaylight.controller.netconf.ssh.threads.Handshaker.java

License:Open Source License

private static ChannelFuture initializeNettyConnection(LocalAddress localAddress, EventLoopGroup bossGroup,
        final SSHClientHandler sshClientHandler) {
    Bootstrap clientBootstrap = new Bootstrap();
    clientBootstrap.group(bossGroup).channel(LocalChannel.class);

    clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
        @Override/*w  ww.  ja va2 s  . co m*/
        public void initChannel(LocalChannel ch) throws Exception {
            ch.pipeline().addLast(sshClientHandler);
        }
    });
    // asynchronously initialize local connection to netconf server
    return clientBootstrap.connect(localAddress);
}

From source file:org.opendaylight.controller.netconf.tcp.netty.ProxyServerHandler.java

License:Open Source License

@Override
public void channelActive(ChannelHandlerContext remoteCtx) {
    final ProxyClientHandler clientHandler = new ProxyClientHandler(remoteCtx);
    clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
        @Override//from w  w w . j  a v  a2  s  .  co m
        public void initChannel(LocalChannel ch) throws Exception {
            ch.pipeline().addLast(clientHandler);
        }
    });
    ChannelFuture clientChannelFuture = clientBootstrap.connect(localAddress).awaitUninterruptibly();
    clientChannel = clientChannelFuture.channel();
}

From source file:org.opendaylight.usc.plugin.UscPlugin.java

License:Open Source License

protected UscPlugin(LocalAddress localAddr) {
    LOG.debug("UscPlugin " + this + "started");
    localServerAddr = localAddr;//from  w  w  w.  j  a  v a2  s.  c  om

    final ServerBootstrap localServerBootstrap = new ServerBootstrap();
    localServerBootstrap.group(localGroup);
    localServerBootstrap.channel(LocalServerChannel.class);
    localServerBootstrap.childHandler(new ChannelInitializer<LocalChannel>() {
        @Override
        public void initChannel(final LocalChannel serverChannel) throws Exception {
            ChannelPipeline p = serverChannel.pipeline();
            p.addLast(new LoggingHandler("localServerBootstrp Handler 4", LogLevel.TRACE));

            // call this first so that the attribute will be visible
            // to the outside once the localAddress is set
            serverChannel.attr(SESSION).setIfAbsent(SettableFuture.<UscSessionImpl>create());

            // register the child channel by address for lookup
            // outside
            LocalAddress localAddress = serverChannel.remoteAddress();
            serverChannels.putIfAbsent(localAddress, SettableFuture.<LocalChannel>create());
            serverChannels.get(localAddress).set(serverChannel);

            p.addLast(new LoggingHandler("localServerBootstrp Handler 3", LogLevel.TRACE));

            // add remote device handler for route remote request
            p.addLast(remoteDeviceHandler);
            p.addLast(new LoggingHandler("localServerBootstrp Handler 2", LogLevel.TRACE));
            p.addLast(getMultiplexer());
            p.addLast(new LoggingHandler("localServerBootstrp Handler 1", LogLevel.TRACE));
        }
    });

    // Start the server.
    final ChannelFuture serverChannelFuture = localServerBootstrap.bind(localServerAddr);
    LOG.debug("serverChannel: " + serverChannelFuture);
}

From source file:org.opendaylight.usc.test.plugin.UscPluginTest.java

License:Open Source License

/**
 * @throws java.lang.Exception/*from  w w w.j  ava 2s.c  om*/
 */
@Before
public void setUp() throws Exception {
    UscConfigurationServiceImpl.setDefaultPropertyFilePath("src/test/resources/etc/usc/usc.properties");

    /*Logger root = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    if (root instanceof SimpleLogger) {
    SimpleLogger.setLevel(SimpleLogger.TRACE);
    }*/
    // set up client bootstrap
    clientBootstrap.group(localGroup);
    clientBootstrap.channel(LocalChannel.class);
    clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
        @Override
        public void initChannel(LocalChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler("UscPluginTest client", LogLevel.TRACE));

            // Decoders
            p.addLast("frameDecoder", new DelimiterBasedFrameDecoder(80, false, Delimiters.lineDelimiter()));
            p.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));

            // Encoder
            p.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));

        }
    });

}

From source file:org.opendaylight.usc.UscChannelServiceImpl.java

License:Open Source License

private Bootstrap getNewBootstrap() {
    Bootstrap ret = new Bootstrap();
    EventLoopGroup localGroup = new LocalEventLoopGroup();

    // set up client bootstrap
    ret.group(localGroup);/*from w  ww . jav a2 s. co  m*/
    ret.channel(LocalChannel.class);
    ret.handler(new ChannelInitializer<LocalChannel>() {
        @Override
        public void initChannel(LocalChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler("Manager Test 1", LogLevel.TRACE));
        }
    });
    return ret;
}