Skip to content

Commit

Permalink
feat(config): apache#13299 Enhance spring boot configuration metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
oxsean committed Nov 2, 2023
1 parent 539bb11 commit 7bd90ae
Show file tree
Hide file tree
Showing 40 changed files with 955 additions and 479 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,20 @@
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_REFLECTIVE_OPERATION_FAILED;
import static org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
import static org.apache.dubbo.common.utils.ClassUtils.isSimpleType;
import static org.apache.dubbo.common.utils.ReflectUtils.findMethodByMethodSignature;
import static org.apache.dubbo.config.Constants.PARAMETERS;

/**
* Utility methods and public methods for parsing configuration
*
* @export
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public abstract class AbstractConfig implements Serializable {

protected static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(AbstractConfig.class);
private static final long serialVersionUID = 4267533505537413570L;

protected static final ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(AbstractConfig.class);

/**
* tag name cache, speed up get tag name frequently
*/
Expand All @@ -97,19 +98,22 @@ public abstract class AbstractConfig implements Serializable {
private static final String[] SUFFIXES = new String[]{"Config", "Bean", "ConfigBase"};

/**
* The config id
* Identifier for this configuration.
*/
private String id;

/**
* Indicates whether the configuration has been refreshed (true if refreshed).
*/
protected final AtomicBoolean refreshed = new AtomicBoolean(false);

/**
* Indicate that if current config needs to being refreshed, default is true
* Specifies if this configuration should be refreshed (true for refreshing).
*/
protected transient volatile boolean needRefresh = true;

/**
* Is default config or not
* Indicates if this is the default configuration (true for default).
*/
protected Boolean isDefault;

Expand Down Expand Up @@ -158,16 +162,12 @@ public static void appendParameters(Map<String, String> parameters, Object confi
appendParameters(parameters, config, null);
}

@SuppressWarnings("unchecked")
public static void appendParameters(Map<String, String> parameters, Object config, String prefix) {
appendParameters0(parameters, config, prefix, true);
}

/**
* Put attributes of specify 'config' into 'parameters' argument
*
* @param parameters
* @param config
*/
public static void appendAttributes(Map<String, String> parameters, Object config) {
appendParameters0(parameters, config, null, false);
Expand Down Expand Up @@ -292,7 +292,7 @@ private static String calculateAttributeFromGetter(String getter) {

private static void invokeSetParameters(Class c, Object o, Map map) {
try {
Method method = findMethodByMethodSignature(c, "setParameters", new String[]{Map.class.getName()});
Method method = ReflectUtils.findMethodByMethodSignature(c, "setParameters", new String[]{Map.class.getName()});
if (method != null && isParametersSetter(method)) {
method.invoke(o, map);
}
Expand All @@ -304,7 +304,7 @@ private static void invokeSetParameters(Class c, Object o, Map map) {
private static Map<String, String> invokeGetParameters(Class c, Object o) {
try {

Method method = findMethodByMethodSignature(c, "getParameters", null);
Method method = ReflectUtils.findMethodByMethodSignature(c, "getParameters", null);
if (method != null && isParametersGetter(method)) {
return (Map<String, String>) method.invoke(o);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@
import static org.apache.dubbo.common.constants.MetricsConstants.PROTOCOL_PROMETHEUS;
import static org.apache.dubbo.config.Constants.DEFAULT_NATIVE_PROXY;


/**
* AbstractDefaultConfig
* Abstract configuration for the interface.
*
* @export
*/
Expand All @@ -69,134 +68,148 @@ public abstract class AbstractInterfaceConfig extends AbstractMethodConfig {
private static final long serialVersionUID = -1559314110797223229L;

/**
* The interface name of the exported service
* Interface name of the exported service.
*/
protected String interfaceName;

/**
* The classLoader of interface belong to
* ClassLoader associated with the interface.
*/
protected transient ClassLoader interfaceClassLoader;

/**
* The remote service version the customer/provider side will reference
* Version of the remote service referenced by the consumer/provider.
*/
protected String version;

/**
* The remote service group the customer/provider side will reference
* Group of the remote service referenced by the consumer/provider.
*/
protected String group;

/**
* Service metadata configuration.
*/
protected ServiceMetadata serviceMetadata;

/**
* Local impl class name for the service interface
* Local implementation class name for the service interface.
*/
protected String local;

/**
* Local stub class name for the service interface
* Local stub class name for the service interface.
*/
protected String stub;

/**
* Service monitor
* Service monitoring configuration.
*/
protected MonitorConfig monitor;

/**
* Strategies for generating dynamic agents,there are two strategies can be chosen: jdk and javassist
* Strategy for generating dynamic agents (options: "jdk" or "javassist").
*/
protected String proxy;

/**
* Cluster type
* Cluster type for service.
*/
protected String cluster;

/**
* The {@code Filter} when the provider side exposed a service or the customer side references a remote service used,
* if there are more than one, you can use commas to separate them
* Filters for service exposure or reference (multiple filters can be separated by commas).
*/
protected String filter;

/**
* The Listener when the provider side exposes a service or the customer side references a remote service used
* if there are more than one, you can use commas to separate them
* Listeners for service exposure or reference (multiple listeners can be separated by commas).
*/
protected String listener;

/**
* The owner of the service providers
* Owner of the service providers.
*/
protected String owner;

/**
* Connection limits, 0 means shared connection, otherwise it defines the connections delegated to the current service
* Connection limits: 0 for shared connection, otherwise specifying connections for the service.
*/
protected Integer connections;

/**
* The layer of service providers
* Layer of service providers.
*/
protected String layer;

/**
* The application info
* Application configuration for the service.
*/
protected ApplicationConfig application;

/**
* The module info
* Module configuration for the service.
*/
protected ModuleConfig module;

/**
* The registry list the service will register to
* Also see {@link #registryIds}, only one of them will work.
* Registries where the service will be registered (use this or registryIds, not both).
*/
protected List<RegistryConfig> registries;

/**
* The method configuration
* Method-specific configuration.
*/
private List<MethodConfig> methods;

/**
* The id list of registries the service will register to
* Also see {@link #registries}, only one of them will work.
* Registry IDs for service registration (use this or registries, not both).
*/
protected String registryIds;

// connection events
/**
* Event handler for connection establishment.
*/
protected String onconnect;

/**
* Disconnection events
* Event handler for disconnection.
*/
protected String ondisconnect;

/**
* The metadata report configuration
* Metadata report configuration.
*/
protected MetadataReportConfig metadataReportConfig;

/**
* Configuration center settings.
*/
protected ConfigCenterConfig configCenter;

// callback limits
/**
* Callback limits for the service.
*/
private Integer callbacks;
// the scope for referring/exporting a service, if it's local, it means searching in current JVM only.

/**
* Service scope ("local" implies searching in the current JVM only).
*/
private String scope;

/**
* Custom tag for the service configuration.
*/
protected String tag;

/**
* Enable service authentication.
*/
private Boolean auth;

/*Indicates to create separate instances or not for services/references that have the same serviceKey.
* By default, all services/references that have the same serviceKey will share the same instance and process.
*
* This key currently can only work when using ReferenceConfig and SimpleReferenceCache together.
* Call ReferenceConfig.get() directly will not check this attribute.
/**
* Use separate instances for services with the same serviceKey (applies when using ReferenceConfig and SimpleReferenceCache together).
* Directly calling ReferenceConfig.get() will not check this attribute.
*/
private Boolean singleton;

Expand Down Expand Up @@ -733,7 +746,6 @@ public void setRegistryIds(String registryIds) {
this.registryIds = registryIds;
}


public List<MethodConfig> getMethods() {
return methods;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import java.util.Optional;

/**
* AbstractMethodConfig
* Abstract configuration for the method.
*
* @export
*/
Expand All @@ -37,73 +37,67 @@ public abstract class AbstractMethodConfig extends AbstractConfig {
private static final long serialVersionUID = 5809761483000878437L;

/**
* The timeout for remote invocation in milliseconds
* Timeout for remote invocation in milliseconds.
*/
protected Integer timeout;

/**
* The retry times
* Retry times for failed invocations.
*/
protected Integer retries;

/**
* max concurrent invocations
* Maximum concurrent invocations allowed.
*/
protected Integer actives;

/**
* The load balance
* Load balancing strategy for service invocation.
*/
protected String loadbalance;

/**
* Whether to async
* note that: it is an unreliable asynchronous that ignores return values and does not block threads.
* Enable asynchronous invocation. Note that it is unreliable asynchronous, ignoring return values and not blocking threads.
*/
protected Boolean async;

/**
* Whether to ack async-sent
* Acknowledge asynchronous-sent invocations.
*/
protected Boolean sent;

/**
* The name of mock class which gets called when a service fails to execute
* <p>
* note that: the mock doesn't support on the provider side,and the mock is executed when a non-business exception
* occurs after a remote service call
* Mock class name to be called when a service fails to execute. The mock doesn't support on the provider side,
* and it is executed when a non-business exception occurs after a remote service call.
*/
protected String mock;

/**
* Merger
* Merger for result data.
*/
protected String merger;

/**
* Cache the return result with the call parameter as key, the following options are available: lru, threadlocal,
* jcache, etc.
* Cache provider for caching return results. available options: lru, threadlocal, jcache etc.
*/
protected String cache;

/**
* Whether JSR303 standard annotation validation is enabled or not, if enabled, annotations on method parameters will
* be validated
* Enable JSR303 standard annotation validation for method parameters.
*/
protected String validation;

/**
* The customized parameters
* Customized parameters for configuration.
*/
protected Map<String, String> parameters;

/**
* Forks for forking cluster
* Forks for forking cluster.
*/
protected Integer forks;

public AbstractMethodConfig() {

}

public AbstractMethodConfig(ModuleModel moduleModel) {
Expand Down
Loading

0 comments on commit 7bd90ae

Please sign in to comment.