use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.
the class AbstractMetadataReportFactory method getMetadataReport.
@Override
public MetadataReport getMetadataReport(URL url) {
url = url.setPath(MetadataReport.class.getName()).removeParameters(EXPORT_KEY, REFER_KEY);
String key = url.toServiceString();
MetadataReport metadataReport = SERVICE_STORE_MAP.get(key);
if (metadataReport != null) {
return metadataReport;
}
// Lock the metadata access process to ensure a single instance of the metadata instance
LOCK.lock();
try {
metadataReport = SERVICE_STORE_MAP.get(key);
if (metadataReport != null) {
return metadataReport;
}
metadataReport = createMetadataReport(url);
if (metadataReport == null) {
throw new IllegalStateException("Can not create metadata Report " + url);
}
SERVICE_STORE_MAP.put(key, metadataReport);
return metadataReport;
} finally {
// Release the lock
LOCK.unlock();
}
}
use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.
the class RemoteMetadataServiceImpl method getMetadata.
public MetadataInfo getMetadata(ServiceInstance instance) {
SubscriberMetadataIdentifier identifier = new SubscriberMetadataIdentifier(instance.getServiceName(), ServiceInstanceMetadataUtils.getExportedServicesRevision(instance));
String registryCluster = instance.getExtendParams().get(REGISTRY_CLUSTER_KEY);
MetadataReport metadataReport = getMetadataReports().get(registryCluster);
if (metadataReport == null) {
metadataReport = getMetadataReports().entrySet().iterator().next().getValue();
}
return metadataReport.getAppMetadata(identifier, instance.getExtendParams());
}
use of org.apache.dubbo.metadata.report.MetadataReport in project dubbo by alibaba.
the class RemoteMetadataServiceImpl method publishMetadata.
public void publishMetadata(String serviceName) {
Map<String, MetadataInfo> metadataInfos = localMetadataService.getMetadataInfos();
metadataInfos.forEach((registryCluster, metadataInfo) -> {
if (!metadataInfo.hasReported()) {
SubscriberMetadataIdentifier identifier = new SubscriberMetadataIdentifier(serviceName, metadataInfo.calAndGetRevision());
metadataInfo.getExtendParams().put(REGISTRY_CLUSTER_KEY, registryCluster);
MetadataReport metadataReport = getMetadataReports().get(registryCluster);
if (metadataReport == null) {
metadataReport = getMetadataReports().entrySet().iterator().next().getValue();
}
logger.info("Publishing metadata to " + metadataReport.getClass().getSimpleName());
if (logger.isDebugEnabled()) {
logger.debug(metadataInfo.toString());
}
metadataReport.publishAppMetadata(identifier, metadataInfo);
metadataInfo.markReported();
}
});
}
use of org.apache.dubbo.metadata.report.MetadataReport 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