예제 #1
0
        public R WithContext <R>(ActorItem self, ActorItem parent, ProcessId sender, ActorRequest request, object msg, Option <SessionId> sessionId, Func <R> f)
        {
            var savedContext = ActorContext.Request;
            var savedSession = ActorContext.SessionId;

            try
            {
                ActorContext.SessionId = sessionId;

                ActorContext.SetContext(new ActorRequestContext(
                                            this,
                                            self,
                                            sender,
                                            parent,
                                            msg,
                                            request,
                                            ProcessFlags.Default,
                                            ProcessOpTransaction.Start(self.Actor.Id),
                                            (from sid in sessionId
                                             from ses in ActorContext.System(self.Actor.Id).Sessions.GetSession(sid)
                                             select ses)
                                            .IfNoneUnsafe((SessionVector)null)
                                            ));
                return(f());
            }
            finally
            {
                ActorContext.SessionId = savedSession;
                ActorContext.SetContext(savedContext);
            }
        }
 public ActorRequestContext SetCurrentRequest(ActorRequest currentRequest) =>
     new ActorRequestContext(
         Self,
         Sender,
         Parent,
         CurrentMsg,
         currentRequest,
         ProcessFlags
     );
예제 #3
0
 public ActorRequestContext SetCurrentRequest(ActorRequest currentRequest) =>
 new ActorRequestContext(
     Self,
     Sender,
     Parent,
     CurrentMsg,
     currentRequest,
     ProcessFlags
     );
 public ActorRequestContext SetCurrentRequest(ActorRequest currentRequest) =>
     new ActorRequestContext(
         System,
         Self,
         Sender,
         Parent,
         CurrentMsg,
         currentRequest,
         ProcessFlags,
         Ops,
         Session
     );
예제 #5
0
 public ActorRequestContext SetCurrentRequest(ActorRequest currentRequest) =>
 new ActorRequestContext(
     System,
     Self,
     Sender,
     Parent,
     CurrentMsg,
     currentRequest,
     ProcessFlags,
     Ops,
     Session
     );
예제 #6
0
 internal static RemoteMessageDTO CreateRequest(ActorRequest req, ProcessId to, ProcessId sender) =>
 new RemoteMessageDTO
 {
     Type        = (int)Message.Type.User,
     Tag         = (int)Message.TagSpec.UserAsk,
     Child       = null,
     Exception   = null,
     To          = to.Path,
     RequestId   = req.RequestId,
     MessageId   = Guid.NewGuid(),
     Sender      = sender.ToString(),
     ReplyTo     = req.ReplyTo.ToString(),
     ContentType = req.Message.GetType().AssemblyQualifiedName,
     Content     = JsonConvert.SerializeObject(req.Message, ActorSystemConfig.Default.JsonSerializerSettings)
 };
 internal static RemoteMessageDTO CreateRequest(ActorRequest req, ProcessId to, ProcessId sender) =>
     new RemoteMessageDTO()
     {
         Type        = (int)Message.Type.User,
         Tag         = (int)Message.TagSpec.UserAsk,
         Child       = null,
         Exception   = null,
         To          = to.Path,
         RequestId   = req.RequestId,
         MessageId   = Guid.NewGuid(),
         Sender      = sender.ToString(),
         ReplyTo     = req.ReplyTo.ToString(),
         ContentType = req.Message.GetType().AssemblyQualifiedName,
         Content     = JsonConvert.SerializeObject(req.Message, ActorConfig.Default.JsonSerializerSettings)
     };
 public ActorRequestContext(
     ActorItem self,
     ProcessId sender,
     ActorItem parent,
     object currentMsg,
     ActorRequest currentRequest,
     ProcessFlags processFlags
     )
 {
     Self = self;
     Sender = sender;
     Parent = parent;
     CurrentMsg = currentMsg;
     CurrentRequest = currentRequest;
     ProcessFlags = processFlags;
 }
