Java Code Examples for com.alibaba.dubbo.common.Constants#PATH_SEPARATOR

The following examples show how to use com.alibaba.dubbo.common.Constants#PATH_SEPARATOR . 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: ZookeeperRegistry.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) {
    super(url);
    if (url.isAnyHost()) {
        throw new IllegalStateException("registry address == null");
    }
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
    if (!group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    this.root = group;
    zkClient = zookeeperTransporter.connect(url);
    zkClient.addStateListener(state -> {
        if (state == StateListener.RECONNECTED) {
            try {
                recover();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    });
}
 
Example 2
Source File: ConsulRegistryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Test
public void toCategoriesPath() {
	URL url = consumerUrl;
	String[] categroies;
	if (Constants.ANY_VALUE.equals(url.getParameter(Constants.CATEGORY_KEY))) {
		categroies = new String[] { Constants.PROVIDERS_CATEGORY, Constants.CONSUMERS_CATEGORY,
				Constants.ROUTERS_CATEGORY, Constants.CONFIGURATORS_CATEGORY };
	} else {
		categroies = url.getParameter(Constants.CATEGORY_KEY, new String[] { Constants.DEFAULT_CATEGORY });
	}
	String[] paths = new String[categroies.length];
	for (int i = 0; i < categroies.length; i++) {
		paths[i] = "dubbo" + Constants.PATH_SEPARATOR + categroies[i];
	}

	for (String s : paths) {
		System.out.println(s);
	}
}
 
Example 3
Source File: ZookeeperRegistry.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) {
    super(url);
    if (url.isAnyHost()) {
		throw new IllegalStateException("registry address == null");
	}
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
    if (! group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    this.root = group;
    zkClient = zookeeperTransporter.connect(url);
    zkClient.addStateListener(new StateListener() {
        public void stateChanged(int state) {
        	if (state == RECONNECTED) {
         	try {
		recover();
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
        	}
        }
    });
}
 
Example 4
Source File: ZookeeperRegistry.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) {
        super(url);
        if (url.isAnyHost()) {
            throw new IllegalStateException("registry address == null");
        }
//        group不进行配置默认值是dubbo
        String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
        if (!group.startsWith(Constants.PATH_SEPARATOR)) {
            group = Constants.PATH_SEPARATOR + group;
        }
        this.root = group;
//        创建zkclient=》
        zkClient = zookeeperTransporter.connect(url);
//        添加监听器
        zkClient.addStateListener(new StateListener() {
            @Override
            public void stateChanged(int state) {
                if (state == RECONNECTED) {
                    try {
//                        恢复注册信息=》
                        recover();
                    } catch (Exception e) {
                        logger.error(e.getMessage(), e);
                    }
                }
            }
        });
    }
 
Example 5
Source File: ZookeeperRegistry.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
private String[] toCategoriesPath(URL url) {
    String[] categroies;
    if (Constants.ANY_VALUE.equals(url.getParameter(Constants.CATEGORY_KEY))) {
        categroies = new String[] {Constants.PROVIDERS_CATEGORY, Constants.CONSUMERS_CATEGORY, 
                Constants.ROUTERS_CATEGORY, Constants.CONFIGURATORS_CATEGORY};
    } else {
        categroies = url.getParameter(Constants.CATEGORY_KEY, new String[] {Constants.DEFAULT_CATEGORY});
    }
    String[] paths = new String[categroies.length];
    for (int i = 0; i < categroies.length; i ++) {
        paths[i] = toServicePath(url) + Constants.PATH_SEPARATOR + categroies[i];
    }
    return paths;
}
 
Example 6
Source File: ConsulRegistry.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public ConsulRegistry(URL url) {
	super(url);
	if (url.isAnyHost()) {
		throw new IllegalStateException("registry address == null");
	}
	String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
	if (!group.startsWith(Constants.PATH_SEPARATOR)) {
		group = Constants.PATH_SEPARATOR + group;
	}
	if (!group.endsWith(Constants.PATH_SEPARATOR)) {
		group = group + Constants.PATH_SEPARATOR;
	}
	this.root = group;
	String host = url.getIp();
	int port = url.getPort() != 0 ? url.getPort() : DEFAULT_CONSUL_PORT;
	this.consulClient = new ConsulClient(host, port);
	this.ttl = 16000L;
	keepAliveFuture = keepAliveExecutor.scheduleWithFixedDelay(new Runnable() {
		public void run() {
			try {
				keepAlive(); // 确保服务在consul的status为passing
			} catch (Throwable t) { // 防御性容错
				logger.error("Unexpected exception occur at defer consul keep alive time, cause: " + t.getMessage(),
						t);
			}
		}
	}, ttl / 2, ttl / 2, TimeUnit.MILLISECONDS);
}
 
Example 7
Source File: ZookeeperRegistry.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private String[] toCategoriesPath(URL url) {
    String[] categroies;
    if (Constants.ANY_VALUE.equals(url.getParameter(Constants.CATEGORY_KEY))) {
        categroies = new String[] {Constants.PROVIDERS_CATEGORY, Constants.CONSUMERS_CATEGORY, 
                Constants.ROUTERS_CATEGORY, Constants.CONFIGURATORS_CATEGORY};
    } else {
        categroies = url.getParameter(Constants.CATEGORY_KEY, new String[] {Constants.DEFAULT_CATEGORY});
    }
    String[] paths = new String[categroies.length];
    for (int i = 0; i < categroies.length; i ++) {
        paths[i] = toServicePath(url) + Constants.PATH_SEPARATOR + categroies[i];
    }
    return paths;
}
 
Example 8
Source File: ZookeeperRegistry.java    From dubbox with Apache License 2.0 4 votes vote down vote up
private String toCategoryPath(URL url) {
    return toServicePath(url) + Constants.PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY);
}
 
Example 9
Source File: ZookeeperRegistry.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
private String toCategoryPath(URL url) {
    return toServicePath(url) + Constants.PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY);
}
 
