Java Code Examples for com.alibaba.dubbo.common.utils.ConfigUtils

The following examples show how to use com.alibaba.dubbo.common.utils.ConfigUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: dubbo-2.6.5   Source File: ValidationFilter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (validation != null && !invocation.getMethodName().startsWith("$")
            && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.VALIDATION_KEY))) {
        try {
            Validator validator = validation.getValidator(invoker.getUrl());
            if (validator != null) {
                validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments());
            }
        } catch (RpcException e) {
            throw e;
        } catch (Throwable t) {
            return new RpcResult(t);
        }
    }
    return invoker.invoke(invocation);
}
 
Example 2
Source Project: dubbo-2.6.5   Source File: ThriftProtocol.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void destroy() {

    super.destroy();

    for (String key : new ArrayList<String>(serverMap.keySet())) {

        ExchangeServer server = serverMap.remove(key);

        if (server != null) {
            try {
                if (logger.isInfoEnabled()) {
                    logger.info("Close dubbo server: " + server.getLocalAddress());
                }
                server.close(ConfigUtils.getServerShutdownTimeout());
            } catch (Throwable t) {
                logger.warn(t.getMessage(), t);
            }
        } // ~ end of if ( server != null )

    } // ~ end of loop serverMap

}
 
Example 3
Source Project: dubbo-2.6.5   Source File: ExtensionLoader.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isActive(Activate activate, URL url) {
    String[] keys = activate.value();
    if (keys.length == 0) {
        return true;
    }
    for (String key : keys) {
        for (Map.Entry<String, String> entry : url.getParameters().entrySet()) {
            String k = entry.getKey();
            String v = entry.getValue();
            if ((k.equals(key) || k.endsWith("." + key))
                    && ConfigUtils.isNotEmpty(v)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 4
Source Project: dubbo-2.6.5   Source File: AbstractInterfaceConfigTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void checkApplication1() throws Exception {
    try {
        ConfigUtils.setProperties(null);
        writeDubboProperties(Constants.SHUTDOWN_WAIT_KEY, "100");
        System.setProperty("dubbo.application.name", "demo");
        InterfaceConfig interfaceConfig = new InterfaceConfig();
        interfaceConfig.checkApplication();
        ApplicationConfig appConfig = interfaceConfig.getApplication();
        TestCase.assertEquals("demo", appConfig.getName());
        TestCase.assertEquals("100", System.getProperty(Constants.SHUTDOWN_WAIT_KEY));

        System.clearProperty(Constants.SHUTDOWN_WAIT_KEY);
        ConfigUtils.setProperties(null);
        writeDubboProperties(Constants.SHUTDOWN_WAIT_SECONDS_KEY, "1000");
        System.setProperty("dubbo.application.name", "demo");
        interfaceConfig = new InterfaceConfig();
        interfaceConfig.checkApplication();
        TestCase.assertEquals("1000", System.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY));
    } finally {
        ConfigUtils.setProperties(null);
        System.clearProperty("dubbo.application.name");
        System.clearProperty(Constants.SHUTDOWN_WAIT_KEY);
        System.clearProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY);
    }
}
 
Example 5
Source Project: dubbo-2.6.5   Source File: AbstractRegistry.java    License: Apache License 2.0 6 votes vote down vote up
public AbstractRegistry(URL url) {
        setUrl(url);
        // Start file save timer 查询注册信息保存本地文件save.file
        syncSaveFile = url.getParameter(Constants.REGISTRY_FILESAVE_SYNC_KEY, false);
//        默认文件名 /Users/jiangweifeng/.dubbo/dubbo-registry-dubbo-provider-192.168.50.251:2181.cache
        String filename = url.getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/.dubbo/dubbo-registry-" + url.getParameter(Constants.APPLICATION_KEY) + "-" + url.getAddress() + ".cache");
        File file = null;
        if (ConfigUtils.isNotEmpty(filename)) {
            file = new File(filename);
            if (!file.exists() && file.getParentFile() != null && !file.getParentFile().exists()) {
                if (!file.getParentFile().mkdirs()) {
                    throw new IllegalArgumentException("Invalid registry store file " + file + ", cause: Failed to create directory " + file.getParentFile() + "!");
                }
            }
        }
        this.file = file;
//        从配置文件中加载注册
        loadProperties();
        notify(url.getBackupUrls());
    }
 
Example 6
Source Project: dubbox   Source File: CacheFilter.java    License: Apache License 2.0 6 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
        Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
        if (cache != null) {
            String key = StringUtils.toArgumentString(invocation.getArguments());
            if (cache != null && key != null) {
                Object value = cache.get(key);
                if (value != null) {
                    return new RpcResult(value);
                }
                Result result = invoker.invoke(invocation);
                if (! result.hasException()) {
                    cache.put(key, result.getValue());
                }
                return result;
            }
        }
    }
    return invoker.invoke(invocation);
}
 
