Search in sources :

Example 1 with SearchRequest

use of com.generallycloud.test.io.protobuf.TestProtoBufBean.SearchRequest in project baseio by generallycloud.

the class Test method main.

public static void main(String[] args) throws InvalidProtocolBufferException {
    ByteString byteString = ByteString.copyFrom("222".getBytes());
    SearchRequest request = SearchRequest.newBuilder().setCorpus(Corpus.IMAGES).setPageNumber(100).setQuery("test").setQueryBytes(byteString).setResultPerPage(-1).build();
    byte[] data = request.toByteArray();
    SearchRequest r2 = SearchRequest.parseFrom(data);
    System.out.println(r2.toString());
    int i = 0b011111111111111111111111;
    System.out.println(i);
}
Also used : SearchRequest(com.generallycloud.test.io.protobuf.TestProtoBufBean.SearchRequest) ByteString(com.google.protobuf.ByteString)

Example 2 with SearchRequest

use of com.generallycloud.test.io.protobuf.TestProtoBufBean.SearchRequest in project baseio by generallycloud.

the class TestProtobufClient method main.

public static void main(String[] args) throws Exception {
    ProtobufUtil protobufUtil = new ProtobufUtil();
    protobufUtil.regist(SearchRequest.getDefaultInstance());
    IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            ProtobaseFuture f = (ProtobaseFuture) future;
            SearchRequest res = (SearchRequest) protobufUtil.getMessage(f);
            System.out.println();
            System.out.println("________" + res);
            System.out.println();
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    context.addSessionEventListener(new LoggerSocketSEListener());
    // context.addSessionEventListener(new SessionActiveSEListener());
    // context.setBeatFutureFactory(new FLBeatFutureFactory());
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    SocketSession session = connector.connect();
    ProtobaseFuture f = new ProtobaseFutureImpl(context);
    ByteString byteString = ByteString.copyFrom("222".getBytes());
    SearchRequest request = SearchRequest.newBuilder().setCorpus(Corpus.IMAGES).setPageNumber(100).setQuery("test").setQueryBytes(byteString).setResultPerPage(-1).build();
    protobufUtil.writeProtobuf(request, f);
    session.flush(f);
    ThreadUtil.sleep(100);
    CloseUtil.close(connector);
}
Also used : SearchRequest(com.generallycloud.test.io.protobuf.TestProtoBufBean.SearchRequest) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ByteString(com.google.protobuf.ByteString) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) ProtobufUtil(com.generallycloud.baseio.codec.protobuf.ProtobufUtil) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future)

Example 3 with SearchRequest

use of com.generallycloud.test.io.protobuf.TestProtoBufBean.SearchRequest in project baseio by generallycloud.

the class TestProtobufServer method main.

public static void main(String[] args) throws Exception {
    ProtobufUtil protobufUtil = new ProtobufUtil();
    protobufUtil.regist(SearchRequest.getDefaultInstance());
    IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            ProtobaseFuture f = (ProtobaseFuture) future;
            SearchRequest req = (SearchRequest) protobufUtil.getMessage(f);
            String message = "yes server already accept your message:\n" + req;
            System.out.println(message);
            SearchRequest res = SearchRequest.newBuilder().mergeFrom(req).setQuery("query_______").build();
            protobufUtil.writeProtobuf(res.getClass().getName(), res, f);
            session.flush(future);
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
    SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
    context.addSessionEventListener(new LoggerSocketSEListener());
    // context.addSessionEventListener(new SessionAliveSEListener());
    context.setIoEventHandleAdaptor(eventHandleAdaptor);
    // context.setBeatFutureFactory(new NIOBeatFutureFactory());
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    acceptor.bind();
}
Also used : SearchRequest(com.generallycloud.test.io.protobuf.TestProtoBufBean.SearchRequest) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) ProtobufUtil(com.generallycloud.baseio.codec.protobuf.ProtobufUtil) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) IoEventHandleAdaptor(com.generallycloud.baseio.component.IoEventHandleAdaptor) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) SocketChannelAcceptor(com.generallycloud.baseio.acceptor.SocketChannelAcceptor)

Aggregations

SearchRequest (com.generallycloud.test.io.protobuf.TestProtoBufBean.SearchRequest)3 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)2 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)2 ProtobufUtil (com.generallycloud.baseio.codec.protobuf.ProtobufUtil)2 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)2 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)2 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)2 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)2 SocketSession (com.generallycloud.baseio.component.SocketSession)2 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)2 Future (com.generallycloud.baseio.protocol.Future)2 ByteString (com.google.protobuf.ByteString)2 SocketChannelAcceptor (com.generallycloud.baseio.acceptor.SocketChannelAcceptor)1 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)1 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)1