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, Method> clazzMethodMap; public static synchronized WFCMessageParseTable getInstance() { if (instance == null) { instance = new WFCMessageParseTable(); } return instance; } private WFCMessageParseTable() { clazzMethodMap = new HashMap, Method>(); } public Method getMethod(Class 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 clazz) { try { Method method = clazz.getMethod("parseFrom", byte[].class); return method; } catch (Exception e) { } return null; } }