Example 7
Source Project: dubbox   Source File: ExtensionLoader.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isActive(Activate activate, URL url) {
    String[] keys = activate.value();
    if (keys == null || keys.length == 0) {
        return true;
    }
    for (String key : keys) {
        for (Map.Entry<String, String> entry : url.getParameters().entrySet()) {
            String k = entry.getKey();
            String v = entry.getValue();
            if ((k.equals(key) || k.endsWith("." + key))
                    && ConfigUtils.isNotEmpty(v)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 8
Source Project: dubbo-plus   Source File: DefaultSyncTransfer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    while (!interrupted()) {
        try {
            Span first = queue.take();
            cacheList.add(first);
            queue.drainTo(cacheList, flushSizeInner);
            if(cacheList.size()<=0){
                continue;
            }
            if(!inited&&collector==null){
                TracingCollectorFactory tracingCollectorFactory = ExtensionLoader
                        .getExtensionLoader(TracingCollectorFactory.class)
                        .getExtension(ConfigUtils.getProperty(DstConstants.TRACING_COLLECTOR
                                ,DstConstants.DEFAULT_COLLECTOR_TYPE));
                collector =tracingCollectorFactory.getTracingCollector();
                inited=true;
            }
            collector.push(cacheList);
            cacheList.clear();
        } catch (InterruptedException e) {
            logger.error("Dst-span-transfer-task-thread occur an error", e);
        }
    }
}
 
Example 9
Source Project: dubbox-hystrix   Source File: ValidationFilter.java    License: Apache License 2.0 6 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (validation != null && ! invocation.getMethodName().startsWith("$") 
            && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.VALIDATION_KEY))) {
        try {
            Validator validator = validation.getValidator(invoker.getUrl());
            if (validator != null) {
                validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments());
            }
        } catch (RpcException e) {
            throw e;
        } catch (Throwable t) {
            throw new RpcException(t.getMessage(), t);
        }
    }
    return invoker.invoke(invocation);
}
 
Example 10
Source Project: dubbox-hystrix   Source File: CacheFilter.java    License: Apache License 2.0 6 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
        Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
        if (cache != null) {
            String key = StringUtils.toArgumentString(invocation.getArguments());
            if (cache != null && key != null) {
                Object value = cache.get(key);
                if (value != null) {
                    return new RpcResult(value);
                }
                Result result = invoker.invoke(invocation);
                if (! result.hasException()) {
                    cache.put(key, result.getValue());
                }
                return result;
            }
        }
    }
    return invoker.invoke(invocation);
}
 
Example 11
Source Project: dubbox-hystrix   Source File: ExtensionLoader.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isActive(Activate activate, URL url) {
    String[] keys = activate.value();
    if (keys == null || keys.length == 0) {
        return true;
    }
    for (String key : keys) {
        for (Map.Entry<String, String> entry : url.getParameters().entrySet()) {
            String k = entry.getKey();
            String v = entry.getValue();
            if ((k.equals(key) || k.endsWith("." + key))
                    && ConfigUtils.isNotEmpty(v)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 12
Source Project: dubbox-hystrix   Source File: AbstractInterfaceConfig.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
protected void checkApplication() {
    // 兼容旧版本
    if (application == null) {
        String applicationName = ConfigUtils.getProperty("dubbo.application.name");
        if (applicationName != null && applicationName.length() > 0) {
            application = new ApplicationConfig();
        }
    }
    if (application == null) {
        throw new IllegalStateException(
                                        "No such application config! Please add <dubbo:application name=\"...\" /> to your spring config.");
    }
    appendProperties(application);
    
    String wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY);
    if (wait != null && wait.trim().length() > 0) {
        System.setProperty(Constants.SHUTDOWN_WAIT_KEY, wait.trim());
    } else {
        wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY);
        if (wait != null && wait.trim().length() > 0) {
            System.setProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY, wait.trim());
        }
    }
}
 
Example 13
Source Project: dubbo3   Source File: ValidationFilter.java    License: Apache License 2.0 6 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (validation != null && ! invocation.getMethodName().startsWith("$") 
            && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.VALIDATION_KEY))) {
        try {
            Validator validator = validation.getValidator(invoker.getUrl());
            if (validator != null) {
                validator.validate(invocation.getMethodName(), invocation.getParameterTypes(), invocation.getArguments());
            }
        } catch (RpcException e) {
            throw e;
        } catch (Throwable t) {
            throw new RpcException(t.getMessage(), t);
        }
    }
    return invoker.invoke(invocation);
}
 
