Search in sources :

Example 1 with Version

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

the class ChannelManager method registerRMChannel.

/**
 * Register rm channel.
 *
 * @param resourceManagerRequest the resource manager request
 * @param channel                the channel
 * @throws IncompatibleVersionException the incompatible  version exception
 */
public static void registerRMChannel(RegisterRMRequest resourceManagerRequest, Channel channel) throws IncompatibleVersionException {
    Version.checkVersion(resourceManagerRequest.getVersion());
    Set<String> dbkeySet = dbKeytoSet(resourceManagerRequest.getResourceIds());
    RpcContext rpcContext;
    if (!IDENTIFIED_CHANNELS.containsKey(channel)) {
        rpcContext = buildChannelHolder(NettyPoolKey.TransactionRole.RMROLE, resourceManagerRequest.getVersion(), resourceManagerRequest.getApplicationId(), resourceManagerRequest.getTransactionServiceGroup(), resourceManagerRequest.getResourceIds(), channel);
        rpcContext.holdInIdentifiedChannels(IDENTIFIED_CHANNELS);
    } else {
        rpcContext = IDENTIFIED_CHANNELS.get(channel);
        rpcContext.addResources(dbkeySet);
    }
    if (dbkeySet == null || dbkeySet.isEmpty()) {
        return;
    }
    for (String resourceId : dbkeySet) {
        String clientIp;
        ConcurrentMap<Integer, RpcContext> portMap = CollectionUtils.computeIfAbsent(RM_CHANNELS, resourceId, key -> new ConcurrentHashMap<>()).computeIfAbsent(resourceManagerRequest.getApplicationId(), key -> new ConcurrentHashMap<>()).computeIfAbsent(clientIp = ChannelUtil.getClientIpFromChannel(channel), key -> new ConcurrentHashMap<>());
        rpcContext.holdInResourceManagerChannels(resourceId, portMap);
        updateChannelsResource(resourceId, clientIp, resourceManagerRequest.getApplicationId());
    }
}
Also used : RpcContext(io.seata.core.rpc.RpcContext) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) RpcContext(io.seata.core.rpc.RpcContext) CollectionUtils(io.seata.common.util.CollectionUtils) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) HashMap(java.util.HashMap) Constants(io.seata.common.Constants) ConcurrentMap(java.util.concurrent.ConcurrentMap) Channel(io.netty.channel.Channel) RegisterRMRequest(io.seata.core.protocol.RegisterRMRequest) HashSet(java.util.HashSet) Map(java.util.Map) RegisterTMRequest(io.seata.core.protocol.RegisterTMRequest) FrameworkException(io.seata.common.exception.FrameworkException) StringUtils(io.seata.common.util.StringUtils) Version(io.seata.core.protocol.Version) IncompatibleVersionException(io.seata.core.protocol.IncompatibleVersionException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Channel (io.netty.channel.Channel)1 Constants (io.seata.common.Constants)1 FrameworkException (io.seata.common.exception.FrameworkException)1 CollectionUtils (io.seata.common.util.CollectionUtils)1 StringUtils (io.seata.common.util.StringUtils)1 IncompatibleVersionException (io.seata.core.protocol.IncompatibleVersionException)1 RegisterRMRequest (io.seata.core.protocol.RegisterRMRequest)1 RegisterTMRequest (io.seata.core.protocol.RegisterTMRequest)1 Version (io.seata.core.protocol.Version)1 RpcContext (io.seata.core.rpc.RpcContext)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 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1