Search in sources :

Example 21 with LoggerChannelOpenListener

use of com.firenio.component.LoggerChannelOpenListener 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 22 with LoggerChannelOpenListener

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

the class TestReconnectClient method main.

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

        @Override
        public void accept(Channel ch, Frame frame) throws Exception {
        }
    };
    ChannelConnector context = new ChannelConnector(8300);
    ReConnector connector = new ReConnector(context);
    connector.setRetryTime(5000);
    context.setIoEventHandle(eventHandleAdaptor);
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.addProtocolCodec(new LengthValueCodec());
    // context.addChannelEventListener(new CloseConnectorSEListener(connector.getRealConnector()));
    connector.connect();
    int count = 99999;
    for (int i = 0; ; i++) {
        Util.sleep(1000);
        if (i > count) {
            break;
        }
    }
    Util.close(connector);
}
Also used : IoEventHandle(com.firenio.component.IoEventHandle) LengthValueCodec(com.firenio.codec.lengthvalue.LengthValueCodec) Frame(com.firenio.component.Frame) Channel(com.firenio.component.Channel) ChannelConnector(com.firenio.component.ChannelConnector) ReConnector(com.firenio.component.ReConnector) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Example 23 with LoggerChannelOpenListener

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

Example 24 with LoggerChannelOpenListener

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

the class TestLengthValueClient method main.

public static void main(String[] args) throws Exception {
    ChannelConnector context = new ChannelConnector("127.0.0.1", 8300);
    IoEventHandle eventHandle = new IoEventHandle() {

        @Override
        public void accept(Channel ch, Frame f) throws Exception {
            System.out.println();
            System.out.println("____________________" + f.getStringContent());
            System.out.println();
            context.close();
        }
    };
    context.setIoEventHandle(eventHandle);
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.addProtocolCodec(new LengthValueCodec());
    Channel ch = context.connect(3000);
    LengthValueFrame frame = new LengthValueFrame();
    frame.setString("hello server!", ch);
    ch.writeAndFlush(frame);
}
Also used : IoEventHandle(com.firenio.component.IoEventHandle) LengthValueCodec(com.firenio.codec.lengthvalue.LengthValueCodec) LengthValueFrame(com.firenio.codec.lengthvalue.LengthValueFrame) Frame(com.firenio.component.Frame) ChannelConnector(com.firenio.component.ChannelConnector) Channel(com.firenio.component.Channel) LengthValueFrame(com.firenio.codec.lengthvalue.LengthValueFrame) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Example 25 with LoggerChannelOpenListener

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

the class TestLengthValueServerJunit method testClientAsync.

public void testClientAsync() throws Exception {
    Waiter<String> w = new Waiter<>();
    ChannelConnector context = new ChannelConnector(8300);
    IoEventHandle eventHandle = new IoEventHandle() {

        @Override
        public void accept(Channel ch, Frame f) throws Exception {
            System.out.println();
            System.out.println("____________________" + f.getStringContent());
            System.out.println();
            context.close();
            w.call(f.getStringContent(), null);
        }
    };
    context.setIoEventHandle(eventHandle);
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.addProtocolCodec(new LengthValueCodec());
    context.connect((ch, ex) -> {
        LengthValueFrame f = new LengthValueFrame();
        f.setString(hello, ch);
        try {
            ch.writeAndFlush(f);
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    w.await(1000);
    v(w.getResponse());
}
Also used : IoEventHandle(com.firenio.component.IoEventHandle) LengthValueCodec(com.firenio.codec.lengthvalue.LengthValueCodec) LengthValueFrame(com.firenio.codec.lengthvalue.LengthValueFrame) Frame(com.firenio.component.Frame) ChannelConnector(com.firenio.component.ChannelConnector) Channel(com.firenio.component.Channel) LengthValueFrame(com.firenio.codec.lengthvalue.LengthValueFrame) Waiter(com.firenio.concurrent.Waiter) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Aggregations

LoggerChannelOpenListener (com.firenio.component.LoggerChannelOpenListener)28 Channel (com.firenio.component.Channel)26 Frame (com.firenio.component.Frame)24 IoEventHandle (com.firenio.component.IoEventHandle)24 ChannelConnector (com.firenio.component.ChannelConnector)17 LengthValueCodec (com.firenio.codec.lengthvalue.LengthValueCodec)14 ChannelAcceptor (com.firenio.component.ChannelAcceptor)10 LengthValueFrame (com.firenio.codec.lengthvalue.LengthValueFrame)9 NioEventLoopGroup (com.firenio.component.NioEventLoopGroup)7 WebSocketCodec (com.firenio.codec.http11.WebSocketCodec)5 ProtobaseCodec (com.firenio.codec.protobase.ProtobaseCodec)5 Waiter (com.firenio.concurrent.Waiter)5 ClientHttpCodec (com.firenio.codec.http11.ClientHttpCodec)4 ClientHttpFrame (com.firenio.codec.http11.ClientHttpFrame)4 ProtobaseFrame (com.firenio.codec.protobase.ProtobaseFrame)4 HttpFrame (com.firenio.codec.http11.HttpFrame)3 ChannelAliveListener (com.firenio.component.ChannelAliveListener)3 ChannelEventListenerAdapter (com.firenio.component.ChannelEventListenerAdapter)3 ByteBuf (com.firenio.buffer.ByteBuf)2 HttpCodec (com.firenio.codec.http11.HttpCodec)2