Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
touzizhuo03
Dubbo
提交
28f87278
D
Dubbo
项目概览
touzizhuo03
/
Dubbo
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Dubbo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
28f87278
编写于
4月 14, 2018
作者:
Y
YunaiV
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
filter
上级
3766a47c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
64 addition
and
16 deletion
+64
-16
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/Filter.java
...o-rpc-api/src/main/java/com/alibaba/dubbo/rpc/Filter.java
+1
-1
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java
...c-api/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java
+27
-5
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java
...pi/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java
+7
-2
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/ClassLoaderFilter.java
.../java/com/alibaba/dubbo/rpc/filter/ClassLoaderFilter.java
+9
-0
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/ConsumerContextFilter.java
...a/com/alibaba/dubbo/rpc/filter/ConsumerContextFilter.java
+8
-3
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/ContextFilter.java
...main/java/com/alibaba/dubbo/rpc/filter/ContextFilter.java
+12
-5
未找到文件。
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/Filter.java
浏览文件 @
28f87278
...
...
@@ -39,7 +39,7 @@ public interface Filter {
* @param invoker service
* @param invocation invocation.
* @return invoke result.
* @throws RpcException
* @throws RpcException
发生 RpcException 异常
* @see com.alibaba.dubbo.rpc.Invoker#invoke(Invocation)
*/
Result
invoke
(
Invoker
<?>
invoker
,
Invocation
invocation
)
throws
RpcException
;
...
...
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/RpcContext.java
浏览文件 @
28f87278
...
...
@@ -56,23 +56,34 @@ import java.util.concurrent.TimeoutException;
*/
public
class
RpcContext
{
/**
* RpcContext 线程变量
*/
private
static
final
ThreadLocal
<
RpcContext
>
LOCAL
=
new
ThreadLocal
<
RpcContext
>()
{
@Override
protected
RpcContext
initialValue
()
{
return
new
RpcContext
();
}
};
/**
* 隐式参数集合
*/
private
final
Map
<
String
,
String
>
attachments
=
new
HashMap
<
String
,
String
>();
// 实际未使用
private
final
Map
<
String
,
Object
>
values
=
new
HashMap
<
String
,
Object
>();
/**
* 异步调用 Future
*/
private
Future
<?>
future
;
/**
* 可调用服务的 URL 对象集合
*/
private
List
<
URL
>
urls
;
/**
* URL 对象
*
调用服务的
URL 对象
*/
private
URL
url
;
/**
...
...
@@ -95,16 +106,27 @@ public class RpcContext {
* 服务提供者地址
*/
private
InetSocketAddress
remoteAddress
;
@Deprecated
@Deprecated
// DUBBO-325 废弃的,使用 urls 属性替代
private
List
<
Invoker
<?>>
invokers
;
@Deprecated
@Deprecated
// DUBBO-325 废弃的,使用 url 属性替代
private
Invoker
<?>
invoker
;
@Deprecated
@Deprecated
// DUBBO-325 废弃的,使用 methodName、parameterTypes、arguments 属性替代
private
Invocation
invocation
;
// now we don't use the 'values' map to hold these objects
// we want these objects to be as generic as possible
/**
* 请求
*
* 例如,在 RestProtocol
*/
private
Object
request
;
/**
* 响应
*
* 例如,在 RestProtocol
*/
private
Object
response
;
protected
RpcContext
()
{
...
...
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/RpcInvocation.java
浏览文件 @
28f87278
...
...
@@ -50,8 +50,12 @@ public class RpcInvocation implements Invocation, Serializable {
* 隐式参数集合
*/
private
Map
<
String
,
String
>
attachments
;
private
transient
Invoker
<?>
invoker
;
// TODO 芋艿,transient
/**
* Invoker 对象
*
* 不序列化
*/
private
transient
Invoker
<?>
invoker
;
public
RpcInvocation
()
{
}
...
...
@@ -120,6 +124,7 @@ public class RpcInvocation implements Invocation, Serializable {
this
.
invoker
=
invoker
;
}
@Override
public
Invoker
<?>
getInvoker
()
{
return
invoker
;
}
...
...
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/ClassLoaderFilter.java
浏览文件 @
28f87278
...
...
@@ -27,16 +27,25 @@ import com.alibaba.dubbo.rpc.RpcException;
/**
* ClassLoaderInvokerFilter
*
* 类加载器切换过滤器
*
* https://github.com/apache/incubator-dubbo/issues/1406
* https://github.com/apache/incubator-dubbo/issues/178
*/
@Activate
(
group
=
Constants
.
PROVIDER
,
order
=
-
30000
)
public
class
ClassLoaderFilter
implements
Filter
{
@Override
public
Result
invoke
(
Invoker
<?>
invoker
,
Invocation
invocation
)
throws
RpcException
{
// 获得原来的类加载器
ClassLoader
ocl
=
Thread
.
currentThread
().
getContextClassLoader
();
// 切换当前线程的类加载器为服务接口的类加载器
Thread
.
currentThread
().
setContextClassLoader
(
invoker
.
getInterface
().
getClassLoader
());
// 服务调用
try
{
return
invoker
.
invoke
(
invocation
);
}
finally
{
// 切换当前线程的类加载器为原来的类加载器
Thread
.
currentThread
().
setContextClassLoader
(
ocl
);
}
}
...
...
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/ConsumerContextFilter.java
浏览文件 @
28f87278
...
...
@@ -30,23 +30,28 @@ import com.alibaba.dubbo.rpc.RpcInvocation;
/**
* ConsumerContextInvokerFilter
*
* 服务消费者的 ContextFilter
*/
@Activate
(
group
=
Constants
.
CONSUMER
,
order
=
-
10000
)
public
class
ConsumerContextFilter
implements
Filter
{
@Override
public
Result
invoke
(
Invoker
<?>
invoker
,
Invocation
invocation
)
throws
RpcException
{
// 设置 RpcContext 对象
RpcContext
.
getContext
()
.
setInvoker
(
invoker
)
.
setInvocation
(
invocation
)
.
setLocalAddress
(
NetUtils
.
getLocalHost
(),
0
)
.
setRemoteAddress
(
invoker
.
getUrl
().
getHost
(),
invoker
.
getUrl
().
getPort
());
.
setLocalAddress
(
NetUtils
.
getLocalHost
(),
0
)
// 本地地址
.
setRemoteAddress
(
invoker
.
getUrl
().
getHost
(),
invoker
.
getUrl
().
getPort
());
// 远程地址
// 设置 RpcInvocation 对象的 `invoker` 属性
if
(
invocation
instanceof
RpcInvocation
)
{
((
RpcInvocation
)
invocation
).
setInvoker
(
invoker
);
}
// 服务调用
try
{
return
invoker
.
invoke
(
invocation
);
}
finally
{
// 清理隐式参数集合
RpcContext
.
getContext
().
clearAttachments
();
}
}
...
...
dubbo-rpc/dubbo-rpc-api/src/main/java/com/alibaba/dubbo/rpc/filter/ContextFilter.java
浏览文件 @
28f87278
...
...
@@ -32,11 +32,14 @@ import java.util.Map;
/**
* ContextInvokerFilter
*
* 服务提供者的 ContextFilter
*/
@Activate
(
group
=
Constants
.
PROVIDER
,
order
=
-
10000
)
public
class
ContextFilter
implements
Filter
{
@Override
public
Result
invoke
(
Invoker
<?>
invoker
,
Invocation
invocation
)
throws
RpcException
{
// 创建新的 `attachments` 集合,清理公用的隐式参数
Map
<
String
,
String
>
attachments
=
invocation
.
getAttachments
();
if
(
attachments
!=
null
)
{
attachments
=
new
HashMap
<
String
,
String
>(
attachments
);
...
...
@@ -46,17 +49,18 @@ public class ContextFilter implements Filter {
attachments
.
remove
(
Constants
.
DUBBO_VERSION_KEY
);
attachments
.
remove
(
Constants
.
TOKEN_KEY
);
attachments
.
remove
(
Constants
.
TIMEOUT_KEY
);
attachments
.
remove
(
Constants
.
ASYNC_KEY
);
// Remove async property to avoid being passed to the following invoke chain.
attachments
.
remove
(
Constants
.
ASYNC_KEY
);
// Remove async property to avoid being passed to the following invoke chain.
// 清空消费端的异步参数
}
// 设置 RpcContext 对象
RpcContext
.
getContext
()
.
setInvoker
(
invoker
)
.
setInvocation
(
invocation
)
// .setAttachments(attachments) // merged from dubbox
.
setLocalAddress
(
invoker
.
getUrl
().
getHost
(),
invoker
.
getUrl
().
getPort
());
.
setLocalAddress
(
invoker
.
getUrl
().
getHost
(),
invoker
.
getUrl
().
getPort
());
// mreged from dubbox
// we may already added some attachments into RpcContext before this filter (e.g. in rest protocol)
// 在此过滤器(例如rest协议)之前,我们可能已经在RpcContext中添加了一些附件。
if
(
attachments
!=
null
)
{
if
(
RpcContext
.
getContext
().
getAttachments
()
!=
null
)
{
RpcContext
.
getContext
().
getAttachments
().
putAll
(
attachments
);
...
...
@@ -64,14 +68,17 @@ public class ContextFilter implements Filter {
RpcContext
.
getContext
().
setAttachments
(
attachments
);
}
}
// 设置 RpcInvocation 对象的 `invoker` 属性
if
(
invocation
instanceof
RpcInvocation
)
{
((
RpcInvocation
)
invocation
).
setInvoker
(
invoker
);
}
// 服务调用
try
{
return
invoker
.
invoke
(
invocation
);
}
finally
{
// 移除上下文
RpcContext
.
removeContext
();
}
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录