Java Code Examples for com.alibaba.dubbo.common.utils.ConfigUtils#getProperty()

The following examples show how to use com.alibaba.dubbo.common.utils.ConfigUtils#getProperty() . 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 File: AbstractInterfaceConfig.java    From dubbox-hystrix with 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 2
Source File: AbstractInterfaceConfig.java    From dubbo3 with 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 3
Source File: AbstractInterfaceConfig.java    From dubbox with 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 4
Source File: SpringContainer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
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]+"));
    context.start();
}
 
Example 5
Source File: AbstractInterfaceConfig.java    From dubbox with 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;
}
 
Example 6
Source File: LogbackContainer.java    From dubbox with 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 7
Source File: RemoteFacadeCircuitBreaker.java    From dubbo-plus with 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 8
Source File: JavaConfigContainer.java    From dubbox-hystrix with 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 9
Source File: CacheFilter.java    From dubbo-ext with Apache License 2.0 5 votes vote down vote up
public CacheFilter() {
    int peroid = Integer.valueOf(ConfigUtils.getProperty("dubbo.cache.filter.clear.peroid", "5000"));
    String prefix = ConfigUtils.getProperty("dubbo.cache.filter.method.name.prefix", "query,get,select");
    methodPrefix = prefix.split(",");
    DaemonTimer.getInstance().addTask(this, peroid);
    logger.info("CacheFilter is running,method prefix:{} peroid:{}", Arrays.toString(methodPrefix), peroid);
}
 
Example 10
Source File: JettyContainer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void start() {
    String serverPort = ConfigUtils.getProperty(JETTY_PORT);
    int port;
    if (serverPort == null || serverPort.length() == 0) {
        port = DEFAULT_JETTY_PORT;
    } else {
        port = Integer.parseInt(serverPort);
    }
    connector = new SelectChannelConnector();
    connector.setPort(port);
    ServletHandler handler = new ServletHandler();
    
    String resources = ConfigUtils.getProperty(JETTY_DIRECTORY);
    if (resources != null && resources.length() > 0) {
        FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT);
        resourceHolder.setInitParameter("resources", resources);
    }
    
    ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*");
    pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES));
    pageHolder.setInitOrder(2);
    
    Server server = new Server();
    server.addConnector(connector);
    server.addHandler(handler);
    try {
        server.start();
    } catch (Exception e) {
        throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e);
    }
}
 
Example 11
Source File: SpringContainer.java    From dubbox with Apache License 2.0 5 votes vote down vote up
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]+"));
    context.start();
}
 
Example 12
Source File: JavaConfigContainer.java    From dubbox with 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 13
Source File: AbstractInterfaceConfig.java    From dubbo3 with 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<>();
    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;
}
 
Example 14
Source File: AbstractInterfaceConfig.java    From dubbox with 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;
}
 
Example 15
Source File: JavaConfigContainer.java    From dubbox with 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 16
Source File: Log4jContainer.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void start() {
    String file = ConfigUtils.getProperty(LOG4J_FILE);
    if (file != null && file.length() > 0) {
        String level = ConfigUtils.getProperty(LOG4J_LEVEL);
        if (level == null || level.length() == 0) {
            level = DEFAULT_LOG4J_LEVEL;
        }
        Properties properties = new Properties();
        properties.setProperty("log4j.rootLogger", level + ",application");
        properties.setProperty("log4j.appender.application", "org.apache.log4j.DailyRollingFileAppender");
        properties.setProperty("log4j.appender.application.File", file);
        properties.setProperty("log4j.appender.application.Append", "true");
        properties.setProperty("log4j.appender.application.DatePattern", "'.'yyyy-MM-dd");
        properties.setProperty("log4j.appender.application.layout", "org.apache.log4j.PatternLayout");
        properties.setProperty("log4j.appender.application.layout.ConversionPattern", "%d [%t] %-5p %C{6} (%F:%L) - %m%n");
        PropertyConfigurator.configure(properties);
    }
    String subdirectory = ConfigUtils.getProperty(LOG4J_SUBDIRECTORY);
    if (subdirectory != null && subdirectory.length() > 0) {
        Enumeration<org.apache.log4j.Logger> ls = LogManager.getCurrentLoggers();
        while (ls.hasMoreElements()) {
            org.apache.log4j.Logger l = ls.nextElement();
            if (l != null) {
                Enumeration<Appender> as = l.getAllAppenders();
                while (as.hasMoreElements()) {
                    Appender a = as.nextElement();
                    if (a instanceof FileAppender) {
                        FileAppender fa = (FileAppender)a;
                        String f = fa.getFile();
                        if (f != null && f.length() > 0) {
                            int i = f.replace('\\', '/').lastIndexOf('/');
                            String path;
                            if (i == -1) {
                                path = subdirectory;
                            } else {
                                path = f.substring(0, i);
                                if (! path.endsWith(subdirectory)) {
                                    path = path + "/" + subdirectory;
                                }
                                f = f.substring(i + 1);
                            }
                            fa.setFile(path + "/" + f);
                            fa.activateOptions();
                        }
                    }
                }
            }
        }
    }
}
 
