Beispiel #1
0
 /// <summary>
 /// Tells the backing Actor(s) the message.
 /// </summary>
 /// <param name="message">the object message</param>
 /// <param name="sender">the ActorRef sender</param>
 public void Tell(object message, ActorRef sender)
 {
     foreach (ActorRef actor in Selections)
     {
         actor.Tell(message, ActorRef.NoSender);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Constructs a new ActorContext.
        /// </summary>
        /// <param name="system">the ActorSystem within which the actor is created</param>
        /// <param name="actorType">the Type of the actor</param>
        /// <param name="actor">the Actor to create</param>
        /// <param name="name">the string name to give the Actor</param>
        /// <param name="props">the Props to pass individually as class arguments</param>
        /// <param name="parent">the ActorRef of the parent of the Actor being created</param>
        /// <param name="parentPath">the ActorPath of the Actor being created</param>
        /// <param name="suspended">the bool indicating whether the actor is being created as suspended</param>
        /// <param name="channel">the IChannel the actor will use</param>
        /// <param name="fiber">the IFiber the actor will use</param>
        internal ActorContext(
            ActorSystem system,
            Type actorType,
            Actor actor,
            string name,
            Props props,
            ActorRef parent,
            ActorPath parentPath,
            bool suspended,
            IChannel<Delivery> channel,
            IFiber fiber)
        {
            Actor = actor;
            Actor.InternalContext = this;
            Channel = channel;
            Fiber = fiber;
            Children = new List<ActorRef>(0);
            Parent = parent;
            Path = parentPath.WithName(name);
            Props = props;
            Receivers = new Stack<Receive>(1);
            Self = new ActorRef(this);
            Sender = ActorRef.NoSender;
            _Suspended = suspended;
            System = system;
            _Terminated = false;
            Type = actorType;

            Start();
        }
        public override void PreStart()
        {
            base.PreStart();

            level2 = Context.ActorOf(
                typeof(EscalateLevel2),
                Props.With((object)levelEvents),
                "escalateLevel2");
        }
 public Manager(
     ActorRef worker,
     EventWaitHandle helloBackEvent,
     EventWaitHandle specificDone)
     : base()
 {
     this.worker = worker;
     this.helloBackEvent = helloBackEvent;
     this.specificDone = specificDone;
 }
        public override void PreStart()
        {
            base.PreStart();

            if (restarted)
            {
                levelEvents[2].Set();
            }

            level3 = Context.ActorOf(
                typeof(EscalateLevel3),
                Props.With((object)levelEvents),
                "escalateLevel3");
        }
 public LoanRateQuote(
     string loanRateQuoteId,
     string taxId,
     int amount,
     int termInMonths,
     ActorRef loanBroker)
 {
     this.loanRateQuoteId = loanRateQuoteId;
     this.taxId = taxId;
     this.amount = amount;
     this.termInMonths = termInMonths;
     this.loanBroker = loanBroker;
 }
 public LoanBroker(
     ActorRef creditBureau,
     ActorRef[] banks,
     AutoResetEvent termination)
 {
     this.creditBureau = creditBureau;
     this.banks = banks;
     this.termination = termination;
 }
Beispiel #8
0
        public ScheduledTimerEvent(
            long delay,
            long frequency,
            ActorRef receiver,
            object message)
        {
            this.frequency = frequency;
            this.receiver = receiver;
            this.message = message;

            timer = new Timer(
                (TimerCallback)this.OnTimedEvent,
                null,
                delay,
                frequency == 0 ? -1 : frequency);
        }
Beispiel #9
0
 /// <summary>
 /// Stops the Actor referenced by actor.
 /// </summary>
 /// <param name="actor">the ActorRef of the Actor to stop</param>
 public void Stop(ActorRef actor)
 {
     if (actor == Self)
     {
         Parent.Context.Stop(actor);
     }
     else
     {
         if (Children.Remove(actor))
         {
             actor.Context.Stop();
         }
         else
         {
             Sweep(actor, new List<ActorRef>(Children));
         }
     }
 }
Beispiel #10
0
 /// <summary>
 /// Stop my child that failed. Note that the context
 /// of this method is the supervisor parent.
 /// </summary>
 /// <param name="e">the Exception that occurred in my child</param>
 private void RecoverByStopping(Exception reason, ActorRef child)
 {
     Stop(child);
 }
        public override void PreStart()
        {
            base.PreStart();

            level3 = Context.ActorOf(
                typeof(ResumeLevel3),
                Props.With((object)levelEvents),
                "resumeLevel3");
        }
Beispiel #12
0
 public TestForwardOriginalActor(ActorRef to)
 {
     this.to = to;
 }
Beispiel #13
0
        internal ActorSelection(ActorRef actor)
        {
            Selections = new List<ActorRef>();

            Selections.Add(actor);
        }
        protected void StartProcess(string processId, ActorRef process)
        {
            if (!processes.ContainsKey(processId))
            {
                processes.Add(processId, process);

                Self.Tell(new ProcessStarted(processId, process), Self);
            }
        }
Beispiel #15
0
        public Counting(ActorRef end)
            : base()
        {
            this.end = end;

            AdditionBehavior = new Addition(this);

            MultiplicationBehavior = new Multiplication(this);
        }
Beispiel #16
0
 /// <summary>
 /// Tells the backing Actor the message that is being
 /// sent by sender.
 /// </summary>
 /// <param name="message">the object message</param>
 /// <param name="sender">the ActorRef of the sender, which may be ActorRef.NoSender</param>
 public void Tell(object message, ActorRef sender)
 {
     if (!Context.Terminated)
     {
         Context.Enqueue(new Delivery(message, sender));
     }
     else
     {
         Context.System.DeadLetters.Tell(message, sender);
     }
 }
Beispiel #17
0
 /// <summary>
 /// Constructs a new Delivery with a message and sender.
 /// </summary>
 /// <param name="message">the object message to deliver</param>
 /// <param name="sender">the ActorRef that sent the message</param>
 public Delivery(object message, ActorRef sender)
 {
     Message = message;
     Sender  = sender;
 }
Beispiel #18
0
 public Operation(int total, int goal, int operations, ActorRef nextOperation)
 {
     Total = total;
     Goal = goal;
     Operations = operations;
     NextOperation = nextOperation;
 }
Beispiel #19
0
 /// <summary>
 /// Resume my child that failed. Note that the context
 /// of this method is the supervisor parent.
 /// </summary>
 /// <param name="reason">the Exception that caused the failure</param>
 /// <param name="child">the ActorRef of the failed child</param>
 private void RecoverByResuming(Exception reason, ActorRef child)
 {
     // ignore
 }
Beispiel #20
0
 public TestForwardFromActor(ActorRef to)
 {
     this.to = to;
 }
Beispiel #21
0
        /// <summary>
        /// Recover from a exceptional failure (reason) that occurred
        /// during a message by means of a supervisorStrategy. Note
        /// that the context of this method is the supervisor parent.
        /// </summary>
        /// <param name="reason">the Exception that caused the failure</param>
        /// <param name="message">the object message that was being processed during failure</param>
        /// <param name="child">the ActorRef of the failed child</param>
        private void RecoverFromFor(Exception reason, object message, ActorRef child)
        {
            SupervisorStrategy.Directive directive =
                Actor.InternalSupervisorStrategy.Decide(reason);

            switch (directive)
            {
                case SupervisorStrategy.Directive.Escalate:
                    RecoverByEscalation(reason);
                    break;
                case SupervisorStrategy.Directive.Restart:
                    RecoverByRestarting(reason, message, child);
                    break;
                case SupervisorStrategy.Directive.Resume:
                    RecoverByResuming(reason, child);
                    break;
                case SupervisorStrategy.Directive.Stop:
                    RecoverByStopping(reason, child);
                    break;
            }
        }
Beispiel #22
0
 /// <summary>
 /// Constructs a new ActorContext.
 /// </summary>
 /// <param name="system">the ActorSystem within which the actor is created</param>
 /// <param name="actor">the Actor to create</param>
 /// <param name="name">the string name to give the Actor</param>
 /// <param name="props">the Props to pass individually as class arguments</param>
 /// <param name="parent">the ActorRef of the parent of the Actor being created</param>
 /// <param name="parentPath">the ActorPath of the Actor being created</param>
 internal ActorContext(
     ActorSystem system,
     Type actorType,
     Actor actor,
     string name,
     Props props,
     ActorRef parent,
     ActorPath parentPath)
     : this(system, actorType, actor, name, props, parent,
            parentPath, false, new Channel<Delivery>(), new PoolFiber())
 {
 }
Beispiel #23
0
        /// <summary>
        /// Stops actor at any level.
        /// </summary>
        /// <param name="actor">the ActorRef</param>
        /// <param name="children">the List<ActorRef> of my children</param>
        private void Sweep(ActorRef actor, List<ActorRef> children)
        {
            foreach (ActorRef child in Children)
            {
                if (child == actor)
                {
                    child.Context.Parent.Context.Stop(child);

                    return;
                }
            }

            foreach (ActorRef child in Children)
            {
                Sweep(actor, child.Context.Children);
            }
        }
Beispiel #24
0
        /// <summary>
        /// Restart my child that failed. Note that the context
        /// of this method is the supervisor parent.
        /// </summary>
        /// <param name="reason">the Exception that caused the failure</param>
        /// <param name="message">the object message that was being processed during failure</param>
        /// <param name="child">the ActorRef of the failed child</param>
        private void RecoverByRestarting(Exception reason, object message, ActorRef child)
        {
            ActorContext childContext = child.Context;

            try
            {
                childContext._Suspended = true;

                childContext.Actor.PreRestart(reason, message);

                Children.Remove(child); // free name

                ActorRef restarted =
                    ActorOf(
                        childContext.Type,
                        childContext.Props,
                        childContext.Path.Name,
                        true,
                        childContext.Channel,
                        childContext.Fiber);

                restarted.Context._Suspended = false;

                childContext.StopContext();

                restarted.Context.Actor.PostRestart(reason);
            }
            finally
            {
                childContext._Suspended = false;
            }
        }
Beispiel #25
0
 /// <summary>
 /// Resume my child that failed. Note that the context
 /// of this method is the supervisor parent.
 /// </summary>
 /// <param name="reason">the Exception that caused the failure</param>
 /// <param name="child">the ActorRef of the failed child</param>
 private void RecoverByResuming(Exception reason, ActorRef child)
 {
     // ignore
 }
Beispiel #26
0
 /// <summary>
 /// Stop my child that failed. Note that the context
 /// of this method is the supervisor parent.
 /// </summary>
 /// <param name="e">the Exception that occurred in my child</param>
 private void RecoverByStopping(Exception reason, ActorRef child)
 {
     Stop(child);
 }
Beispiel #27
0
 /// <summary>
 /// Stops the Actor referenced by actor.
 /// </summary>
 /// <param name="actor">the ActorRef ofthe Actor to stop</param>
 public void Stop(ActorRef actor)
 {
     Context.Stop(actor);
 }
Beispiel #28
0
        /// <summary>
        /// Schedules a recurring timer event.
        /// </summary>
        /// <param name="delay">the long number of milliseconds before the event is rasied</param>
        /// <param name="receiver">the ActorRef of the actor to receive notification</param>
        /// <param name="message">the object message to send to the receiver when the event occurs</param>
        /// <returns>Cancellable</returns>
        public Cancellable Schedule(
            long initialDelay,
            long frequency,
            ActorRef receiver,
            object message)
        {
            if (initialDelay < 0)
            {
                throw new NotSupportedException("The initial delay must be zero or greater.");
            }

            if (frequency < 1)
            {
                throw new NotSupportedException("The frequency must be greater than zero.");
            }

            if (receiver == ActorRef.None || message == null)
            {
                throw new NotSupportedException("Must provide a receiver and message.");
            }

            return new ScheduledTimerEvent(initialDelay, frequency, receiver, message);
        }
Beispiel #29
0
        /// <summary>
        /// Schedules a single timer event.
        /// </summary>
        /// <param name="delay">the long number of milliseconds before the event is rasied</param>
        /// <param name="receiver">the ActorRef of the actor to receive notification</param>
        /// <param name="message">the object message to send to the receiver when the event occurs</param>
        /// <returns>Cancellable</returns>
        public Cancellable ScheduleOnce(
            long delay,
            ActorRef receiver,
            object message)
        {
            if (delay < 1)
            {
                throw new NotSupportedException("Delay must be greater than zero.");
            }

            if (receiver == ActorRef.None || message == null)
            {
                throw new NotSupportedException("Must provide a receiver and message.");
            }

            return new ScheduledTimerEvent(delay, 0, receiver, message);
        }
Beispiel #30
0
 /// <summary>
 /// Constructs a new Delivery with a message and sender.
 /// </summary>
 /// <param name="message">the object message to deliver</param>
 /// <param name="sender">the ActorRef that sent the message</param>
 public Delivery(object message, ActorRef sender)
 {
     Message = message;
     Sender = sender;
 }
 public ProcessStopped(string processId, ActorRef process)
 {
     this.ProcessId = processId;
     this.Process = process;
 }