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);
}
}
}
}
}
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());
}
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;
}
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;
}
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);
}
Aggregations