Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into zk-service-discov…
Browse files Browse the repository at this point in the history
…er-support-multi-address
  • Loading branch information
horizonzy committed Mar 6, 2021
2 parents c8de5ff + eef6b45 commit 7abcc17
Show file tree
Hide file tree
Showing 25 changed files with 305 additions and 37 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ jobs:
with:
path: ~/.m2/repository/org/apache/dubbo
key: ${{ runner.os }}-dubbo-snapshot-${{ github.sha }}
- name: "Calculate Dubbo Version"
id: dubbo-version
run: |
REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' ./dubbo/pom.xml`
echo "::set-output name=version::$REVISION"
echo "dubbo version: $REVISION"
- name: "Build Dubbo with Maven"
run: |
cd ./dubbo
./mvnw --batch-mode -U -e --no-transfer-progress clean install -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.count=5 -Dmaven.test.skip=true -Dmaven.test.skip.exec=true
- name: "Build Dubbo Spring Boot with Maven"
run: |
cd ./dubbo-spring-boot-project
./mvnw --batch-mode --no-transfer-progress clean install -Dmaven.test.skip=true -Dmaven.test.skip.exec=true
- name: "Calculate Dubbo Version"
id: dubbo-version
run: |
REVISION=`awk '/<revision>[^<]+<\/revision>/{gsub(/<revision>|<\/revision>/,"",$1);print $1;exit;}' ./dubbo/pom.xml`
echo "::set-output name=version::$REVISION"
echo "dubbo version: $REVISION"
./mvnw --batch-mode --no-transfer-progress clean install -Drevision=${{ steps.dubbo-version.outputs.version }} -Dmaven.test.skip=true -Dmaven.test.skip.exec=true
unit-test:
needs: [build-source]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@

