use of org.apache.dubbo.config.ApplicationConfig in project dubbo by alibaba.
the class RegistryProtocolTest method setUp.
@BeforeEach
public void setUp() {
ApplicationModel.setApplication("RegistryProtocolTest");
ConfigManager configManager = ApplicationModel.getConfigManager();
ApplicationConfig applicationConfig = new ApplicationConfig("dubbo-demo-provider");
configManager.setApplication(applicationConfig);
ApplicationModel.getServiceRepository().registerService(RegistryService.class);
}
use of org.apache.dubbo.config.ApplicationConfig in project dubbo by alibaba.
the class DubboBootstrap method getApplication.
public ApplicationConfig getApplication() {
ApplicationConfig application = configManager.getApplication().orElseGet(() -> {
ApplicationConfig applicationConfig = new ApplicationConfig();
configManager.setApplication(applicationConfig);
return applicationConfig;
});
application.refresh();
return application;
}
use of org.apache.dubbo.config.ApplicationConfig 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);
}
use of org.apache.dubbo.config.ApplicationConfig in project dubbo by alibaba.
the class DubboBootstrap method startMetadataCenter.
private void startMetadataCenter() {
useRegistryAsMetadataCenterIfNecessary();
ApplicationConfig applicationConfig = getApplication();
String metadataType = applicationConfig.getMetadataType();
// FIXME, multiple metadata config support.
Collection<MetadataReportConfig> metadataReportConfigs = configManager.getMetadataConfigs();
if (CollectionUtils.isEmpty(metadataReportConfigs)) {
if (REMOTE_METADATA_STORAGE_TYPE.equals(metadataType)) {
throw new IllegalStateException("No MetadataConfig found, Metadata Center address is required when 'metadata=remote' is enabled.");
}
return;
}
for (MetadataReportConfig metadataReportConfig : metadataReportConfigs) {
ConfigValidationUtils.validateMetadataConfig(metadataReportConfig);
if (!metadataReportConfig.isValid()) {
continue;
}
MetadataReportInstance.init(metadataReportConfig);
}
}
use of org.apache.dubbo.config.ApplicationConfig in project dubbo by alibaba.
the class ConfigValidationUtils method loadMonitor.
public static URL loadMonitor(AbstractInterfaceConfig interfaceConfig, URL registryURL) {
Map<String, String> map = new HashMap<String, String>();
map.put(INTERFACE_KEY, MonitorService.class.getName());
AbstractInterfaceConfig.appendRuntimeParameters(map);
// set ip
String hostToRegistry = ConfigUtils.getSystemProperty(DUBBO_IP_TO_REGISTRY);
if (StringUtils.isEmpty(hostToRegistry)) {
hostToRegistry = NetUtils.getLocalHost();
} else if (NetUtils.isInvalidLocalHost(hostToRegistry)) {
throw new IllegalArgumentException("Specified invalid registry ip from property:" + DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
}
map.put(REGISTER_IP_KEY, hostToRegistry);
MonitorConfig monitor = interfaceConfig.getMonitor();
ApplicationConfig application = interfaceConfig.getApplication();
AbstractConfig.appendParameters(map, monitor);
AbstractConfig.appendParameters(map, application);
String address = null;
String sysaddress = System.getProperty(DUBBO_MONITOR_ADDRESS);
if (sysaddress != null && sysaddress.length() > 0) {
address = sysaddress;
} else if (monitor != null) {
address = monitor.getAddress();
}
if (ConfigUtils.isNotEmpty(address)) {
if (!map.containsKey(PROTOCOL_KEY)) {
if (getExtensionLoader(MonitorFactory.class).hasExtension(LOGSTAT_PROTOCOL)) {
map.put(PROTOCOL_KEY, LOGSTAT_PROTOCOL);
} else {
map.put(PROTOCOL_KEY, DUBBO_PROTOCOL);
}
}
return UrlUtils.parseURL(address, map);
} else if (monitor != null && (REGISTRY_PROTOCOL.equals(monitor.getProtocol()) || SERVICE_REGISTRY_PROTOCOL.equals(monitor.getProtocol())) && registryURL != null) {
return URLBuilder.from(registryURL).setProtocol(DUBBO_PROTOCOL).addParameter(PROTOCOL_KEY, monitor.getProtocol()).addParameterAndEncoded(REFER_KEY, StringUtils.toQueryString(map)).build();
}
return null;
}
Aggregations