public void HandleRpc(ISender caller, string methname, IList arguments, object request_state)
{
MethodInfo mi = null;
/*
* Lookup this method name in our table.
* This uses a cache, so it should be fast
* after the first time
*/
lock ( _sync ) {
mi = (MethodInfo)_method_cache[methname];
if (mi == null)
{
mi = _type.GetMethod(methname);
_method_cache[methname] = mi;
}
}
if (_use_sender)
{
arguments = new ArrayList(arguments);
arguments.Add(caller);
}
object[] arg_array = new object[arguments.Count];
arguments.CopyTo(arg_array, 0);
//Console.Error.WriteLine("About to call: {0}.{1} with args",handler, mname);
//foreach(object arg in pa) { Console.Error.WriteLine("arg: {0}",arg); }
//make the following happen asynchronously in a separate thread
//build an invocation record for the call
Object result = null;
try {
#if RPC_DEBUG
Console.Error.WriteLine("[RpcServer: {0}] Invoking method: {1}", _rrman.Info, mi);
#endif
result = mi.Invoke(_handler, arg_array);
} catch (ArgumentException argx) {
#if RPC_DEBUG
Console.Error.WriteLine("[RpcServer: {0}] Argument exception. {1}", _rrman.Info, mi);
#endif
result = new AdrException(-32602, argx);
}
catch (TargetParameterCountException argx) {
#if RPC_DEBUG
Console.Error.WriteLine("[RpcServer: {0}] Parameter count exception. {1}", _rrman.Info, mi);
#endif
result = new AdrException(-32602, argx);
}
catch (TargetInvocationException x) {
#if RPC_DEBUG
Console.Error.WriteLine("[RpcServer: {0}] Exception thrown by method: {1}, {2}", _rrman.Info, mi, x.InnerException.Message);
#endif
if (x.InnerException is AdrException)
{
result = x.InnerException;
}
else
{
result = new AdrException(-32608, x.InnerException);
}
}
catch (Exception x) {
#if RPC_DEBUG
Console.Error.WriteLine("[RpcServer: {0}] General exception. {1}", _rrman.Info, mi);
#endif
result = x;
}
finally {
_rpc.SendResult(request_state, result);
}
}