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


Java Event类代码示例

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


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

示例1: testCloseInFlush

import io.netty.channel.LoggingHandler.Event; //导入依赖的package包/类
@Test
public void testCloseInFlush() throws Exception {

    LocalAddress addr = new LocalAddress("testCloseInFlush");

    ServerBootstrap sb = getLocalServerBootstrap();
    sb.bind(addr).sync().channel();

    Bootstrap cb = getLocalClientBootstrap();

    setInterest(Event.WRITE, Event.FLUSH, Event.CLOSE, Event.EXCEPTION);

    Channel clientChannel = cb.connect(addr).sync().channel();

    clientChannel.pipeline().addLast(new ChannelOutboundHandlerAdapter() {

        @Override
        public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
            promise.addListener(new GenericFutureListener<Future<? super Void>>() {
                @Override
                public void operationComplete(Future<? super Void> future) throws Exception {
                    ctx.channel().close();
                }
            });
            super.write(ctx, msg, promise);
            ctx.channel().flush();
        }
    });

    clientChannel.write(createTestBuf(2000)).sync();
    clientChannel.closeFuture().sync();

    assertLog("WRITE\nFLUSH\nCLOSE\n");
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:35,代码来源:ReentrantChannelTest.java

示例2: testWritabilityChanged

import io.netty.channel.LoggingHandler.Event; //导入依赖的package包/类
@Test
public void testWritabilityChanged() throws Exception {

    LocalAddress addr = new LocalAddress("testWritabilityChanged");

    ServerBootstrap sb = getLocalServerBootstrap();
    sb.bind(addr).sync().channel();

    Bootstrap cb = getLocalClientBootstrap();

    setInterest(Event.WRITE, Event.FLUSH, Event.WRITABILITY);

    Channel clientChannel = cb.connect(addr).sync().channel();
    clientChannel.config().setWriteBufferLowWaterMark(512);
    clientChannel.config().setWriteBufferHighWaterMark(1024);

    ChannelFuture future = clientChannel.write(createTestBuf(2000));
    clientChannel.flush();
    future.sync();

    clientChannel.close().sync();

    assertLog(
        "WRITABILITY: writable=false\n" +
        "WRITABILITY: writable=true\n" +
        "WRITE\n" +
        "WRITABILITY: writable=false\n" +
        "FLUSH\n" +
        "WRITABILITY: writable=true\n");
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:31,代码来源:ReentrantChannelTest.java

示例3: testFlushInWritabilityChanged

import io.netty.channel.LoggingHandler.Event; //导入依赖的package包/类
@Test
public void testFlushInWritabilityChanged() throws Exception {

    LocalAddress addr = new LocalAddress("testFlushInWritabilityChanged");

    ServerBootstrap sb = getLocalServerBootstrap();
    sb.bind(addr).sync().channel();

    Bootstrap cb = getLocalClientBootstrap();

    setInterest(Event.WRITE, Event.FLUSH, Event.WRITABILITY);

    Channel clientChannel = cb.connect(addr).sync().channel();
    clientChannel.config().setWriteBufferLowWaterMark(512);
    clientChannel.config().setWriteBufferHighWaterMark(1024);

    clientChannel.pipeline().addLast(new ChannelInboundHandlerAdapter() {
        @Override
        public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
            if (!ctx.channel().isWritable()) {
                ctx.channel().flush();
            }
            ctx.fireChannelWritabilityChanged();
        }
    });

    assertTrue(clientChannel.isWritable());
    clientChannel.write(createTestBuf(2000)).sync();
    clientChannel.close().sync();

    assertLog(
        "WRITABILITY: writable=false\n" +
        "FLUSH\n" +
        "WRITABILITY: writable=true\n" +
        "WRITE\n" +
        "WRITABILITY: writable=false\n" +
        "FLUSH\n" +
        "WRITABILITY: writable=true\n");
}
 
开发者ID:kyle-liu,项目名称:netty4study,代码行数:40,代码来源:ReentrantChannelTest.java

示例4: testFlushInWritabilityChanged

import io.netty.channel.LoggingHandler.Event; //导入依赖的package包/类
@Test
public void testFlushInWritabilityChanged() throws Exception {

    LocalAddress addr = new LocalAddress("testFlushInWritabilityChanged");

    ServerBootstrap sb = getLocalServerBootstrap();
    sb.bind(addr).sync().channel();

    Bootstrap cb = getLocalClientBootstrap();

    setInterest(Event.WRITE, Event.FLUSH, Event.WRITABILITY);

    Channel clientChannel = cb.connect(addr).sync().channel();
    clientChannel.config().setWriteBufferLowWaterMark(512);
    clientChannel.config().setWriteBufferHighWaterMark(1024);

    clientChannel.pipeline().addLast(new ChannelHandlerAdapter() {
        @Override
        public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
            if (!ctx.channel().isWritable()) {
                ctx.channel().flush();
            }
            ctx.fireChannelWritabilityChanged();
        }
    });

    assertTrue(clientChannel.isWritable());
    clientChannel.write(createTestBuf(2000)).sync();
    clientChannel.close().sync();

    assertLog(
        "WRITABILITY: writable=false\n" +
        "FLUSH\n" +
        "WRITABILITY: writable=true\n" +
        "WRITE\n" +
        "WRITABILITY: writable=false\n" +
        "FLUSH\n" +
        "WRITABILITY: writable=true\n");
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:40,代码来源:ReentrantChannelTest.java

示例5: testCloseInFlush

