Search in sources :

Example 6 with ProtobaseFuture

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());
    }
}
Also used : ApplicationContext(com.generallycloud.baseio.container.ApplicationContext) Parameters(com.generallycloud.baseio.component.Parameters) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) SocketSessionManager(com.generallycloud.baseio.component.SocketSessionManager) LoginCenter(com.generallycloud.baseio.container.LoginCenter) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext)

Example 7 with ProtobaseFuture

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);
    }
}
Also used : ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Authority(com.generallycloud.baseio.container.authority.Authority) RTPException(com.generallycloud.baseio.container.rtp.RTPException) MapMessage(com.generallycloud.baseio.container.jms.MapMessage) IOException(java.io.IOException)

Example 8 with ProtobaseFuture

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);
}
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 9 with ProtobaseFuture

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);
}
Also used : ProtobaseProtocolFactory(com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory) SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 10 with ProtobaseFuture

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);
}
Also used : SocketChannelConnector(com.generallycloud.baseio.connector.SocketChannelConnector) LoggerSocketSEListener(com.generallycloud.baseio.component.LoggerSocketSEListener) OnFuture(com.generallycloud.baseio.container.OnFuture) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) FixedSession(com.generallycloud.baseio.container.FixedSession) SimpleIoEventHandle(com.generallycloud.baseio.container.SimpleIoEventHandle) 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) ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) Future(com.generallycloud.baseio.protocol.Future) OnFuture(com.generallycloud.baseio.container.OnFuture)

Aggregations

ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)27 SocketChannelContext (com.generallycloud.baseio.component.SocketChannelContext)17 LoggerSocketSEListener (com.generallycloud.baseio.component.LoggerSocketSEListener)16 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)16 ServerConfiguration (com.generallycloud.baseio.configuration.ServerConfiguration)16 ProtobaseProtocolFactory (com.generallycloud.baseio.codec.protobase.ProtobaseProtocolFactory)15 SocketChannelConnector (com.generallycloud.baseio.connector.SocketChannelConnector)15 SocketSession (com.generallycloud.baseio.component.SocketSession)12 Future (com.generallycloud.baseio.protocol.Future)11 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)10 IoEventHandleAdaptor (com.generallycloud.baseio.component.IoEventHandleAdaptor)8 FixedSession (com.generallycloud.baseio.container.FixedSession)8 SimpleIoEventHandle (com.generallycloud.baseio.container.SimpleIoEventHandle)8 IOException (java.io.IOException)6 MQException (com.generallycloud.baseio.container.jms.MQException)4 ParamedProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFuture)3 JSONObject (com.alibaba.fastjson.JSONObject)2 ProtobufUtil (com.generallycloud.baseio.codec.protobuf.ProtobufUtil)2 OnFuture (com.generallycloud.baseio.container.OnFuture)2 BytedMessage (com.generallycloud.baseio.container.jms.BytedMessage)2