Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
嗝屁小孩纸
guide-rpc-framework
提交
c003c9ff
G
guide-rpc-framework
项目概览
嗝屁小孩纸
/
guide-rpc-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
guide-rpc-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c003c9ff
编写于
3月 06, 2022
作者:
G
guide
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[imporve]工具类完善
上级
815d73a5
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
53 addition
and
60 deletion
+53
-60
rpc-framework-common/src/main/java/github/javaguide/extension/ExtensionLoader.java
...main/java/github/javaguide/extension/ExtensionLoader.java
+2
-2
rpc-framework-common/src/main/java/github/javaguide/utils/CollectionUtil.java
.../src/main/java/github/javaguide/utils/CollectionUtil.java
+17
-0
rpc-framework-common/src/main/java/github/javaguide/utils/CollectionUtils.java
...src/main/java/github/javaguide/utils/CollectionUtils.java
+0
-19
rpc-framework-common/src/main/java/github/javaguide/utils/StringUtil.java
...mmon/src/main/java/github/javaguide/utils/StringUtil.java
+22
-0
rpc-framework-common/src/main/java/github/javaguide/utils/StringUtils.java
...mon/src/main/java/github/javaguide/utils/StringUtils.java
+0
-27
rpc-framework-common/src/main/java/github/javaguide/utils/concurrent/threadpool/ThreadPoolFactoryUtil.java
...de/utils/concurrent/threadpool/ThreadPoolFactoryUtil.java
+2
-2
rpc-framework-simple/src/main/java/github/javaguide/config/CustomShutdownHook.java
...main/java/github/javaguide/config/CustomShutdownHook.java
+2
-2
rpc-framework-simple/src/main/java/github/javaguide/loadbalance/AbstractLoadBalance.java
...ava/github/javaguide/loadbalance/AbstractLoadBalance.java
+2
-2
rpc-framework-simple/src/main/java/github/javaguide/registry/zk/ZkServiceDiscoveryImpl.java
.../github/javaguide/registry/zk/ZkServiceDiscoveryImpl.java
+2
-2
rpc-framework-simple/src/main/java/github/javaguide/remoting/transport/netty/server/NettyRpcServer.java
...guide/remoting/transport/netty/server/NettyRpcServer.java
+2
-2
rpc-framework-simple/src/main/java/github/javaguide/remoting/transport/socket/SocketRpcServer.java
.../javaguide/remoting/transport/socket/SocketRpcServer.java
+2
-2
未找到文件。
rpc-framework-common/src/main/java/github/javaguide/extension/ExtensionLoader.java
浏览文件 @
c003c9ff
package
github.javaguide.extension
;
import
github.javaguide.utils.StringUtil
s
;
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
(
StringUtil
s
.
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
...
...
rpc-framework-common/src/main/java/github/javaguide/utils/CollectionUtil.java
0 → 100644
浏览文件 @
c003c9ff
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
();
}
}
rpc-framework-common/src/main/java/github/javaguide/utils/CollectionUtils.java
已删除
100644 → 0
浏览文件 @
815d73a5
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
);
}
}
rpc-framework-common/src/main/java/github/javaguide/utils/StringUtil.java
0 → 100644
浏览文件 @
c003c9ff
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
;
}
}
rpc-framework-common/src/main/java/github/javaguide/utils/StringUtils.java
已删除
100644 → 0
浏览文件 @
815d73a5
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
);
}
}
rpc-framework-common/src/main/java/github/javaguide/utils/concurrent/threadpool/ThreadPoolFactoryUtil
s
.java
→
rpc-framework-common/src/main/java/github/javaguide/utils/concurrent/threadpool/ThreadPoolFactoryUtil.java
浏览文件 @
c003c9ff
...
...
@@ -20,7 +20,7 @@ import java.util.concurrent.TimeUnit;
* @createTime 2020年05月26日 16:00:00
*/
@Slf4j
public
final
class
ThreadPoolFactoryUtil
s
{
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
ThreadPoolFactoryUtil
s
()
{
private
ThreadPoolFactoryUtil
()
{
}
...
...
rpc-framework-simple/src/main/java/github/javaguide/config/CustomShutdownHook.java
浏览文件 @
c003c9ff
...
...
@@ -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.ThreadPoolFactoryUtil
s
;
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
)
{
}
ThreadPoolFactoryUtil
s
.
shutDownAllThreadPool
();
ThreadPoolFactoryUtil
.
shutDownAllThreadPool
();
}));
}
}
rpc-framework-simple/src/main/java/github/javaguide/loadbalance/AbstractLoadBalance.java
浏览文件 @
c003c9ff
package
github.javaguide.loadbalance
;
import
github.javaguide.remoting.dto.RpcRequest
;
import
github.javaguide.utils.CollectionUtil
s
;
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
(
CollectionUtil
s
.
isEmpty
(
serviceAddresses
))
{
if
(
CollectionUtil
.
isEmpty
(
serviceAddresses
))
{
return
null
;
}
if
(
serviceAddresses
.
size
()
==
1
)
{
...
...
rpc-framework-simple/src/main/java/github/javaguide/registry/zk/ZkServiceDiscoveryImpl.java
浏览文件 @
c003c9ff
...
...
@@ -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.CollectionUtil
s
;
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
(
CollectionUtil
s
.
isEmpty
(
serviceUrlList
))
{
if
(
CollectionUtil
.
isEmpty
(
serviceUrlList
))
{
throw
new
RpcException
(
RpcErrorMessageEnum
.
SERVICE_CAN_NOT_BE_FOUND
,
rpcServiceName
);
}
// load balancing
...
...
rpc-framework-simple/src/main/java/github/javaguide/remoting/transport/netty/server/NettyRpcServer.java
浏览文件 @
c003c9ff
...
...
@@ -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.ThreadPoolFactoryUtil
s
;
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
,
ThreadPoolFactoryUtil
s
.
createThreadFactory
(
"service-handler-group"
,
false
)
ThreadPoolFactoryUtil
.
createThreadFactory
(
"service-handler-group"
,
false
)
);
try
{
ServerBootstrap
b
=
new
ServerBootstrap
();
...
...
rpc-framework-simple/src/main/java/github/javaguide/remoting/transport/socket/SocketRpcServer.java
浏览文件 @
c003c9ff
...
...
@@ -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.ThreadPoolFactoryUtil
s
;
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
=
ThreadPoolFactoryUtil
s
.
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录