Example 10
Source File: RedisRegistry.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
private String toCategoryPath(URL url) {
    return toServicePath(url) + Constants.PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY);
}
 
Example 11
Source File: ZookeeperRegistry.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
private String toRootDir() {
    if (root.equals(Constants.PATH_SEPARATOR)) {
        return root;
    }
    return root + Constants.PATH_SEPARATOR;
}
 
Example 12
Source File: RedisRegistry.java    From dubbox with Apache License 2.0 4 votes vote down vote up
private String toCategoryPath(URL url) {
    return toServicePath(url) + Constants.PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY);
}
 
Example 13
Source File: ZookeeperRegistry.java    From dubbox with Apache License 2.0 4 votes vote down vote up
private String toUrlPath(URL url) {
    return toCategoryPath(url) + Constants.PATH_SEPARATOR + URL.encode(url.toFullString());
}
 
Example 14
Source File: RedisRegistry.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public RedisRegistry(URL url) {
    super(url);
    if (url.isAnyHost()) {
		throw new IllegalStateException("registry address == null");
	}
    GenericObjectPool.Config config = new GenericObjectPool.Config();
    config.testOnBorrow = url.getParameter("test.on.borrow", true);
    config.testOnReturn = url.getParameter("test.on.return", false);
    config.testWhileIdle = url.getParameter("test.while.idle", false);
    if (url.getParameter("max.idle", 0) > 0)
        config.maxIdle = url.getParameter("max.idle", 0);
    if (url.getParameter("min.idle", 0) > 0)
        config.minIdle = url.getParameter("min.idle", 0);
    if (url.getParameter("max.active", 0) > 0)
        config.maxActive = url.getParameter("max.active", 0);
    if (url.getParameter("max.wait", url.getParameter("timeout", 0)) > 0)
        config.maxWait = url.getParameter("max.wait", url.getParameter("timeout", 0));
    if (url.getParameter("num.tests.per.eviction.run", 0) > 0)
        config.numTestsPerEvictionRun = url.getParameter("num.tests.per.eviction.run", 0);
    if (url.getParameter("time.between.eviction.runs.millis", 0) > 0)
        config.timeBetweenEvictionRunsMillis = url.getParameter("time.between.eviction.runs.millis", 0);
    if (url.getParameter("min.evictable.idle.time.millis", 0) > 0)
        config.minEvictableIdleTimeMillis = url.getParameter("min.evictable.idle.time.millis", 0);
    
    String cluster = url.getParameter("cluster", "failover");
    if (! "failover".equals(cluster) && ! "replicate".equals(cluster)) {
    	throw new IllegalArgumentException("Unsupported redis cluster: " + cluster + ". The redis cluster only supported failover or replicate.");
    }
    replicate = "replicate".equals(cluster);
    
    List<String> addresses = new ArrayList<String>();
    addresses.add(url.getAddress());
    String[] backups = url.getParameter(Constants.BACKUP_KEY, new String[0]);
    if (backups != null && backups.length > 0) {
        addresses.addAll(Arrays.asList(backups));
    }
    for (String address : addresses) {
        int i = address.indexOf(':');
        String host;
        int port;
        if (i > 0) {
            host = address.substring(0, i);
            port = Integer.parseInt(address.substring(i + 1));
        } else {
            host = address;
            port = DEFAULT_REDIS_PORT;
        }
        this.jedisPools.put(address, new JedisPool(config, host, port, 
                url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)));
    }
    
    this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD);
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
    if (! group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    if (! group.endsWith(Constants.PATH_SEPARATOR)) {
        group = group + Constants.PATH_SEPARATOR;
    }
    this.root = group;
    
    this.expirePeriod = url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_SESSION_TIMEOUT);
    this.expireFuture = expireExecutor.scheduleWithFixedDelay(new Runnable() {
        public void run() {
            try {
                deferExpired(); // 延长过期时间
            } catch (Throwable t) { // 防御性容错
                logger.error("Unexpected exception occur at defer expire time, cause: " + t.getMessage(), t);
            }
        }
    }, expirePeriod / 2, expirePeriod / 2, TimeUnit.MILLISECONDS);
}
 