/**
* ConditionRouter
*
* It supports the conditional routing configured by "override://", in 2.6.x,
* refer to https://dubbo.apache.org/en/docs/v2.7/user/examples/routing-rule/ .
* For 2.7.x and later, please refer to {@link org.apache.dubbo.rpc.cluster.router.condition.config.ServiceRouter}
* and {@link org.apache.dubbo.rpc.cluster.router.condition.config.AppRouter}
* refer to https://dubbo.apache.org/zh/docs/v2.7/user/examples/routing-rule/ .
*/
public class ConditionRouter extends AbstractRouter {
public static final String NAME = "condition";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

/**
* ConditionRouterFactory
*
* Load when "override://" is configured {@link ConditionRouter}
*/
public class ConditionRouterFactory implements RouterFactory {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.wrapper;

import org.apache.dubbo.common.extension.SPI;

@SPI("demo")
public interface Demo {
String echo(String msg);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.wrapper;

import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.extension.wrapper.impl.DemoWrapper;
import org.apache.dubbo.common.extension.wrapper.impl.DemoWrapper2;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* {@link org.apache.dubbo.common.extension.Wrapper} Test
*
* @since 2.7.5
*/
public class WrapperTest {

@Test
public void testWrapper() {
Demo demoWrapper = ExtensionLoader.getExtensionLoader(Demo.class).getExtension("demo");
assertTrue(demoWrapper instanceof DemoWrapper);
Demo demoWrapper2 = ExtensionLoader.getExtensionLoader(Demo.class).getExtension("demo2");
assertTrue(demoWrapper2 instanceof DemoWrapper2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.wrapper.impl;

import org.apache.dubbo.common.extension.wrapper.Demo;

public class DemoImpl implements Demo {
@Override
public String echo(String msg) {
return msg;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.wrapper.impl;

import org.apache.dubbo.common.extension.Wrapper;
import org.apache.dubbo.common.extension.wrapper.Demo;

@Wrapper(matches = {"demo"}, mismatches = "demo2")
public class DemoWrapper implements Demo {
private Demo demo;

public DemoWrapper(Demo demo) {
this.demo = demo;
}

public String echo(String msg) {
return demo.echo(msg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.common.extension.wrapper.impl;

import org.apache.dubbo.common.extension.Wrapper;
import org.apache.dubbo.common.extension.wrapper.Demo;

@Wrapper(matches = {"demo2"}, mismatches = {"demo"})
public class DemoWrapper2 implements Demo {
private Demo demo;

public DemoWrapper2(Demo demo) {
this.demo = demo;
}

public String echo(String msg) {
return demo.echo(msg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
demo=org.apache.dubbo.common.extension.wrapper.impl.DemoImpl
wrapper=org.apache.dubbo.common.extension.wrapper.impl.DemoWrapper
wrapper2=org.apache.dubbo.common.extension.wrapper.impl.DemoWrapper2
demo2=org.apache.dubbo.common.extension.wrapper.impl.DemoImpl
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ public void destroy() {
unreferServices();

destroyRegistries();
DubboShutdownHook.destroyProtocols();

destroyServiceDiscoveries();
destroyExecutorRepository();
clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.config.spring.ServiceBean;
import org.apache.dubbo.config.spring.context.DubboBootstrapApplicationListener;
import org.apache.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner;
import org.apache.dubbo.config.spring.schema.AnnotationBeanDefinitionParser;

Expand Down Expand Up @@ -67,6 +68,7 @@
import java.util.Objects;
import java.util.Set;

import static com.alibaba.spring.util.BeanRegistrar.registerInfrastructureBean;
import static com.alibaba.spring.util.ObjectUtils.of;
import static java.util.Arrays.asList;
import static org.apache.dubbo.config.spring.beans.factory.annotation.ServiceBeanNameBuilder.create;
Expand Down Expand Up @@ -123,6 +125,9 @@ public ServiceClassPostProcessor(Set<String> packagesToScan) {
@Override
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

// @since 2.7.5
registerInfrastructureBean(registry, DubboBootstrapApplicationListener.BEAN_NAME, DubboBootstrapApplicationListener.class);

Set<String> resolvedPackagesToScan = resolvePackagesToScan(packagesToScan);

if (!CollectionUtils.isEmpty(resolvedPackagesToScan)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) t
p.addLast(new StringDecoder(CharsetUtil.UTF_8));
p.addLast(new StringEncoder(CharsetUtil.UTF_8));
p.addLast(new IdleStateHandler(0, 0, 5 * 60));
p.addLast(new TelnetIdleEventHandler());
p.addLast(new TelnetProcessHandler());
p.remove(this);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.qos.server.handler;

import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.timeout.IdleStateEvent;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;

public class TelnetIdleEventHandler extends ChannelDuplexHandler {
private static final Logger log = LoggerFactory.getLogger(TelnetIdleEventHandler.class);

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
// server will close channel when server don't receive any request from client util timeout.
if (evt instanceof IdleStateEvent) {
Channel channel = ctx.channel();
log.info("IdleStateEvent triggered, close channel " + channel);
channel.close();
} else {
super.userEventTriggered(ctx, evt);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,18 @@ public boolean unsubscribeURL(URL url) {
@Override
public void publishServiceDefinition(URL providerUrl) {
try {
String interfaceName = providerUrl.getParameter(INTERFACE_KEY);
if (StringUtils.isNotEmpty(interfaceName)
&& !ProtocolUtils.isGeneric(providerUrl.getParameter(GENERIC_KEY))) {
Class interfaceClass = Class.forName(interfaceName);
ServiceDefinition serviceDefinition = ServiceDefinitionBuilder.build(interfaceClass);
Gson gson = new Gson();
String data = gson.toJson(serviceDefinition);
serviceDefinitions.put(providerUrl.getServiceKey(), data);
return;
if(!ProtocolUtils.isGeneric(providerUrl.getParameter(GENERIC_KEY))){
String interfaceName = providerUrl.getParameter(INTERFACE_KEY);
if (StringUtils.isNotEmpty(interfaceName)) {
Class interfaceClass = Class.forName(interfaceName);
ServiceDefinition serviceDefinition = ServiceDefinitionBuilder.build(interfaceClass);
Gson gson = new Gson();
String data = gson.toJson(serviceDefinition);
serviceDefinitions.put(providerUrl.getServiceKey(), data);
return;
}
logger.error("publishProvider interfaceName is empty . providerUrl: " + providerUrl.toFullString());
}
logger.error("publishProvider interfaceName is empty . providerUrl: " + providerUrl.toFullString());
} catch (ClassNotFoundException e) {
//ignore error
logger.error("publishProvider getServiceDescriptor error. providerUrl: " + providerUrl.toFullString(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,22 @@ public static void destroyAll() {
}
}

@Override
public Registry getRegistry(URL url) {
private Registry getDefaultNopRegistryIfDestroyed() {
if (destroyed.get()) {
LOGGER.warn("All registry instances have been destroyed, failed to fetch any instance. " +
"Usually, this means no need to try to do unnecessary redundant resource clearance, all registries has been taken care of.");
return DEFAULT_NOP_REGISTRY;
}
return null;
}

@Override
public Registry getRegistry(URL url) {

Registry defaultNopRegistry = getDefaultNopRegistryIfDestroyed();
if (null != defaultNopRegistry) {
return defaultNopRegistry;
}

url = URLBuilder.from(url)
.setPath(RegistryService.class.getName())
Expand All @@ -126,6 +135,13 @@ public Registry getRegistry(URL url) {
// Lock the registry access process to ensure a single instance of the registry
LOCK.lock();
try {
// double check
// fix https://github.com/apache/dubbo/issues/7265.
defaultNopRegistry = getDefaultNopRegistryIfDestroyed();
if (null != defaultNopRegistry) {
return defaultNopRegistry;
}

Registry registry = REGISTRIES.get(key);
if (registry != null) {
return registry;
Expand Down
Loading

0 comments on commit 7abcc17

Please sign in to comment.