예제 #9
0
 public ActorRequestContext(
     ActorItem self,
     ProcessId sender,
     ActorItem parent,
     object currentMsg,
     ActorRequest currentRequest,
     ProcessFlags processFlags
     )
 {
     Self           = self;
     Sender         = sender;
     Parent         = parent;
     CurrentMsg     = currentMsg;
     CurrentRequest = currentRequest;
     ProcessFlags   = processFlags;
 }
 public ActorRequestContext(
     ActorSystem system,
     ActorItem self,
     ProcessId sender,
     ActorItem parent,
     object currentMsg,
     ActorRequest currentRequest,
     ProcessFlags processFlags,
     ProcessOpTransaction ops,
     SessionVector session
     )
 {
     Self = self;
     Sender = sender;
     Parent = parent;
     CurrentMsg = currentMsg;
     CurrentRequest = currentRequest;
     ProcessFlags = processFlags;
     Ops = ops;
     System = system;
     Session = session;
 }
예제 #11
0
 public ActorRequestContext(
     ActorSystem system,
     ActorItem self,
     ProcessId sender,
     ActorItem parent,
     object currentMsg,
     ActorRequest currentRequest,
     ProcessFlags processFlags,
     ProcessOpTransaction ops,
     SessionVector session
     )
 {
     Self           = self;
     Sender         = sender;
     Parent         = parent;
     CurrentMsg     = currentMsg;
     CurrentRequest = currentRequest;
     ProcessFlags   = processFlags;
     Ops            = ops;
     System         = system;
     Session        = session;
 }
예제 #12
0
 public Unit ProcessAsk(ActorRequest request) => Unit.Default;
 internal static RemoteMessageDTO CreateRequest(ActorRequest req, ProcessId to, ProcessId sender, Option<SessionId> sessionId) =>
     new RemoteMessageDTO
     {
         Type        = (int)Message.Type.User,
         Tag         = (int)Message.TagSpec.UserAsk,
         Child       = null,
         Exception   = null,
         To          = to.ToString(),
         RequestId   = req.RequestId,
         MessageId   = Guid.NewGuid(),
         Sender      = sender.ToString(),
         ReplyTo     = req.ReplyTo.ToString(),
         ContentType = req.Message.GetType().AssemblyQualifiedName,
         Content     = JsonConvert.SerializeObject(req.Message, ActorSystemConfig.Default.JsonSerializerSettings),
         SessionId  = sessionId.Map(s => s.Value).IfNoneUnsafe(() => null)
     };
예제 #14
0
        public Unit ProcessAsk(ActorRequest request)
        {
            var savedMsg   = ActorContext.CurrentMsg;
            var savedFlags = ActorContext.ProcessFlags;
            var savedReq   = ActorContext.CurrentRequest;

            try
            {
                ActorContext.CurrentRequest = request;
                ActorContext.ProcessFlags   = flags;
                ActorContext.CurrentMsg     = request.Message;

                if (typeof(T) != typeof(string) && request.Message is string)
                {
                    state = PreProcessMessageContent(request.Message).Match(
                        Some: tmsg =>
                    {
                        var stateIn  = GetState();
                        var stateOut = actorFn(stateIn, tmsg);
                        try
                        {
                            if (stateOut != null && !stateOut.Equals(stateIn))
                            {
                                stateSubject.OnNext(stateOut);
                            }
                        }
                        catch (Exception ue)
                        {
                            logErr(ue);
                        }
                        return(stateOut);
                    },
                        None: () => state
                        );
                }
                else if (request.Message is T)
                {
                    T   msg      = (T)request.Message;
                    var stateIn  = GetState();
                    var stateOut = actorFn(stateIn, msg);
                    try
                    {
                        if (stateOut != null && !stateOut.Equals(stateIn))
                        {
                            stateSubject.OnNext(stateOut);
                        }
                    }
                    catch (Exception ue)
                    {
                        logErr(ue);
                    }
                    state = stateOut;
                }
                else if (request.Message is Message)
                {
                    ProcessSystemMessage((Message)request.Message);
                }
                else
                {
                    logErr("ProcessAsk request.Message is not T " + request.Message);
                }
            }
            catch (SystemKillActorException)
            {
                kill(Id);
            }
            catch (Exception e)
            {
                // TODO: Add extra strategy behaviours here
                Restart();
                replyError(e);
                tell(ActorContext.Errors, e);
                tell(ActorContext.DeadLetters, DeadLetter.create(request.ReplyTo, request.To, e, "Process error (ask): ", request.Message));
            }
            finally
            {
                ActorContext.CurrentMsg     = savedMsg;
                ActorContext.ProcessFlags   = savedFlags;
                ActorContext.CurrentRequest = savedReq;
            }
            return(unit);
        }
