当前位置: 首页>>代码示例>>Java>>正文


Java AbstractChannel类代码示例

本文整理汇总了Java中io.netty.channel.AbstractChannel的典型用法代码示例。如果您正苦于以下问题:Java AbstractChannel类的具体用法?Java AbstractChannel怎么用?Java AbstractChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AbstractChannel类属于io.netty.channel包,在下文中一共展示了AbstractChannel类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initChannel

import io.netty.channel.AbstractChannel; //导入依赖的package包/类
public void initChannel(AbstractChannel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();

    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }

    // Add the text line codec combination first,
    pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
    // the encoder and decoder are static as these are sharable
    pipeline.addLast(DECODER);
    pipeline.addLast(ENCODER);

    // and then business logic.
    pipeline.addLast(iotNettyTcpHandler);
}
 
开发者ID:wendal,项目名称:whale,代码行数:17,代码来源:IotNettyTcpServerInitializer.java

示例2: initChannel

import io.netty.channel.AbstractChannel; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @see io.netty.channel.ChannelInitializer#initChannel(io.netty.channel.Channel)
 */
@Override
protected void initChannel(final AbstractChannel ch) throws Exception {
	ChannelPipeline p = ch.pipeline();
	p.addLast("bytesDecoder", bytesDecoder);
	p.addLast("framer", new LineBasedFrameDecoder(1024, true, true));
	p.addLast("linehandler", new StringMetricHandler());
}
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:12,代码来源:UDPPipelineFactory.java

示例3: createChannelWithDecoder

import io.netty.channel.AbstractChannel; //导入依赖的package包/类
public static ChannelInitializer<AbstractChannel> createChannelWithDecoder(
        @Nonnull final BmpSessionFactory sessionFactory,
        @Nonnull final BmpHandlerFactory hf,
        @Nonnull final BmpSessionListenerFactory slf) {
    return new ChannelInitializer<AbstractChannel>() {
        @Override
        protected void initChannel(final AbstractChannel ch) throws Exception {
            ch.pipeline().addLast(hf.getDecoders());
            ch.pipeline().addLast(sessionFactory.getSession(ch, slf));
        }
    };
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:13,代码来源:BmpDispatcherUtil.java

示例4: createChannelWithEncoder

import io.netty.channel.AbstractChannel; //导入依赖的package包/类
public static ChannelInitializer<AbstractChannel> createChannelWithEncoder(
        @Nonnull final BmpSessionFactory sessionFactory,
        @Nonnull final BmpHandlerFactory hf,
        @Nonnull final BmpSessionListenerFactory slf) {
    return new ChannelInitializer<AbstractChannel>() {
        @Override
        protected void initChannel(final AbstractChannel ch) throws Exception {
            ch.pipeline().addLast(hf.getEncoders());
            ch.pipeline().addLast(sessionFactory.getSession(ch, slf));
        }
    };
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:13,代码来源:BmpDispatcherUtil.java

示例5: testWriteFailsFastOnClosedChannel

import io.netty.channel.AbstractChannel; //导入依赖的package包/类
@Test
public void testWriteFailsFastOnClosedChannel() throws Exception {
    EventLoopGroup clientGroup = new LocalEventLoopGroup();
    EventLoopGroup serverGroup = new LocalEventLoopGroup();
    LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
    Bootstrap cb = new Bootstrap();
    ServerBootstrap sb = new ServerBootstrap();

    cb.group(clientGroup)
            .channel(LocalChannel.class)
            .handler(new TestHandler());

    sb.group(serverGroup)
            .channel(LocalServerChannel.class)
            .childHandler(new ChannelInitializer<LocalChannel>() {
                @Override
                public void initChannel(LocalChannel ch) throws Exception {
                    ch.pipeline().addLast(new TestHandler());
                }
            });

    // Start server
    sb.bind(addr).sync();

    // Connect to the server
    final Channel cc = cb.connect(addr).sync().channel();

    // Close the channel and write something.
    cc.close().sync();
    try {
        cc.writeAndFlush(new Object()).sync();
        fail("must raise a ClosedChannelException");
    } catch (Exception e) {
        assertThat(e, is(instanceOf(ClosedChannelException.class)));
        // Ensure that the actual write attempt on a closed channel was never made by asserting that
        // the ClosedChannelException has been created by AbstractUnsafe rather than transport implementations.
        if (e.getStackTrace().length > 0) {
            assertThat(
                    e.getStackTrace()[0].getClassName(), is(AbstractChannel.class.getName() + "$AbstractUnsafe"));
            e.printStackTrace();
        }
    }

    serverGroup.shutdownGracefully();
    clientGroup.shutdownGracefully();
    serverGroup.terminationFuture().sync();
    clientGroup.terminationFuture().sync();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:49,代码来源:LocalChannelTest.java

示例6: create

import io.netty.channel.AbstractChannel; //导入依赖的package包/类
ChannelInitializer<AbstractChannel> create(@Nonnull BmpSessionFactory sessionFactory,
@Nonnull BmpHandlerFactory hf, @Nonnull BmpSessionListenerFactory slf);
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:3,代码来源:BmpDispatcherUtil.java

示例7: testWriteFailsFastOnClosedChannel

import io.netty.channel.AbstractChannel; //导入依赖的package包/类
@Test
public void testWriteFailsFastOnClosedChannel() throws Exception {
    EventLoopGroup clientGroup = new DefaultEventLoopGroup();
    EventLoopGroup serverGroup = new DefaultEventLoopGroup();
    LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
    Bootstrap cb = new Bootstrap();
    ServerBootstrap sb = new ServerBootstrap();

    cb.group(clientGroup)
            .channel(LocalChannel.class)
            .handler(new TestHandler());

    sb.group(serverGroup)
            .channel(LocalServerChannel.class)
            .childHandler(new ChannelInitializer<LocalChannel>() {
                @Override
                public void initChannel(LocalChannel ch) throws Exception {
                    ch.pipeline().addLast(new TestHandler());
                }
            });

    // Start server
    sb.bind(addr).sync();

    // Connect to the server
    final Channel cc = cb.connect(addr).sync().channel();

    // Close the channel and write something.
    cc.close().sync();
    try {
        cc.writeAndFlush(new Object()).sync();
        fail("must raise a ClosedChannelException");
    } catch (Exception e) {
        assertThat(e, is(instanceOf(ClosedChannelException.class)));
        // Ensure that the actual write attempt on a closed channel was never made by asserting that
        // the ClosedChannelException has been created by AbstractUnsafe rather than transport implementations.
        if (e.getStackTrace().length > 0) {
            assertThat(
                    e.getStackTrace()[0].getClassName(), is(AbstractChannel.class.getName() + "$AbstractUnsafe"));
            e.printStackTrace();
        }
    }

    serverGroup.shutdownGracefully();
    clientGroup.shutdownGracefully();
    serverGroup.terminationFuture().sync();
    clientGroup.terminationFuture().sync();
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:49,代码来源:LocalChannelTest.java


注:本文中的io.netty.channel.AbstractChannel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。