use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture in project baseio by generallycloud.
the class RTPServerDPAcceptor method execute.
@Override
protected void execute(DatagramSession dSession, DatagramRequest request) {
String serviceName = request.getFutureName();
if (BIND_SESSION.equals(serviceName)) {
Parameters parameters = request.getParameters();
ApplicationContext context = ApplicationContext.getInstance();
LoginCenter loginCenter = AuthorityContext.getInstance().getLoginCenter();
if (!loginCenter.isValidate(parameters)) {
return;
}
// FIXME udp
SocketChannelContext channelContext = context.getChannelContext();
SocketSessionManager sessionManager = channelContext.getSessionManager();
// Session session = factory.getSession(username);
SocketSession session = null;
if (session == null) {
return;
}
// session.setDatagramChannel(channel); //FIXME udp
ProtobaseFuture future = new ProtobaseFutureImpl(session.getContext(), BIND_SESSION_CALLBACK);
logger.debug("___________________bind___session___{}", session);
future.write("1");
session.flush(future);
} else {
logger.debug(">>>> {}", request.getFutureName());
}
}
use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture in project baseio by generallycloud.
the class RTPClient method leaveRoom.
public boolean leaveRoom() throws RTPException {
try {
Authority authority = session.getAuthority();
if (authority == null) {
throw new RTPException("not login");
}
ProtobaseFuture future = session.request(RTPJoinRoomServlet.SERVICE_NAME, roomId);
this.handle.onBreak(this, new MapMessage("", authority.getUuid()));
return JmsUtil.isTrue(future);
} catch (IOException e) {
throw new RTPException(e.getMessage(), e);
}
}
use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture 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);
}
use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture in project baseio by generallycloud.
the class TestGetPhoneNO method main.
public static void main(String[] args) throws Exception {
String serviceKey = "TestGetPhoneNOServlet";
LoggerFactory.configure();
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
ServerConfiguration configuration = new ServerConfiguration(8300);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
connector.getContext().setProtocolFactory(new ProtobaseProtocolFactory());
FixedSession session = new FixedSession(connector.connect());
ProtobaseFuture future = session.request(serviceKey, null);
System.out.println(future.getReadText());
CloseUtil.close(connector);
}
use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture in project baseio by generallycloud.
the class TestSessionDisconnect method main.
public static void main(String[] args) throws Exception {
String serviceName = "TestSessionDisconnectServlet";
String param = "ttt";
LoggerFactory.configure();
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
ServerConfiguration configuration = new ServerConfiguration(8300);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
session.login("admin", "admin100");
ProtobaseFuture future = session.request(serviceName, param);
System.out.println(future.getReadText());
session.listen(serviceName, new OnFuture() {
@Override
public void onResponse(SocketSession session, Future future) {
ProtobaseFuture f = (ProtobaseFuture) future;
System.out.println(f.getReadText());
}
});
session.write(serviceName, param);
ThreadUtil.sleep(9999);
CloseUtil.close(connector);
}
Aggregations