Search in sources :

Example 1 with ChannelActiveListener

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

the class TestProtobaseHeartBeat 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 ProtobaseCodec());
    context.setIoEventHandle(eventHandleAdaptor);
    Channel ch = context.connect();
    String param = "tttt";
    long old = Util.now_f();
    for (int i = 0; i < 5; i++) {
        Frame f = new ProtobaseFrame();
        f.setString(param, ch);
        ch.writeAndFlush(f);
        Util.sleep(300);
    }
    System.out.println("Time:" + (Util.past(old)));
    Thread.sleep(2000);
    Util.close(context);
}
Also used : IoEventHandle(com.firenio.component.IoEventHandle) ProtobaseFrame(com.firenio.codec.protobase.ProtobaseFrame) Frame(com.firenio.component.Frame) ChannelActiveListener(com.firenio.component.ChannelActiveListener) ProtobaseFrame(com.firenio.codec.protobase.ProtobaseFrame) Channel(com.firenio.component.Channel) ChannelConnector(com.firenio.component.ChannelConnector) ProtobaseCodec(com.firenio.codec.protobase.ProtobaseCodec) NioEventLoopGroup(com.firenio.component.NioEventLoopGroup) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Example 2 with ChannelActiveListener

use of com.firenio.component.ChannelActiveListener 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

Channel (com.firenio.component.Channel)2 ChannelActiveListener (com.firenio.component.ChannelActiveListener)2 ChannelConnector (com.firenio.component.ChannelConnector)2 Frame (com.firenio.component.Frame)2 IoEventHandle (com.firenio.component.IoEventHandle)2 LoggerChannelOpenListener (com.firenio.component.LoggerChannelOpenListener)2 NioEventLoopGroup (com.firenio.component.NioEventLoopGroup)2 LengthValueCodec (com.firenio.codec.lengthvalue.LengthValueCodec)1 LengthValueFrame (com.firenio.codec.lengthvalue.LengthValueFrame)1 ProtobaseCodec (com.firenio.codec.protobase.ProtobaseCodec)1 ProtobaseFrame (com.firenio.codec.protobase.ProtobaseFrame)1