Fix compile errors

This commit is contained in:
ken.lj 2019-10-14 12:58:42 +08:00
parent 1be3c999d1
commit 7621c9e3d1
49 changed files with 421 additions and 98 deletions

View File

@ -98,6 +98,11 @@
<artifactId>dubbo-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bootstrap</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-config-spring</artifactId>

View File

@ -71,6 +71,7 @@ import static org.apache.dubbo.common.constants.CommonConstants.FILE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.HOST_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PASSWORD_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
@ -113,7 +114,6 @@ import static org.apache.dubbo.rpc.Constants.PROXY_KEY;
import static org.apache.dubbo.rpc.Constants.RETURN_PREFIX;
import static org.apache.dubbo.rpc.Constants.THROW_PREFIX;
import static org.apache.dubbo.rpc.Constants.TOKEN_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.LOADBALANCE_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
/**

View File

@ -30,7 +30,6 @@ import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.cluster.Constants;
import org.apache.dubbo.rpc.cluster.router.AbstractRouter;
import org.apache.dubbo.rpc.cluster.router.tag.model.TagRouterRule;
import org.apache.dubbo.rpc.cluster.router.tag.model.TagRuleParser;
@ -40,8 +39,8 @@ import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
import static org.apache.dubbo.rpc.Constants.FORCE_USE_TAG;
import static org.apache.dubbo.rpc.cluster.Constants.TAG_KEY;
/**
* TagRouter, "application.tag-router"
@ -97,8 +96,8 @@ public class TagRouter extends AbstractRouter implements ConfigurationListener {
}
List<Invoker<T>> result = invokers;
String tag = StringUtils.isEmpty((String) invocation.getAttachment(Constants.TAG_KEY)) ? url.getParameter(Constants.TAG_KEY) :
(String) invocation.getAttachment(Constants.TAG_KEY);
String tag = StringUtils.isEmpty((String) invocation.getAttachment(TAG_KEY)) ? url.getParameter(TAG_KEY) :
(String) invocation.getAttachment(TAG_KEY);
// if we are requesting for a Provider with a specific tag
if (StringUtils.isNotEmpty(tag)) {
@ -113,7 +112,7 @@ public class TagRouter extends AbstractRouter implements ConfigurationListener {
} else {
// dynamic tag group doesn't have any item about the requested app OR it's null after filtered by
// dynamic tag group but force=false. check static tag
result = filterInvoker(invokers, invoker -> tag.equals(invoker.getUrl().getParameter(Constants.TAG_KEY)));
result = filterInvoker(invokers, invoker -> tag.equals(invoker.getUrl().getParameter(TAG_KEY)));
}
// If there's no tagged providers that can match the current tagged request. force.tag is set by default
// to false, which means it will invoke any providers without a tag unless it's explicitly disallowed.
@ -124,7 +123,7 @@ public class TagRouter extends AbstractRouter implements ConfigurationListener {
else {
List<Invoker<T>> tmp = filterInvoker(invokers, invoker -> addressNotMatches(invoker.getUrl(),
tagRouterRuleCopy.getAddresses()));
return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(Constants.TAG_KEY)));
return filterInvoker(tmp, invoker -> StringUtils.isEmpty(invoker.getUrl().getParameter(TAG_KEY)));
}
} else {
// List<String> addresses = tagRouterRule.filter(providerApp);
@ -140,7 +139,7 @@ public class TagRouter extends AbstractRouter implements ConfigurationListener {
// static tag group.
}
return filterInvoker(result, invoker -> {
String localTag = invoker.getUrl().getParameter(Constants.TAG_KEY);
String localTag = invoker.getUrl().getParameter(TAG_KEY);
return StringUtils.isEmpty(localTag) || !tagRouterRuleCopy.getTagNames().contains(localTag);
});
}
@ -163,8 +162,8 @@ public class TagRouter extends AbstractRouter implements ConfigurationListener {
private <T> List<Invoker<T>> filterUsingStaticTag(List<Invoker<T>> invokers, URL url, Invocation invocation) {
List<Invoker<T>> result = invokers;
// Dynamic param
String tag = StringUtils.isEmpty((String) invocation.getAttachment(Constants.TAG_KEY)) ? url.getParameter(Constants.TAG_KEY) :
(String) invocation.getAttachment(Constants.TAG_KEY);
String tag = StringUtils.isEmpty((String) invocation.getAttachment(TAG_KEY)) ? url.getParameter(TAG_KEY) :
(String) invocation.getAttachment(TAG_KEY);
// Tag request
if (!StringUtils.isEmpty(tag)) {
result = filterInvoker(invokers, invoker -> tag.equals(invoker.getUrl().getParameter(TAG_KEY)));

View File

@ -39,12 +39,12 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_LOADBALANCE;
import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_AVAILABLE_CHECK_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_STICKY_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_CLUSTER_AVAILABLE_CHECK;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_CLUSTER_STICKY;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_LOADBALANCE;
import static org.apache.dubbo.rpc.cluster.Constants.LOADBALANCE_KEY;
/**
* AbstractClusterInvoker

View File

@ -26,20 +26,20 @@ import static org.apache.dubbo.common.constants.CommonConstants.ALIVE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.CORE_THREADS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_KEY_PREFIX;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INVOKER_LISTENER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REFERENCE_FILTER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REMOTE_APPLICATION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREADPOOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.rpc.Constants.INVOKER_LISTENER_KEY;
import static org.apache.dubbo.rpc.Constants.REFERENCE_FILTER_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.TAG_KEY;
/**
* ClusterUtils

View File

@ -35,8 +35,8 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_FAILBACK_TIMES;
import static org.apache.dubbo.rpc.cluster.Constants.RETRIES_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_FAILBACK_TIMES;
import static org.apache.dubbo.common.constants.CommonConstants.RETRIES_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_FAILBACK_TASKS;
import static org.apache.dubbo.rpc.cluster.Constants.FAIL_BACK_TASKS_KEY;

View File

@ -34,8 +34,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_RETRIES;
import static org.apache.dubbo.rpc.cluster.Constants.RETRIES_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_RETRIES;
import static org.apache.dubbo.common.constants.CommonConstants.RETRIES_KEY;
/**
* When invoke fails, log the initial error and retry other invokers (retry n times, which means at most n different invokers will be invoked)

View File

@ -34,10 +34,10 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_FORKS;
import static org.apache.dubbo.rpc.cluster.Constants.FORKS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
import static org.apache.dubbo.common.constants.CommonConstants.FORKS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.DEFAULT_FORKS;
/**
* NOTICE! This implementation does not work well with async call.

View File

@ -28,7 +28,7 @@ import org.apache.dubbo.rpc.cluster.Directory;
import java.util.List;
import static org.apache.dubbo.rpc.Constants.REFERENCE_INTERCEPTOR_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REFERENCE_INTERCEPTOR_KEY;
public abstract class AbstractCluster implements Cluster {

View File

@ -0,0 +1,113 @@
/*
* 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 com.alibaba.dubbo.config.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Deprecated
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE})
public @interface Reference {
Class<?> interfaceClass() default void.class;
String interfaceName() default "";
String version() default "";
String group() default "";
String url() default "";
String client() default "";
boolean generic() default false;
boolean injvm() default true;
boolean check() default true;
boolean init() default false;
boolean lazy() default false;
boolean stubevent() default false;
String reconnect() default "";
boolean sticky() default false;
String proxy() default "";
String stub() default "";
String cluster() default "";
int connections() default 0;
int callbacks() default 0;
String onconnect() default "";
String ondisconnect() default "";
String owner() default "";
String layer() default "";
int retries() default 2;
String loadbalance() default "";
boolean async() default false;
int actives() default 0;
boolean sent() default false;
String mock() default "";
String validation() default "";
int timeout() default 0;
String cache() default "";
String[] filter() default {};
String[] listener() default {};
String[] parameters() default {};
String application() default "";
String module() default "";
String consumer() default "";
String monitor() default "";
String[] registry() default {};
}

View File

@ -0,0 +1,120 @@
/*
* 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 com.alibaba.dubbo.config.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Deprecated
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Inherited
public @interface Service {
Class<?> interfaceClass() default void.class;
String interfaceName() default "";
String version() default "";
String group() default "";
String path() default "";
boolean export() default false;
String token() default "";
boolean deprecated() default false;
boolean dynamic() default true;
String accesslog() default "";
int executes() default 0;
boolean register() default false;
int weight() default 0;
String document() default "";
int delay() default 0;
String local() default "";
String stub() default "";
String cluster() default "";
String proxy() default "";
int connections() default 0;
int callbacks() default 0;
String onconnect() default "";
String ondisconnect() default "";
String owner() default "";
String layer() default "";
int retries() default 0;
String loadbalance() default "";
boolean async() default false;
int actives() default 0;
boolean sent() default false;
String mock() default "";
String validation() default "";
int timeout() default 0;
String cache() default "";
String[] filter() default {};
String[] listener() default {};
String[] parameters() default {};
String application() default "";
String module() default "";
String provider() default "";
String[] protocol() default {};
String monitor() default "";
String[] registry() default {};
}

View File

@ -30,6 +30,11 @@
<skip_maven_deploy>false</skip_maven_deploy>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-common</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bootstrap</artifactId>

View File

@ -16,6 +16,7 @@
*/
package org.apache.dubbo.config.spring.beans.factory.annotation;
import org.apache.dubbo.bootstrap.ReferenceConfigCache;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.ReferenceBean;
import org.apache.dubbo.config.spring.ServiceBean;
@ -266,7 +267,7 @@ public class ReferenceAnnotationBeanPostProcessor extends AnnotationInjectedBean
}
private void init() {
this.bean = referenceBean.get();
this.bean = ReferenceConfigCache.ReferHelper.refer(referenceBean);
}
}

