use of io.seata.core.rpc.RpcContext in project seata by seata.
the class ChannelManager method updateChannelsResource.
private static void updateChannelsResource(String resourceId, String clientIp, String applicationId) {
ConcurrentMap<Integer, RpcContext> sourcePortMap = RM_CHANNELS.get(resourceId).get(applicationId).get(clientIp);
for (ConcurrentMap.Entry<String, ConcurrentMap<String, ConcurrentMap<String, ConcurrentMap<Integer, RpcContext>>>> rmChannelEntry : RM_CHANNELS.entrySet()) {
if (rmChannelEntry.getKey().equals(resourceId)) {
continue;
}
ConcurrentMap<String, ConcurrentMap<String, ConcurrentMap<Integer, RpcContext>>> applicationIdMap = rmChannelEntry.getValue();
if (!applicationIdMap.containsKey(applicationId)) {
continue;
}
ConcurrentMap<String, ConcurrentMap<Integer, RpcContext>> clientIpMap = applicationIdMap.get(applicationId);
if (!clientIpMap.containsKey(clientIp)) {
continue;
}
ConcurrentMap<Integer, RpcContext> portMap = clientIpMap.get(clientIp);
for (ConcurrentMap.Entry<Integer, RpcContext> portMapEntry : portMap.entrySet()) {
Integer port = portMapEntry.getKey();
if (!sourcePortMap.containsKey(port)) {
RpcContext rpcContext = portMapEntry.getValue();
sourcePortMap.put(port, rpcContext);
rpcContext.holdInResourceManagerChannels(resourceId, port);
}
}
}
}
use of io.seata.core.rpc.RpcContext in project seata by seata.
the class ChannelManager method buildChannelHolder.
private static RpcContext buildChannelHolder(NettyPoolKey.TransactionRole clientRole, String version, String applicationId, String txServiceGroup, String dbkeys, Channel channel) {
RpcContext holder = new RpcContext();
holder.setClientRole(clientRole);
holder.setVersion(version);
holder.setClientId(buildClientId(applicationId, channel));
holder.setApplicationId(applicationId);
holder.setTransactionServiceGroup(txServiceGroup);
holder.addResources(dbKeytoSet(dbkeys));
holder.setChannel(channel);
return holder;
}
use of io.seata.core.rpc.RpcContext in project seata by seata.
the class ChannelManager method getSameClientChannel.
/**
* Gets get same income client channel.
*
* @param channel the channel
* @return the get same income client channel
*/
public static Channel getSameClientChannel(Channel channel) {
if (channel.isActive()) {
return channel;
}
RpcContext rpcContext = getContextFromIdentified(channel);
if (rpcContext == null) {
LOGGER.error("rpcContext is null,channel:{},active:{}", channel, channel.isActive());
return null;
}
if (rpcContext.getChannel().isActive()) {
// recheck
return rpcContext.getChannel();
}
Integer clientPort = ChannelUtil.getClientPortFromChannel(channel);
NettyPoolKey.TransactionRole clientRole = rpcContext.getClientRole();
if (clientRole == NettyPoolKey.TransactionRole.TMROLE) {
String clientIdentified = rpcContext.getApplicationId() + Constants.CLIENT_ID_SPLIT_CHAR + ChannelUtil.getClientIpFromChannel(channel);
if (!TM_CHANNELS.containsKey(clientIdentified)) {
return null;
}
ConcurrentMap<Integer, RpcContext> clientRpcMap = TM_CHANNELS.get(clientIdentified);
return getChannelFromSameClientMap(clientRpcMap, clientPort);
} else if (clientRole == NettyPoolKey.TransactionRole.RMROLE) {
for (Map<Integer, RpcContext> clientRmMap : rpcContext.getClientRMHolderMap().values()) {
Channel sameClientChannel = getChannelFromSameClientMap(clientRmMap, clientPort);
if (sameClientChannel != null) {
return sameClientChannel;
}
}
}
return null;
}
use of io.seata.core.rpc.RpcContext in project seata by seata.
the class ServerOnResponseProcessor method onResponseMessage.
private void onResponseMessage(ChannelHandlerContext ctx, RpcMessage rpcMessage) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("server received:{},clientIp:{},vgroup:{}", rpcMessage.getBody(), NetUtil.toIpAddress(ctx.channel().remoteAddress()), ChannelManager.getContextFromIdentified(ctx.channel()).getTransactionServiceGroup());
} else {
try {
BatchLogHandler.INSTANCE.getLogQueue().put(rpcMessage.getBody() + ",clientIp:" + NetUtil.toIpAddress(ctx.channel().remoteAddress()) + ",vgroup:" + ChannelManager.getContextFromIdentified(ctx.channel()).getTransactionServiceGroup());
} catch (InterruptedException e) {
LOGGER.error("put message to logQueue error: {}", e.getMessage(), e);
}
}
if (rpcMessage.getBody() instanceof AbstractResultMessage) {
RpcContext rpcContext = ChannelManager.getContextFromIdentified(ctx.channel());
transactionMessageHandler.onResponse((AbstractResultMessage) rpcMessage.getBody(), rpcContext);
}
}
use of io.seata.core.rpc.RpcContext 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);
}
}
Aggregations