本文整理汇总了Java中com.alibaba.dubbo.common.utils.StringUtils.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java StringUtils.isEmpty方法的具体用法?Java StringUtils.isEmpty怎么用?Java StringUtils.isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.common.utils.StringUtils
的用法示例。
在下文中一共展示了StringUtils.isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSampler
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
private Sampler createSampler(URL url) {
String sampler = url.getParameter("sampler");
if (StringUtils.isEmpty(sampler)) {
return Sampler.ALWAYS_SAMPLE;
} else {
String rate = url.getParameter("samplerate");
if (StringUtils.isEmpty(rate)) {
return Sampler.ALWAYS_SAMPLE;
}
switch (sampler) {
case "counting":
return CountingSampler.create(Float.valueOf(rate));
case "boundary":
return BoundarySampler.create(Float.valueOf(rate));
default:
throw new IllegalArgumentException("unknown sampler type, sampler: " + sampler +
", supported sampler: { counting, boundary }");
}
}
}
示例2: overridesToWeights
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
public static List<Weight> overridesToWeights(List<Override> overrides){
List<Weight> weights = new ArrayList<Weight>();
if(overrides == null){
return weights;
}
for(Override o : overrides){
if(StringUtils.isEmpty(o.getParams())){
continue;
}else{
Map<String,String> params = StringUtils.parseQueryString(o.getParams());
for(Map.Entry<String, String> entry : params.entrySet()){
if(entry.getKey().equals("weight")){
Weight weight = new Weight();
weight.setAddress(o.getAddress());
weight.setId(o.getId());
weight.setService(o.getService());
weight.setWeight(Integer.valueOf(entry.getValue()));
weights.add(weight);
}
}
}
}
return weights;
}
示例3: appendParamsToUri
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
public static String appendParamsToUri(String uri, Map<String, String> params) {
StringBuilder buf = new StringBuilder(uri);
boolean first = (uri.indexOf('?') < 0);
for(Map.Entry<String, String> entry : params.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if(StringUtils.isEmpty(key) || StringUtils.isEmpty(value))
continue;
if (first) {
buf.append("?");
first = false;
} else {
buf.append("&");
}
buf.append(key);
buf.append("=");
buf.append(value);
}
return buf.toString();
}
示例4: createClient
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
protected T createClient(Class<T> cls, String targetIP, int targetPort, int connectTimeout,int clientNums, String protocol, String serialization){
ReferenceConfig<T> referenceConfig = new ReferenceConfig<T>();
referenceConfig.setInterface(cls);
StringBuilder url = new StringBuilder();
url.append(protocol);
url.append("://");
url.append(targetIP);
url.append(":");
url.append(targetPort);
url.append("/");
url.append(cls.getName());
url.append("?optimizer=com.alibaba.dubbo.rpc.benchmark.SerializationOptimizerImpl");
if (!StringUtils.isEmpty(serialization)) {
url.append("&serialization=");
url.append(serialization);
}
referenceConfig.setUrl(url.toString());
// hardcode
referenceConfig.setConnections(clientNums);
ApplicationConfig application = new ApplicationConfig();
application.setName("dubbo_consumer");
referenceConfig.setApplication(application);
referenceConfig.setTimeout(connectTimeout);
return referenceConfig.get();
}
示例5: filter
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
public void filter(ContainerRequestContext requestContext) throws IOException {
HttpServletRequest request = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
RpcContext.getContext().setRequest(request);
// this only works for servlet containers
if (request != null && RpcContext.getContext().getRemoteAddress() == null) {
RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
}
RpcContext.getContext().setResponse(ResteasyProviderFactory.getContextData(HttpServletResponse.class));
String headers = requestContext.getHeaderString(DUBBO_ATTACHMENT_HEADER);
if (headers != null) {
for (String header : headers.split(",")) {
int index = header.indexOf("=");
if (index > 0) {
String key = header.substring(0, index);
String value = header.substring(index + 1);
if (!StringUtils.isEmpty(key)) {
RpcContext.getContext().setAttachment(key.trim(), value.trim());
}
}
}
}
}
示例6: isMatchGlobPatternsNeedInterpolate
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
/**
* 是否匹配Glob模式。Glob模式是要插值的表达式。Glob模式有多个,只要匹配一个模式,就认为匹配成功。
*
* @param patternsNeedInterpolate 多个要进行插值的Glob模式
* @param interpolateParams 用于插值的变量集
* @param value 进行Glob模式的值
*/
public static boolean isMatchGlobPatternsNeedInterpolate(
Collection<String> patternsNeedInterpolate,
Map<String, String> interpolateParams, String value) {
if(patternsNeedInterpolate != null && ! patternsNeedInterpolate.isEmpty()) {
for (String patternNeedItp : patternsNeedInterpolate) {
if(StringUtils.isEmpty(patternNeedItp)) {
continue;
}
// FIXME ERROR!! 原来的实现,这里只和第一个不为空的pattern比较,返回对应的结果! 和梁飞确认
String pattern = interpolate(patternNeedItp, interpolateParams);
if(isMatchGlobPattern(pattern, value)) {
return true;
}
}
}
return false;
}
示例7: appendParamToUri
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
public static String appendParamToUri(String uri, String name, String value) {
if (StringUtils.isEmpty(name) || StringUtils.isEmpty(value)) return uri;
if (uri.indexOf('?') != -1) {
uri += "&" + name + "=" + value;
} else {
uri += "?" + name + "=" + value;
}
return uri;
}
示例8: serviceName2Map
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
public static Map<String, String> serviceName2Map(String serviceName) {
String group = null;
String version = null;
int i = serviceName.indexOf("/");
if (i > 0) {
group = serviceName.substring(0, i);
serviceName = serviceName.substring(i + 1);
}
i = serviceName.lastIndexOf(":");
if (i > 0) {
version = serviceName.substring(i + 1);
serviceName = serviceName.substring(0, i);
}
Map<String, String> ret = new HashMap<String, String>();
if(!StringUtils.isEmpty(serviceName)) {
ret.put(Constants.INTERFACE_KEY, serviceName);
}
if(!StringUtils.isEmpty(version)) {
ret.put(Constants.VERSION_KEY, version);
}
if(!StringUtils.isEmpty(group)) {
ret.put(Constants.GROUP_KEY, group);
}
return ret;
}
示例9: serviceName2Map
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
public static Map<String, String> serviceName2Map(String serviceName) {
String group = null;
String version = null;
int i = serviceName.indexOf("/");
if (i > 0) {
group = serviceName.substring(0, i);
serviceName = serviceName.substring(i + 1);
}
i = serviceName.lastIndexOf(":");
if (i > 0) {
version = serviceName.substring(i + 1);
serviceName = serviceName.substring(0, i);
}
Map<String, String> ret = new HashMap<String, String>();
if (!StringUtils.isEmpty(serviceName)) {
ret.put(Constants.INTERFACE_KEY, serviceName);
}
if (!StringUtils.isEmpty(version)) {
ret.put(Constants.VERSION_KEY, version);
}
if (!StringUtils.isEmpty(group)) {
ret.put(Constants.GROUP_KEY, group);
}
return ret;
}
示例10: loadProviders
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
protected void loadProviders(String value) {
for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(value)) {
if (!StringUtils.isEmpty(clazz)) {
getDeployment().getProviderClasses().add(clazz.trim());
}
}
}
示例11: deploy
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
public void deploy(Class resourceDef, Object resourceInstance, String contextPath) {
if (StringUtils.isEmpty(contextPath)) {
getDeployment().getRegistry().addResourceFactory(new DubboResourceFactory(resourceInstance, resourceDef));
} else {
getDeployment().getRegistry().addResourceFactory(new DubboResourceFactory(resourceInstance, resourceDef), contextPath);
}
}
示例12: parseAndReflectResponse
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
/**
* 解析请求响应类
* 根据从Mock系统中得到相关的响应类进行解析,并根据Mock系统中设置的值进行注入
*
* @return
*/
private Result parseAndReflectResponse(MockTestConfig mockTestConfig) {
RpcResult result = new RpcResult();
try {
String responsePath = mockTestConfig.getResponsePath();
if (StringUtils.isEmpty(responsePath)) {
throw new RpcException("服务接口类全路径名称(facadeClass)为null");
}
Class responseClass = Class.forName(responsePath);
Object responseBean = responseClass.newInstance();
String responseJson = mockTestConfig.getResponseJson();
responseBean = parseMockData(responseJson, responseBean.getClass());
if (responseBean == null) {
log.error( "响应json串映射成javaBean,ResponseBean为空! facadeClass:" + responsePath +
" responseJson:" + responseJson);
return result;
}
result.setValue(responseBean);
} catch (Exception e) {
log.error( e.toString(), e);
}
return result;
}
示例13: overridesToLoadBalances
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
public static List<LoadBalance> overridesToLoadBalances(List<Override> overrides){
List<LoadBalance> loadBalances = new ArrayList<LoadBalance>();
if(overrides == null){
return loadBalances;
}
for(Override o : overrides){
if(StringUtils.isEmpty(o.getParams())){
continue;
}else{
Map<String,String> params = StringUtils.parseQueryString(o.getParams());
for(Map.Entry<String, String> entry : params.entrySet()){
if(entry.getKey().endsWith("loadbalance")){
LoadBalance loadBalance = new LoadBalance();
String method = null;
if(entry.getKey().endsWith(".loadbalance")){
method = entry.getKey().split(".loadbalance")[0];
}else{
method = "*";
}
loadBalance.setMethod(method);
loadBalance.setId(o.getId());
loadBalance.setService(o.getService());
loadBalance.setStrategy(entry.getValue());
loadBalances.add(loadBalance);
}
}
}
}
return loadBalances;
}
示例14: doRefer
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
if (connectionMonitor == null) {
connectionMonitor = new ConnectionMonitor();
}
// TODO more configs to add
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
// 20 is the default maxTotal of current PoolingClientConnectionManager
connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));
connectionMonitor.addConnectionManager(connectionManager);
// BasicHttpContext localContext = new BasicHttpContext();
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
return Long.parseLong(value) * 1000;
}
}
// TODO constant
return 30 * 1000;
}
});
HttpParams params = httpClient.getParams();
// TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
HttpConnectionParams.setTcpNoDelay(params, true);
HttpConnectionParams.setSoKeepalive(params, true);
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);
ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
clients.add(client);
client.register(RpcContextFilter.class);
for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
if (!StringUtils.isEmpty(clazz)) {
try {
client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
} catch (ClassNotFoundException e) {
throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
}
}
}
// TODO protocol
ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
return target.proxy(serviceType);
}
示例15: RedisRegistry
import com.alibaba.dubbo.common.utils.StringUtils; //导入方法依赖的package包/类
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);
}