Cache jvm system parameters to prevent each call from being executed, affecting performance (#10839)
* Cache jvm system parameters to prevent each call from being executed, affecting performance Signed-off-by: crazyhzm <crazyhzm@gmail.com> * fix npe Signed-off-by: crazyhzm <crazyhzm@gmail.com> * optimization performance Signed-off-by: crazyhzm <crazyhzm@gmail.com> * remove unused import Signed-off-by: crazyhzm <crazyhzm@gmail.com> * add default config value Signed-off-by: crazyhzm <crazyhzm@gmail.com> * change getProperty method Signed-off-by: crazyhzm <crazyhzm@gmail.com> * change convert method Signed-off-by: crazyhzm <crazyhzm@gmail.com> * change getInternalProperty by default value Signed-off-by: crazyhzm <crazyhzm@gmail.com> * add overwrite cache api Signed-off-by: crazyhzm <crazyhzm@gmail.com> * add clear cache api Signed-off-by: crazyhzm <crazyhzm@gmail.com> * fix ut Signed-off-by: crazyhzm <crazyhzm@gmail.com> * fix ut Signed-off-by: crazyhzm <crazyhzm@gmail.com> * fix ut Signed-off-by: crazyhzm <crazyhzm@gmail.com> * reset DubboBootstrap Signed-off-by: crazyhzm <crazyhzm@gmail.com> * change serialization.security.check config to app scopemodel Signed-off-by: crazyhzm <crazyhzm@gmail.com> * fix url without scopemodel Signed-off-by: crazyhzm <crazyhzm@gmail.com> * fix url without scopemodel Signed-off-by: crazyhzm <crazyhzm@gmail.com> Signed-off-by: crazyhzm <crazyhzm@gmail.com>
This commit is contained in:
parent
9b9b12033f
commit
1470c7ca1e
|
|
@ -89,4 +89,20 @@ public class CompositeConfiguration implements Configuration {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
for (Configuration config : configList) {
|
||||
try {
|
||||
Object value = config.getProperty(key, defaultValue);
|
||||
if (!ConfigurationUtils.isEmptyValue(value)) {
|
||||
return value;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error when trying to get value for key " + key + " from " + config + ", " +
|
||||
"will continue to try the next one.");
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,18 +127,19 @@ public interface Configuration {
|
|||
* Gets a property from the configuration. The default value will return if the configuration doesn't contain
|
||||
* the mapping for the specified key.
|
||||
*
|
||||
* @param key property to retrieve
|
||||
* @param key property to retrieve
|
||||
* @param defaultValue default value
|
||||
* @return the value to which this configuration maps the specified key, or default value if the configuration
|
||||
* contains no mapping for this key.
|
||||
*/
|
||||
default Object getProperty(String key, Object defaultValue) {
|
||||
Object value = getInternalProperty(key);
|
||||
return value != null ? value : defaultValue;
|
||||
return getInternalProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
Object getInternalProperty(String key);
|
||||
|
||||
Object getInternalProperty(String key, Object defaultValue);
|
||||
|
||||
/**
|
||||
* Check if the configuration contains the specified key.
|
||||
*
|
||||
|
|
@ -153,9 +154,12 @@ public interface Configuration {
|
|||
|
||||
default <T> T convert(Class<T> cls, String key, T defaultValue) {
|
||||
// we only process String properties for now
|
||||
String value = (String) getProperty(key);
|
||||
Object value = getProperty(key, defaultValue);
|
||||
|
||||
if (value == null) {
|
||||
if (!String.class.isInstance(value)) {
|
||||
if (cls.isInstance(value)) {
|
||||
return cls.cast(value);
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
|
|
@ -164,24 +168,26 @@ public interface Configuration {
|
|||
return cls.cast(value);
|
||||
}
|
||||
|
||||
String str = (String) value;
|
||||
|
||||
if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) {
|
||||
obj = Boolean.valueOf(value);
|
||||
obj = Boolean.valueOf(str);
|
||||
} else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) {
|
||||
if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) {
|
||||
obj = Integer.valueOf(value);
|
||||
obj = Integer.valueOf(str);
|
||||
} else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) {
|
||||
obj = Long.valueOf(value);
|
||||
obj = Long.valueOf(str);
|
||||
} else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) {
|
||||
obj = Byte.valueOf(value);
|
||||
obj = Byte.valueOf(str);
|
||||
} else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) {
|
||||
obj = Short.valueOf(value);
|
||||
obj = Short.valueOf(str);
|
||||
} else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) {
|
||||
obj = Float.valueOf(value);
|
||||
obj = Float.valueOf(str);
|
||||
} else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) {
|
||||
obj = Double.valueOf(value);
|
||||
obj = Double.valueOf(str);
|
||||
}
|
||||
} else if (cls.isEnum()) {
|
||||
obj = Enum.valueOf(cls.asSubclass(Enum.class), value);
|
||||
obj = Enum.valueOf(cls.asSubclass(Enum.class), str);
|
||||
}
|
||||
|
||||
return cls.cast(obj);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,19 @@ public class EnvironmentConfiguration implements Configuration {
|
|||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
String value = System.getenv(key);
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
value = System.getenv(StringUtils.toOSStyleKey(key));
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return System.getenv();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,16 @@ public class InmemoryConfiguration implements Configuration {
|
|||
return store.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = store.get(key);
|
||||
if (v != null) {
|
||||
return v;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add one property into the store, the previous value will be replaced if the key exists
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -68,6 +68,16 @@ public class OrderedPropertiesConfiguration implements Configuration {
|
|||
return properties.getProperty(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = properties.getProperty(key);
|
||||
if (v != null){
|
||||
return v;
|
||||
}else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void setProperty(String key, String value) {
|
||||
properties.setProperty(key, value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,4 +42,17 @@ public class PrefixedConfiguration implements Configuration {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
if (StringUtils.isBlank(prefix)) {
|
||||
return origin.getInternalProperty(key, defaultValue);
|
||||
}
|
||||
|
||||
Object value = origin.getInternalProperty(prefix + "." + key, defaultValue);
|
||||
if (!ConfigurationUtils.isEmptyValue(value)) {
|
||||
return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,16 @@ public class PropertiesConfiguration implements Configuration {
|
|||
return properties.getProperty(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = properties.getProperty(key);
|
||||
if (v != null){
|
||||
return v;
|
||||
}else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public void setProperty(String key, String value) {
|
||||
properties.setProperty(key, value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,17 +18,61 @@ package org.apache.dubbo.common.config;
|
|||
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Configuration from system properties
|
||||
* FIXME: is this really necessary? PropertiesConfiguration should have already covered this:
|
||||
*
|
||||
* @See ConfigUtils#getProperty(String)
|
||||
* @see PropertiesConfiguration
|
||||
*/
|
||||
public class SystemConfiguration implements Configuration {
|
||||
|
||||
private final Map<String, Object> cache = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key) {
|
||||
return System.getProperty(key);
|
||||
if (cache.containsKey(key)) {
|
||||
return cache.get(key);
|
||||
} else {
|
||||
Object val = System.getProperty(key);
|
||||
if (val != null) {
|
||||
cache.putIfAbsent(key, val);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
if (cache.containsKey(key)) {
|
||||
return cache.get(key);
|
||||
} else {
|
||||
Object val = System.getProperty(key);
|
||||
if (val != null) {
|
||||
cache.putIfAbsent(key, val);
|
||||
} else {
|
||||
val = defaultValue;
|
||||
if (defaultValue != null) {
|
||||
cache.putIfAbsent(key, defaultValue);
|
||||
}
|
||||
}
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
public void overwriteCache(String key, Object value) {
|
||||
if (value != null) {
|
||||
cache.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return (Map) System.getProperties();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,6 +120,11 @@ public abstract class AbstractDynamicConfiguration implements DynamicConfigurati
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void close() throws Exception {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,11 @@ public class NopDynamicConfiguration implements DynamicConfiguration {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(String key, String group, ConfigurationListener listener) {
|
||||
// no-op
|
||||
|
|
|
|||
|
|
@ -75,6 +75,11 @@ public class CompositeDynamicConfiguration implements DynamicConfiguration {
|
|||
return iterateConfigOperation(configuration -> configuration.getInternalProperty(key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
return iterateConfigOperation(configuration -> configuration.getInternalProperty(key, defaultValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean publishConfig(String key, String group, String content) throws UnsupportedOperationException {
|
||||
boolean publishedAll = true;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,16 @@ public class ConfigConfigurationAdapter implements Configuration {
|
|||
return metaData.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = metaData.get(key);
|
||||
if (v != null) {
|
||||
return v;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return metaData;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,23 +70,23 @@ class SystemConfigurationTest {
|
|||
void testConvert() {
|
||||
Assertions.assertEquals(
|
||||
MOCK_STRING_VALUE, sysConfig.convert(String.class, NOT_EXIST_KEY, MOCK_STRING_VALUE));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_BOOL_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_BOOL_VALUE));
|
||||
Assertions.assertEquals(MOCK_BOOL_VALUE, sysConfig.convert(Boolean.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_STRING_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_STRING_VALUE));
|
||||
Assertions.assertEquals(MOCK_STRING_VALUE, sysConfig.convert(String.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_INT_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_INT_VALUE));
|
||||
Assertions.assertEquals(MOCK_INT_VALUE, sysConfig.convert(Integer.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_LONG_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_LONG_VALUE));
|
||||
Assertions.assertEquals(MOCK_LONG_VALUE, sysConfig.convert(Long.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_SHORT_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_SHORT_VALUE));
|
||||
Assertions.assertEquals(MOCK_SHORT_VALUE, sysConfig.convert(Short.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_FLOAT_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_FLOAT_VALUE));
|
||||
Assertions.assertEquals(MOCK_FLOAT_VALUE, sysConfig.convert(Float.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_DOUBLE_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_DOUBLE_VALUE));
|
||||
Assertions.assertEquals(MOCK_DOUBLE_VALUE, sysConfig.convert(Double.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(MOCK_BYTE_VALUE));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(MOCK_BYTE_VALUE));
|
||||
Assertions.assertEquals(MOCK_BYTE_VALUE, sysConfig.convert(Byte.class, MOCK_KEY, null));
|
||||
System.setProperty(MOCK_KEY, String.valueOf(ConfigMock.MockOne));
|
||||
sysConfig.overwriteCache(MOCK_KEY, String.valueOf(ConfigMock.MockOne));
|
||||
Assertions.assertEquals(ConfigMock.MockOne, sysConfig.convert(ConfigMock.class, MOCK_KEY, null));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,9 +16,11 @@
|
|||
*/
|
||||
package org.apache.dubbo.common.utils;
|
||||
|
||||
import org.apache.dubbo.common.config.SystemConfiguration;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
|
||||
import javassist.compiler.Javac;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
|
@ -57,14 +59,16 @@ class SerializeClassCheckerTest {
|
|||
serializeClassChecker.validateClass(int.class.getName().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()-> {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
serializeClassChecker.validateClass(Socket.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddAllow() {
|
||||
System.setProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST, Socket.class.getName() + "," + Javac.class.getName());
|
||||
SystemConfiguration systemConfiguration = ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration();
|
||||
|
||||
systemConfiguration.overwriteCache(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST, Socket.class.getName() + "," + Javac.class.getName());
|
||||
|
||||
SerializeClassChecker serializeClassChecker = SerializeClassChecker.getInstance();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
|
@ -72,40 +76,44 @@ class SerializeClassCheckerTest {
|
|||
serializeClassChecker.validateClass(Javac.class.getName());
|
||||
}
|
||||
|
||||
System.clearProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST);
|
||||
systemConfiguration.clearCache();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddBlock() {
|
||||
System.setProperty(CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST, LinkedList.class.getName() + "," + Integer.class.getName());
|
||||
SystemConfiguration systemConfiguration = ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration();
|
||||
systemConfiguration.overwriteCache(CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST, LinkedList.class.getName() + "," + Integer.class.getName());
|
||||
|
||||
SerializeClassChecker serializeClassChecker = SerializeClassChecker.getInstance();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()-> {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
serializeClassChecker.validateClass(LinkedList.class.getName());
|
||||
});
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()-> {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
serializeClassChecker.validateClass(Integer.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
System.clearProperty(CommonConstants.CLASS_DESERIALIZE_BLOCKED_LIST);
|
||||
systemConfiguration.clearCache();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBlockAll() {
|
||||
System.setProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL, "true");
|
||||
System.setProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST, LinkedList.class.getName());
|
||||
SystemConfiguration systemConfiguration = ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration();
|
||||
|
||||
systemConfiguration.overwriteCache(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL, "true");
|
||||
systemConfiguration.overwriteCache(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST, LinkedList.class.getName());
|
||||
|
||||
SerializeClassChecker serializeClassChecker = SerializeClassChecker.getInstance();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
serializeClassChecker.validateClass(LinkedList.class.getName());
|
||||
Assertions.assertThrows(IllegalArgumentException.class, ()-> {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> {
|
||||
serializeClassChecker.validateClass(Integer.class.getName());
|
||||
});
|
||||
}
|
||||
|
||||
System.clearProperty(CommonConstants.CLASS_DESERIALIZE_BLOCK_ALL);
|
||||
System.clearProperty(CommonConstants.CLASS_DESERIALIZE_ALLOWED_LIST);
|
||||
systemConfiguration.clearCache();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -122,7 +122,6 @@ class MultiInstanceTest {
|
|||
@AfterEach
|
||||
public void afterEach() {
|
||||
SysProps.clear();
|
||||
DubboBootstrap.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -154,12 +153,12 @@ class MultiInstanceTest {
|
|||
|
||||
@Test
|
||||
void testDefaultProviderApplication() {
|
||||
DubboBootstrap.reset();
|
||||
DubboBootstrap dubboBootstrap = DubboBootstrap.getInstance();
|
||||
try {
|
||||
configProviderApp(dubboBootstrap).start();
|
||||
} finally {
|
||||
dubboBootstrap.destroy();
|
||||
DubboBootstrap.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -174,13 +173,12 @@ class MultiInstanceTest {
|
|||
Assertions.assertTrue(e.toString().contains("No provider available"), StringUtils.toString(e));
|
||||
} finally {
|
||||
dubboBootstrap.destroy();
|
||||
DubboBootstrap.reset();
|
||||
SysProps.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultMixedApplication() {
|
||||
DubboBootstrap.reset();
|
||||
DubboBootstrap dubboBootstrap = DubboBootstrap.getInstance();
|
||||
try {
|
||||
dubboBootstrap.application("mixed-app");
|
||||
|
|
@ -191,7 +189,6 @@ class MultiInstanceTest {
|
|||
testConsumer(dubboBootstrap);
|
||||
} finally {
|
||||
dubboBootstrap.destroy();
|
||||
DubboBootstrap.reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -221,6 +218,8 @@ class MultiInstanceTest {
|
|||
void testMultiModuleApplication() throws InterruptedException {
|
||||
|
||||
//SysProps.setProperty(METADATA_PUBLISH_DELAY_KEY, "100");
|
||||
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
String version1 = "1.0";
|
||||
String version2 = "2.0";
|
||||
String version3 = "3.0";
|
||||
|
|
@ -230,7 +229,7 @@ class MultiInstanceTest {
|
|||
|
||||
try {
|
||||
// provider app
|
||||
providerBootstrap = DubboBootstrap.newInstance();
|
||||
providerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
|
||||
ServiceConfig serviceConfig1 = new ServiceConfig();
|
||||
serviceConfig1.setInterface(DemoService.class);
|
||||
|
|
@ -274,7 +273,7 @@ class MultiInstanceTest {
|
|||
//Thread.sleep(200);
|
||||
|
||||
// consumer app
|
||||
consumerBootstrap = DubboBootstrap.newInstance();
|
||||
consumerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
consumerBootstrap.application("consumer-app")
|
||||
.registry(registryConfig)
|
||||
.reference(builder -> builder
|
||||
|
|
@ -308,10 +307,12 @@ class MultiInstanceTest {
|
|||
|
||||
@Test
|
||||
void testMultiProviderApplicationsStopOneByOne() {
|
||||
DubboBootstrap.reset();
|
||||
|
||||
String version1 = "1.0";
|
||||
String version2 = "2.0";
|
||||
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
DubboBootstrap providerBootstrap1 = null;
|
||||
DubboBootstrap providerBootstrap2 = null;
|
||||
|
||||
|
|
@ -328,7 +329,7 @@ class MultiInstanceTest {
|
|||
|
||||
ProtocolConfig protocolConfig1 = new ProtocolConfig("dubbo", NetUtils.getAvailablePort());
|
||||
|
||||
providerBootstrap1 = DubboBootstrap.getInstance();
|
||||
providerBootstrap1 = DubboBootstrap.newInstance(frameworkModel);
|
||||
providerBootstrap1.application("provider1")
|
||||
.registry(registryConfig)
|
||||
.service(serviceConfig1)
|
||||
|
|
@ -351,7 +352,7 @@ class MultiInstanceTest {
|
|||
|
||||
ProtocolConfig protocolConfig2 = new ProtocolConfig("dubbo", NetUtils.getAvailablePort());
|
||||
|
||||
providerBootstrap2 = DubboBootstrap.newInstance();
|
||||
providerBootstrap2 = DubboBootstrap.newInstance(frameworkModel);
|
||||
providerBootstrap2.application("provider2")
|
||||
.registry(registryConfig2)
|
||||
.service(serviceConfig2)
|
||||
|
|
@ -430,6 +431,7 @@ class MultiInstanceTest {
|
|||
String version2 = "2.0";
|
||||
String version3 = "3.0";
|
||||
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
String serviceKey1 = DemoService.class.getName() + ":" + version1;
|
||||
String serviceKey2 = DemoService.class.getName() + ":" + version2;
|
||||
String serviceKey3 = DemoService.class.getName() + ":" + version3;
|
||||
|
|
@ -439,7 +441,7 @@ class MultiInstanceTest {
|
|||
|
||||
try {
|
||||
// provider app
|
||||
providerBootstrap = DubboBootstrap.newInstance();
|
||||
providerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
|
||||
ServiceConfig serviceConfig1 = new ServiceConfig();
|
||||
serviceConfig1.setInterface(DemoService.class);
|
||||
|
|
@ -477,7 +479,7 @@ class MultiInstanceTest {
|
|||
Assertions.assertNull(frameworkServiceRepository.lookupExportedServiceWithoutGroup(serviceKey3));
|
||||
|
||||
// consumer module 1
|
||||
consumerBootstrap = DubboBootstrap.newInstance();
|
||||
consumerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
consumerBootstrap.application("consumer-app")
|
||||
.registry(registryConfig)
|
||||
.reference(builder -> builder
|
||||
|
|
@ -572,6 +574,7 @@ class MultiInstanceTest {
|
|||
String version2 = "2.0";
|
||||
String version3 = "3.0";
|
||||
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
String serviceKey1 = DemoService.class.getName() + ":" + version1;
|
||||
String serviceKey2 = DemoService.class.getName() + ":" + version2;
|
||||
String serviceKey3 = DemoService.class.getName() + ":" + version3;
|
||||
|
|
@ -579,7 +582,7 @@ class MultiInstanceTest {
|
|||
// provider app
|
||||
DubboBootstrap providerBootstrap = null;
|
||||
try {
|
||||
providerBootstrap = DubboBootstrap.newInstance();
|
||||
providerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
|
||||
ServiceConfig serviceConfig1 = new ServiceConfig();
|
||||
serviceConfig1.setInterface(DemoService.class);
|
||||
|
|
@ -652,6 +655,7 @@ class MultiInstanceTest {
|
|||
String version2 = "2.0";
|
||||
String version3 = "3.0";
|
||||
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
String serviceKey1 = DemoService.class.getName() + ":" + version1;
|
||||
String serviceKey2 = DemoService.class.getName() + ":" + version2;
|
||||
String serviceKey3 = DemoService.class.getName() + ":" + version3;
|
||||
|
|
@ -659,7 +663,7 @@ class MultiInstanceTest {
|
|||
// provider app
|
||||
DubboBootstrap providerBootstrap = null;
|
||||
try {
|
||||
providerBootstrap = DubboBootstrap.newInstance();
|
||||
providerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
|
||||
ServiceConfig serviceConfig1 = new ServiceConfig();
|
||||
serviceConfig1.setInterface(DemoService.class);
|
||||
|
|
@ -706,6 +710,7 @@ class MultiInstanceTest {
|
|||
@Test
|
||||
void testOldApiDeploy() throws Exception {
|
||||
|
||||
DubboBootstrap.reset();
|
||||
try {
|
||||
// provider app
|
||||
ApplicationModel providerApplicationModel = ApplicationModel.defaultModel();
|
||||
|
|
@ -781,8 +786,10 @@ class MultiInstanceTest {
|
|||
|
||||
@Test
|
||||
void testAsyncExportAndReferServices() throws ExecutionException, InterruptedException {
|
||||
DubboBootstrap providerBootstrap = DubboBootstrap.newInstance();
|
||||
DubboBootstrap consumerBootstrap = DubboBootstrap.newInstance();
|
||||
FrameworkModel frameworkModel = new FrameworkModel();
|
||||
|
||||
DubboBootstrap providerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
DubboBootstrap consumerBootstrap = DubboBootstrap.newInstance(frameworkModel);
|
||||
try {
|
||||
|
||||
ServiceConfig serviceConfig = new ServiceConfig();
|
||||
|
|
|
|||
|
|
@ -215,6 +215,16 @@ public class ApolloDynamicConfiguration implements DynamicConfiguration {
|
|||
return dubboConfig.getProperty(key, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = dubboConfig.getProperty(key, null);
|
||||
if (v != null) {
|
||||
return v;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignores the group parameter.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -220,6 +220,17 @@ public class NacosDynamicConfiguration implements DynamicConfiguration {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = defaultValue;
|
||||
try {
|
||||
v = configService.getConfig(key, DEFAULT_GROUP, getDefaultTimeout());
|
||||
} catch (NacosException e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean publishConfig(String key, String group, String content) {
|
||||
boolean published = false;
|
||||
|
|
|
|||
|
|
@ -85,6 +85,16 @@ public class ZookeeperDynamicConfiguration extends TreePathDynamicConfiguration
|
|||
return zkClient.getContent(buildPathKey("", key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getInternalProperty(String key, Object defaultValue) {
|
||||
Object v = zkClient.getContent(buildPathKey("", key));
|
||||
if (v != null) {
|
||||
return v;
|
||||
} else {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doClose() throws Exception {
|
||||
// remove data listener
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import org.apache.dubbo.common.constants.CommonConstants;
|
|||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.threadpool.ThreadlessExecutor;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
import org.apache.dubbo.rpc.model.ConsumerMethodModel;
|
||||
import org.apache.dubbo.rpc.protocol.dubbo.FutureAdapter;
|
||||
|
||||
|
|
@ -66,11 +67,6 @@ public class AsyncRpcResult implements Result {
|
|||
|
||||
private CompletableFuture<AppResponse> responseFuture;
|
||||
|
||||
/**
|
||||
* Whether set future to Thread Local when invocation mode is sync
|
||||
*/
|
||||
private static final boolean setFutureWhenSync = Boolean.parseBoolean(System.getProperty(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true"));
|
||||
|
||||
public AsyncRpcResult(CompletableFuture<AppResponse> future, Invocation invocation) {
|
||||
this.responseFuture = future;
|
||||
this.invocation = invocation;
|
||||
|
|
@ -216,7 +212,11 @@ public class AsyncRpcResult implements Result {
|
|||
fn.accept(v, t);
|
||||
});
|
||||
|
||||
if (setFutureWhenSync || ((RpcInvocation) invocation).getInvokeMode() != InvokeMode.SYNC) {
|
||||
// Whether set future to Thread Local when invocation mode is sync
|
||||
String setFutureWhenSync = ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration()
|
||||
.getString(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true");
|
||||
|
||||
if (Boolean.parseBoolean(setFutureWhenSync) || ((RpcInvocation) invocation).getInvokeMode() != InvokeMode.SYNC) {
|
||||
// Necessary! update future in context, see https://github.com/apache/dubbo/issues/9461
|
||||
RpcContext.getServiceContext().setFuture(new FutureAdapter<>(this.responseFuture));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public class AccessLogFilter implements Filter {
|
|||
|
||||
private AtomicBoolean scheduled = new AtomicBoolean();
|
||||
|
||||
private static final String LINE_SEPARATOR = "line.separator";
|
||||
private final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
|
||||
/**
|
||||
* Default constructor initialize demon thread for writing into access log file with names with access log key
|
||||
|
|
@ -173,7 +173,7 @@ public class AccessLogFilter implements Filter {
|
|||
try {
|
||||
while (!logQueue.isEmpty()) {
|
||||
writer.write(logQueue.poll().getLogMessage());
|
||||
writer.write(System.getProperty(LINE_SEPARATOR));
|
||||
writer.write(LINE_SEPARATOR);
|
||||
}
|
||||
} finally {
|
||||
writer.flush();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import org.apache.dubbo.rpc.Result;
|
|||
import org.apache.dubbo.rpc.RpcContext;
|
||||
import org.apache.dubbo.rpc.RpcException;
|
||||
import org.apache.dubbo.rpc.RpcInvocation;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
import org.apache.dubbo.rpc.protocol.dubbo.FutureAdapter;
|
||||
import org.apache.dubbo.rpc.support.RpcUtils;
|
||||
|
||||
|
|
@ -87,11 +88,6 @@ public abstract class AbstractInvoker<T> implements Invoker<T> {
|
|||
*/
|
||||
private boolean destroyed = false;
|
||||
|
||||
/**
|
||||
* Whether set future to Thread Local when invocation mode is sync
|
||||
*/
|
||||
private static final boolean setFutureWhenSync = Boolean.parseBoolean(System.getProperty(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true"));
|
||||
|
||||
// -- Constructor
|
||||
|
||||
public AbstractInvoker(Class<T> type, URL url) {
|
||||
|
|
@ -242,7 +238,11 @@ public abstract class AbstractInvoker<T> implements Invoker<T> {
|
|||
asyncResult = AsyncRpcResult.newDefaultAsyncResult(null, e, invocation);
|
||||
}
|
||||
|
||||
if (setFutureWhenSync || invocation.getInvokeMode() != InvokeMode.SYNC) {
|
||||
// Whether set future to Thread Local when invocation mode is sync
|
||||
String setFutureWhenSync = ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration()
|
||||
.getString(CommonConstants.SET_FUTURE_IN_SYNC_MODE, "true");
|
||||
|
||||
if (Boolean.parseBoolean(setFutureWhenSync) || invocation.getInvokeMode() != InvokeMode.SYNC) {
|
||||
// set server context
|
||||
RpcContext.getServiceContext().setFuture(new FutureAdapter<>(asyncResult.getResponseFuture()));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.apache.dubbo.rpc.protocol.dubbo;
|
||||
|
||||
|
||||
import org.apache.dubbo.common.config.ConfigurationUtils;
|
||||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.common.serialize.Cleanable;
|
||||
|
|
@ -37,6 +38,7 @@ import org.apache.dubbo.rpc.model.FrameworkServiceRepository;
|
|||
import org.apache.dubbo.rpc.model.MethodDescriptor;
|
||||
import org.apache.dubbo.rpc.model.ModuleModel;
|
||||
import org.apache.dubbo.rpc.model.ProviderModel;
|
||||
import org.apache.dubbo.rpc.model.ScopeModel;
|
||||
import org.apache.dubbo.rpc.model.ServiceDescriptor;
|
||||
import org.apache.dubbo.rpc.support.RpcUtils;
|
||||
|
||||
|
|
@ -134,7 +136,17 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec
|
|||
|
||||
ClassLoader originClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
if (Boolean.parseBoolean(System.getProperty(SERIALIZATION_SECURITY_CHECK_KEY, "true"))) {
|
||||
ScopeModel scopeModel = channel.getUrl().getScopeModel();
|
||||
if (scopeModel instanceof ModuleModel) {
|
||||
scopeModel = scopeModel.getParent();
|
||||
} else {
|
||||
scopeModel = ApplicationModel.defaultModel();
|
||||
}
|
||||
String serializationSecurityCheck = ConfigurationUtils.getSystemConfiguration(
|
||||
scopeModel).getString(SERIALIZATION_SECURITY_CHECK_KEY, "true");
|
||||
|
||||
|
||||
if (Boolean.parseBoolean(serializationSecurityCheck)) {
|
||||
CodecSupport.checkSerialization(frameworkModel.getServiceRepository(), path, version, serializationType);
|
||||
}
|
||||
Object[] args = DubboCodec.EMPTY_OBJECT_ARRAY;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.apache.dubbo.rpc.protocol.dubbo.decode;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.url.component.ServiceConfigURL;
|
||||
|
|
@ -38,10 +41,6 @@ import org.apache.dubbo.rpc.model.ModuleServiceRepository;
|
|||
import org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation;
|
||||
import org.apache.dubbo.rpc.protocol.dubbo.DubboCodec;
|
||||
import org.apache.dubbo.rpc.protocol.dubbo.support.DemoService;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
|
@ -78,13 +77,13 @@ class DubboTelnetDecodeTest {
|
|||
|
||||
// disable org.apache.dubbo.remoting.transport.CodecSupport.checkSerialization to avoid error:
|
||||
// java.io.IOException: Service org.apache.dubbo.rpc.protocol.dubbo.support.DemoService with version 0.0.0 not found, invocation rejected.
|
||||
System.setProperty(SERIALIZATION_SECURITY_CHECK_KEY, "false");
|
||||
ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration().overwriteCache(SERIALIZATION_SECURITY_CHECK_KEY, "false");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void teardown() {
|
||||
FrameworkModel.defaultModel().destroy();
|
||||
System.clearProperty(SERIALIZATION_SECURITY_CHECK_KEY);
|
||||
ApplicationModel.defaultModel().getModelEnvironment().getSystemConfiguration().clearCache();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -101,25 +100,26 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler(null,
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubbo.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubbo.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(dubboByteBuf);
|
||||
} catch (Exception e) {
|
||||
|
|
@ -148,6 +148,7 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler((msg) -> {
|
||||
|
|
@ -155,19 +156,19 @@ class DubboTelnetDecodeTest {
|
|||
telnet.incrementAndGet();
|
||||
}
|
||||
},
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(telnetByteBuf);
|
||||
} catch (Exception e) {
|
||||
|
|
@ -192,13 +193,13 @@ class DubboTelnetDecodeTest {
|
|||
* | telnet(incomplete) |
|
||||
* +--------------------------------------------------+
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* Second ByteBuf:
|
||||
* +--------------------------++----------------------+
|
||||
* | telnet(the remaining) || dubbo(complete) |
|
||||
* +--------------------------++----------------------+
|
||||
* ||
|
||||
* Magic Code
|
||||
* ||
|
||||
* Magic Code
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
|
|
@ -211,6 +212,7 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler((msg) -> {
|
||||
|
|
@ -218,23 +220,23 @@ class DubboTelnetDecodeTest {
|
|||
telnetDubbo.incrementAndGet();
|
||||
}
|
||||
},
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
telnetDubbo.incrementAndGet();
|
||||
}
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
telnetDubbo.incrementAndGet();
|
||||
}
|
||||
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(telnetByteBuf);
|
||||
ch.writeInbound(Unpooled.wrappedBuffer(Unpooled.wrappedBuffer("\n".getBytes()), dubboByteBuf));
|
||||
|
|
@ -265,7 +267,7 @@ class DubboTelnetDecodeTest {
|
|||
* | telnet(incomplete) |
|
||||
* +--------------------------------------------------+
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* Second ByteBuf (secondByteBuf):
|
||||
* +--------------------------------------------------+
|
||||
* | telnet(the remaining) | telnet(complete) |
|
||||
|
|
@ -283,6 +285,7 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler((msg) -> {
|
||||
|
|
@ -290,19 +293,19 @@ class DubboTelnetDecodeTest {
|
|||
telnetTelnet.incrementAndGet();
|
||||
}
|
||||
},
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(firstByteBuf);
|
||||
ch.writeInbound(secondByteBuf);
|
||||
|
|
@ -336,8 +339,8 @@ class DubboTelnetDecodeTest {
|
|||
* +-------------------------++-----------------------+
|
||||
* | dubbo(the remaining) || dubbo(complete) |
|
||||
* +-------------------------++-----------------------+
|
||||
* ||
|
||||
* Magic Code
|
||||
* ||
|
||||
* Magic Code
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
|
|
@ -354,25 +357,26 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler(null,
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubboDubbo.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubboDubbo.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(firstDubboByteBuf);
|
||||
ch.writeInbound(secondDubboByteBuf);
|
||||
|
|
@ -421,6 +425,7 @@ class DubboTelnetDecodeTest {
|
|||
try {
|
||||
Codec2 codec = ExtensionLoader.getExtensionLoader(Codec2.class).getExtension("dubbo");
|
||||
URL url = new ServiceConfigURL("dubbo", "localhost", 22226);
|
||||
url = url.setScopeModel(ApplicationModel.defaultModel().newModule());
|
||||
NettyCodecAdapter adapter = new NettyCodecAdapter(codec, url, new MockChannelHandler());
|
||||
|
||||
MockHandler mockHandler = new MockHandler((msg) -> {
|
||||
|
|
@ -428,22 +433,22 @@ class DubboTelnetDecodeTest {
|
|||
dubboTelnet.incrementAndGet();
|
||||
}
|
||||
},
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubboTelnet.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
new MultiMessageHandler(
|
||||
new DecodeHandler(
|
||||
new HeaderExchangeHandler(new ExchangeHandlerAdapter() {
|
||||
@Override
|
||||
public CompletableFuture<Object> reply(ExchangeChannel channel, Object msg) {
|
||||
if (checkDubboDecoded(msg)) {
|
||||
dubboTelnet.incrementAndGet();
|
||||
}
|
||||
return getDefaultFuture();
|
||||
}
|
||||
}))));
|
||||
|
||||
ch = new LocalEmbeddedChannel();
|
||||
ch.pipeline()
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
.addLast("decoder", adapter.getDecoder())
|
||||
.addLast("handler", mockHandler);
|
||||
|
||||
ch.writeInbound(firstDubboByteBuf);
|
||||
ch.writeInbound(secondByteBuf);
|
||||
|
|
@ -496,13 +501,13 @@ class DubboTelnetDecodeTest {
|
|||
if (msg instanceof DecodeableRpcInvocation) {
|
||||
DecodeableRpcInvocation invocation = (DecodeableRpcInvocation) msg;
|
||||
if ("sayHello".equals(invocation.getMethodName())
|
||||
&& invocation.getParameterTypes().length == 1
|
||||
&& String.class.equals(invocation.getParameterTypes()[0])
|
||||
&& invocation.getArguments().length == 1
|
||||
&& "dubbo".equals(invocation.getArguments()[0])
|
||||
&& DemoService.class.getName().equals(invocation.getAttachment("path"))
|
||||
&& DemoService.class.getName().equals(invocation.getAttachment("interface"))
|
||||
&& "0.0.0".equals(invocation.getAttachment("version"))) {
|
||||
&& invocation.getParameterTypes().length == 1
|
||||
&& String.class.equals(invocation.getParameterTypes()[0])
|
||||
&& invocation.getArguments().length == 1
|
||||
&& "dubbo".equals(invocation.getArguments()[0])
|
||||
&& DemoService.class.getName().equals(invocation.getAttachment("path"))
|
||||
&& DemoService.class.getName().equals(invocation.getAttachment("interface"))
|
||||
&& "0.0.0".equals(invocation.getAttachment("version"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class DefaultHessian2FactoryInitializer extends AbstractHessian2FactoryIn
|
|||
@Override
|
||||
protected SerializerFactory createSerializerFactory() {
|
||||
Hessian2SerializerFactory hessian2SerializerFactory = new Hessian2SerializerFactory();
|
||||
hessian2SerializerFactory.setAllowNonSerializable(Boolean.parseBoolean(System.getProperty("dubbo.hessian.allowNonSerializable", "false")));
|
||||
hessian2SerializerFactory.setAllowNonSerializable(Boolean.parseBoolean(ALLOW_NON_SERIALIZABLE));
|
||||
hessian2SerializerFactory.getClassFactory().allow("org.apache.dubbo.*");
|
||||
return hessian2SerializerFactory;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@ import com.alibaba.com.caucho.hessian.io.SerializerFactory;
|
|||
@SPI(value = "default", scope = ExtensionScope.FRAMEWORK)
|
||||
public interface Hessian2FactoryInitializer {
|
||||
String ALLOW = System.getProperty("dubbo.application.hessian2.allow");
|
||||
|
||||
String DENY = System.getProperty("dubbo.application.hessian2.deny");
|
||||
|
||||
String WHITELIST = System.getProperty("dubbo.application.hessian2.whitelist");
|
||||
|
||||
String ALLOW_NON_SERIALIZABLE = System.getProperty("dubbo.hessian.allowNonSerializable", "false");
|
||||
|
|
|
|||
Loading…
Reference in New Issue