コード例 #1
0
ファイル: ActorSelection.cs プロジェクト: RichieYang/Dotsero
 /// <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);
     }
 }
コード例 #2
0
ファイル: ActorContext.cs プロジェクト: RichieYang/Dotsero
        /// <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();
        }
コード例 #3
0
        public override void PreStart()
        {
            base.PreStart();

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

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

            level3 = Context.ActorOf(
                typeof(EscalateLevel3),
                Props.With((object)levelEvents),
                "escalateLevel3");
        }
コード例 #6
0
 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;
 }
コード例 #7
0
 public LoanBroker(
     ActorRef creditBureau,
     ActorRef[] banks,
     AutoResetEvent termination)
 {
     this.creditBureau = creditBureau;
     this.banks = banks;
     this.termination = termination;
 }
コード例 #8
0
ファイル: ActorSystem.cs プロジェクト: RichieYang/Dotsero
        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);
        }
コード例 #9
0
ファイル: ActorContext.cs プロジェクト: RichieYang/Dotsero
 /// <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));
         }
     }
 }
コード例 #10
0
ファイル: ActorContext.cs プロジェクト: xiaofneglin/Dotsero
 /// <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);
 }
コード例 #11
0
        public override void PreStart()
        {
            base.PreStart();

            level3 = Context.ActorOf(
                typeof(ResumeLevel3),
                Props.With((object)levelEvents),
                "resumeLevel3");
        }
コード例 #12
0
ファイル: ActorTests.cs プロジェクト: RichieYang/Dotsero
 public TestForwardOriginalActor(ActorRef to)
 {
     this.to = to;
 }
コード例 #13
0
ファイル: ActorSelection.cs プロジェクト: RichieYang/Dotsero
        internal ActorSelection(ActorRef actor)
        {
            Selections = new List<ActorRef>();

            Selections.Add(actor);
        }
コード例 #14
0
        protected void StartProcess(string processId, ActorRef process)
        {
            if (!processes.ContainsKey(processId))
            {
                processes.Add(processId, process);

                Self.Tell(new ProcessStarted(processId, process), Self);
            }
        }
コード例 #15
0
ファイル: BecomeTests.cs プロジェクト: RichieYang/Dotsero
        public Counting(ActorRef end)
            : base()
        {
            this.end = end;

            AdditionBehavior = new Addition(this);

            MultiplicationBehavior = new Multiplication(this);
        }
コード例 #16
0
ファイル: ActorRef.cs プロジェクト: RichieYang/Dotsero
 /// <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);
     }
 }
コード例 #17
0
ファイル: ActorContext.cs プロジェクト: xiaofneglin/Dotsero
 /// <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;
 }
コード例 #18
0
ファイル: ActorTests.cs プロジェクト: RichieYang/Dotsero
 public Operation(int total, int goal, int operations, ActorRef nextOperation)
 {
     Total = total;
     Goal = goal;
     Operations = operations;
     NextOperation = nextOperation;
 }
コード例 #19
0
ファイル: ActorContext.cs プロジェクト: RichieYang/Dotsero
 /// <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
 }
コード例 #20
0
ファイル: ActorTests.cs プロジェクト: RichieYang/Dotsero
 public TestForwardFromActor(ActorRef to)
 {
     this.to = to;
 }
コード例 #21
0
ファイル: ActorContext.cs プロジェクト: RichieYang/Dotsero
        /// <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;
            }
        }
コード例 #22
0
ファイル: ActorContext.cs プロジェクト: RichieYang/Dotsero
 /// <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())
 {
 }
コード例 #23
0
ファイル: ActorContext.cs プロジェクト: RichieYang/Dotsero
        /// <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);
            }
        }
コード例 #24
0
ファイル: ActorContext.cs プロジェクト: RichieYang/Dotsero
        /// <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;
            }
        }
コード例 #25
0
ファイル: ActorContext.cs プロジェクト: xiaofneglin/Dotsero
 /// <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
 }
コード例 #26
0
ファイル: ActorContext.cs プロジェクト: RichieYang/Dotsero
 /// <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);
 }
コード例 #27
0
ファイル: ActorSystem.cs プロジェクト: RichieYang/Dotsero
 /// <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);
 }
コード例 #28
0
ファイル: ActorSystem.cs プロジェクト: RichieYang/Dotsero
        /// <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);
        }
コード例 #29
0
ファイル: ActorSystem.cs プロジェクト: RichieYang/Dotsero
        /// <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);
        }
コード例 #30
0
ファイル: ActorContext.cs プロジェクト: RichieYang/Dotsero
 /// <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;
 }
コード例 #31
0
 public ProcessStopped(string processId, ActorRef process)
 {
     this.ProcessId = processId;
     this.Process = process;
 }