Example 14
Source Project: dubbo3   Source File: CacheFilter.java    License: Apache License 2.0 6 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
        Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
        if (cache != null) {
            String key = StringUtils.toArgumentString(invocation.getArguments());
            Object value = cache.get(key);
            if (value != null) {
                return new RpcResult(value);
            }
            Result result = invoker.invoke(invocation);
            if (! result.hasException()) {
                cache.put(key, result.getValue());
            }
            return result;
        }
    }
    return invoker.invoke(invocation);
}
 
Example 15
Source Project: dubbox   Source File: AbstractInterfaceConfig.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
protected void checkApplication() {
    // 兼容旧版本
    if (application == null) {
        String applicationName = ConfigUtils.getProperty("dubbo.application.name");
        if (applicationName != null && applicationName.length() > 0) {
            application = new ApplicationConfig();
        }
    }
    if (application == null) {
        throw new IllegalStateException(
                                        "No such application config! Please add <dubbo:application name=\"...\" /> to your spring config.");
    }
    appendProperties(application);
    
    String wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY);
    if (wait != null && wait.trim().length() > 0) {
        System.setProperty(Constants.SHUTDOWN_WAIT_KEY, wait.trim());
    } else {
        wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY);
        if (wait != null && wait.trim().length() > 0) {
            System.setProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY, wait.trim());
        }
    }
}
 
Example 16
Source Project: dubbo3   Source File: ExtensionLoader.java    License: Apache License 2.0 6 votes vote down vote up
private boolean isActive(Activate activate, URL url) {
    String[] keys = activate.value();
    if (keys.length == 0) {
        return true;
    }
    for (String key : keys) {
        for (Map.Entry<String, String> entry : url.getParameters().entrySet()) {
            String k = entry.getKey();
            String v = entry.getValue();
            if ((k.equals(key) || k.endsWith("." + key))
                    && ConfigUtils.isNotEmpty(v)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 17
Source Project: dubbo3   Source File: AbstractInterfaceConfig.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
protected void checkApplication() {
    // 兼容旧版本
    if (application == null) {
        String applicationName = ConfigUtils.getProperty("dubbo.application.name");
        if (applicationName != null && applicationName.length() > 0) {
            application = new ApplicationConfig();
        }
    }
    if (application == null) {
        throw new IllegalStateException(
                                        "No such application config! Please add <dubbo:application name=\"...\" /> to your spring config.");
    }
    appendProperties(application);
    
    String wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY);
    if (wait != null && wait.trim().length() > 0) {
        System.setProperty(Constants.SHUTDOWN_WAIT_KEY, wait.trim());
    } else {
        wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY);
        if (wait != null && wait.trim().length() > 0) {
            System.setProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY, wait.trim());
        }
    }
}
 
Example 18
Source Project: dubbox   Source File: CacheFilter.java    License: Apache License 2.0 6 votes vote down vote up
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
        Cache cache = cacheFactory.getCache(invoker.getUrl().addParameter(Constants.METHOD_KEY, invocation.getMethodName()));
        if (cache != null) {
            String key = StringUtils.toArgumentString(invocation.getArguments());
            if (cache != null && key != null) {
                Object value = cache.get(key);
                if (value != null) {
                    return new RpcResult(value);
                }
                Result result = invoker.invoke(invocation);
                if (! result.hasException()) {
                    cache.put(key, result.getValue());
                }
                return result;
            }
        }
    }
    return invoker.invoke(invocation);
}
 
Example 19
Source Project: dubbox   Source File: AbstractInterfaceConfig.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
protected void checkApplication() {
    // 兼容旧版本
    if (application == null) {
        String applicationName = ConfigUtils.getProperty("dubbo.application.name");
        if (applicationName != null && applicationName.length() > 0) {
            application = new ApplicationConfig();
        }
    }
    if (application == null) {
        throw new IllegalStateException(
                                        "No such application config! Please add <dubbo:application name=\"...\" /> to your spring config.");
    }
    appendProperties(application);
    
    String wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_KEY);
    if (wait != null && wait.trim().length() > 0) {
        System.setProperty(Constants.SHUTDOWN_WAIT_KEY, wait.trim());
    } else {
        wait = ConfigUtils.getProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY);
        if (wait != null && wait.trim().length() > 0) {
            System.setProperty(Constants.SHUTDOWN_WAIT_SECONDS_KEY, wait.trim());
        }
    }
}
 
