提交 c003c9ff 编写于 作者: G guide

[imporve]工具类完善

上级 815d73a5
package github.javaguide.extension;
import github.javaguide.utils.StringUtils;
import github.javaguide.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;
import java.io.BufferedReader;
......@@ -52,7 +52,7 @@ public final class ExtensionLoader<T> {
}
public T getExtension(String name) {
if (StringUtils.isBlank(name)) {
if (StringUtil.isBlank(name)) {
throw new IllegalArgumentException("Extension name should not be null or empty.");
}
// firstly get from cache, if not hit, create one
......
package github.javaguide.utils;
import java.util.Collection;
/**
* 集合工具类
*
* @author zhanghua
* @createTime 2022/3/6 12:58 上午
*/
public class CollectionUtil {
public static boolean isEmpty(Collection<?> c) {
return c == null || c.isEmpty();
}
}
package github.javaguide.utils;
import java.util.Collection;
/**
* @Description:
* @Author: zhanghua
* @Date: 2022/3/6 12:58 上午
*/
public class CollectionUtils {
public static boolean isEmpty(Collection coll) {
return coll == null || coll.isEmpty();
}
public static boolean isNotEmpty(Collection coll) {
return isEmpty(coll);
}
}
package github.javaguide.utils;
/**
* String 工具类
*
* @author zhanghua
* @createTime 2022/3/6 12:58 上午
*/
public class StringUtil {
public static boolean isBlank(String s) {
if (s == null || s.length() == 0) {
return true;
}
for (int i = 0; i < s.length(); ++i) {
if (!Character.isWhitespace(s.charAt(i))) {
return false;
}
}
return true;
}
}
package github.javaguide.utils;
/**
* @Description:
* @Author: zhanghua
* @Date: 2022/3/6 12:58 上午
*/
public class StringUtils {
public static boolean isBlank(String s){
int strLen ;
if(s == null || (strLen = s.length()) == 0){
return true;
}
for(int i = 0; i < strLen; ++i) {
if (!Character.isWhitespace(s.charAt(i))) {
return false;
}
}
return true;
}
public static boolean isNotBlank(String s){
return !isBlank(s);
}
}
......@@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit;
* @createTime 2020年05月26日 16:00:00
*/
@Slf4j
public final class ThreadPoolFactoryUtils {
public final class ThreadPoolFactoryUtil {
/**
* 通过 threadNamePrefix 来区分不同线程池(我们可以把相同 threadNamePrefix 的线程池看作是为同一业务场景服务)。
......@@ -29,7 +29,7 @@ public final class ThreadPoolFactoryUtils {
*/
private static final Map<String, ExecutorService> THREAD_POOLS = new ConcurrentHashMap<>();
private ThreadPoolFactoryUtils() {
private ThreadPoolFactoryUtil() {
}
......
......@@ -2,7 +2,7 @@ package github.javaguide.config;
import github.javaguide.registry.zk.util.CuratorUtils;
import github.javaguide.remoting.transport.netty.server.NettyRpcServer;
import github.javaguide.utils.concurrent.threadpool.ThreadPoolFactoryUtils;
import github.javaguide.utils.concurrent.threadpool.ThreadPoolFactoryUtil;
import lombok.extern.slf4j.Slf4j;
import java.net.InetAddress;
......@@ -31,7 +31,7 @@ public class CustomShutdownHook {
CuratorUtils.clearRegistry(CuratorUtils.getZkClient(), inetSocketAddress);
} catch (UnknownHostException ignored) {
}
ThreadPoolFactoryUtils.shutDownAllThreadPool();
ThreadPoolFactoryUtil.shutDownAllThreadPool();
}));
}
}
package github.javaguide.loadbalance;
import github.javaguide.remoting.dto.RpcRequest;
import github.javaguide.utils.CollectionUtils;
import github.javaguide.utils.CollectionUtil;
import java.util.List;
......@@ -14,7 +14,7 @@ import java.util.List;
public abstract class AbstractLoadBalance implements LoadBalance {
@Override
public String selectServiceAddress(List<String> serviceAddresses, RpcRequest rpcRequest) {
if (CollectionUtils.isEmpty(serviceAddresses)) {
if (CollectionUtil.isEmpty(serviceAddresses)) {
return null;
}
if (serviceAddresses.size() == 1) {
......
......@@ -7,7 +7,7 @@ import github.javaguide.loadbalance.LoadBalance;
import github.javaguide.registry.ServiceDiscovery;
import github.javaguide.registry.zk.util.CuratorUtils;
import github.javaguide.remoting.dto.RpcRequest;
import github.javaguide.utils.CollectionUtils;
import github.javaguide.utils.CollectionUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
......@@ -33,7 +33,7 @@ public class ZkServiceDiscoveryImpl implements ServiceDiscovery {
String rpcServiceName = rpcRequest.getRpcServiceName();
CuratorFramework zkClient = CuratorUtils.getZkClient();
List<String> serviceUrlList = CuratorUtils.getChildrenNodes(zkClient, rpcServiceName);
if (CollectionUtils.isEmpty(serviceUrlList)) {
if (CollectionUtil.isEmpty(serviceUrlList)) {
throw new RpcException(RpcErrorMessageEnum.SERVICE_CAN_NOT_BE_FOUND, rpcServiceName);
}
// load balancing
......
......@@ -8,7 +8,7 @@ import github.javaguide.provider.impl.ZkServiceProviderImpl;
import github.javaguide.remoting.transport.netty.codec.RpcMessageDecoder;
import github.javaguide.remoting.transport.netty.codec.RpcMessageEncoder;
import github.javaguide.utils.RuntimeUtil;
import github.javaguide.utils.concurrent.threadpool.ThreadPoolFactoryUtils;
import github.javaguide.utils.concurrent.threadpool.ThreadPoolFactoryUtil;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
......@@ -56,7 +56,7 @@ public class NettyRpcServer {
EventLoopGroup workerGroup = new NioEventLoopGroup();
DefaultEventExecutorGroup serviceHandlerGroup = new DefaultEventExecutorGroup(
RuntimeUtil.cpus() * 2,
ThreadPoolFactoryUtils.createThreadFactory("service-handler-group", false)
ThreadPoolFactoryUtil.createThreadFactory("service-handler-group", false)
);
try {
ServerBootstrap b = new ServerBootstrap();
......
......@@ -5,7 +5,7 @@ import github.javaguide.config.RpcServiceConfig;
import github.javaguide.factory.SingletonFactory;
import github.javaguide.provider.ServiceProvider;
import github.javaguide.provider.impl.ZkServiceProviderImpl;
import github.javaguide.utils.concurrent.threadpool.ThreadPoolFactoryUtils;
import github.javaguide.utils.concurrent.threadpool.ThreadPoolFactoryUtil;
import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
......@@ -29,7 +29,7 @@ public class SocketRpcServer {
public SocketRpcServer() {
threadPool = ThreadPoolFactoryUtils.createCustomThreadPoolIfAbsent("socket-server-rpc-pool");
threadPool = ThreadPoolFactoryUtil.createCustomThreadPoolIfAbsent("socket-server-rpc-pool");
serviceProvider = SingletonFactory.getInstance(ZkServiceProviderImpl.class);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册