use of org.apache.dubbo.metadata.MetadataParamsFilter in project dubbo by alibaba.
the class ServiceInstanceMetadataCustomizer method customize.
@Override
public void customize(ServiceInstance serviceInstance) {
ExtensionLoader<MetadataParamsFilter> loader = ExtensionLoader.getExtensionLoader(MetadataParamsFilter.class);
Set<MetadataParamsFilter> paramsFilters = loader.getSupportedExtensionInstances();
WritableMetadataService localMetadataService = WritableMetadataService.getDefaultExtension();
// pick the first interface metadata available.
// FIXME, check the same key in different urls has the same value
MetadataInfo metadataInfo = localMetadataService.getMetadataInfos().values().iterator().next();
MetadataInfo.ServiceInfo serviceInfo = metadataInfo.getServices().values().iterator().next();
Map<String, String> allParams = new HashMap<>(serviceInfo.getUrl().getParameters());
// load instance params users want to load.
// TODO, duplicate logic with that in ApplicationConfig
Set<InfraAdapter> adapters = ExtensionLoader.getExtensionLoader(InfraAdapter.class).getSupportedExtensionInstances();
if (CollectionUtils.isNotEmpty(adapters)) {
Map<String, String> inputParameters = new HashMap<>();
inputParameters.put(APPLICATION_KEY, ApplicationModel.getName());
for (InfraAdapter adapter : adapters) {
Map<String, String> extraParameters = adapter.getExtraAttributes(inputParameters);
if (CollectionUtils.isNotEmptyMap(extraParameters)) {
extraParameters.forEach(allParams::putIfAbsent);
}
}
}
if (CollectionUtils.isEmpty(paramsFilters)) {
serviceInstance.getMetadata().putAll(allParams);
return;
}
paramsFilters.forEach(filter -> {
String[] included = filter.instanceParamsIncluded();
if (included == null) {
serviceInstance.getMetadata().putAll(allParams);
} else {
for (String p : included) {
if (allParams.get(p) != null) {
serviceInstance.getMetadata().put(p, allParams.get(p));
}
}
}
});
}
Aggregations