Search in sources :

Example 11 with ChannelConnector

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

Example 12 with ChannelConnector

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

the class TestLengthValueServerJunit method testClient.

public void testClient() 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());
    Channel ch = context.connect();
    LengthValueFrame f = new LengthValueFrame();
    f.setString(hello, ch);
    ch.writeAndFlush(f);
    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)

Example 13 with ChannelConnector

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

the class TestByteBufPool method main.

public static void main(String[] args) throws Exception {
    ChannelConnector context = new ChannelConnector("192.168.1.102", 6500);
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.addProtocolCodec(new LengthValueCodec());
    Channel ch = context.connect(3000);
    ByteBuf buf = ch.allocate();
    ch.close();
    buf.release();
}
Also used : LengthValueCodec(com.firenio.codec.lengthvalue.LengthValueCodec) ChannelConnector(com.firenio.component.ChannelConnector) Channel(com.firenio.component.Channel) ByteBuf(com.firenio.buffer.ByteBuf) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Example 14 with ChannelConnector

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

the class TestLengthValueClient1 method main.

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

        @Override
        public void accept(Channel ch, Frame frame) throws Exception {
            LengthValueFrame f = (LengthValueFrame) frame;
            System.out.println();
            System.out.println("____________________" + f.getStringContent());
            System.out.println();
        }
    };
    ChannelConnector context = new ChannelConnector(8300);
    context.setIoEventHandle(eventHandleAdaptor);
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.addProtocolCodec(new LengthValueCodec());
    Channel ch = context.connect();
    StringBuilder sb = new StringBuilder(1024 * 6);
    for (int i = 0; i < 1; i++) {
        sb.append("hello!");
    }
    for (int i = 0; i < 20; i++) {
        LengthValueFrame frame = new LengthValueFrame();
        frame.write(sb.toString(), ch);
        ch.writeAndFlush(frame);
    }
    Util.sleep(100);
    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) Channel(com.firenio.component.Channel) LengthValueFrame(com.firenio.codec.lengthvalue.LengthValueFrame) ChannelConnector(com.firenio.component.ChannelConnector) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Example 15 with ChannelConnector

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

the class TestProtobase method testText.

public void testText() throws Exception {
    Waiter<String> w = new Waiter<>();
    IoEventHandle eventHandleAdaptor = new IoEventHandle() {

        @Override
        public void accept(Channel ch, Frame frame) {
            String text = frame.getStringContent();
            System.out.println();
            System.out.println("____________________" + text);
            System.out.println();
            Util.close(ch);
            w.call(text, null);
        }
    };
    ChannelConnector context = new ChannelConnector(8300);
    context.setIoEventHandle(eventHandleAdaptor);
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.addProtocolCodec(new ProtobaseCodec());
    Channel ch = context.connect();
    ProtobaseFrame f = new ProtobaseFrame();
    f.setString(hello, ch);
    ch.writeAndFlush(f);
    w.await(3000);
    Assert.assertEquals(w.getResponse(), res + hello);
}
Also used : IoEventHandle(com.firenio.component.IoEventHandle) ProtobaseFrame(com.firenio.codec.protobase.ProtobaseFrame) Frame(com.firenio.component.Frame) ProtobaseFrame(com.firenio.codec.protobase.ProtobaseFrame) Channel(com.firenio.component.Channel) ChannelConnector(com.firenio.component.ChannelConnector) ProtobaseCodec(com.firenio.codec.protobase.ProtobaseCodec) Waiter(com.firenio.concurrent.Waiter) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Aggregations

Channel (com.firenio.component.Channel)19 ChannelConnector (com.firenio.component.ChannelConnector)19 Frame (com.firenio.component.Frame)18 IoEventHandle (com.firenio.component.IoEventHandle)18 LoggerChannelOpenListener (com.firenio.component.LoggerChannelOpenListener)17 LengthValueCodec (com.firenio.codec.lengthvalue.LengthValueCodec)11 LengthValueFrame (com.firenio.codec.lengthvalue.LengthValueFrame)8 ClientHttpCodec (com.firenio.codec.http11.ClientHttpCodec)5 NioEventLoopGroup (com.firenio.component.NioEventLoopGroup)5 Waiter (com.firenio.concurrent.Waiter)5 ClientHttpFrame (com.firenio.codec.http11.ClientHttpFrame)4 WebSocketCodec (com.firenio.codec.http11.WebSocketCodec)3 ProtobaseCodec (com.firenio.codec.protobase.ProtobaseCodec)3 ProtobaseFrame (com.firenio.codec.protobase.ProtobaseFrame)3 ByteBuf (com.firenio.buffer.ByteBuf)2 HttpFrame (com.firenio.codec.http11.HttpFrame)2 ChannelActiveListener (com.firenio.component.ChannelActiveListener)2 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2