Example 17
Source File: Log4jContainer.java    From dubbox with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public void start() {
    String file = ConfigUtils.getProperty(LOG4J_FILE);
    if (file != null && file.length() > 0) {
        String level = ConfigUtils.getProperty(LOG4J_LEVEL);
        if (level == null || level.length() == 0) {
            level = DEFAULT_LOG4J_LEVEL;
        }
        Properties properties = new Properties();
        properties.setProperty("log4j.rootLogger", level + ",application");
        properties.setProperty("log4j.appender.application", "org.apache.log4j.DailyRollingFileAppender");
        properties.setProperty("log4j.appender.application.File", file);
        properties.setProperty("log4j.appender.application.Append", "true");
        properties.setProperty("log4j.appender.application.DatePattern", "'.'yyyy-MM-dd");
        properties.setProperty("log4j.appender.application.layout", "org.apache.log4j.PatternLayout");
        properties.setProperty("log4j.appender.application.layout.ConversionPattern", "%d [%t] %-5p %C{6} (%F:%L) - %m%n");
        PropertyConfigurator.configure(properties);
    }
    String subdirectory = ConfigUtils.getProperty(LOG4J_SUBDIRECTORY);
    if (subdirectory != null && subdirectory.length() > 0) {
        Enumeration<org.apache.log4j.Logger> ls = LogManager.getCurrentLoggers();
        while (ls.hasMoreElements()) {
            org.apache.log4j.Logger l = ls.nextElement();
            if (l != null) {
                Enumeration<Appender> as = l.getAllAppenders();
                while (as.hasMoreElements()) {
                    Appender a = as.nextElement();
                    if (a instanceof FileAppender) {
                        FileAppender fa = (FileAppender)a;
                        String f = fa.getFile();
                        if (f != null && f.length() > 0) {
                            int i = f.replace('\\', '/').lastIndexOf('/');
                            String path;
                            if (i == -1) {
                                path = subdirectory;
                            } else {
                                path = f.substring(0, i);
                                if (! path.endsWith(subdirectory)) {
                                    path = path + "/" + subdirectory;
                                }
                                f = f.substring(i + 1);
                            }
                            fa.setFile(path + "/" + f);
                            fa.activateOptions();
                        }
                    }
                }
            }
        }
    }
}
 
Example 18
Source File: Config.java    From dubbo-plus with Apache License 2.0 3 votes vote down vote up
/**
 * 获取某个方法或者某个接口的判定为出现异常的次数
 * 提供在配置中心和dubbo.properties两种途径配置
 * 如果两个地方均有配置,配置中心的为准
 * @param interfaceConfig
 * @param methodConfig
 * @return
 */
public static int getBreakLimit(StringBuffer interfaceConfig,StringBuffer methodConfig){
    methodConfig.append(".break.limit");
    interfaceConfig.append(".break.limit");
    String breakLimitConf = ConfigUtils.getProperty(methodConfig.toString(), ConfigUtils.getProperty(interfaceConfig.toString(), ConfigUtils.getProperty("dubbo.reference.default.break.limit", DEFAULT_BREAK_LIMIT)));
    return Integer.parseInt(breakLimitConf);
}
 
Example 19
Source File: ApplicationContext.java    From AsuraFramework with Apache License 2.0 2 votes vote down vote up
/**
 * 
 * 获取当前应用名称
 *
 * @author zhangshaobin
 * @created 2013-4-9 下午12:30:10
 *
 * @return	应用名称
 */
public static String getApplicationName() {
	return ConfigUtils.getProperty("dubbo.application.name");
}
 
Example 20
Source File: ApplicationContext.java    From AsuraFramework with Apache License 2.0 2 votes vote down vote up
/**
 * 
 * 获取注册中心地址
 *
 * @author zhangshaobin
 * @created 2013-4-9 下午12:32:38
 *
 * @return
 */
public static String getRegistryAddress() {
	return ConfigUtils.getProperty("dubbo.registry.address");
}