Search in sources :

Example 1 with MergeResultMessage

use of io.seata.core.protocol.MergeResultMessage in project seata by seata.

the class ClientOnResponseProcessor method process.

@Override
public void process(ChannelHandlerContext ctx, RpcMessage rpcMessage) throws Exception {
    if (rpcMessage.getBody() instanceof MergeResultMessage) {
        MergeResultMessage results = (MergeResultMessage) rpcMessage.getBody();
        MergedWarpMessage mergeMessage = (MergedWarpMessage) mergeMsgMap.remove(rpcMessage.getId());
        for (int i = 0; i < mergeMessage.msgs.size(); i++) {
            int msgId = mergeMessage.msgIds.get(i);
            MessageFuture future = futures.remove(msgId);
            if (future == null) {
                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info("msg: {} is not found in futures.", msgId);
                }
            } else {
                future.setResultMessage(results.getMsgs()[i]);
            }
        }
    } else {
        MessageFuture messageFuture = futures.remove(rpcMessage.getId());
        if (messageFuture != null) {
            messageFuture.setResultMessage(rpcMessage.getBody());
        } else {
            if (rpcMessage.getBody() instanceof AbstractResultMessage) {
                if (transactionMessageHandler != null) {
                    transactionMessageHandler.onResponse((AbstractResultMessage) rpcMessage.getBody(), null);
                }
            }
        }
    }
}
Also used : AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) MergeResultMessage(io.seata.core.protocol.MergeResultMessage) MergedWarpMessage(io.seata.core.protocol.MergedWarpMessage) MessageFuture(io.seata.core.protocol.MessageFuture)

Example 2 with MergeResultMessage

use of io.seata.core.protocol.MergeResultMessage in project seata by seata.

the class MergeResultMessageConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    MergeResultMessage mergeResultMessage = new MergeResultMessage();
    AbstractResultMessage[] msgs = new AbstractResultMessage[1];
    final GlobalCommitResponse globalCommitResponse = new GlobalCommitResponse();
    globalCommitResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
    globalCommitResponse.setMsg("msg");
    globalCommitResponse.setResultCode(ResultCode.Failed);
    globalCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRegisterFailed);
    msgs[0] = globalCommitResponse;
    mergeResultMessage.setMsgs(msgs);
    MergeResultMessageConvertor convertor = new MergeResultMessageConvertor();
    MergedResultMessageProto proto = convertor.convert2Proto(mergeResultMessage);
    MergeResultMessage real = convertor.convert2Model(proto);
    GlobalCommitResponse realObj = (GlobalCommitResponse) real.getMsgs()[0];
    assertThat((realObj.getTypeCode())).isEqualTo(globalCommitResponse.getTypeCode());
    assertThat((realObj.getMsg())).isEqualTo(globalCommitResponse.getMsg());
    assertThat((realObj.getResultCode())).isEqualTo(globalCommitResponse.getResultCode());
    assertThat((realObj.getTransactionExceptionCode())).isEqualTo(globalCommitResponse.getTransactionExceptionCode());
}
Also used : AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) GlobalCommitResponse(io.seata.core.protocol.transaction.GlobalCommitResponse) MergeResultMessage(io.seata.core.protocol.MergeResultMessage) MergedResultMessageProto(io.seata.serializer.protobuf.generated.MergedResultMessageProto) Test(org.junit.jupiter.api.Test)

Example 3 with MergeResultMessage

use of io.seata.core.protocol.MergeResultMessage in project seata by seata.

the class MergeResultMessageConvertor method convert2Proto.

