AbstractCacheRequestResponse.java
1.29 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.ISearchTransfer;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
public abstract class AbstractCacheRequestResponse<Request extends ICacheRequest,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 ISearchTransfer<String, Response> getToResponseTransfer(){
return v->{
Type superClass = getClass().getGenericSuperclass();
Type type = ((ParameterizedType) superClass).getActualTypeArguments()[1];
return JSON.parseObject(v,type);
};
}
public ISearchTransfer<Response, String> getFromResponseTransfer(){
return (v)-> JSON.toJSONString(v);
}
}