Search in sources :

Example 1 with RegisterRMRequest

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

the class RegRmProcessor method onRegRmMessage.

private void onRegRmMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) {
    RegisterRMRequest message = (RegisterRMRequest) rpcMessage.getBody();
    String ipAndPort = NetUtil.toStringAddress(ctx.channel().remoteAddress());
    boolean isSuccess = false;
    String errorInfo = StringUtils.EMPTY;
    try {
        if (null == checkAuthHandler || checkAuthHandler.regResourceManagerCheckAuth(message)) {
            ChannelManager.registerRMChannel(message, ctx.channel());
            Version.putChannelVersion(ctx.channel(), message.getVersion());
            isSuccess = true;
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("checkAuth for client:{},vgroup:{},applicationId:{} is OK", ipAndPort, message.getTransactionServiceGroup(), message.getApplicationId());
            }
        }
    } catch (Exception exx) {
        isSuccess = false;
        errorInfo = exx.getMessage();
        LOGGER.error("RM register fail, error message:{}", errorInfo);
    }
    RegisterRMResponse response = new RegisterRMResponse(isSuccess);
    if (StringUtils.isNotEmpty(errorInfo)) {
        response.setMsg(errorInfo);
    }
    remotingServer.sendAsyncResponse(rpcMessage, ctx.channel(), response);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("RM register success,message:{},channel:{},client version:{}", message, ctx.channel(), message.getVersion());
    }
}
Also used : RegisterRMResponse(io.seata.core.protocol.RegisterRMResponse) RegisterRMRequest(io.seata.core.protocol.RegisterRMRequest)

Example 2 with RegisterRMRequest

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

the class NettyClientChannelManager method doConnect.

private Channel doConnect(String serverAddress) {
    Channel channelToServer = channels.get(serverAddress);
    if (channelToServer != null && channelToServer.isActive()) {
        return channelToServer;
    }
    Channel channelFromPool;
    try {
        NettyPoolKey currentPoolKey = poolKeyFunction.apply(serverAddress);
        NettyPoolKey previousPoolKey = poolKeyMap.putIfAbsent(serverAddress, currentPoolKey);
        if (previousPoolKey != null && previousPoolKey.getMessage() instanceof RegisterRMRequest) {
            RegisterRMRequest registerRMRequest = (RegisterRMRequest) currentPoolKey.getMessage();
            ((RegisterRMRequest) previousPoolKey.getMessage()).setResourceIds(registerRMRequest.getResourceIds());
        }
        channelFromPool = nettyClientKeyPool.borrowObject(poolKeyMap.get(serverAddress));
        channels.put(serverAddress, channelFromPool);
    } catch (Exception exx) {
        LOGGER.error("{} register RM failed.", FrameworkErrorCode.RegisterRM.getErrCode(), exx);
        throw new FrameworkException("can not register RM,err:" + exx.getMessage());
    }
    return channelFromPool;
}
Also used : FrameworkException(io.seata.common.exception.FrameworkException) Channel(io.netty.channel.Channel) RegisterRMRequest(io.seata.core.protocol.RegisterRMRequest) FrameworkException(io.seata.common.exception.FrameworkException)

Example 3 with RegisterRMRequest

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

the class RmNettyRemotingClient method onRegisterMsgFail.

@Override
public void onRegisterMsgFail(String serverAddress, Channel channel, Object response, AbstractMessage requestMessage) {
    RegisterRMRequest registerRMRequest = (RegisterRMRequest) requestMessage;
    RegisterRMResponse registerRMResponse = (RegisterRMResponse) response;
    String errMsg = String.format("register RM failed. client version: %s,server version: %s, errorMsg: %s, " + "channel: %s", registerRMRequest.getVersion(), registerRMResponse.getVersion(), registerRMResponse.getMsg(), channel);
    throw new FrameworkException(errMsg);
}
Also used : FrameworkException(io.seata.common.exception.FrameworkException) RegisterRMResponse(io.seata.core.protocol.RegisterRMResponse) RegisterRMRequest(io.seata.core.protocol.RegisterRMRequest)

Example 4 with RegisterRMRequest

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

the class RmNettyRemotingClient method sendRegisterMessage.

public void sendRegisterMessage(String serverAddress, Channel channel, String resourceId) {
    RegisterRMRequest message = new RegisterRMRequest(applicationId, transactionServiceGroup);
    message.setResourceIds(resourceId);
    try {
        super.sendAsyncRequest(channel, message);
    } catch (FrameworkException e) {
        if (e.getErrcode() == FrameworkErrorCode.ChannelIsNotWritable && serverAddress != null) {
            getClientChannelManager().releaseChannel(channel, serverAddress);
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("remove not writable channel:{}", channel);
            }
        } else {
            LOGGER.error("register resource failed, channel:{},resourceId:{}", channel, resourceId, e);
        }
    }
}
Also used : FrameworkException(io.seata.common.exception.FrameworkException) RegisterRMRequest(io.seata.core.protocol.RegisterRMRequest)

Example 5 with RegisterRMRequest

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

the class DefaultServerMessageListenerImpl method onRegRmMessage.

@Override
public void onRegRmMessage(RpcMessage request, ChannelHandlerContext ctx, RegisterCheckAuthHandler checkAuthHandler) {
    RegisterRMRequest message = (RegisterRMRequest) request.getBody();
    String ipAndPort = NetUtil.toStringAddress(ctx.channel().remoteAddress());
    boolean isSuccess = false;
    String errorInfo = StringUtils.EMPTY;
    try {
        if (checkAuthHandler == null || checkAuthHandler.regResourceManagerCheckAuth(message)) {
            ChannelManager.registerRMChannel(message, ctx.channel());
            Version.putChannelVersion(ctx.channel(), message.getVersion());
            isSuccess = true;
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("checkAuth for client:{},vgroup:{},applicationId:{} is OK", ipAndPort, message.getTransactionServiceGroup(), message.getApplicationId());
            }
        }
    } catch (Exception exx) {
        isSuccess = false;
        errorInfo = exx.getMessage();
        LOGGER.error("RM register fail, error message:{}", errorInfo);
    }
    RegisterRMResponse response = new RegisterRMResponse(isSuccess);
    if (StringUtils.isNotEmpty(errorInfo)) {
        response.setMsg(errorInfo);
    }
    getServerMessageSender().sendAsyncResponse(request, ctx.channel(), response);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("RM register success,message:{},channel:{},client version:{}", message, ctx.channel(), message.getVersion());
    }
}
Also used : RegisterRMResponse(io.seata.core.protocol.RegisterRMResponse) RegisterRMRequest(io.seata.core.protocol.RegisterRMRequest)

Aggregations

RegisterRMRequest (io.seata.core.protocol.RegisterRMRequest)12 FrameworkException (io.seata.common.exception.FrameworkException)4 RegisterRMResponse (io.seata.core.protocol.RegisterRMResponse)4 Channel (io.netty.channel.Channel)2 Test (org.junit.jupiter.api.Test)2 Constants (io.seata.common.Constants)1 CollectionUtils (io.seata.common.util.CollectionUtils)1 StringUtils (io.seata.common.util.StringUtils)1 IncompatibleVersionException (io.seata.core.protocol.IncompatibleVersionException)1 RegisterTMRequest (io.seata.core.protocol.RegisterTMRequest)1 Version (io.seata.core.protocol.Version)1 RpcContext (io.seata.core.rpc.RpcContext)1 AbstractIdentifyRequestProto (io.seata.serializer.protobuf.generated.AbstractIdentifyRequestProto)1 RegisterRMRequestProto (io.seata.serializer.protobuf.generated.RegisterRMRequestProto)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1