getAttachments();
44 |
45 | /**
46 | * set framework param
47 | *
48 | * @return
49 | */
50 | void setAttachment(String name, String value);
51 |
52 | /**
53 | * request id
54 | *
55 | * @return
56 | */
57 | long getRequestId();
58 |
59 | /**
60 | * retries
61 | *
62 | * @return
63 | */
64 | int getRetries();
65 |
66 | /**
67 | * set retries
68 | */
69 | void setRetries(int retries);
70 |
71 | /**
72 | * set the serialization number.
73 | * same to the protocol version, this value only used in server end for compatible.
74 | *
75 | * @param number
76 | */
77 | void setSerializationNumber(int number);
78 |
79 | int getSerializationNumber();
80 | }
81 |
--------------------------------------------------------------------------------
/jaws-core/src/main/java/org/hongxi/jaws/rpc/Response.java:
--------------------------------------------------------------------------------
1 | package org.hongxi.jaws.rpc;
2 |
3 | import java.util.Map;
4 |
5 | /**
6 | * Created by shenhongxi on 2020/6/14.
7 | */
8 | public interface Response {
9 |
10 | /**
11 | *
12 | * 如果 request 正常处理,那么会返回 Object value,而如果 request 处理有异常,那么 getValue 会抛出异常
13 | *
14 | *
15 | * @return
16 | * @throws RuntimeException
17 | */
18 | Object getValue();
19 |
20 | /**
21 | * 如果request处理有异常,那么调用该方法return exception 如果request还没处理完或者request处理正常,那么return null
22 | *
23 | *
24 | * 该方法不会阻塞,无论该request是处理中还是处理完成
25 | *
26 | *
27 | * @return
28 | */
29 | Exception getException();
30 |
31 | /**
32 | * 与 Request 的 requestId 相对应
33 | *
34 | * @return
35 | */
36 | long getRequestId();
37 |
38 | /**
39 | * 业务处理时间
40 | *
41 | * @return
42 | */
43 | long getProcessTime();
44 |
45 | /**
46 | * 业务处理时间
47 | *
48 | * @param time
49 | */
50 | void setProcessTime(long time);
51 |
52 | int getTimeout();
53 |
54 | Map getAttachments();
55 |
56 | void setAttachment(String key, String value);
57 |
58 | /**
59 | * set the serialization number.
60 | * same to the protocol version, this value only used in server end for compatible.
61 | *
62 | * @param number
63 | */
64 | void setSerializationNumber(int number);
65 |
66 | int getSerializationNumber();
67 | }
68 |
--------------------------------------------------------------------------------
/jaws-core/src/main/java/org/hongxi/jaws/rpc/ResponseFuture.java:
--------------------------------------------------------------------------------
1 | package org.hongxi.jaws.rpc;
2 |
3 | /**
4 | * Created by shenhongxi on 2020/7/30.
5 | */
6 | public interface ResponseFuture extends Future, Response {
7 |
8 | void onSuccess(Response response);
9 |
10 | void onFailure(Response response);
11 |
12 | long getCreateTime();
13 |
14 | void setReturnType(Class> clazz);
15 | }
16 |
--------------------------------------------------------------------------------
/jaws-core/src/main/java/org/hongxi/jaws/rpc/RpcContext.java:
--------------------------------------------------------------------------------
1 | package org.hongxi.jaws.rpc;
2 |
3 | import org.hongxi.jaws.common.URLParamType;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | /**
9 | * Created by shenhongxi on 2020/6/26.
10 | */
11 | public class RpcContext {
12 | private static final ThreadLocal LOCAL_CONTEXT = ThreadLocal.withInitial(() -> new RpcContext());
13 | private Map