Search in sources :

Example 1 with InMemoryWritableMetadataService

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);
}
Also used : InMemoryWritableMetadataService(org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService) ApplicationConfig(org.apache.dubbo.config.ApplicationConfig) DefaultServiceInstance(org.apache.dubbo.registry.client.DefaultServiceInstance) ServiceInstance(org.apache.dubbo.registry.client.ServiceInstance) URL(org.apache.dubbo.common.URL)

Aggregations

URL (org.apache.dubbo.common.URL)1 ApplicationConfig (org.apache.dubbo.config.ApplicationConfig)1 DefaultServiceInstance (org.apache.dubbo.registry.client.DefaultServiceInstance)1 ServiceInstance (org.apache.dubbo.registry.client.ServiceInstance)1 InMemoryWritableMetadataService (org.apache.dubbo.registry.client.metadata.store.InMemoryWritableMetadataService)1