package chat.server.im;
|
|
import java.lang.reflect.Method;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import com.google.protobuf.GeneratedMessage;
|
|
public class WFCMessageParseTable {
|
|
private static WFCMessageParseTable instance;
|
private Map<Class<? extends GeneratedMessage>, Method> clazzMethodMap;
|
|
public static synchronized WFCMessageParseTable getInstance() {
|
if (instance == null) {
|
instance = new WFCMessageParseTable();
|
}
|
|
return instance;
|
}
|
|
private WFCMessageParseTable() {
|
clazzMethodMap = new HashMap<Class<? extends GeneratedMessage>, Method>();
|
}
|
|
public Method getMethod(Class<? extends GeneratedMessage> clazz) {
|
if (clazz == null) {
|
return null;
|
}
|
|
Method result = clazzMethodMap.get(clazz);
|
|
if (result == null) {
|
synchronized (this) {
|
result = clazzMethodMap.get(clazz);
|
|
if (result == null) {
|
result = doGetMethod(clazz);
|
clazzMethodMap.put(clazz, result);
|
}
|
}
|
}
|
|
return result;
|
}
|
|
private Method doGetMethod(Class<? extends GeneratedMessage> clazz) {
|
try {
|
Method method = clazz.getMethod("parseFrom", byte[].class);
|
return method;
|
}
|
catch (Exception e) {
|
}
|
|
return null;
|
}
|
|
}
|