Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
嗝屁小孩纸
guide-rpc-framework
提交
341ed955
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,发现更多精彩内容 >>
提交
341ed955
编写于
11月 02, 2020
作者:
G
guide
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[refractor]zk utils
上级
31101914
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
14 addition
and
21 deletion
+14
-21
README.md
README.md
+1
-1
rpc-framework-common/src/main/java/github/javaguide/extension/ExtensionLoader.java
...main/java/github/javaguide/extension/ExtensionLoader.java
+0
-2
rpc-framework-common/src/main/java/github/javaguide/extension/Holder.java
...mmon/src/main/java/github/javaguide/extension/Holder.java
+1
-1
rpc-framework-common/src/main/java/github/javaguide/utils/PropertiesFileUtil.java
.../main/java/github/javaguide/utils/PropertiesFileUtil.java
+3
-3
rpc-framework-simple/src/main/java/github/javaguide/registry/zk/ZkServiceDiscovery.java
...java/github/javaguide/registry/zk/ZkServiceDiscovery.java
+1
-1
rpc-framework-simple/src/main/java/github/javaguide/registry/zk/util/CuratorUtils.java
.../java/github/javaguide/registry/zk/util/CuratorUtils.java
+8
-13
未找到文件。
README.md
浏览文件 @
341ed955
...
...
@@ -115,7 +115,7 @@ fork 项目到自己的仓库,然后克隆项目到自己的本地:`git clon
### CheckStyle 插件下载和配置
IntelliJ IDEA-> Preferences->Plugins->搜索下载 CheckStyle 插件
,然后按照如下方式进行配置。
`IntelliJ IDEA-> Preferences->Plugins->搜索下载 CheckStyle 插件`
,然后按照如下方式进行配置。
![
CheckStyle 插件下载和配置
](
./images/setting-check-style.png
)
...
...
rpc-framework-common/src/main/java/github/javaguide/extension/ExtensionLoader.java
浏览文件 @
341ed955
package
github.javaguide.extension
;
import
github.javaguide.utils.Holder
;
import
lombok.extern.slf4j.Slf4j
;
import
java.io.BufferedReader
;
...
...
@@ -88,7 +87,6 @@ public final class ExtensionLoader<T> {
instance
=
(
T
)
EXTENSION_INSTANCES
.
get
(
clazz
);
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
());
throw
new
RuntimeException
(
"Fail to create an instance of the extension class "
+
clazz
);
}
}
return
instance
;
...
...
rpc-framework-common/src/main/java/github/javaguide/
utils
/Holder.java
→
rpc-framework-common/src/main/java/github/javaguide/
extension
/Holder.java
浏览文件 @
341ed955
package
github.javaguide.
utils
;
package
github.javaguide.
extension
;
public
class
Holder
<
T
>
{
...
...
rpc-framework-common/src/main/java/github/javaguide/utils/
file/PropertiesFileUtils
.java
→
rpc-framework-common/src/main/java/github/javaguide/utils/
PropertiesFileUtil
.java
浏览文件 @
341ed955
package
github.javaguide.utils
.file
;
package
github.javaguide.utils
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -14,8 +14,8 @@ import java.util.Properties;
* @createTime 2020年07月21日 14:25:00
**/
@Slf4j
public
final
class
PropertiesFileUtil
s
{
private
PropertiesFileUtil
s
()
{
public
final
class
PropertiesFileUtil
{
private
PropertiesFileUtil
()
{
}
public
static
Properties
readPropertiesFile
(
String
fileName
)
{
...
...
rpc-framework-simple/src/main/java/github/javaguide/registry/zk/ZkServiceDiscovery.java
浏览文件 @
341ed955
...
...
@@ -30,7 +30,7 @@ public class ZkServiceDiscovery implements ServiceDiscovery {
public
InetSocketAddress
lookupService
(
String
rpcServiceName
)
{
CuratorFramework
zkClient
=
CuratorUtils
.
getZkClient
();
List
<
String
>
serviceUrlList
=
CuratorUtils
.
getChildrenNodes
(
zkClient
,
rpcServiceName
);
if
(
serviceUrlList
.
size
()
==
0
)
{
if
(
serviceUrlList
==
null
||
serviceUrlList
.
size
()
==
0
)
{
throw
new
RpcException
(
RpcErrorMessageEnum
.
SERVICE_CAN_NOT_BE_FOUND
,
rpcServiceName
);
}
// load balancing
...
...
rpc-framework-simple/src/main/java/github/javaguide/registry/zk/util/CuratorUtils.java
浏览文件 @
341ed955
package
github.javaguide.registry.zk.util
;
import
github.javaguide.enums.RpcConfigEnum
;
import
github.javaguide.exception.RpcException
;
import
github.javaguide.utils.file.PropertiesFileUtils
;
import
github.javaguide.utils.PropertiesFileUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.curator.RetryPolicy
;
import
org.apache.curator.framework.CuratorFramework
;
...
...
@@ -55,7 +54,7 @@ public final class CuratorUtils {
}
REGISTERED_PATH_SET
.
add
(
path
);
}
catch
(
Exception
e
)
{
throw
new
RpcException
(
e
.
getMessage
(),
e
.
getCause
()
);
log
.
error
(
"create persistent node for path [{}] fail"
,
path
);
}
}
...
...
@@ -69,14 +68,14 @@ public final class CuratorUtils {
if
(
SERVICE_ADDRESS_MAP
.
containsKey
(
rpcServiceName
))
{
return
SERVICE_ADDRESS_MAP
.
get
(
rpcServiceName
);
}
List
<
String
>
result
;
List
<
String
>
result
=
null
;
String
servicePath
=
ZK_REGISTER_ROOT_PATH
+
"/"
+
rpcServiceName
;
try
{
result
=
zkClient
.
getChildren
().
forPath
(
servicePath
);
SERVICE_ADDRESS_MAP
.
put
(
rpcServiceName
,
result
);
registerWatcher
(
rpcServiceName
,
zkClient
);
}
catch
(
Exception
e
)
{
throw
new
RpcException
(
e
.
getMessage
(),
e
.
getCause
()
);
log
.
error
(
"get children nodes for path [{}] fail"
,
servicePath
);
}
return
result
;
}
...
...
@@ -89,7 +88,7 @@ public final class CuratorUtils {
try
{
zkClient
.
delete
().
forPath
(
p
);
}
catch
(
Exception
e
)
{
throw
new
RpcException
(
e
.
getMessage
(),
e
.
getCause
()
);
log
.
error
(
"clear registry for path [{}] fail"
,
p
);
}
});
log
.
info
(
"All registered services on the server are cleared:[{}]"
,
REGISTERED_PATH_SET
.
toString
());
...
...
@@ -97,7 +96,7 @@ public final class CuratorUtils {
public
static
CuratorFramework
getZkClient
()
{
// check if user has set zk address
Properties
properties
=
PropertiesFileUtil
s
.
readPropertiesFile
(
RpcConfigEnum
.
RPC_CONFIG_PATH
.
getPropertyValue
());
Properties
properties
=
PropertiesFileUtil
.
readPropertiesFile
(
RpcConfigEnum
.
RPC_CONFIG_PATH
.
getPropertyValue
());
if
(
properties
!=
null
)
{
defaultZookeeperAddress
=
properties
.
getProperty
(
RpcConfigEnum
.
ZK_ADDRESS
.
getPropertyValue
());
}
...
...
@@ -121,7 +120,7 @@ public final class CuratorUtils {
*
* @param rpcServiceName rpc service name eg:github.javaguide.HelloServicetest2version
*/
private
static
void
registerWatcher
(
String
rpcServiceName
,
CuratorFramework
zkClient
)
{
private
static
void
registerWatcher
(
String
rpcServiceName
,
CuratorFramework
zkClient
)
throws
Exception
{
String
servicePath
=
ZK_REGISTER_ROOT_PATH
+
"/"
+
rpcServiceName
;
PathChildrenCache
pathChildrenCache
=
new
PathChildrenCache
(
zkClient
,
servicePath
,
true
);
PathChildrenCacheListener
pathChildrenCacheListener
=
(
curatorFramework
,
pathChildrenCacheEvent
)
->
{
...
...
@@ -129,11 +128,7 @@ public final class CuratorUtils {
SERVICE_ADDRESS_MAP
.
put
(
rpcServiceName
,
serviceAddresses
);
};
pathChildrenCache
.
getListenable
().
addListener
(
pathChildrenCacheListener
);
try
{
pathChildrenCache
.
start
();
}
catch
(
Exception
e
)
{
throw
new
RpcException
(
e
.
getMessage
(),
e
.
getCause
());
}
pathChildrenCache
.
start
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录