Search in sources :

Example 6 with MergedWarpMessage

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);
}
Also used : MergedWarpMessage(io.seata.core.protocol.MergedWarpMessage) ByteBuffer(java.nio.ByteBuffer)

Example 7 with MergedWarpMessage

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());
}
Also used : MergedWarpMessageProto(io.seata.serializer.protobuf.generated.MergedWarpMessageProto) GlobalBeginRequest(io.seata.core.protocol.transaction.GlobalBeginRequest) AbstractMessage(io.seata.core.protocol.AbstractMessage) ArrayList(java.util.ArrayList) MergedWarpMessage(io.seata.core.protocol.MergedWarpMessage) Test(org.junit.jupiter.api.Test)

Example 8 with MergedWarpMessage

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);
    }
}
Also used : RpcContext(io.seata.core.rpc.RpcContext) AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) AbstractMessage(io.seata.core.protocol.AbstractMessage) MergedWarpMessage(io.seata.core.protocol.MergedWarpMessage) MergeResultMessage(io.seata.core.protocol.MergeResultMessage)

Example 9 with MergedWarpMessage

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);
    }
}
Also used : AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) AbstractMessage(io.seata.core.protocol.AbstractMessage) MergedWarpMessage(io.seata.core.protocol.MergedWarpMessage) MergeResultMessage(io.seata.core.protocol.MergeResultMessage)

Aggregations

MergedWarpMessage (io.seata.core.protocol.MergedWarpMessage)9 AbstractMessage (io.seata.core.protocol.AbstractMessage)6 AbstractResultMessage (io.seata.core.protocol.AbstractResultMessage)3 MergeResultMessage (io.seata.core.protocol.MergeResultMessage)3 ArrayList (java.util.ArrayList)3 Any (com.google.protobuf.Any)2 GlobalBeginRequest (io.seata.core.protocol.transaction.GlobalBeginRequest)2 MergedWarpMessageProto (io.seata.serializer.protobuf.generated.MergedWarpMessageProto)2 Test (org.junit.jupiter.api.Test)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Message (com.google.protobuf.Message)1 ByteBuf (io.netty.buffer.ByteBuf)1 ShouldNeverHappenException (io.seata.common.exception.ShouldNeverHappenException)1 MessageFuture (io.seata.core.protocol.MessageFuture)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