use of com.generallycloud.baseio.component.NioSocketChannelContext 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();
}
Aggregations