In native scenarios, Compiler and Proxy are set to jdk by default (#12530)
* In native scenarios, Compiler and Proxy are set to jdk by default Signed-off-by: crazyhzm <crazyhzm@gmail.com> * Fix UT Signed-off-by: crazyhzm <crazyhzm@gmail.com> --------- Signed-off-by: crazyhzm <crazyhzm@gmail.com>
This commit is contained in:
parent
fd14e7b76f
commit
1e59ab524a
|
|
@ -19,6 +19,7 @@ package org.apache.dubbo.config;
|
|||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.Version;
|
||||
import org.apache.dubbo.common.aot.NativeDetector;
|
||||
import org.apache.dubbo.common.compiler.support.AdaptiveCompiler;
|
||||
import org.apache.dubbo.common.config.ConfigurationUtils;
|
||||
import org.apache.dubbo.common.config.Environment;
|
||||
import org.apache.dubbo.common.config.InmemoryConfiguration;
|
||||
|
|
@ -55,6 +56,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
|
|||
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
|
||||
import static org.apache.dubbo.common.constants.LoggerCodeConstants.CONFIG_NO_METHOD_FOUND;
|
||||
import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMETHEUS;
|
||||
import static org.apache.dubbo.config.Constants.DEFAULT_NATIVE_PROXY;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -255,7 +257,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
for (RegistryConfig registryConfig : registries) {
|
||||
if (!registryConfig.isValid()) {
|
||||
throw new IllegalStateException("No registry config found or it's not a valid config! " +
|
||||
"The registry config is: " + registryConfig);
|
||||
"The registry config is: " + registryConfig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -343,7 +345,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
java.lang.reflect.Parameter[] arguments = method.getParameters();
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
if (getArgumentByIndex(methodConfig, i) == null &&
|
||||
hasArgumentConfigProps(configProperties, methodConfig.getName(), i)) {
|
||||
hasArgumentConfigProps(configProperties, methodConfig.getName(), i)) {
|
||||
|
||||
ArgumentConfig argumentConfig = new ArgumentConfig();
|
||||
argumentConfig.setIndex(i);
|
||||
|
|
@ -358,7 +360,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
if (methodConfigs != null && methodConfigs.size() > 0) {
|
||||
// whether ignore invalid method config
|
||||
Object ignoreInvalidMethodConfigVal = getEnvironment().getConfiguration()
|
||||
.getProperty(ConfigKeys.DUBBO_CONFIG_IGNORE_INVALID_METHOD_CONFIG, "false");
|
||||
.getProperty(ConfigKeys.DUBBO_CONFIG_IGNORE_INVALID_METHOD_CONFIG, "false");
|
||||
boolean ignoreInvalidMethodConfig = Boolean.parseBoolean(ignoreInvalidMethodConfigVal.toString());
|
||||
|
||||
Class<?> finalInterfaceClass = interfaceClass;
|
||||
|
|
@ -389,8 +391,8 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
String methodName = methodConfig.getName();
|
||||
if (StringUtils.isEmpty(methodName)) {
|
||||
String msg = "<dubbo:method> name attribute is required! Please check: " +
|
||||
"<dubbo:service interface=\"" + interfaceName + "\" ... >" +
|
||||
"<dubbo:method name=\"\" ... /></<dubbo:reference>";
|
||||
"<dubbo:service interface=\"" + interfaceName + "\" ... >" +
|
||||
"<dubbo:method name=\"\" ... /></<dubbo:reference>";
|
||||
if (ignoreInvalidMethodConfig) {
|
||||
logger.warn(CONFIG_NO_METHOD_FOUND, "", "", msg);
|
||||
return false;
|
||||
|
|
@ -402,7 +404,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
boolean hasMethod = Arrays.stream(interfaceClass.getMethods()).anyMatch(method -> method.getName().equals(methodName));
|
||||
if (!hasMethod) {
|
||||
String msg = "Found invalid method config, the interface " + interfaceClass.getName() + " not found method \""
|
||||
+ methodName + "\" : [" + methodConfig + "]";
|
||||
+ methodName + "\" : [" + methodConfig + "]";
|
||||
if (ignoreInvalidMethodConfig) {
|
||||
logger.warn(CONFIG_NO_METHOD_FOUND, "", "", msg);
|
||||
return false;
|
||||
|
|
@ -464,7 +466,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
private void verifyStubAndLocal(String className, String label, Class<?> interfaceClass) {
|
||||
if (ConfigUtils.isNotEmpty(className)) {
|
||||
Class<?> localClass = ConfigUtils.isDefault(className) ?
|
||||
ReflectUtils.forName(interfaceClass.getName() + label) : ReflectUtils.forName(className);
|
||||
ReflectUtils.forName(interfaceClass.getName() + label) : ReflectUtils.forName(className);
|
||||
verify(interfaceClass, localClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -472,7 +474,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
private void verify(Class<?> interfaceClass, Class<?> localClass) {
|
||||
if (!interfaceClass.isAssignableFrom(localClass)) {
|
||||
throw new IllegalStateException("The local implementation class " + localClass.getName() +
|
||||
" not implement interface " + interfaceClass.getName());
|
||||
" not implement interface " + interfaceClass.getName());
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -480,7 +482,7 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
ReflectUtils.findConstructor(localClass, interfaceClass);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new IllegalStateException("No such constructor \"public " + localClass.getSimpleName() +
|
||||
"(" + interfaceClass.getName() + ")\" in local implementation class " + localClass.getName());
|
||||
"(" + interfaceClass.getName() + ")\" in local implementation class " + localClass.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -612,11 +614,20 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
|
|||
}
|
||||
|
||||
public String getProxy() {
|
||||
return proxy;
|
||||
if (NativeDetector.inNativeImage()) {
|
||||
return DEFAULT_NATIVE_PROXY;
|
||||
} else {
|
||||
return this.proxy;
|
||||
}
|
||||
}
|
||||
|
||||
public void setProxy(String proxy) {
|
||||
this.proxy = proxy;
|
||||
if (NativeDetector.inNativeImage()) {
|
||||
this.proxy = DEFAULT_NATIVE_PROXY;
|
||||
AdaptiveCompiler.setDefaultCompiler(DEFAULT_NATIVE_PROXY);
|
||||
} else {
|
||||
this.proxy = proxy;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getConnections() {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.dubbo.config;
|
||||
|
||||
import org.apache.dubbo.common.aot.NativeDetector;
|
||||
import org.apache.dubbo.common.compiler.support.AdaptiveCompiler;
|
||||
import org.apache.dubbo.common.infra.InfraAdapter;
|
||||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
|
|
@ -66,6 +67,7 @@ import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT;
|
|||
import static org.apache.dubbo.common.constants.QosConstants.QOS_PORT_COMPATIBLE;
|
||||
import static org.apache.dubbo.common.constants.RegistryConstants.ENABLE_EMPTY_PROTECTION_KEY;
|
||||
import static org.apache.dubbo.common.constants.RegistryConstants.REGISTER_MODE_KEY;
|
||||
import static org.apache.dubbo.config.Constants.DEFAULT_NATIVE_COMPILER;
|
||||
import static org.apache.dubbo.config.Constants.DEVELOPMENT_ENVIRONMENT;
|
||||
import static org.apache.dubbo.config.Constants.PRODUCTION_ENVIRONMENT;
|
||||
import static org.apache.dubbo.config.Constants.TEST_ENVIRONMENT;
|
||||
|
|
@ -275,7 +277,7 @@ public class ApplicationConfig extends AbstractConfig {
|
|||
try {
|
||||
hostname = InetAddress.getLocalHost().getHostName();
|
||||
} catch (UnknownHostException e) {
|
||||
LOGGER.warn(COMMON_UNEXPECTED_EXCEPTION,"","","Failed to get the hostname of current instance.", e);
|
||||
LOGGER.warn(COMMON_UNEXPECTED_EXCEPTION, "", "", "Failed to get the hostname of current instance.", e);
|
||||
hostname = "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
|
@ -335,15 +337,15 @@ public class ApplicationConfig extends AbstractConfig {
|
|||
|
||||
public void setEnvironment(String environment) {
|
||||
if (environment != null && !(DEVELOPMENT_ENVIRONMENT.equals(environment)
|
||||
|| TEST_ENVIRONMENT.equals(environment)
|
||||
|| PRODUCTION_ENVIRONMENT.equals(environment))) {
|
||||
|| TEST_ENVIRONMENT.equals(environment)
|
||||
|| PRODUCTION_ENVIRONMENT.equals(environment))) {
|
||||
|
||||
throw new IllegalStateException(String.format("Unsupported environment: %s, only support %s/%s/%s, default is %s.",
|
||||
environment,
|
||||
DEVELOPMENT_ENVIRONMENT,
|
||||
TEST_ENVIRONMENT,
|
||||
PRODUCTION_ENVIRONMENT,
|
||||
PRODUCTION_ENVIRONMENT));
|
||||
environment,
|
||||
DEVELOPMENT_ENVIRONMENT,
|
||||
TEST_ENVIRONMENT,
|
||||
PRODUCTION_ENVIRONMENT,
|
||||
PRODUCTION_ENVIRONMENT));
|
||||
}
|
||||
this.environment = environment;
|
||||
}
|
||||
|
|
@ -389,12 +391,22 @@ public class ApplicationConfig extends AbstractConfig {
|
|||
}
|
||||
|
||||
public String getCompiler() {
|
||||
return compiler;
|
||||
if (NativeDetector.inNativeImage()) {
|
||||
return DEFAULT_NATIVE_COMPILER;
|
||||
} else {
|
||||
return compiler;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCompiler(String compiler) {
|
||||
this.compiler = compiler;
|
||||
AdaptiveCompiler.setDefaultCompiler(compiler);
|
||||
|
||||
if (NativeDetector.inNativeImage()) {
|
||||
this.compiler = DEFAULT_NATIVE_COMPILER;
|
||||
AdaptiveCompiler.setDefaultCompiler(DEFAULT_NATIVE_COMPILER);
|
||||
} else {
|
||||
this.compiler = compiler;
|
||||
AdaptiveCompiler.setDefaultCompiler(compiler);
|
||||
}
|
||||
}
|
||||
|
||||
public String getLogger() {
|
||||
|
|
|
|||
|
|
@ -152,4 +152,8 @@ public interface Constants {
|
|||
String CLIENT_THREAD_POOL_NAME = "DubboClientHandler";
|
||||
|
||||
String REST_PROTOCOL="rest";
|
||||
|
||||
String DEFAULT_NATIVE_COMPILER="jdk";
|
||||
|
||||
String DEFAULT_NATIVE_PROXY="jdk";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue