use of org.apache.dubbo.metadata.report.MetadataReportFactory in project dubbo by alibaba.
the class FailoverMetadataReportTest method getFailoverReport.
protected FailoverMetadataReport getFailoverReport(URL url) {
MetadataReportFactory reportFactory = reportLoader.getExtension(url.getProtocol());
Assertions.assertTrue(reportFactory instanceof FailoverMetadataReportFactory, "expect " + FailoverMetadataReportFactory.class.getName() + " instance type, " + "actual " + reportFactory.getClass().getName() + " instance type");
MetadataReport report = reportFactory.getMetadataReport(url);
Assertions.assertTrue(report instanceof FailoverMetadataReport, "expect " + FailoverMetadataReport.class.getName() + " instance type, " + "actual " + report.getClass().getName() + " instance type");
FailoverMetadataReport failover = (FailoverMetadataReport) report;
return failover;
}
use of org.apache.dubbo.metadata.report.MetadataReportFactory in project dubbo by alibaba.
the class FailoverMetadataReport method buildProxyReports.
protected List<MetadataReportHolder> buildProxyReports() {
List<MetadataReportHolder> reports = new ArrayList<>();
if (CollectionUtils.isNotEmpty(this.failoverUrls)) {
ExtensionLoader<MetadataReportFactory> factoryLoader = ExtensionLoader.getExtensionLoader(MetadataReportFactory.class);
for (URL url : this.failoverUrls) {
try {
MetadataReportHolder holder = new MetadataReportHolder(url, factoryLoader.getExtension(url.getProtocol()).getMetadataReport(url));
reports.add(holder);
} catch (Exception e) {
if (url.getParameter(CHECK_KEY, true)) {
throw new RuntimeException("Failed to create + '" + url.getProtocol() + "' metadata report extension instance", e);
}
if (logger.isWarnEnabled()) {
logger.warn("Failed to create + '" + url.getProtocol() + "' metadata report extension instance, check=false found.");
}
}
}
}
Collections.shuffle(reports);
/**
* Select the local priority metadata cluster.
* In order to prevent clients from all connecting
* to the same cluster, random sorting has been done.
*/
reports.forEach(holder -> {
if (isLocalDataCenter(holder.url)) {
this.localDataCenterReportHolder = holder;
}
});
return reports;
}
use of org.apache.dubbo.metadata.report.MetadataReportFactory in project dubbo by alibaba.
the class FailoverMetadataReportTest method clearFailoverFactory.
private void clearFailoverFactory() {
MetadataReportFactory factory = reportLoader.getExtension(mockURL.getProtocol());
try {
Field reportCache = AbstractMetadataReportFactory.class.getDeclaredField("SERVICE_STORE_MAP");
if (!reportCache.isAccessible()) {
ReflectUtils.makeAccessible(reportCache);
}
Map<String, MetadataReport> serviceStore = (Map<String, MetadataReport>) reportCache.get(factory);
if (serviceStore != null) {
for (Iterator<Map.Entry<String, MetadataReport>> iterator = serviceStore.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, MetadataReport> entry = iterator.next();
if (entry.getKey().startsWith(mockURL.getProtocol())) {
iterator.remove();
}
}
}
} catch (NoSuchFieldException | IllegalAccessException ignored) {
}
}
Aggregations