Example 20
Source Project: dubbo-2.6.5   Source File: LogbackContainer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
    String file = ConfigUtils.getProperty(LOGBACK_FILE);
    if (file != null && file.length() > 0) {
        String level = ConfigUtils.getProperty(LOGBACK_LEVEL);
        if (level == null || level.length() == 0) {
            level = DEFAULT_LOGBACK_LEVEL;
        }
        // maxHistory=0 Infinite history
        int maxHistory = StringUtils.parseInteger(ConfigUtils.getProperty(LOGBACK_MAX_HISTORY));

        doInitializer(file, level, maxHistory);
    }
}
 
Example 21
Source Project: dubbo-2.6.5   Source File: SpringContainer.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void start() {
    String configPath = ConfigUtils.getProperty(SPRING_CONFIG);
    if (configPath == null || configPath.length() == 0) {
        configPath = DEFAULT_SPRING_CONFIG;
    }
    context = new ClassPathXmlApplicationContext(configPath.split("[,\\s]+"), false);
    context.addApplicationListener(new DubboApplicationListener());
    context.registerShutdownHook();
    context.refresh();
    context.start();
}
 
Example 22
Source Project: dubbo-2.6.5   Source File: MockInvoker.java    License: Apache License 2.0 5 votes vote down vote up
private String normallizeMock(String mock) {
    if (mock == null || mock.trim().length() == 0) {
        return mock;
    } else if (ConfigUtils.isDefault(mock) || "fail".equalsIgnoreCase(mock.trim()) || "force".equalsIgnoreCase(mock.trim())) {
        mock = url.getServiceInterface() + "Mock";
    }
    if (mock.startsWith(Constants.FAIL_PREFIX)) {
        mock = mock.substring(Constants.FAIL_PREFIX.length()).trim();
    } else if (mock.startsWith(Constants.FORCE_PREFIX)) {
        mock = mock.substring(Constants.FORCE_PREFIX.length()).trim();
    }
    return mock;
}
 
Example 23
Source Project: dubbox   Source File: MockInvoker.java    License: Apache License 2.0 5 votes vote down vote up
private String normallizeMock(String mock) {
	if (mock == null || mock.trim().length() ==0){
		return mock;
	} else if (ConfigUtils.isDefault(mock) || "fail".equalsIgnoreCase(mock.trim()) || "force".equalsIgnoreCase(mock.trim())){
		mock = url.getServiceInterface()+"Mock";
	}
	if (mock.startsWith(Constants.FAIL_PREFIX)) {
        mock = mock.substring(Constants.FAIL_PREFIX.length()).trim();
    } else if (mock.startsWith(Constants.FORCE_PREFIX)) {
        mock = mock.substring(Constants.FORCE_PREFIX.length()).trim();
    }
	return mock;
}
 
Example 24
Source Project: dubbo-plus   Source File: RemoteFacadeCircuitBreaker.java    License: Apache License 2.0 5 votes vote down vote up
public RemoteFacadeCircuitBreaker(){
    String intervalConf = ConfigUtils.getProperty("dubbo.reference.check.break.marker.interval", "60000");
    logger.info("[{}] has already been initialized circuit breaker,check break marker interval [{}]",localHost,intervalConf);
    long interval = Long.parseLong(intervalConf);
    for(int i=0;i<breakCounterLoops.length;i++){
        BreakCounterLoop loop = new BreakCounterLoop(interval);
        breakCounterLoops[i]=loop;
    }
}
 
Example 25
Source Project: dubbo-2.6.5   Source File: ServiceConfig.java    License: Apache License 2.0 5 votes vote down vote up
private String getValueFromConfig(ProtocolConfig protocolConfig, String key) {
    String protocolPrefix = protocolConfig.getName().toUpperCase() + "_";
    String port = ConfigUtils.getSystemProperty(protocolPrefix + key);
    if (port == null || port.length() == 0) {
        port = ConfigUtils.getSystemProperty(key);
    }
    return port;
}
 
Example 26
Source Project: dubbo-2.6.5   Source File: AbstractConfigTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAppendProperties3() throws Exception {
    try {
        Properties p = new Properties();
        p.put("dubbo.properties.str", "dubbo");
        ConfigUtils.setProperties(p);
        PropertiesConfig config = new PropertiesConfig();
        AbstractConfig.appendProperties(config);
        TestCase.assertEquals("dubbo", config.getStr());
    } finally {
        System.clearProperty(Constants.DUBBO_PROPERTIES_KEY);
        ConfigUtils.setProperties(null);
    }
}
 