import io.netty.channel.LoggingHandler.Event; //导入依赖的package包/类
@Test
public void testCloseInFlush() throws Exception {

    LocalAddress addr = new LocalAddress("testCloseInFlush");

    ServerBootstrap sb = getLocalServerBootstrap();
    sb.bind(addr).sync().channel();

    Bootstrap cb = getLocalClientBootstrap();

    setInterest(Event.WRITE, Event.FLUSH, Event.CLOSE, Event.EXCEPTION);

    Channel clientChannel = cb.connect(addr).sync().channel();

    clientChannel.pipeline().addLast(new ChannelHandlerAdapter() {

        @Override
        public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
            promise.addListener(new GenericFutureListener<Future<? super Void>>() {
                @Override
                public void operationComplete(Future<? super Void> future) throws Exception {
                    ctx.channel().close();
                }
            });
            super.write(ctx, msg, promise);
            ctx.channel().flush();
        }
    });

    clientChannel.write(createTestBuf(2000)).sync();
    clientChannel.closeFuture().sync();

    assertLog(
        "WRITE\n" +
        "FLUSH\n" +
        "CLOSE\n");
}
 
开发者ID:nathanchen,项目名称:netty-netty-5.0.0.Alpha1,代码行数:38,代码来源:ReentrantChannelTest.java

示例6: testWritabilityChanged

import io.netty.channel.LoggingHandler.Event; //导入依赖的package包/类
@Test
public void testWritabilityChanged() throws Exception {

    LocalAddress addr = new LocalAddress("testWritabilityChanged");

    ServerBootstrap sb = getLocalServerBootstrap();
    sb.bind(addr).sync().channel();

    Bootstrap cb = getLocalClientBootstrap();

    setInterest(Event.WRITE, Event.FLUSH, Event.WRITABILITY);

    Channel clientChannel = cb.connect(addr).sync().channel();
    clientChannel.config().setWriteBufferLowWaterMark(512);
    clientChannel.config().setWriteBufferHighWaterMark(1024);

    // What is supposed to happen from this point:
    //
    // 1. Because this write attempt has been made from a non-I/O thread,
    //    ChannelOutboundBuffer.pendingWriteBytes will be increased before
    //    write() event is really evaluated.
    //    -> channelWritabilityChanged() will be triggered,
    //       because the Channel became unwritable.
    //
    // 2. The write() event is handled by the pipeline in an I/O thread.
    //    -> write() will be triggered.
    //
    // 3. Once the write() event is handled, ChannelOutboundBuffer.pendingWriteBytes
    //    will be decreased.
    //    -> channelWritabilityChanged() will be triggered,
    //       because the Channel became writable again.
    //
    // 4. The message is added to the ChannelOutboundBuffer and thus
    //    pendingWriteBytes will be increased again.
    //    -> channelWritabilityChanged() will be triggered.
    //
    // 5. The flush() event causes the write request in theChannelOutboundBuffer
    //    to be removed.
    //    -> flush() and channelWritabilityChanged() will be triggered.
    //
    // Note that the channelWritabilityChanged() in the step 4 can occur between
    // the flush() and the channelWritabilityChanged() in the stap 5, because
    // the flush() is invoked from a non-I/O thread while the other are from
    // an I/O thread.

    ChannelFuture future = clientChannel.write(createTestBuf(2000));

    clientChannel.flush();
    future.sync();

    clientChannel.close().sync();

    assertLog(
            // Case 1:
            "WRITABILITY: writable=false\n" +
            "WRITE\n" +
            "WRITABILITY: writable=false\n" +
            "WRITABILITY: writable=false\n" +
            "FLUSH\n" +
            "WRITABILITY: writable=true\n",
            // Case 2:
            "WRITABILITY: writable=false\n" +
            "WRITE\n" +
            "WRITABILITY: writable=false\n" +
            "FLUSH\n" +
            "WRITABILITY: writable=true\n" +
            "WRITABILITY: writable=true\n");
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:69,代码来源:ReentrantChannelTest.java

示例7: testFlushInWritabilityChanged

import io.netty.channel.LoggingHandler.Event; //导入依赖的package包/类
/**
 * Similar to {@link #testWritabilityChanged()} with slight variation.
 */
@Test
public void testFlushInWritabilityChanged() throws Exception {

    LocalAddress addr = new LocalAddress("testFlushInWritabilityChanged");

    ServerBootstrap sb = getLocalServerBootstrap();
    sb.bind(addr).sync().channel();

    Bootstrap cb = getLocalClientBootstrap();

    setInterest(Event.WRITE, Event.FLUSH, Event.WRITABILITY);

    Channel clientChannel = cb.connect(addr).sync().channel();
    clientChannel.config().setWriteBufferLowWaterMark(512);
    clientChannel.config().setWriteBufferHighWaterMark(1024);

    clientChannel.pipeline().addLast(new ChannelInboundHandlerAdapter() {
        @Override
        public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
            if (!ctx.channel().isWritable()) {
                ctx.channel().flush();
            }
            ctx.fireChannelWritabilityChanged();
        }
    });

    assertTrue(clientChannel.isWritable());

    clientChannel.write(createTestBuf(2000)).sync();
    clientChannel.close().sync();

    assertLog(
            // Case 1:
            "WRITABILITY: writable=false\n" +
            "FLUSH\n" +
            "WRITE\n" +
            "WRITABILITY: writable=false\n" +
            "WRITABILITY: writable=false\n" +
            "FLUSH\n" +
            "WRITABILITY: writable=true\n",
            // Case 2:
            "WRITABILITY: writable=false\n" +
            "FLUSH\n" +
            "WRITE\n" +
            "WRITABILITY: writable=false\n" +
            "FLUSH\n" +
            "WRITABILITY: writable=true\n" +
            "WRITABILITY: writable=true\n");
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:53,代码来源:ReentrantChannelTest.java


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