Search in sources :

Example 1 with MetadataReportFactory

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;
}
Also used : MetadataReport(org.apache.dubbo.metadata.report.MetadataReport) MetadataReportFactory(org.apache.dubbo.metadata.report.MetadataReportFactory) AbstractMetadataReportFactory(org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory)

Example 2 with MetadataReportFactory

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;
}
Also used : MetadataReportFactory(org.apache.dubbo.metadata.report.MetadataReportFactory) ArrayList(java.util.ArrayList) URL(org.apache.dubbo.common.URL)

Example 3 with MetadataReportFactory

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) {
    }
}
Also used : Field(java.lang.reflect.Field) MetadataReport(org.apache.dubbo.metadata.report.MetadataReport) MetadataReportFactory(org.apache.dubbo.metadata.report.MetadataReportFactory) AbstractMetadataReportFactory(org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MetadataReportFactory (org.apache.dubbo.metadata.report.MetadataReportFactory)3 MetadataReport (org.apache.dubbo.metadata.report.MetadataReport)2 AbstractMetadataReportFactory (org.apache.dubbo.metadata.report.support.AbstractMetadataReportFactory)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 URL (org.apache.dubbo.common.URL)1