View File

@ -67,7 +67,7 @@ public class DubboNamespaceHandler extends NamespaceHandlerSupport implements Co
registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
registerBeanDefinitionParser("annotation", new AnnotationBeanDefinitionParser());
registerBeanDefinitionParser("com/alibaba/dubbo/config/annotation", new AnnotationBeanDefinitionParser());
}
/**

View File

@ -31,8 +31,8 @@
<!-- Annotation 注册 -->
<dubbo:annotation id="doubleServiceAnnotationBeanPostProcessor"
package="org.apache.dubbo.config.spring.context.annotation.provider ,
org.apache.dubbo.config.spring.context.annotation.provider"/>
package="org.apache.dubbo.config.spring.context.com.alibaba.dubbo.config.annotation.provider ,
org.apache.dubbo.config.spring.context.com.alibaba.dubbo.config.annotation.provider"/>
<dubbo:annotation id="emptyServiceAnnotationBeanPostProcessor"
package=" "/>

View File

@ -43,6 +43,6 @@
<dubbo:protocol name="dubbo" port="12345" />
<dubbo:annotation package="org.apache.dubbo.config.spring.annotation.provider"/>
<dubbo:annotation package="org.apache.dubbo.config.spring.com.alibaba.dubbo.config.annotation.provider"/>
</beans>

View File

@ -23,6 +23,6 @@
<dubbo:application name="annotation-consumer"/>
<dubbo:registry address="127.0.0.1:4548"/>
<dubbo:annotation package="org.apache.dubbo.config.spring.annotation.consumer"/>
<dubbo:annotation package="org.apache.dubbo.config.spring.com.alibaba.dubbo.config.annotation.consumer"/>
</beans>

View File

@ -23,6 +23,6 @@
<dubbo:application name="annotation-provider"/>
<dubbo:registry address="127.0.0.1:4548"/>
<dubbo:annotation package="org.apache.dubbo.config.spring.annotation.provider"/>
<dubbo:annotation package="org.apache.dubbo.config.spring.com.alibaba.dubbo.config.annotation.provider"/>
</beans>

View File

@ -23,6 +23,6 @@
<dubbo:application name="annotation-consumer"/>
<dubbo:registry address="127.0.0.1:4548"/>
<dubbo:annotation package="org.apache.dubbo.config.spring.annotation.consumer"/>
<dubbo:annotation package="org.apache.dubbo.config.spring.com.alibaba.dubbo.config.annotation.consumer"/>
</beans>

View File

@ -23,6 +23,6 @@
<dubbo:application name="annotation-provider"/>
<dubbo:registry address="127.0.0.1:4548"/>
<dubbo:annotation package="org.apache.dubbo.config.spring.annotation.provider"/>
<dubbo:annotation package="org.apache.dubbo.config.spring.com.alibaba.dubbo.config.annotation.provider"/>
</beans>

View File

@ -39,6 +39,10 @@
<artifactId>dubbo-demo-interface</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-multicast</artifactId>

View File

@ -18,6 +18,8 @@
*/
package org.apache.dubbo.demo.consumer;
import org.apache.dubbo.bootstrap.DubboBootstrap;
import org.apache.dubbo.bootstrap.ReferenceConfigCache;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
@ -26,11 +28,16 @@ import org.apache.dubbo.demo.DemoService;
public class Application {
public static void main(String[] args) {
ReferenceConfig<DemoService> reference = new ReferenceConfig<>();
reference.setApplication(new ApplicationConfig("dubbo-demo-api-consumer"));
reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
reference.setInterface(DemoService.class);
DemoService service = reference.get();
String message = service.sayHello("dubbo");
DubboBootstrap bootstrap = new DubboBootstrap();
bootstrap
.application(new ApplicationConfig("dubbo-demo-api-consumer"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.reference(reference)
.start();
String message = ReferenceConfigCache.getCache().get(reference).sayHello("dubbo");
System.out.println(message);
}
}

View File

@ -41,6 +41,10 @@
<artifactId>dubbo-demo-interface</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-multicast</artifactId>

View File

@ -18,6 +18,7 @@
*/
package org.apache.dubbo.demo.provider;
import org.apache.dubbo.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
@ -26,11 +27,15 @@ import org.apache.dubbo.demo.DemoService;
public class Application {
public static void main(String[] args) throws Exception {
ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
service.setApplication(new ApplicationConfig("dubbo-demo-api-provider"));
service.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.export();
System.in.read();
DubboBootstrap bootstrap = new DubboBootstrap();
bootstrap
.application(new ApplicationConfig("dubbo-demo-api-provider"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.service(service)
.start()
.await();
}
}

View File

@ -28,7 +28,6 @@ public class Application {
* launch the application
*/
public static void main(String[] args) throws Exception {
public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml");
context.start();
DemoService demoService = context.getBean("demoService", DemoService.class);

View File

@ -29,8 +29,8 @@ import org.apache.dubbo.rpc.model.ApplicationModel;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_PROTOCOL;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REFERENCE_FILTER_KEY;
import static org.apache.dubbo.remoting.Constants.CHECK_KEY;
import static org.apache.dubbo.rpc.Constants.REFERENCE_FILTER_KEY;
/**
* DefaultMonitorFactory

View File

@ -58,14 +58,14 @@ import java.util.concurrent.atomic.AtomicBoolean;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_PROTOCOL;
import static org.apache.dubbo.common.constants.CommonConstants.EXECUTOR_SERVICE_COMPONENT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METRICS_PORT;
import static org.apache.dubbo.common.constants.CommonConstants.METRICS_PROTOCOL;
import static org.apache.dubbo.monitor.Constants.DUBBO_CONSUMER;
import static org.apache.dubbo.monitor.Constants.DUBBO_CONSUMER_METHOD;
import static org.apache.dubbo.monitor.Constants.DUBBO_GROUP;
import static org.apache.dubbo.monitor.Constants.DUBBO_PROVIDER;
import static org.apache.dubbo.monitor.Constants.DUBBO_PROVIDER_METHOD;
import static org.apache.dubbo.monitor.Constants.METHOD;
import static org.apache.dubbo.monitor.Constants.METRICS_PORT;
import static org.apache.dubbo.monitor.Constants.METRICS_PROTOCOL;
import static org.apache.dubbo.monitor.Constants.SERVICE;
public class MetricsFilter implements Filter {

View File

@ -28,6 +28,7 @@ import java.util.Map;
import java.util.stream.Collectors;
import static java.lang.Boolean.TRUE;
import static org.apache.dubbo.common.constants.CommonConstants.LAZY_CONNECT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PID_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER;
@ -35,7 +36,6 @@ import static org.apache.dubbo.common.constants.CommonConstants.SIDE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMESTAMP_KEY;
import static org.apache.dubbo.common.constants.RegistryConstants.CATEGORY_KEY;
import static org.apache.dubbo.registry.Constants.REGISTER_KEY;
import static org.apache.dubbo.rpc.Constants.LAZY_CONNECT_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_STICKY_KEY;
/**

View File

@ -59,9 +59,12 @@ import static org.apache.dubbo.common.constants.CommonConstants.ANY_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.APPLICATION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.CLUSTER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.EXTRA_KEYS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.HIDE_KEY_PREFIX;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.LOADBALANCE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
@ -86,7 +89,6 @@ import static org.apache.dubbo.common.utils.UrlUtils.classifyUrls;
import static org.apache.dubbo.registry.Constants.CONFIGURATORS_SUFFIX;
import static org.apache.dubbo.registry.Constants.CONSUMER_PROTOCOL;
import static org.apache.dubbo.registry.Constants.DEFAULT_REGISTRY;
import static org.apache.dubbo.registry.Constants.EXTRA_KEYS_KEY;
import static org.apache.dubbo.registry.Constants.PROVIDER_PROTOCOL;
import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY;
import static org.apache.dubbo.registry.Constants.REGISTER_KEY;
@ -96,7 +98,6 @@ import static org.apache.dubbo.remoting.Constants.BIND_PORT_KEY;
import static org.apache.dubbo.remoting.Constants.CHECK_KEY;
import static org.apache.dubbo.remoting.Constants.CODEC_KEY;
import static org.apache.dubbo.remoting.Constants.CONNECTIONS_KEY;
import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.remoting.Constants.EXCHANGER_KEY;
import static org.apache.dubbo.remoting.Constants.SERIALIZATION_KEY;
import static org.apache.dubbo.rpc.Constants.DEPRECATED_KEY;
@ -104,7 +105,6 @@ import static org.apache.dubbo.rpc.Constants.INTERFACES;
import static org.apache.dubbo.rpc.Constants.MOCK_KEY;
import static org.apache.dubbo.rpc.Constants.TOKEN_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.EXPORT_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.LOADBALANCE_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.WARMUP_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.WEIGHT_KEY;

View File

@ -36,16 +36,16 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import static org.apache.dubbo.common.constants.CommonConstants.CALLBACK_INSTANCES_LIMIT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.COMMA_SPLIT_PATTERN;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.LAZY_CONNECT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
import static org.apache.dubbo.common.constants.RemotingConstants.BACKUP_KEY;
import static org.apache.dubbo.registry.Constants.CONSUMER_PROTOCOL;
import static org.apache.dubbo.remoting.Constants.CONNECT_TIMEOUT_KEY;
import static org.apache.dubbo.remoting.Constants.RECONNECT_KEY;
import static org.apache.dubbo.rpc.Constants.CALLBACK_INSTANCES_LIMIT_KEY;
import static org.apache.dubbo.rpc.Constants.LAZY_CONNECT_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_STICKY_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.EXPORT_KEY;
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;

View File

@ -42,8 +42,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
import static org.apache.dubbo.rpc.support.RpcUtils.getErrorCode;
import static org.apache.dubbo.rpc.support.RpcUtils.getRpcException;
/**
* AbstractProxyProtocol
@ -137,6 +135,13 @@ public abstract class AbstractProxyProtocol extends AbstractProtocol {
return invoker;
}
protected RpcException getRpcException(Class<?> type, URL url, Invocation invocation, Throwable e) {
RpcException re = new RpcException("Failed to invoke remote service: " + type + ", method: "
+ invocation.getMethodName() + ", cause: " + e.getMessage(), e);
re.setCode(getErrorCode(e));
return re;
}
protected String getAddr(URL url) {
String bindIp = url.getParameter(Constants.BIND_IP_KEY, url.getHost());
if (url.getParameter(ANYHOST_KEY, false)) {
@ -145,6 +150,10 @@ public abstract class AbstractProxyProtocol extends AbstractProtocol {
return NetUtils.getIpByHost(bindIp) + ":" + url.getParameter(Constants.BIND_PORT_KEY, url.getPort());
}
protected int getErrorCode(Throwable e) {
return RpcException.UNKNOWN_EXCEPTION;
}
protected abstract <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException;
protected abstract <T> T doRefer(Class<T> type, URL url) throws RpcException;

View File

@ -23,7 +23,6 @@ import org.apache.dubbo.common.utils.ReflectUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.InvokeMode;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.RpcInvocation;
import java.lang.reflect.Method;
@ -201,15 +200,4 @@ public class RpcUtils {
}
return isOneway;
}
public static RpcException getRpcException(Class<?> type, URL url, Invocation invocation, Throwable e) {
RpcException re = new RpcException("Failed to invoke remote service: " + type + ", method: "
+ invocation.getMethodName() + ", cause: " + e.getMessage(), e);
re.setCode(getErrorCode(e));
return re;
}
public static int getErrorCode(Throwable e) {
return RpcException.UNKNOWN_EXCEPTION;
}
}

View File

@ -37,12 +37,12 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import static org.apache.dubbo.common.constants.CommonConstants.CALLBACK_INSTANCES_LIMIT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_CALLBACK_INSTANCES;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.METHODS_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.rpc.Constants.CALLBACK_INSTANCES_LIMIT_KEY;
import static org.apache.dubbo.rpc.Constants.DEFAULT_CALLBACK_INSTANCES;
import static org.apache.dubbo.rpc.Constants.IS_SERVER_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.CALLBACK_SERVICE_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.CALLBACK_SERVICE_PROXY_KEY;

View File

@ -41,10 +41,10 @@ import java.util.Map;
import java.util.Optional;
import static org.apache.dubbo.common.URL.buildKey;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.decodeInvocationArgument;
public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Decodeable {
@ -138,7 +138,7 @@ public class DecodeableRpcInvocation extends RpcInvocation implements Codec, Dec
}
setParameterTypes(pts);
Map<String, String> map = in.readAttachments();
Map<String, Object> map = in.readAttachments();
if (map != null && map.size() > 0) {
Map<String, Object> attachment = getAttachments();
if (attachment == null) {

View File

@ -36,9 +36,9 @@ import org.apache.dubbo.rpc.RpcInvocation;
import java.io.IOException;
import java.io.InputStream;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.CallbackServiceCodec.encodeInvocationArgument;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DECODE_IN_IO_THREAD_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_DECODE_IN_IO_THREAD;

View File

@ -62,7 +62,9 @@ import java.util.function.Function;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.INTERFACE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.LAZY_CONNECT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.STUB_EVENT_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.VERSION_KEY;
import static org.apache.dubbo.remoting.Constants.CHANNEL_READONLYEVENT_SENT_KEY;
import static org.apache.dubbo.remoting.Constants.CLIENT_KEY;
@ -75,8 +77,6 @@ import static org.apache.dubbo.remoting.Constants.SERVER_KEY;
import static org.apache.dubbo.rpc.Constants.DEFAULT_REMOTING_SERVER;
import static org.apache.dubbo.rpc.Constants.DEFAULT_STUB_EVENT;
import static org.apache.dubbo.rpc.Constants.IS_SERVER_KEY;
import static org.apache.dubbo.rpc.Constants.LAZY_CONNECT_KEY;
import static org.apache.dubbo.rpc.Constants.STUB_EVENT_KEY;
import static org.apache.dubbo.rpc.Constants.STUB_EVENT_METHODS_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.CALLBACK_SERVICE_KEY;
import static org.apache.dubbo.rpc.protocol.dubbo.Constants.DEFAULT_SHARE_CONNECTIONS;

View File

@ -24,9 +24,8 @@ import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.protocol.AbstractInvoker;
import io.grpc.ManagedChannel;
import static org.apache.dubbo.rpc.support.RpcUtils.getErrorCode;
import static org.apache.dubbo.rpc.support.RpcUtils.getRpcException;
import io.grpc.Status;
import io.grpc.StatusException;
public class GrpcInvoker<T> extends AbstractInvoker<T> {
@ -79,4 +78,30 @@ public class GrpcInvoker<T> extends AbstractInvoker<T> {
super.destroy();
channel.shutdown();
}
private RpcException getRpcException(Class<?> type, URL url, Invocation invocation, Throwable e) {
RpcException re = new RpcException("Failed to invoke remote service: " + type + ", method: "
+ invocation.getMethodName() + ", cause: " + e.getMessage(), e);
re.setCode(getErrorCode(e));
return re;
}
/**
* FIXME, convert gRPC exceptions to equivalent Dubbo exceptions.
*
* @param e
* @return
*/
private int getErrorCode(Throwable e) {
if (e instanceof StatusException) {
StatusException statusException = (StatusException) e;
Status status = statusException.getStatus();
if (status.getCode() == Status.Code.DEADLINE_EXCEEDED) {
return RpcException.TIMEOUT_EXCEPTION;
} else if (status.getCode() == Status.Code.DEADLINE_EXCEEDED) {
//
}
}
return RpcException.UNKNOWN_EXCEPTION;
}
}

View File

@ -163,7 +163,7 @@ public class GrpcOptionsUtils {
return configurator.configureCallOptions(callOptions, url);
}
static SslContext buildServerSslContext(URL url) {
private static SslContext buildServerSslContext(URL url) {
SslContextBuilder sslClientContextBuilder = null;
try {
String password = url.getParameter(SSL_SERVER_KEY_PASSWORD_KEY);
@ -190,7 +190,7 @@ public class GrpcOptionsUtils {
}
}
static SslContext buildClientSslContext(URL url) {
private static SslContext buildClientSslContext(URL url) {
SslContextBuilder builder = GrpcSslContexts.forClient();
String trustCertCollectionFilePath = url.getParameter(SSL_CLIENT_TRUST_CERT_PATH_KEY);
try {

View File

@ -44,9 +44,9 @@ public class RpcContextInterceptor implements ClientInterceptor, ServerIntercept
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
RpcContext rpcContext = RpcContext.getContext();
Map<String, String> attachments = rpcContext.getAttachments();
Map<String, Object> attachments = rpcContext.getAttachments();
if (attachments != null) {
for (Map.Entry<String, String> entry : attachments.entrySet()) {
for (Map.Entry<String, Object> entry : attachments.entrySet()) {
callOptions = callOptions.withOption(CallOptions.Key.create(DUBBO + entry.getKey()), entry.getValue());
}
}

View File

@ -17,8 +17,8 @@
package org.apache.dubbo.rpc.protocol.httpinvoker;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.remoting.Constants;
import org.apache.dubbo.remoting.http.HttpBinder;
import org.apache.dubbo.remoting.http.HttpHandler;
@ -48,9 +48,9 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;
import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
/**

View File

@ -17,6 +17,7 @@
package org.apache.dubbo.rpc.protocol.http;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.RemotingServer;
import org.apache.dubbo.remoting.http.HttpBinder;
import org.apache.dubbo.remoting.http.HttpHandler;
import org.apache.dubbo.rpc.ProtocolServer;
@ -45,8 +46,6 @@ public class HttpProtocol extends AbstractProxyProtocol {
public static final String ACCESS_CONTROL_ALLOW_METHODS_HEADER = "Access-Control-Allow-Methods";
public static final String ACCESS_CONTROL_ALLOW_HEADERS_HEADER = "Access-Control-Allow-Headers";
private final Map<String, HttpServer> serverMap = new ConcurrentHashMap<>();
private final Map<String, JsonRpcServer> skeletonMap = new ConcurrentHashMap<>();
private HttpBinder httpBinder;
@ -104,7 +103,7 @@ public class HttpProtocol extends AbstractProxyProtocol {
String addr = getAddr(url);
ProtocolServer protocolServer = serverMap.get(addr);
if (protocolServer == null) {
RemotingServer remotingServer = httpBinder.bind(url, new InternalHandler());
RemotingServer remotingServer = httpBinder.bind(url, new InternalHandler(url.getParameter("cors", false)));
serverMap.put(addr, new ProxyProtocolServer(remotingServer));
}
final String path = url.getAbsolutePath();
@ -124,7 +123,6 @@ public class HttpProtocol extends AbstractProxyProtocol {
return (T) jsonProxyFactoryBean.getObject();
}
@Override
protected int getErrorCode(Throwable e) {
if (e instanceof RemoteAccessException) {
e = e.getCause();
@ -146,7 +144,7 @@ public class HttpProtocol extends AbstractProxyProtocol {
public void destroy() {
super.destroy();
for (String key : new ArrayList<>(serverMap.keySet())) {
HttpServer server = serverMap.remove(key);
ProtocolServer server = serverMap.remove(key);
if (server != null) {
try {
if (logger.isInfoEnabled()) {

View File

@ -25,7 +25,6 @@ import org.apache.dubbo.rpc.ProtocolServer;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.protocol.AbstractProxyProtocol;
import org.apache.dubbo.rpc.support.RpcUtils;
import org.apache.http.HeaderElement;
import org.apache.http.HeaderElementIterator;
@ -199,9 +198,10 @@ public class RestProtocol extends AbstractProxyProtocol {
return target.proxy(serviceType);
}
@Override
protected int getErrorCode(Throwable e) {
// TODO
return RpcUtils.getErrorCode(e);
return super.getErrorCode(e);
}
@Override

View File

@ -33,8 +33,8 @@ import java.rmi.RemoteException;
import static org.apache.dubbo.common.Version.isRelease263OrHigher;
import static org.apache.dubbo.common.Version.isRelease270OrHigher;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.RELEASE_KEY;
import static org.apache.dubbo.remoting.Constants.DUBBO_VERSION_KEY;
import static org.apache.dubbo.rpc.Constants.GENERIC_KEY;
/**

View File

@ -83,7 +83,7 @@ public interface ObjectInput extends DataInput {
return readObject();
}
default Map<String, String> readAttachments() throws IOException, ClassNotFoundException {
default Map<String, Object> readAttachments() throws IOException, ClassNotFoundException {
return readObject(Map.class);
}
}

View File

@ -53,7 +53,7 @@ public interface ObjectOutput extends DataOutput {
writeObject(data);
}
default void writeAttachments(Map<String, String> attachments) throws IOException {
default void writeAttachments(Map<String, Object> attachments) throws IOException {
writeObject(attachments);
}

View File

@ -34,6 +34,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import static org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT;
@ -134,10 +135,22 @@ public class GenericProtobufJsonObjectInput implements ObjectInput {
return ProtobufUtils.convertToException(throwableProto);
}
/**
* FIXME, only supports transmission of String values.
*
* @return
* @throws IOException
* @throws ClassNotFoundException
*/
@Override
public Map<String, String> readAttachments() throws IOException, ClassNotFoundException {
public Map<String, Object> readAttachments() throws IOException, ClassNotFoundException {
String json = readLine();
return ProtobufUtils.deserializeJson(json, MapValue.Map.class).getAttachmentsMap();
Map<String, String> attachments = ProtobufUtils.deserializeJson(json, MapValue.Map.class).getAttachmentsMap();
Map<String, Object> genericAttachments = new HashMap<>();
attachments.forEach((k, v) -> {
genericAttachments.put(k, v);
});
return genericAttachments;
}
@Override

View File

@ -32,6 +32,7 @@ import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import static org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT;
@ -132,9 +133,21 @@ public class GenericProtobufJsonObjectOutput implements ObjectOutput {
writeUTF((String) data);
}
/**
* FIXME, only supports transmission of String values.
*
* @param attachments
* @throws IOException
*/
@Override
public void writeAttachments(Map<String, String> attachments) throws IOException {
MapValue.Map proto = MapValue.Map.newBuilder().putAllAttachments(attachments).build();
public void writeAttachments(Map<String, Object> attachments) throws IOException {
if (attachments == null) {
return;
}
Map<String, String> stringAttachments = new HashMap<>();
attachments.forEach((k, v) -> stringAttachments.put(k, (String) v));
MapValue.Map proto = MapValue.Map.newBuilder().putAllAttachments(stringAttachments).build();
writer.write(ProtobufUtils.serializeJson(proto));
writer.println();
writer.flush();

View File

@ -31,6 +31,7 @@ import com.google.protobuf.StringValue;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;
import static org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT;
@ -133,7 +134,13 @@ public class GenericProtobufObjectInput implements ObjectInput {
}
@Override
public Map<String, String> readAttachments() throws IOException {
return ProtobufUtils.deserialize(is, MapValue.Map.class).getAttachmentsMap();
public Map<String, Object> readAttachments() throws IOException {
Map<String, String> stringAttachments = ProtobufUtils.deserialize(is, MapValue.Map.class).getAttachmentsMap();
Map<String, Object> attachments = new HashMap<>();
if (stringAttachments != null) {
stringAttachments.forEach((k, v) -> attachments.put(k, v));
}
return attachments;
}
}

View File

@ -31,6 +31,7 @@ import com.google.protobuf.StringValue;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import static org.apache.dubbo.common.constants.CommonConstants.HEARTBEAT_EVENT;
@ -136,8 +137,15 @@ public class GenericProtobufObjectOutput implements ObjectOutput {
}
@Override
public void writeAttachments(Map<String, String> attachments) throws IOException {
ProtobufUtils.serialize(MapValue.Map.newBuilder().putAllAttachments(attachments).build(), os);
public void writeAttachments(Map<String, Object> attachments) throws IOException {
if (attachments == null) {
return;
}
Map<String, String> stringAttachments = new HashMap<>();
attachments.forEach((k, v) -> stringAttachments.put(k, (String) v));
ProtobufUtils.serialize(MapValue.Map.newBuilder().putAllAttachments(stringAttachments).build(), os);
os.flush();
}