예제 #15
0
        public InboxDirective ProcessAsk(ActorRequest request)
        {
            lock (sync)
            {
                var savedMsg   = ActorContext.CurrentMsg;
                var savedFlags = ActorContext.ProcessFlags;
                var savedReq   = ActorContext.CurrentRequest;

                try
                {
                    ActorContext.CurrentRequest = request;
                    ActorContext.ProcessFlags   = flags;
                    ActorContext.CurrentMsg     = request.Message;

                    //ActorContext.AssertSession();

                    if (typeof(T) != typeof(string) && request.Message is string)
                    {
                        state = PreProcessMessageContent(request.Message).Match(
                            Some: tmsg =>
                        {
                            var stateIn  = GetState();
                            var stateOut = actorFn(stateIn, tmsg);
                            try
                            {
                                if (notnull(stateOut) && !stateOut.Equals(stateIn))
                                {
                                    stateSubject.OnNext(stateOut);
                                }
                            }
                            catch (Exception ue)
                            {
                                // Not our errors, so just log and move on
                                logErr(ue);
                            }
                            return(stateOut);
                        },
                            None: () =>
                        {
                            replyError(new AskException($"Can't ask {Id.Path}, message is not {typeof(T).GetTypeInfo().Name} : {request.Message}"));
                            return(state);
                        }
                            );
                    }
                    else if (request.Message is T)
                    {
                        var msg      = (T)request.Message;
                        var stateIn  = GetState();
                        var stateOut = actorFn(stateIn, msg);
                        try
                        {
                            if (notnull(stateOut) && !stateOut.Equals(stateIn))
                            {
                                stateSubject.OnNext(stateOut);
                            }
                        }
                        catch (Exception ue)
                        {
                            // Not our errors, so just log and move on
                            logErr(ue);
                        }
                        state = stateOut;
                    }
                    else if (request.Message is Message)
                    {
                        ProcessSystemMessage((Message)request.Message);
                    }
                    else
                    {
                        // Failure to deserialise is not our problem, its the sender's
                        // so we don't throw here.
                        replyError(new AskException($"Can't ask {Id.Path}, message is not {typeof(T).GetTypeInfo().Name} : {request.Message}"));
                        return(InboxDirective.Default);
                    }

                    strategyState = strategyState.With(
                        Failures: 0,
                        LastFailure: DateTime.MaxValue,
                        BackoffAmount: 0 * seconds
                        );
                }
                catch (Exception e)
                {
                    replyError(e);
                    return(DefaultErrorHandler(request, e));
                }
                finally
                {
                    ActorContext.CurrentMsg     = savedMsg;
                    ActorContext.ProcessFlags   = savedFlags;
                    ActorContext.CurrentRequest = savedReq;
                }
                return(InboxDirective.Default);
            }
        }
예제 #16
0
 public InboxDirective ProcessAsk(ActorRequest request) => InboxDirective.Default;
예제 #17
0
 public static Unit WithContext(ActorItem self, ActorItem parent, ProcessId sender, ActorRequest request, object msg, Option <string> sessionId, Action f) =>
 WithContext(self, parent, sender, request, msg, sessionId, fun(f));
예제 #18
0
        public static R WithContext <R>(ActorItem self, ActorItem parent, ProcessId sender, ActorRequest request, object msg, Option <string> sessionId, Func <R> f)
        {
            var savedContext = context;
            var savedSession = SessionManager.SessionId;

            try
            {
                SessionManager.SessionId = sessionId;
                context = new ActorRequestContext(
                    self,
                    sender,
                    parent,
                    msg,
                    request,
                    ProcessFlags.Default,
                    ProcessOpTransaction.Start(self.Actor.Id)
                    );
                return(f());
            }
            finally
            {
                SessionManager.SessionId = savedSession;
                context = savedContext;
            }
        }
예제 #19
0
        public static R WithContext <R>(ActorItem self, ActorItem parent, ProcessId sender, ActorRequest request, object msg, Func <R> f)
        {
            var savedContext = context;

            try
            {
                context = new ActorRequestContext(
                    self,
                    sender,
                    parent,
                    msg,
                    request,
                    ProcessFlags.Default
                    );

                return(f());
            }
            finally
            {
                context = savedContext;
            }
        }