Search in sources :

Example 11 with AbstractMessage

use of io.seata.core.protocol.AbstractMessage 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 12 with AbstractMessage

use of io.seata.core.protocol.AbstractMessage 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

AbstractMessage (io.seata.core.protocol.AbstractMessage)12 MergedWarpMessage (io.seata.core.protocol.MergedWarpMessage)6 AbstractResultMessage (io.seata.core.protocol.AbstractResultMessage)5 ArrayList (java.util.ArrayList)5 MergeResultMessage (io.seata.core.protocol.MergeResultMessage)4 MessageSeataCodec (io.seata.serializer.seata.MessageSeataCodec)4 Any (com.google.protobuf.Any)2 Message (com.google.protobuf.Message)2 ByteBuf (io.netty.buffer.ByteBuf)2 GlobalBeginRequest (io.seata.core.protocol.transaction.GlobalBeginRequest)2 AbstractMessageProto (io.seata.serializer.protobuf.generated.AbstractMessageProto)2 MergedWarpMessageProto (io.seata.serializer.protobuf.generated.MergedWarpMessageProto)2 ByteBuffer (java.nio.ByteBuffer)2 Test (org.junit.jupiter.api.Test)2 RpcContext (io.seata.core.rpc.RpcContext)1 MergedResultMessageProto (io.seata.serializer.protobuf.generated.MergedResultMessageProto)1