Example 27
Source Project: dubbox   Source File: SimpleMonitorService.java    License: Apache License 2.0 5 votes vote down vote up
public SimpleMonitorService() {
    queue = new LinkedBlockingQueue<URL>(Integer.parseInt(ConfigUtils.getProperty("dubbo.monitor.queue", "100000")));
    writeThread = new Thread(new Runnable() {
        public void run() {
            while (running) {
                try {
                    write(); // 记录统计日志
                } catch (Throwable t) { // 防御性容错
                    logger.error("Unexpected error occur at write stat log, cause: " + t.getMessage(), t);
                    try {
                        Thread.sleep(5000); // 失败延迟
                    } catch (Throwable t2) {
                    }
                }
            }
        }
    });
    writeThread.setDaemon(true);
    writeThread.setName("DubboMonitorAsyncWriteLogThread");
    writeThread.start();
    chartFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() {
        public void run() {
            try {
                draw(); // 绘制图表
            } catch (Throwable t) { // 防御性容错
                logger.error("Unexpected error occur at draw stat chart, cause: " + t.getMessage(), t);
            }
        }
    }, 1, 300, TimeUnit.SECONDS);
    INSTANCE = this;
}
 
Example 28
Source Project: dubbox   Source File: LogbackContainer.java    License: Apache License 2.0 5 votes vote down vote up
public void start() {
	String file = ConfigUtils.getProperty(LOGBACK_FILE);
	if (file != null && file.length() > 0) {
		String level = ConfigUtils.getProperty(LOGBACK_LEVEL);
		if (level == null || level.length() == 0) {
			level = DEFAULT_LOGBACK_LEVEL;
		}
		// maxHistory=0 Infinite history
		int maxHistory = StringUtils.parseInteger(ConfigUtils.getProperty(LOGBACK_MAX_HISTORY));

		doInitializer(file, level, maxHistory);
	}
}
 
Example 29
Source Project: dubbox   Source File: JavaConfigContainer.java    License: Apache License 2.0 5 votes vote down vote up
public void start() {
    String configPath = ConfigUtils.getProperty(SPRING_JAVACONFIG);
    if (configPath == null || configPath.length() == 0) {
        configPath = DEFAULT_SPRING_JAVACONFIG;
    }
    context = new AnnotationConfigApplicationContext(configPath);
    context.start();
}
 
Example 30
Source Project: dubbox   Source File: AbstractInterfaceConfig.java    License: Apache License 2.0 5 votes vote down vote up
protected URL loadMonitor(URL registryURL) {
    if (monitor == null) {
        String monitorAddress = ConfigUtils.getProperty("dubbo.monitor.address");
        String monitorProtocol = ConfigUtils.getProperty("dubbo.monitor.protocol");
        if (monitorAddress != null && monitorAddress.length() > 0
                || monitorProtocol != null && monitorProtocol.length() > 0) {
            monitor = new MonitorConfig();
        } else {
            return null;
        }
    }
    appendProperties(monitor);
    Map<String, String> map = new HashMap<String, String>();
    map.put(Constants.INTERFACE_KEY, MonitorService.class.getName());
    map.put("dubbo", Version.getVersion());
    map.put(Constants.TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
    if (ConfigUtils.getPid() > 0) {
        map.put(Constants.PID_KEY, String.valueOf(ConfigUtils.getPid()));
    }
    appendParameters(map, monitor);
    String address = monitor.getAddress();
    String sysaddress = System.getProperty("dubbo.monitor.address");
    if (sysaddress != null && sysaddress.length() > 0) {
        address = sysaddress;
    }
    if (ConfigUtils.isNotEmpty(address)) {
        if (! map.containsKey(Constants.PROTOCOL_KEY)) {
            if (ExtensionLoader.getExtensionLoader(MonitorFactory.class).hasExtension("logstat")) {
                map.put(Constants.PROTOCOL_KEY, "logstat");
            } else {
                map.put(Constants.PROTOCOL_KEY, "dubbo");
            }
        }
        return UrlUtils.parseURL(address, map);
    } else if (Constants.REGISTRY_PROTOCOL.equals(monitor.getProtocol()) && registryURL != null) {
        return registryURL.setProtocol("dubbo").addParameter(Constants.PROTOCOL_KEY, "registry").addParameterAndEncoded(Constants.REFER_KEY, StringUtils.toQueryString(map));
    }
    return null;
}