Search in sources :

Example 11 with ProtobaseFuture

use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture in project baseio by generallycloud.

the class TestSimple method main.

public static void main(String[] args) throws Exception {
    String serviceKey = "/test-simple";
    String param = "ttt";
    IoEventHandleAdaptor eventHandle = new IoEventHandleAdaptor() {

        @Override
        public void accept(SocketSession session, Future future) throws Exception {
            System.out.println("________________________" + future.getReadText());
        }
    };
    SocketChannelContext context = new NioSocketChannelContext(new ServerConfiguration(18300));
    SocketChannelConnector connector = new SocketChannelConnector(context);
    context.setProtocolFactory(new ProtobaseProtocolFactory());
    context.addSessionEventListener(new LoggerSocketSEListener());
    context.setIoEventHandleAdaptor(eventHandle);
    SocketSession session = connector.connect();
    ProtobaseFuture f = new ProtobaseFutureImpl(connector.getContext(), serviceKey);
    f.write(param);
    session.flush(f);
    ThreadUtil.sleep(500);
    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) SocketSession(com.generallycloud.baseio.component.SocketSession) ServerConfiguration(com.generallycloud.baseio.configuration.ServerConfiguration) 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) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext) SocketChannelContext(com.generallycloud.baseio.component.SocketChannelContext) NioSocketChannelContext(com.generallycloud.baseio.component.NioSocketChannelContext)

Example 12 with ProtobaseFuture

use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture in project baseio by generallycloud.

the class RTPClient method createRoom.

public boolean createRoom(String inviteUsername) throws RTPException {
    ProtobaseFuture future;
    try {
        future = session.request(RTPCreateRoomServlet.SERVICE_NAME, null);
    } catch (IOException e) {
        throw new RTPException(e.getMessage(), e);
    }
    String roomId = future.getReadText();
    if ("-1".equals(roomId)) {
        throw new RTPException("create room failed");
    }
    this.roomId = roomId;
    this.inviteCustomer(inviteUsername);
    return true;
}
Also used : ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) RTPException(com.generallycloud.baseio.container.rtp.RTPException) IOException(java.io.IOException)

Example 13 with ProtobaseFuture

use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture in project baseio by generallycloud.

the class DefaultMessageConsumer method transactionVal.

private boolean transactionVal(String action) throws MQException {
    try {
        WaiterOnFuture onReadFuture = new WaiterOnFuture();
        session.listen(MQTransactionServlet.SERVICE_NAME, onReadFuture);
        session.write(MQTransactionServlet.SERVICE_NAME, action);
        if (onReadFuture.await(3000)) {
            throw MQException.TIME_OUT;
        }
        ProtobaseFuture future = (ProtobaseFuture) onReadFuture.getReadFuture();
        RESMessage message = RESMessageDecoder.decode(future.getReadText());
        if (message.getCode() == 0) {
            return true;
        } else {
            throw new MQException(message.getDescription());
        }
    } catch (IOException e) {
        throw new MQException(e.getMessage(), e);
    }
}
Also used : ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) MQException(com.generallycloud.baseio.container.jms.MQException) RESMessage(com.generallycloud.baseio.container.RESMessage) IOException(java.io.IOException) WaiterOnFuture(com.generallycloud.baseio.container.WaiterOnFuture)

Example 14 with ProtobaseFuture

use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture in project baseio by generallycloud.

the class DefaultMessageProducer method offer.

private boolean offer(Message message, String serviceName) throws MQException {
    String param = message.toString();
    ProtobaseFuture future = null;
    int msgType = message.getMsgType();
    try {
        if (msgType == Message.TYPE_TEXT || msgType == Message.TYPE_MAP) {
            future = session.request(serviceName, param);
        } else if (msgType == Message.TYPE_TEXT_BYTE || msgType == Message.TYPE_MAP_BYTE) {
            BytedMessage _message = (BytedMessage) message;
            future = session.request(serviceName, param, _message.getByteArray());
        } else {
            throw new MQException("msgType:" + msgType);
        }
    } catch (IOException e) {
        throw new MQException(e.getMessage(), e);
    }
    String result = future.getReadText();
    if (result.length() == 1) {
        return "T".equals(result);
    }
    throw new MQException(result);
}
Also used : ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) MQException(com.generallycloud.baseio.container.jms.MQException) IOException(java.io.IOException) BytedMessage(com.generallycloud.baseio.container.jms.BytedMessage)

Example 15 with ProtobaseFuture

use of com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture in project baseio by generallycloud.

the class Consumer method push.

// FIXME push 失败时对message进行回收,并移除Consumer
public void push(Message message) throws IOException {
    this.message = message;
    TransactionSection section = attachment.getTransactionSection();
    if (section != null) {
        section.offerMessage(message);
    }
    int msgType = message.getMsgType();
    String content = message.toString();
    SocketSession session = this.session;
    ProtobaseFuture f = new ProtobaseFutureImpl(session.getContext(), future.getFutureId(), future.getFutureName());
    f.write(content);
    if (msgType == Message.TYPE_TEXT || msgType == Message.TYPE_MAP) {
        session.flush(f);
    } else if (msgType == Message.TYPE_TEXT_BYTE || msgType == Message.TYPE_MAP_BYTE) {
        BytedMessage byteMessage = (BytedMessage) message;
        byte[] bytes = byteMessage.getByteArray();
        f.writeBinary(bytes);
        session.flush(f);
    }
}
Also used : ProtobaseFuture(com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture) SocketSession(com.generallycloud.baseio.component.SocketSession) ProtobaseFutureImpl(com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl) BytedMessage(com.generallycloud.baseio.container.jms.BytedMessage)

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