@Override
public MergedResultMessageProto convert2Proto(MergeResultMessage mergeResultMessage) {
    final short typeCode = mergeResultMessage.getTypeCode();
    final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(MessageTypeProto.forNumber(typeCode)).build();
    List<Any> lists = new ArrayList<>();
    for (AbstractMessage msg : mergeResultMessage.msgs) {
        final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor(msg.getClass().getName());
        lists.add(Any.pack((Message) pbConvertor.convert2Proto(msg)));
    }
    MergedResultMessageProto mergedWarpMessageProto = MergedResultMessageProto.newBuilder().setAbstractMessage(abstractMessage).addAllMsgs(lists).build();
    return mergedWarpMessageProto;
}
Also used : AbstractMessage(io.seata.core.protocol.AbstractMessage) MergeResultMessage(io.seata.core.protocol.MergeResultMessage) AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) AbstractMessage(io.seata.core.protocol.AbstractMessage) Message(com.google.protobuf.Message) ArrayList(java.util.ArrayList) Any(com.google.protobuf.Any) AbstractMessageProto(io.seata.serializer.protobuf.generated.AbstractMessageProto) MergedResultMessageProto(io.seata.serializer.protobuf.generated.MergedResultMessageProto)

Example 4 with MergeResultMessage

use of io.seata.core.protocol.MergeResultMessage in project seata by seata.

the class MergeResultMessageConvertor method convert2Model.

@Override
public MergeResultMessage convert2Model(MergedResultMessageProto mergedResultMessageProto) {
    MergeResultMessage result = new MergeResultMessage();
    List<Any> anys = mergedResultMessageProto.getMsgsList();
    List<AbstractResultMessage> temp = new ArrayList<>();
    for (Any any : anys) {
        final Class clazz = ProtobufConvertManager.getInstance().fetchProtoClass(getTypeNameFromTypeUrl(any.getTypeUrl()));
        if (any.is(clazz)) {
            try {
                Object ob = any.unpack(clazz);
                final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchReversedConvertor(clazz.getName());
                Object model = pbConvertor.convert2Model(ob);
                temp.add((AbstractResultMessage) model);
            } catch (InvalidProtocolBufferException e) {
                throw new ShouldNeverHappenException(e);
            }
        }
    }
    result.setMsgs(temp.toArray(new AbstractResultMessage[temp.size()]));
    return result;
}
Also used : AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) ArrayList(java.util.ArrayList) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ShouldNeverHappenException(io.seata.common.exception.ShouldNeverHappenException) MergeResultMessage(io.seata.core.protocol.MergeResultMessage) Any(com.google.protobuf.Any)

Example 5 with MergeResultMessage

use of io.seata.core.protocol.MergeResultMessage in project seata by seata.

the class MergeResultMessageCodec method decode.

@Override
public <T> void decode(T t, ByteBuffer in) {
    MergeResultMessage mergeResultMessage = (MergeResultMessage) t;
    if (in.remaining() < 4) {
        return;
    }
    int length = in.getInt();
    if (in.remaining() < length) {
        return;
    }
    byte[] buffer = new byte[length];
    in.get(buffer);
    ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
    decode(mergeResultMessage, byteBuffer);
}
Also used : MergeResultMessage(io.seata.core.protocol.MergeResultMessage) ByteBuffer(java.nio.ByteBuffer)

Aggregations

MergeResultMessage (io.seata.core.protocol.MergeResultMessage)9 AbstractResultMessage (io.seata.core.protocol.AbstractResultMessage)8 AbstractMessage (io.seata.core.protocol.AbstractMessage)4 MergedWarpMessage (io.seata.core.protocol.MergedWarpMessage)3 Any (com.google.protobuf.Any)2 MergedResultMessageProto (io.seata.serializer.protobuf.generated.MergedResultMessageProto)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Message (com.google.protobuf.Message)1 ShouldNeverHappenException (io.seata.common.exception.ShouldNeverHappenException)1 MessageFuture (io.seata.core.protocol.MessageFuture)1 GlobalBeginResponse (io.seata.core.protocol.transaction.GlobalBeginResponse)1 GlobalCommitResponse (io.seata.core.protocol.transaction.GlobalCommitResponse)1 RpcContext (io.seata.core.rpc.RpcContext)1 AbstractMessageProto (io.seata.serializer.protobuf.generated.AbstractMessageProto)1 MessageSeataCodec (io.seata.serializer.seata.MessageSeataCodec)1 ByteBuffer (java.nio.ByteBuffer)1