Search in sources :

Example 6 with LengthValueCodec

use of com.firenio.codec.lengthvalue.LengthValueCodec in project baseio by generallycloud.

the class TestLengthValueServer method main.

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

        @Override
        public void accept(Channel ch, Frame f) throws Exception {
            String text = f.getStringContent();
            f.setContent(ch.allocateWithSkipHeader(1));
            f.write("yes server already accept your message:", ch);
            f.write(text, ch);
            ch.writeAndFlush(f);
        }
    };
    ChannelAcceptor context = new ChannelAcceptor(8300);
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.setIoEventHandle(eventHandleAdaptor);
    context.addProtocolCodec(new LengthValueCodec());
    context.bind();
}
Also used : IoEventHandle(com.firenio.component.IoEventHandle) LengthValueCodec(com.firenio.codec.lengthvalue.LengthValueCodec) Frame(com.firenio.component.Frame) Channel(com.firenio.component.Channel) ChannelAcceptor(com.firenio.component.ChannelAcceptor) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Example 7 with LengthValueCodec

use of com.firenio.codec.lengthvalue.LengthValueCodec 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 8 with LengthValueCodec

use of com.firenio.codec.lengthvalue.LengthValueCodec in project baseio by generallycloud.

the class TestLengthValueBroadcastServer method main.

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

        @Override
        public void accept(Channel ch, Frame frame) throws Exception {
            LengthValueFrame f = (LengthValueFrame) frame;
            frame.write("yes server already accept your message:", ch);
            frame.write(f.getStringContent(), ch);
            ch.writeAndFlush(f);
        }
    };
    ChannelAcceptor context = new ChannelAcceptor(8300);
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.addChannelEventListener(new SetOptionListener());
    context.addChannelEventListener(channelManagerListener);
    context.setIoEventHandle(eventHandleAdaptor);
    context.addProtocolCodec(new LengthValueCodec());
    context.bind();
    Util.exec(() -> {
        for (; ; ) {
            Util.sleep(1000);
            LengthValueFrame frame = new LengthValueFrame();
            frame.setContent("broadcast msg ........".getBytes());
            try {
                channelManagerListener.broadcast(frame);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : IoEventHandle(com.firenio.component.IoEventHandle) LengthValueCodec(com.firenio.codec.lengthvalue.LengthValueCodec) ChannelManagerListener(com.firenio.component.ChannelManagerListener) LengthValueFrame(com.firenio.codec.lengthvalue.LengthValueFrame) Frame(com.firenio.component.Frame) Channel(com.firenio.component.Channel) LengthValueFrame(com.firenio.codec.lengthvalue.LengthValueFrame) ChannelAcceptor(com.firenio.component.ChannelAcceptor) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Example 9 with LengthValueCodec

use of com.firenio.codec.lengthvalue.LengthValueCodec 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 10 with LengthValueCodec

use of com.firenio.codec.lengthvalue.LengthValueCodec 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)

Aggregations

LengthValueCodec (com.firenio.codec.lengthvalue.LengthValueCodec)15 Channel (com.firenio.component.Channel)15 Frame (com.firenio.component.Frame)14 IoEventHandle (com.firenio.component.IoEventHandle)14 LoggerChannelOpenListener (com.firenio.component.LoggerChannelOpenListener)14 ChannelConnector (com.firenio.component.ChannelConnector)11 LengthValueFrame (com.firenio.codec.lengthvalue.LengthValueFrame)10 ChannelAcceptor (com.firenio.component.ChannelAcceptor)3 NioEventLoopGroup (com.firenio.component.NioEventLoopGroup)3 ByteBuf (com.firenio.buffer.ByteBuf)2 ThreadEventLoopGroup (com.firenio.concurrent.ThreadEventLoopGroup)2 Waiter (com.firenio.concurrent.Waiter)2 ChannelActiveListener (com.firenio.component.ChannelActiveListener)1 ChannelEventListenerAdapter (com.firenio.component.ChannelEventListenerAdapter)1 ChannelManagerListener (com.firenio.component.ChannelManagerListener)1 ReConnector (com.firenio.component.ReConnector)1 Logger (com.firenio.log.Logger)1 BigDecimal (java.math.BigDecimal)1 Scanner (java.util.Scanner)1 CountDownLatch (java.util.concurrent.CountDownLatch)1