RainYuY commented on code in PR #15406: URL: https://github.com/apache/dubbo/pull/15406#discussion_r2268637234
########## dubbo-plugin/dubbo-mcp/src/main/java/org/apache/dubbo/mcp/tool/DubboMcpGenericCaller.java: ########## @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.dubbo.mcp.tool; + +import org.apache.dubbo.common.logger.ErrorTypeAwareLogger; +import org.apache.dubbo.common.logger.LoggerFactory; +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.rpc.model.ApplicationModel; +import org.apache.dubbo.rpc.service.GenericService; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION; + +public class DubboMcpGenericCaller { + + private static final ErrorTypeAwareLogger logger = + LoggerFactory.getErrorTypeAwareLogger(DubboMcpGenericCaller.class); + + private final ApplicationConfig applicationConfig; + + private final Map<String, GenericService> serviceCache = new ConcurrentHashMap<>(); + + public DubboMcpGenericCaller(ApplicationModel applicationModel) { + if (applicationModel == null) { + logger.error( + COMMON_UNEXPECTED_EXCEPTION, "", "", "ApplicationModel cannot be null for DubboMcpGenericCaller."); + throw new IllegalArgumentException("ApplicationModel cannot be null."); + } + this.applicationConfig = applicationModel.getCurrentConfig(); + if (this.applicationConfig == null) { + + String errMsg = "ApplicationConfig is null in the provided ApplicationModel. Application Name: " + + (applicationModel.getApplicationName() != null ? applicationModel.getApplicationName() : "N/A"); + logger.error(COMMON_UNEXPECTED_EXCEPTION, "", "", errMsg); + throw new IllegalStateException(errMsg); + } + } + + public Object execute( + String interfaceName, + String methodName, + List<String> orderedJavaParameterNames, + Class<?>[] parameterJavaTypes, + Map<String, Object> mcpProvidedParameters, + String group, + String version) { + String cacheKey = interfaceName + ":" + (group == null ? "" : group) + ":" + (version == null ? "" : version); + GenericService genericService = serviceCache.get(cacheKey); + if (genericService == null) { + ReferenceConfig<GenericService> reference = new ReferenceConfig<>(); + reference.setApplication(this.applicationConfig); + reference.setInterface(interfaceName); + reference.setGeneric("true"); // Defaults to 'bean' or 'true' for POJO generalization. + reference.setScope("local"); Review Comment: Emm... just local is fine, I think, because in Dubbo it has a special meaning. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
