Exemple #1
0
 public static object Invoke11(ProcessId pid, string method, Type rettyp, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, object arg11)
 {
     return(ActorContext.Ask(pid, new ProxyMsg
     {
         Method = method,
         Args = new string[] {
             JsonConvert.SerializeObject(arg1),
             JsonConvert.SerializeObject(arg2),
             JsonConvert.SerializeObject(arg3),
             JsonConvert.SerializeObject(arg4),
             JsonConvert.SerializeObject(arg5),
             JsonConvert.SerializeObject(arg6),
             JsonConvert.SerializeObject(arg7),
             JsonConvert.SerializeObject(arg8),
             JsonConvert.SerializeObject(arg9),
             JsonConvert.SerializeObject(arg10),
             JsonConvert.SerializeObject(arg11)
         },
         ArgTypes = new string[] {
             arg1.GetType().GetTypeInfo().FullName,
             arg2.GetType().GetTypeInfo().FullName,
             arg3.GetType().GetTypeInfo().FullName,
             arg4.GetType().GetTypeInfo().FullName,
             arg5.GetType().GetTypeInfo().FullName,
             arg6.GetType().GetTypeInfo().FullName,
             arg7.GetType().GetTypeInfo().FullName,
             arg8.GetType().GetTypeInfo().FullName,
             arg9.GetType().GetTypeInfo().FullName,
             arg10.GetType().GetTypeInfo().FullName,
             arg11.GetType().GetTypeInfo().FullName
         },
         ReturnType = rettyp.GetTypeInfo().FullName
     }));
 }
Exemple #2
0
 public static object Invoke0(ProcessId pid, string method, Type rettyp)
 {
     return(ActorContext.Ask(pid, new ProxyMsg
     {
         Method = method,
         Args = new string[0],
         ArgTypes = new string[0],
         ReturnType = rettyp.GetTypeInfo().FullName
     }));
 }
Exemple #3
0
 public static object Invoke1(ProcessId pid, string method, Type rettyp, object arg1)
 {
     return(ActorContext.Ask(pid, new ProxyMsg
     {
         Method = method,
         Args = new string[] {
             JsonConvert.SerializeObject(arg1)
         },
         ArgTypes = new string[] {
             arg1.GetType().GetTypeInfo().FullName
         },
         ReturnType = rettyp.GetTypeInfo().FullName
     }));
 }
Exemple #4
0
        public static object Invoke(ProcessId pid, string method, Type rettyp, params object[] args)
        {
            if (args.Filter(a => a == null).Any())
            {
                throw new ArgumentNullException();
            }

            return(ActorContext.Ask(pid, new ProxyMsg
            {
                Method = method,
                Args = args.Map(JsonConvert.SerializeObject).ToArray(),
                ArgTypes = args.Map(a => a.GetType().GetTypeInfo().AssemblyQualifiedName).ToArray(),
                ReturnType = rettyp.GetTypeInfo().AssemblyQualifiedName
            }));
        }
Exemple #5
0
        public R ProcessRequest <R>(ProcessId pid, object message)
        {
            try
            {
                if (request != null)
                {
                    throw new Exception("async ask not allowed");
                }

                response = null;
                request  = new AutoResetEvent(false);
                ActorContext.Ask(pid, new ActorRequest(message, pid, Self, 0), Self);
                request.WaitOne(ActorConfig.Default.Timeout);

                if (response == null)
                {
                    throw new TimeoutException("Request timed out");
                }
                else
                {
                    if (response.IsFaulted)
                    {
                        var ex = (Exception)response.Message;
                        throw new ProcessException("Process issue: " + ex.Message, pid.Path, Self.Path, ex);
                    }
                    else
                    {
                        return((R)response.Message);
                    }
                }
            }
            finally
            {
                if (request != null)
                {
                    request.Dispose();
                    request = null;
                }
            }
        }
Exemple #6
0
        public static Tuple <long, Dictionary <long, AskActorReq> > Inbox(Tuple <long, Dictionary <long, AskActorReq> > state, object msg)
        {
            logInfo("AskActor.Inbox start");

            var reqId = state.Item1;
            var dict  = state.Item2;

            if (msg is AskActorReq)
            {
                reqId++;

                var req = (AskActorReq)msg;

                logInfo($"About to send ask request - reqId: {reqId}");
                ActorContext.Ask(req.To, new ActorRequest(req.Message, req.To, Self, reqId), Self);

                logInfo($"Sent ask request - reqId: {reqId}");
                dict.Add(reqId, req);
            }
            else
            {
                var res = (ActorResponse)msg;
                if (dict.ContainsKey(res.RequestId))
                {
                    logInfo($"Ask response has returned - reqId: {reqId}");
                    var req = dict[res.RequestId];
                    try
                    {
                        if (res.IsFaulted)
                        {
                            Exception ex = null;

                            // Let's be reeeally safe here and do everything we can to get some valid information out of
                            // the response to report to the process doing the 'ask'.
                            try
                            {
                                var msgtype = Type.GetType(res.ResponseMessageType);
                                if (msgtype == res.Message.GetType() && typeof(Exception).GetTypeInfo().IsAssignableFrom(msgtype.GetTypeInfo()))
                                {
                                    // Type is fine, just return it as an error
                                    ex = (Exception)res.Message;
                                }
                                else
                                {
                                    if (res.Message is string)
                                    {
                                        ex = (Exception)JsonConvert.DeserializeObject(res.Message.ToString(), msgtype);
                                    }
                                    else
                                    {
                                        ex = (Exception)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(res.Message), msgtype);
                                    }
                                }
                            }
                            catch
                            {
                                ex = new Exception(res.Message == null ? $"An unknown error was thrown by {req.To}" : res.Message.ToString());
                            }

                            req.Complete(new AskActorRes(new ProcessException($"Process issue: {ex.Message}", req.To.Path, req.ReplyTo.Path, ex)));
                        }
                        else
                        {
                            req.Complete(new AskActorRes(res.Message));
                        }
                    }
                    catch (Exception e)
                    {
                        req.Complete(new AskActorRes(new ProcessException($"Process issue: {e.Message}", req.To.Path, req.ReplyTo.Path, e)));
                        logSysErr(e);
                    }
                    finally
                    {
                        dict.Remove(res.RequestId);
                    }
                }
                else
                {
                    logWarn($"Request ID doesn't exist: {res.RequestId}");
                }
            }

            logInfo("AskActor.Inbox done");

            return(new Tuple <long, Dictionary <long, AskActorReq> >(reqId, dict));
        }
Exemple #7
0
 /// <summary>
 /// Ask a process for a reply
 /// </summary>
 /// <param name="pid">Process to ask</param>
 /// <param name="message">Message to send</param>
 /// <returns>The response to the request</returns>
 public static T ask <T>(ProcessId pid, object message) =>
 ActorContext.Ask <T>(pid, message);