Alachisoft.NCache.Common.RPCFramework.RPCMethodCache Maven / Gradle / Ivy
package Alachisoft.NCache.Common.RPCFramework;
public class RPCMethodCache {
private IRPCTargetObject _targetObject;
private java.util.Map _cache = new java.util.HashMap();
public RPCMethodCache(IRPCTargetObject targetObject) {
_targetObject = targetObject;
PopulateCache();
}
private static String GetCacheKey(String methodName, int overload) {
return methodName + "$" + overload;
}
private void PopulateCache() {
if (_targetObject != null) {
ITargetMethod[] methods = _targetObject.GetAllMethods();
for (int i = 0; i < methods.length; i++) {
ITargetMethod method = methods[i];
String key = GetCacheKey(method.GetMethodName(), method.GetOverlaod());
if (!_cache.containsKey(key)) {
_cache.put(key, method);
} else {
throw new RuntimeException("Duplicate method exists in the target object. (Method :" + method.GetMethodName() + " , overlaod :" + method.GetOverlaod() + ")");
}
}
}
}
public final ITargetMethod GetTargetMethod(String methodName, int overload) {
String key = GetCacheKey(methodName, overload);
if (_cache.containsKey(key)) {
return _cache.get(key);
} else {
return null;
}
}
public final IRPCTargetObject GetTargetObject() {
return _targetObject;
}
}