Search in sources :

Example 11 with NioEventLoopGroup

use of com.firenio.component.NioEventLoopGroup in project baseio by generallycloud.

the class TestHeartBeat method main.

public static void main(String[] args) throws Exception {
    IoEventHandle eventHandleAdaptor = new IoEventHandle() {

        @Override
        public void accept(Channel ch, Frame frame) throws Exception {
            DebugUtil.debug("______________" + frame);
        }
    };
    NioEventLoopGroup group = new NioEventLoopGroup();
    group.setIdleTime(20);
    ChannelConnector context = new ChannelConnector(group, "127.0.0.1", 8300);
    context.addChannelIdleEventListener(new ChannelActiveListener());
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.addProtocolCodec(new LengthValueCodec());
    context.setIoEventHandle(eventHandleAdaptor);
    Channel ch = context.connect();
    String param = "tttt";
    long old = Util.now();
    for (int i = 0; i < 5; i++) {
        Frame frame = new LengthValueFrame();
        frame.setString(param, ch);
        ch.writeAndFlush(frame);
        Util.sleep(300);
    }
    System.out.println("Time:" + (Util.past(old)));
    Thread.sleep(2000);
    Util.close(context);
}
Also used : IoEventHandle(com.firenio.component.IoEventHandle) LengthValueCodec(com.firenio.codec.lengthvalue.LengthValueCodec) LengthValueFrame(com.firenio.codec.lengthvalue.LengthValueFrame) Frame(com.firenio.component.Frame) ChannelActiveListener(com.firenio.component.ChannelActiveListener) Channel(com.firenio.component.Channel) ChannelConnector(com.firenio.component.ChannelConnector) LengthValueFrame(com.firenio.codec.lengthvalue.LengthValueFrame) NioEventLoopGroup(com.firenio.component.NioEventLoopGroup) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Aggregations

NioEventLoopGroup (com.firenio.component.NioEventLoopGroup)11 Channel (com.firenio.component.Channel)10 Frame (com.firenio.component.Frame)9 IoEventHandle (com.firenio.component.IoEventHandle)9 LoggerChannelOpenListener (com.firenio.component.LoggerChannelOpenListener)7 ChannelAcceptor (com.firenio.component.ChannelAcceptor)5 ChannelConnector (com.firenio.component.ChannelConnector)5 ByteBuf (com.firenio.buffer.ByteBuf)3 HttpCodec (com.firenio.codec.http11.HttpCodec)3 HttpFrame (com.firenio.codec.http11.HttpFrame)3 WebSocketCodec (com.firenio.codec.http11.WebSocketCodec)3 LengthValueCodec (com.firenio.codec.lengthvalue.LengthValueCodec)3 ThreadEventLoopGroup (com.firenio.concurrent.ThreadEventLoopGroup)3 ClientHttpCodec (com.firenio.codec.http11.ClientHttpCodec)2 Http2Codec (com.firenio.codec.http2.Http2Codec)2 LengthValueFrame (com.firenio.codec.lengthvalue.LengthValueFrame)2 ChannelActiveListener (com.firenio.component.ChannelActiveListener)2 LifeCycle (com.firenio.LifeCycle)1 LifeCycleListener (com.firenio.LifeCycleListener)1 ByteBufAllocatorGroup (com.firenio.buffer.ByteBufAllocatorGroup)1