Skip to content

Commit 8d5ea10

Browse files
committed
remove some sout
1 parent c6a07a3 commit 8d5ea10

File tree

2 files changed

+95
-81
lines changed

2 files changed

+95
-81
lines changed

‎07rpc/rpc01/rpcfx-core/src/main/java/io/kimmking/rpcfx/client/Rpcfx.java‎

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -103,85 +103,4 @@ private static <T> Object create(Class<T> serviceClass, List<String> invokers, R
103103
newRpcfxInvocationHandler(serviceClass, invokers, router,loadBalance, filters));
104104
}
105105

106-
publicstaticclassRpcfxInvocationHandlerimplementsInvocationHandler{
107-
108-
publicstaticfinalMediaTypeJSONTYPE = MediaType.get("application/json; charset=utf-8");
109-
110-
privatefinalClass<?> serviceClass;
111-
privatefinalList<String> invokers;
112-
privatefinalRouterrouter;
113-
privatefinalLoadBalancerloadBalance;
114-
privatefinalFilter[] filters;
115-
116-
public <T> RpcfxInvocationHandler(Class<T> serviceClass, List<String> invokers, Routerrouter, LoadBalancerloadBalance, Filter... filters){
117-
this.serviceClass = serviceClass;
118-
this.invokers = invokers;
119-
this.router = router;
120-
this.loadBalance = loadBalance;
121-
this.filters = filters;
122-
}
123-
124-
// 可以尝试,自己去写对象序列化,二进制还是文本的,,,rpcfx是xml自定义序列化、反序列化,json: code.google.com/p/rpcfx
125-
// int byte char float double long bool
126-
// [], data class
127-
128-
@Override
129-
publicObjectinvoke(Objectproxy, Methodmethod, Object[] params) throwsThrowable{
130-
131-
List<String> urls = router.route(invokers);
132-
// System.out.println("router.route => ");
133-
// urls.forEach(System.out::println);
134-
Stringurl = loadBalance.select(urls); // router, loadbalance
135-
// System.out.println("loadBalance.select => ");
136-
// System.out.println("final => " + url);
137-
138-
if (url == null){
139-
thrownewRuntimeException("No available providers from registry center.");
140-
}
141-
142-
// 加filter地方之二
143-
// mock == true, new Student("hubao");
144-
145-
RpcfxRequestrequest = newRpcfxRequest();
146-
request.setServiceClass(this.serviceClass.getName());
147-
request.setMethod(method.getName());
148-
request.setParams(params);
149-
150-
if (null!=filters){
151-
for (Filterfilter : filters){
152-
if (!filter.filter(request)){
153-
returnnull;
154-
}
155-
}
156-
}
157-
158-
RpcfxResponseresponse = post(request, url);
159-
160-
// 加filter地方之三
161-
// Student.setTeacher("cuijing");
162-
163-
// 这里判断response.status,处理异常
164-
// 考虑封装一个全局的RpcfxException
165-
166-
returnJSON.parse(response.getResult().toString());
167-
}
168-
169-
OkHttpClientclient = newOkHttpClient();
170-
171-
privateRpcfxResponsepost(RpcfxRequestreq, Stringurl) throwsIOException{
172-
StringreqJson = JSON.toJSONString(req);
173-
// System.out.println("req json: "+reqJson);
174-
175-
// 1.可以复用client
176-
// 2.尝试使用httpclient或者netty client
177-
178-
finalRequestrequest = newRequest.Builder()
179-
.url(url)
180-
.post(RequestBody.create(JSONTYPE, reqJson))
181-
.build();
182-
StringrespJson = client.newCall(request).execute().body().string();
183-
// System.out.println("resp json: "+respJson);
184-
returnJSON.parseObject(respJson, RpcfxResponse.class);
185-
}
186-
}
187106
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
packageio.kimmking.rpcfx.client;
2+
3+
importcom.alibaba.fastjson.JSON;
4+
importio.kimmking.rpcfx.api.*;
5+
importokhttp3.MediaType;
6+
importokhttp3.OkHttpClient;
7+
importokhttp3.Request;
8+
importokhttp3.RequestBody;
9+
10+
importjava.io.IOException;
11+
importjava.lang.reflect.InvocationHandler;
12+
importjava.lang.reflect.Method;
13+
importjava.util.List;
14+
15+
publicclassRpcfxInvocationHandlerimplementsInvocationHandler{
16+
17+
publicstaticfinalMediaTypeJSONTYPE = MediaType.get("application/json; charset=utf-8");
18+
19+
privatefinalClass<?> serviceClass;
20+
privatefinalList<String> invokers;
21+
privatefinalRouterrouter;
22+
privatefinalLoadBalancerloadBalance;
23+
privatefinalFilter[] filters;
24+
25+
public <T> RpcfxInvocationHandler(Class<T> serviceClass, List<String> invokers, Routerrouter, LoadBalancerloadBalance, Filter... filters){
26+
this.serviceClass = serviceClass;
27+
this.invokers = invokers;
28+
this.router = router;
29+
this.loadBalance = loadBalance;
30+
this.filters = filters;
31+
}
32+
33+
// 可以尝试,自己去写对象序列化,二进制还是文本的,,,rpcfx是xml自定义序列化、反序列化,json: code.google.com/p/rpcfx
34+
// int byte char float double long bool
35+
// [], data class
36+
37+
@Override
38+
publicObjectinvoke(Objectproxy, Methodmethod, Object[] params) throwsThrowable{
39+
40+
List<String> urls = router.route(invokers);
41+
// System.out.println("router.route => ");
42+
// urls.forEach(System.out::println);
43+
Stringurl = loadBalance.select(urls); // router, loadbalance
44+
// System.out.println("loadBalance.select => ");
45+
// System.out.println("final => " + url);
46+
47+
if (url == null){
48+
thrownewRuntimeException("No available providers from registry center.");
49+
}
50+
51+
// 加filter地方之二
52+
// mock == true, new Student("hubao");
53+
54+
RpcfxRequestrequest = newRpcfxRequest();
55+
request.setServiceClass(this.serviceClass.getName());
56+
request.setMethod(method.getName());
57+
request.setParams(params);
58+
59+
if (null!=filters){
60+
for (Filterfilter : filters){
61+
if (!filter.filter(request)){
62+
returnnull;
63+
}
64+
}
65+
}
66+
67+
RpcfxResponseresponse = post(request, url);
68+
69+
// 加filter地方之三
70+
// Student.setTeacher("cuijing");
71+
72+
// 这里判断response.status,处理异常
73+
// 考虑封装一个全局的RpcfxException
74+
75+
returnJSON.parse(response.getResult().toString());
76+
}
77+
78+
OkHttpClientclient = newOkHttpClient();
79+
80+
privateRpcfxResponsepost(RpcfxRequestreq, Stringurl) throwsIOException{
81+
StringreqJson = JSON.toJSONString(req);
82+
// System.out.println("req json: "+reqJson);
83+
84+
// 1.可以复用client
85+
// 2.尝试使用httpclient或者netty client
86+
87+
finalRequestrequest = newRequest.Builder()
88+
.url(url)
89+
.post(RequestBody.create(JSONTYPE, reqJson))
90+
.build();
91+
StringrespJson = client.newCall(request).execute().body().string();
92+
// System.out.println("resp json: "+respJson);
93+
returnJSON.parseObject(respJson, RpcfxResponse.class);
94+
}
95+
}

0 commit comments

Comments
(0)