use of org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService in project dubbo by alibaba.
the class DubboBootstrap method registerServiceInstance.
private void registerServiceInstance() {
if (CollectionUtils.isEmpty(getServiceDiscoveries())) {
return;
}
ApplicationConfig application = getApplication();
String serviceName = application.getName();
URL exportedURL = selectMetadataServiceExportedURL();
String host = exportedURL.getHost();
int port = exportedURL.getPort();
ServiceInstance serviceInstance = createServiceInstance(serviceName, host, port);
doRegisterServiceInstance(serviceInstance);
// scheduled task for updating Metadata and ServiceInstance
executorRepository.nextScheduledExecutor().scheduleAtFixedRate(() -> {
try {
InMemoryWritableMetadataService localMetadataService = (InMemoryWritableMetadataService) WritableMetadataService.getDefaultExtension();
localMetadataService.blockUntilUpdated();
ServiceInstanceMetadataUtils.refreshMetadataAndInstance();
} catch (Throwable e) {
logger.error("refresh metadata and instance failed", e);
}
}, 0, ConfigurationUtils.get(METADATA_PUBLISH_DELAY_KEY, DEFAULT_METADATA_PUBLISH_DELAY), TimeUnit.MILLISECONDS);
}
Aggregations