Skip to content

Commit

Permalink
Dubbo cloud native (#4817)
Browse files Browse the repository at this point in the history
* Polish #4542 : [Enhancement] Adapt the Java standard Event/Listener mechanism

* Polish #4541 : [Feature] Add local File System DynamicConfigurationFactory‘s extension

* Polish #4541 : Bugfix

* Polish #4541 : Optimization

* Polish #4541 : Add the compatibility for PollingWatchService on the some platforms

* Polish #4541 : Add delay publish without ThreadPoolExecutor

* Polish #4541 : Refactor the extension name

* Polish #4541 : Add remove ops

* Polish #4541 : Add testable constructor

* Polish #4541 : Add getConfigGroups method

* Polish #4610 : [Refactor] Refactor the bootstrap module

* Polish #4541 : Fix the nulling URL issue

* Polish #4622 : [Refactor] Refactor ConfigManager

* Polish #4622 : [Refactor] Refactor ConfigManager

* Polish #4622 : Support multiple configcenters

* Polish #4671 : ServiceNameMapping will not map the group, version and protocol

* update referenceCount log (#4683)

Add comments to support multiple shared connections

* Polish /#4687 : Remove the duplicated test code in dubbo-config-spring (#4688)

* #4685  修改代码if判断false问题 if (hasException == false)修改成if (!hasException) (#4695)

* Fixed Service annotation method parameters are not in effect (#4598)

* keep demo simple, and switch to use zookeeper as registry center (#4705)

* keep demo simple, and switch to use zookeeper as registry center

* remove comment

* @reference auto-wires the instance of generic interface #4594 (#4677)

* try to shorten maven output to make travis build pass (#4710)

* use CountDownLatch to check zk registry if establish connection (#4589)

* Minor change

* Rename the extension name of WritableMetadataService

* Polish #4759 : [Refactor] Change the signature of methods of MetadataService #4759

* Merge remote-tracking branch 'upstream/master' into dubbo-cloud-native

# Conflicts:
#	dubbo-all/pom.xml
#	dubbo-bom/pom.xml
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ApplicationConfig.java
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/RegistryConfig.java
#	dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java
#	dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ReferenceConfigTest.java
#	dubbo-configcenter/dubbo-configcenter-api/src/main/java/org/apache/dubbo/configcenter/DynamicConfiguration.java
#	dubbo-configcenter/dubbo-configcenter-api/src/test/java/org/apache/dubbo/configcenter/mock/MockDynamicConfiguration.java
#	dubbo-configcenter/dubbo-configcenter-consul/src/main/java/org/apache/dubbo/configcenter/consul/ConsulDynamicConfiguration.java
#	dubbo-configcenter/dubbo-configcenter-etcd/src/test/java/org/apache/dubbo/configcenter/support/etcd/EtcdDynamicConfigurationTest.java
#	dubbo-configcenter/dubbo-configcenter-nacos/src/main/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfiguration.java
#	dubbo-configcenter/dubbo-configcenter-nacos/src/test/java/org/apache/dubbo/configcenter/support/nacos/NacosDynamicConfigurationTest.java
#	dubbo-configcenter/dubbo-configcenter-zookeeper/src/main/java/org/apache/dubbo/configcenter/support/zookeeper/ZookeeperDynamicConfiguration.java
#	dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/definition/model/MethodDefinition.java
#	dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifier.java
#	dubbo-metadata/dubbo-metadata-api/src/main/java/org/apache/dubbo/metadata/report/support/AbstractMetadataReport.java
#	dubbo-metadata/dubbo-metadata-api/src/test/java/org/apache/dubbo/metadata/report/identifier/MetadataIdentifierTest.java
#	dubbo-metadata/dubbo-metadata-definition-protobuf/src/main/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilder.java
#	dubbo-metadata/dubbo-metadata-definition-protobuf/src/test/java/org/apache/dubbo/metadata/definition/protobuf/ProtobufTypeBuilderTest.java
#	dubbo-metadata/pom.xml
#	dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/AbstractConfiguratorListener.java
#	dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistry.java
#	dubbo-registry/dubbo-registry-nacos/src/main/java/org/apache/dubbo/registry/nacos/NacosRegistryFactory.java
#	dubbo-rpc/dubbo-rpc-xml/src/main/java/org/apache/dubbo/xml/rpc/protocol/xmlrpc/XmlRpcProtocol.java

* Polish #3984 : Add the implementation of Page<ServiceInstance> getInstances(String serviceName, int offset, int pageSize, boolean healthyOnly)

* Code merge

* Fix the cases

* Merge remote-tracking branch 'upstream/cloud-native' into dubbo-cloud-native

# Conflicts:
#	dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProviderBootstrap.java
#	dubbo-metadata/dubbo-metadata-definition-protobuf/pom.xml
#	dubbo-registry/dubbo-registry-api/src/test/java/org/apache/dubbo/registry/support/ServiceOrientedRegistryTest.java
#	dubbo-registry/dubbo-registry-consul/src/main/java/org/apache/dubbo/registry/consul/ConsulServiceDiscoveryFactory.java
#	dubbo-registry/dubbo-registry-etcd3/src/main/java/org/apache/dubbo/registry/etcd/EtcdServiceDiscovery.java

* Refactor ConfigManager

* Refactor ConfigManager

* Resolve the issues on ConfigManager

* Refactor and add test-cases for ConfigManager

* Polish #4774 : [Feature] Dubbo Cloud Native - To Support in Spring

* Polish #4808 : [Feature] Add the registered/unregistered event mechanism ShutdownHook

* Polish #4807 : [Feature] Add the callback mechanism ShutdownHook #4807

* Polish #4813 : [Feature] add Prioritized implementation for ServiceInstanceCustomizer

* Polish #4815 : [Feature] Add the ServiceLoader for Dubbo's services or components

* Polish #4815 : [Feature] Add the ServiceLoader for Dubbo's services or components
  • Loading branch information
mercyblitz committed Aug 14, 2019
1 parent 36e1a1c commit 12e1532
Show file tree
Hide file tree
Showing 21 changed files with 856 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import org.apache.dubbo.common.config.Environment;
import org.apache.dubbo.common.config.configcenter.DynamicConfiguration;
import org.apache.dubbo.common.config.configcenter.wrapper.CompositeDynamicConfiguration;
import org.apache.dubbo.common.context.Lifecycle;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.config.AbstractConfig;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ConfigCenterConfig;
import org.apache.dubbo.config.ConsumerConfig;
Expand All @@ -38,7 +38,6 @@
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.builders.AbstractBuilder;
import org.apache.dubbo.config.builders.ApplicationBuilder;
import org.apache.dubbo.config.builders.ConsumerBuilder;
import org.apache.dubbo.config.builders.ProtocolBuilder;
Expand All @@ -64,7 +63,6 @@
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -90,7 +88,7 @@
*
* @since 2.7.4
*/
public class DubboBootstrap {
public class DubboBootstrap implements Lifecycle {

public static final String DEFAULT_REGISTRY_ID = "REGISTRY#DEFAULT";

Expand Down Expand Up @@ -409,25 +407,26 @@ public DubboBootstrap cache(ReferenceConfigCache cache) {
/**
* Initialize
*/
public void init() {
public DubboBootstrap initialize() {
if (!isInitialized()) {

if (isInitialized()) {
return;
}
startConfigCenter();

startConfigCenter();
startMetadataReport();

startMetadataReport();
loadRemoteConfigs();

loadRemoteConfigs();
useRegistryAsConfigCenterIfNecessary();

useRegistryAsConfigCenterIfNecessary();
initialized = true;

initialized = true;
if (logger.isInfoEnabled()) {
logger.info(NAME + " has been initialized!");
}

if (logger.isInfoEnabled()) {
logger.info(NAME + " has been initialized!");
}

return this;
}

private void loadRemoteConfigs() {
Expand Down Expand Up @@ -505,12 +504,12 @@ private Collection<ServiceDiscovery> getServiceDiscoveries() {
/**
* Start the bootstrap
*/
@Override
public DubboBootstrap start() {

if (!isInitialized()) {
initialize();
}
if (!isStarted()) {
if (!isInitialized()) {
init();
}

exportServices();

Expand Down Expand Up @@ -574,32 +573,26 @@ public DubboBootstrap await() {
/**
* Stop the bootstrap
*/
public void stop() {

if (!isInitialized() || !isStarted()) {
return;
@Override
public DubboBootstrap stop() {
if (isInitialized() && isStarted()) {
unregisterServiceInstance();
unexportServices();
started = false;
}

unregisterServiceInstance();

destroy();

clear();

release();

shutdown();
return this;
}

@Override
public boolean isInitialized() {
return initialized;
}

@Override
public boolean isStarted() {
return started;
}


/* serve for builder apis, begin */
private ApplicationBuilder createApplicationBuilder(String name) {
return new ApplicationBuilder().name(name);
Expand Down Expand Up @@ -716,11 +709,11 @@ private List<URL> exportMetadataService(ApplicationConfig applicationConfig,
}

private void exportServices() {
configManager.getServices().forEach(this::exportServiceConfig);
configManager.getServices().forEach(ServiceConfig::export);
}

public void exportServiceConfig(ServiceConfig<?> serviceConfig) {
serviceConfig.export();
private void unexportServices() {
configManager.getServices().forEach(ServiceConfig::unexport);
}

private void referServices() {
Expand Down Expand Up @@ -803,22 +796,29 @@ private ServiceInstance initServiceInstance(String serviceName, String host, int
return this.serviceInstance;
}

private void destroy() {
public void destroy() {

destroyProtocolConfigs();
stop();

destroyReferenceConfigs();
destroyProtocols();

destroyReferences();

clear();

release();

shutdown();
}

private void destroyProtocolConfigs() {
private void destroyProtocols() {
configManager.getProtocols().forEach(ProtocolConfig::destroy);
if (logger.isDebugEnabled()) {
logger.debug(NAME + "'s all ProtocolConfigs have been destroyed.");
}
}

private void destroyReferenceConfigs() {
private void destroyReferences() {
configManager.getReferences().forEach(ReferenceConfig::destroy);
if (logger.isDebugEnabled()) {
logger.debug(NAME + "'s all ReferenceConfigs have been destroyed.");
Expand Down Expand Up @@ -862,13 +862,4 @@ private void executeMutually(Runnable runnable) {
lock.unlock();
}
}

private static <C extends AbstractConfig, B extends
AbstractBuilder> List<C> buildConfigs(Map<String, B> map) {
List<C> configs = new ArrayList<>();
map.entrySet().forEach(entry -> {
configs.add((C) entry.getValue().build());
});
return configs;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.dubbo.bootstrap.DubboBootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public class CompositeDynamicConfiguration implements DynamicConfiguration {
private Set<DynamicConfiguration> configurations = new HashSet<>();

public void addConfiguration(DynamicConfiguration configuration) {
this.configurations.add(configuration);
if (configuration != null) {
this.configurations.add(configuration);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.context;

/**
* The Lifecycle of Dubbo component
*
* @since 2.7.4
*/
public interface Lifecycle {

/**
* Initialize the component before {@link #start() start}
*
* @return current {@link Lifecycle}
* @throws IllegalStateException
*/
Lifecycle initialize() throws IllegalStateException;

/**
* Initialized or not
*
* @return if initialized, return <code>true</code>, or <code>false</code>
*/
boolean isInitialized();

/**
* Start the component
*
* @return current {@link Lifecycle}
* @throws IllegalStateException
*/
Lifecycle start() throws IllegalStateException;

/**
* The component is started or not
*
* @return if started, return <code>true</code>, or <code>false</code>
*/
boolean isStarted();

/**
* Stop the component
*
* @return current {@link Lifecycle}
*/
Lifecycle stop() throws IllegalStateException;

/**
* The component is stopped or not
*
* @return if stopped, return <code>true</code>, or <code>false</code>
*/
default boolean isStopped() {
return !isStarted();
}

/**
* Destroy the component
*
* @throws IllegalStateException
*/
void destroy() throws IllegalStateException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* 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.lang;

import java.util.Comparator;

import static java.lang.Integer.compare;

/**
* {@code Prioritized} interface can be implemented by objects that
* should be sorted, for example the tasks in executable queue.
*
* @since 2.7.4
*/
public interface Prioritized extends Comparable<Prioritized> {

/**
* The {@link Comparator} of {@link Prioritized}
*/
Comparator<Object> COMPARATOR = (one, two) -> {
boolean b1 = one instanceof Prioritized;
boolean b2 = two instanceof Prioritized;
if (b1 && !b2) { // one is Prioritized, two is not
return -1;
} else if (b2 && !b1) { // two is Prioritized, one is not
return 1;
} else if (b1 && b2) { // one and two both Prioritized
return ((Prioritized) one).compareTo((Prioritized) two);
} else { // no different
return 0;
}
};

/**
* The maximum priority
*/
int MAX_PRIORITY = Integer.MIN_VALUE;

/**
* The minimum priority
*/
int MIN_PRIORITY = Integer.MAX_VALUE;

/**
* Get the priority
*
* @return the default is {@link #MIN_PRIORITY minimum one}
*/
default int getPriority() {
return MIN_PRIORITY;
}

@Override
default int compareTo(Prioritized that) {
return compare(this.getPriority(), that.getPriority());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.lang;

/**
* Dubbo ShutdownHook callback interface
*
* @since 2.7.4
*/
public interface ShutdownHookCallback extends Prioritized {

/**
* Callback execution
*
* @throws Throwable if met with some errors
*/
void callback() throws Throwable;
}

0 comments on commit 12e1532

Please sign in to comment.