AbstractCacheRequestResponse.java
1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.yoho.search.cache.model;
import com.alibaba.fastjson.JSON;
import com.yoho.search.base.utils.Transfer;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
public abstract class AbstractCacheRequestResponse<Request extends ICacheRequest,Response> extends AbstractCacheResponse<Response> {
private Request request;
private Response response;
private boolean needRecache = false;
public AbstractCacheRequestResponse(Request request){
this.request = request;
}
public Request getRequest() {
return request;
}
public Response getResponse() {
return response;
}
public void setResponse(Response response,boolean needRecache) {
this.response = response;
this.needRecache = needRecache;
}
public boolean isNeedRecache() {
return needRecache;
}
public Transfer<String, Response> getToResponseTransfer(){
return v->{
Type superClass = getClass().getGenericSuperclass();
Type type = ((ParameterizedType) superClass).getActualTypeArguments()[1];
return JSON.parseObject(v,type);
};
}
public Transfer<Response, String> getFromResponseTransfer(){
return (v)-> JSON.toJSONString(v);
}
}