Search in sources :

Example 16 with ServiceInstance

use of org.apache.dubbo.registry.client.ServiceInstance 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

ServiceInstance (org.apache.dubbo.registry.client.ServiceInstance)16 DefaultServiceInstance (org.apache.dubbo.registry.client.DefaultServiceInstance)11 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)4 ServiceInstancesChangedEvent (org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent)4 Instance (com.alibaba.nacos.api.naming.pojo.Instance)3 LinkedList (java.util.LinkedList)3 ServiceInstancesChangedListener (org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener)3 HashMap (java.util.HashMap)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 URL (org.apache.dubbo.common.URL)2 MetadataInfo (org.apache.dubbo.metadata.MetadataInfo)2 NacosNamingServiceUtils.toInstance (org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.toInstance)2 Gson (com.google.gson.Gson)1 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 Application (com.netflix.discovery.shared.Application)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1