use of io.seata.core.protocol.MergedWarpMessage in project seata by seata.
the class MergedWarpMessageCodec method decode.
@Override
public <T> void decode(T t, ByteBuffer in) {
MergedWarpMessage mergedWarpMessage = (MergedWarpMessage) 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);
doDecode(mergedWarpMessage, byteBuffer);
}
use of io.seata.core.protocol.MergedWarpMessage in project seata by seata.
the class MergeMessageConvertorTest method test.
@Test
public void test() {
MergedWarpMessage mergedWarpMessage = new MergedWarpMessage();
final ArrayList<AbstractMessage> msgs = new ArrayList<>();
final GlobalBeginRequest globalBeginRequest = buildGlobalBeginRequest();
msgs.add(globalBeginRequest);
mergedWarpMessage.msgs = msgs;
MergedWarpMessageConvertor pbConvertor = new MergedWarpMessageConvertor();
MergedWarpMessageProto globalBeginRequestProto = pbConvertor.convert2Proto(mergedWarpMessage);
MergedWarpMessage model = pbConvertor.convert2Model(globalBeginRequestProto);
GlobalBeginRequest decodeModel = (GlobalBeginRequest) model.msgs.get(0);
assertThat(decodeModel.getTransactionName()).isEqualTo(globalBeginRequest.getTransactionName());
assertThat(decodeModel.getTimeout()).isEqualTo(globalBeginRequest.getTimeout());
assertThat(decodeModel.getTypeCode()).isEqualTo(globalBeginRequest.getTypeCode());
}
use of io.seata.core.protocol.MergedWarpMessage in project seata by seata.
the class ServerOnRequestProcessor method onRequestMessage.
private void onRequestMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) {
Object message = rpcMessage.getBody();
RpcContext rpcContext = ChannelManager.getContextFromIdentified(ctx.channel());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("server received:{},clientIp:{},vgroup:{}", message, NetUtil.toIpAddress(ctx.channel().remoteAddress()), rpcContext.getTransactionServiceGroup());
} else {
try {
BatchLogHandler.INSTANCE.getLogQueue().put(message + ",clientIp:" + NetUtil.toIpAddress(ctx.channel().remoteAddress()) + ",vgroup:" + rpcContext.getTransactionServiceGroup());
} catch (InterruptedException e) {
LOGGER.error("put message to logQueue error: {}", e.getMessage(), e);
}
}
if (!(message instanceof AbstractMessage)) {
return;
}
if (message instanceof MergedWarpMessage) {
AbstractResultMessage[] results = new AbstractResultMessage[((MergedWarpMessage) message).msgs.size()];
for (int i = 0; i < results.length; i++) {
final AbstractMessage subMessage = ((MergedWarpMessage) message).msgs.get(i);
results[i] = transactionMessageHandler.onRequest(subMessage, rpcContext);
}
MergeResultMessage resultMessage = new MergeResultMessage();
resultMessage.setMsgs(results);
remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), resultMessage);
} else {
// the single send request message
final AbstractMessage msg = (AbstractMessage) message;
AbstractResultMessage result = transactionMessageHandler.onRequest(msg, rpcContext);
remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), result);
}
}
use of io.seata.core.protocol.MergedWarpMessage in project seata by seata.
the class DefaultServerMessageListenerImpl method onTrxMessage.
@Override
public void onTrxMessage(RpcMessage request, ChannelHandlerContext ctx) {
Object message = request.getBody();
RpcContext rpcContext = ChannelManager.getContextFromIdentified(ctx.channel());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("server received:{},clientIp:{},vgroup:{}", message, NetUtil.toIpAddress(ctx.channel().remoteAddress()), rpcContext.getTransactionServiceGroup());
} else {
try {
logQueue.put(message + ",clientIp:" + NetUtil.toIpAddress(ctx.channel().remoteAddress()) + ",vgroup:" + rpcContext.getTransactionServiceGroup());
} catch (InterruptedException e) {
LOGGER.error("put message to logQueue error: {}", e.getMessage(), e);
}
}
if (!(message instanceof AbstractMessage)) {
return;
}
if (message instanceof MergedWarpMessage) {
AbstractResultMessage[] results = new AbstractResultMessage[((MergedWarpMessage) message).msgs.size()];
for (int i = 0; i < results.length; i++) {
final AbstractMessage subMessage = ((MergedWarpMessage) message).msgs.get(i);
results[i] = transactionMessageHandler.onRequest(subMessage, rpcContext);
}
MergeResultMessage resultMessage = new MergeResultMessage();
resultMessage.setMsgs(results);
getServerMessageSender().sendAsyncResponse(request, ctx.channel(), resultMessage);
} else if (message instanceof AbstractResultMessage) {
transactionMessageHandler.onResponse((AbstractResultMessage) message, rpcContext);
} else {
// the single send request message
final AbstractMessage msg = (AbstractMessage) message;
AbstractResultMessage result = transactionMessageHandler.onRequest(msg, rpcContext);
getServerMessageSender().sendAsyncResponse(request, ctx.channel(), result);
}
}
Aggregations