Search in sources :

Example 26 with LoggerChannelOpenListener

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

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

the class TestProtobaseServer 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 ProtobaseCodec());
    context.bind();
}
Also used : IoEventHandle(com.firenio.component.IoEventHandle) Frame(com.firenio.component.Frame) Channel(com.firenio.component.Channel) ChannelAcceptor(com.firenio.component.ChannelAcceptor) ProtobaseCodec(com.firenio.codec.protobase.ProtobaseCodec) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Example 28 with LoggerChannelOpenListener

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

the class TestReconnectClient2 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(8087);
    context.setIoEventHandle(eventHandleAdaptor);
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.addProtocolCodec(new LengthValueCodec());
    context.connect();
    int count = 5;
    for (int i = 0; i < count; i++) {
        context.getChannel().close();
        context.connect();
    }
    Util.sleep(Long.MAX_VALUE);
    Util.close(context);
}
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) 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