Example 15
Source File: ZookeeperRegistry.java    From dubbox with Apache License 2.0 4 votes vote down vote up
private String toRootDir() {
    if (root.equals(Constants.PATH_SEPARATOR)) {
        return root;
    }
    return root + Constants.PATH_SEPARATOR;
}
 
Example 16
Source File: RedisRegistry.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public RedisRegistry(URL url) {
    super(url);
    if (url.isAnyHost()) {
        throw new IllegalStateException("registry address == null");
    }
    GenericObjectPool.Config config = new GenericObjectPool.Config();
    config.testOnBorrow = url.getParameter("test.on.borrow", true);
    config.testOnReturn = url.getParameter("test.on.return", false);
    config.testWhileIdle = url.getParameter("test.while.idle", false);
    if (url.getParameter("max.idle", 0) > 0)
        config.maxIdle = url.getParameter("max.idle", 0);
    if (url.getParameter("min.idle", 0) > 0)
        config.minIdle = url.getParameter("min.idle", 0);
    if (url.getParameter("max.active", 0) > 0)
        config.maxActive = url.getParameter("max.active", 0);
    if (url.getParameter("max.wait", url.getParameter("timeout", 0)) > 0)
        config.maxWait = url.getParameter("max.wait", url.getParameter("timeout", 0));
    if (url.getParameter("num.tests.per.eviction.run", 0) > 0)
        config.numTestsPerEvictionRun = url.getParameter("num.tests.per.eviction.run", 0);
    if (url.getParameter("time.between.eviction.runs.millis", 0) > 0)
        config.timeBetweenEvictionRunsMillis = url.getParameter("time.between.eviction.runs.millis", 0);
    if (url.getParameter("min.evictable.idle.time.millis", 0) > 0)
        config.minEvictableIdleTimeMillis = url.getParameter("min.evictable.idle.time.millis", 0);

    String cluster = url.getParameter("cluster", "failover");
    if (! "failover".equals(cluster) && ! "replicate".equals(cluster)) {
        throw new IllegalArgumentException("Unsupported redis cluster: " + cluster + ". The redis cluster only supported failover or replicate.");
    }
    replicate = "replicate".equals(cluster);

    List<String> addresses = new ArrayList<String>();
    addresses.add(url.getAddress());
    String[] backups = url.getParameter(Constants.BACKUP_KEY, new String[0]);
    if (backups != null && backups.length > 0) {
        addresses.addAll(Arrays.asList(backups));
    }

    // 增加Redis密码支持
    String password = url.getPassword();
    for (String address : addresses) {
        int i = address.indexOf(':');
        String host;
        int port;
        if (i > 0) {
            host = address.substring(0, i);
            port = Integer.parseInt(address.substring(i + 1));
        } else {
            host = address;
            port = DEFAULT_REDIS_PORT;
        }
        if (StringUtils.isEmpty(password)) {
            this.jedisPools.put(address, new JedisPool(config, host, port,
                    url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)));
        } else {
            // 使用密码连接。  此处要求备用redis与主要redis使用相同的密码
            this.jedisPools.put(address, new JedisPool(config, host, port,
                    url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT), password));
        }
    }

    this.reconnectPeriod = url.getParameter(Constants.REGISTRY_RECONNECT_PERIOD_KEY, Constants.DEFAULT_REGISTRY_RECONNECT_PERIOD);
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
    if (! group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    if (! group.endsWith(Constants.PATH_SEPARATOR)) {
        group = group + Constants.PATH_SEPARATOR;
    }
    this.root = group;

    this.expirePeriod = url.getParameter(Constants.SESSION_TIMEOUT_KEY, Constants.DEFAULT_SESSION_TIMEOUT);
    this.expireFuture = expireExecutor.scheduleWithFixedDelay(new Runnable() {
        public void run() {
            try {
                deferExpired(); // 延长过期时间
            } catch (Throwable t) { // 防御性容错
                logger.error("Unexpected exception occur at defer expire time, cause: " + t.getMessage(), t);
            }
        }
    }, expirePeriod / 2, expirePeriod / 2, TimeUnit.MILLISECONDS);
}
 
Example 17
Source File: RedisRegistry.java    From dubbox with Apache License 2.0 4 votes vote down vote up
private String toCategoryPath(URL url) {
    return toServicePath(url) + Constants.PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY);
}
 
Example 18
Source File: RedisRegistry.java    From dubbo3 with Apache License 2.0 4 votes vote down vote up
private String toCategoryPath(URL url) {
    return toServicePath(url) + Constants.PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY);
}
 
Example 19
Source File: ZookeeperRegistry.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
private String toRootDir() {
    if (root.equals(Constants.PATH_SEPARATOR)) {
        return root;
    }
    return root + Constants.PATH_SEPARATOR;
}
 
Example 20
Source File: RedisRegistry.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
private String toCategoryPath(URL url) {
    return toServicePath(url) + Constants.PATH_SEPARATOR + url.getParameter(Constants.CATEGORY_KEY, Constants.DEFAULT_CATEGORY);
}