示例#1
0
        /// <summary> Checks a given condition whenever the given other actor changes state; if
        /// the condition passes, a given action is invoked, but all of this only while in the
        /// current state (or given super-state). </summary>
        /// <remarks> If the condition is already met, the callback is invoked immediately (but not in this call) with null transition information. </remarks>
        protected void WatchOtherWhileInState <OA, OS, OT>(IStatefulActor <OA, OS, OT> other, WatchOtherCondition <OS, OT> condition, Action action, TState?whileIn = null)
            where OS : struct
        {
            var inState = whileIn ?? State;

            if (InState(inState))
            {
                void changedHandler(OS oldState, StateMachine <OS, OT> .Transition transition)
                {
                    Act(() =>
                    {
                        if (InState(inState) && condition(transition.Target, transition))
                        {
                            action();
                        }
                    }
                        );
                }

                other.Atomically(_ =>
                {
                    var otherState      = other.State;
                    other.StateChanged += changedHandler;
                    Act(() =>
                    {
                        if (InState(inState) && condition(otherState, null))
                        {
                            action();
                        }
                    });
                });
                WatchState(inState, () => { other.StateChanged -= changedHandler; });
            }
        }
示例#2
0
        public int GetStatefulPositionCount()
        {
            var            actorId      = new ActorId(11111);
            var            actorAddress = new Uri("fabric:/DartShooting/StatefulActorService");
            IStatefulActor proxy        = ActorProxy.Create <IStatefulActor>(actorId, actorAddress);

            return(proxy.GetCountAsync().Result);
        }
示例#3
0
        public StatefulActor.Interfaces.Models.Location GetStatefulPosition()
        {
            var actorId = new ActorId(11111);

            var            actorAddress = new Uri("fabric:/DartShooting/StatefulActorService");
            IStatefulActor proxy        = ActorProxy.Create <IStatefulActor>(actorId, actorAddress);

            return(proxy.GetRandomPosition().Result);
        }
示例#4
0
 /// <summary> Checks to see if the current states transition's conditions are satisfied
 /// in response to any state change in the given other actor, but only while in the
 /// current state (or optionally given super-state).  If the other actor goes to any given
 /// fault state, an exception is thrown for this actor. </summary>
 protected void WatchOtherAndUpdate <OA, OS, OT>(IStatefulActor <OA, OS, OT> other, OS[] errorStates, TState?whileIn = null)
     where OS : struct
 => WatchOtherWhileInState
 (
     other,
     (s, t) => true,
     () =>
 {
     if (errorStates.Any(es => other.InState(es)))
     {
         throw new FrameworkWatchedStateException(other.GetType().Name + " unexpectedly went to state " + other.State, other);
     }
     else
     {
         UpdateStates();
     }
 },
     whileIn
 );
        public static void WaitForState <TActor, TState, TTrigger>(this IStatefulActor <TActor, TState, TTrigger> actor, TState desired, int timeout)
            where TState : struct
        {
            var completionSource = new System.Threading.Tasks.TaskCompletionSource <bool>();

            void waitForUnstarted(TState oldState, StateMachine <TState, TTrigger> .Transition transition)
            {
                if (actor.InState(desired))
                {
                    completionSource.TrySetResult(true);
                }
            };
            actor.StateChanged += waitForUnstarted;

            // Check for synchronous completion
            if (actor.InState(desired))
            {
                completionSource.TrySetResult(true);
            }

            completionSource.Task.Wait(timeout);
            actor.StateChanged -= waitForUnstarted;
        }
示例#6
0
 /// <summary> Checks to see if the current states transition's conditions are satisfied
 /// in response to any state change in the given other actor, but only while in the
 /// current state (or optionally given super-state).  If the other actor goes to a given
 /// fault state, an exception is thrown for this actor. </summary>
 protected void WatchOtherAndUpdate <OA, OS, OT>(IStatefulActor <OA, OS, OT> other, OS errorState, TState?whileIn = null)
     where OS : struct
 => WatchOtherAndUpdate(other, new OS[] { errorState }, whileIn);
示例#7
0
 /// <summary> Checks to see if the current states transition's conditions are satisfied
 /// in response to any state change in the given other actor, but only while in the
 /// current state (or optionally given super-state). </summary>
 protected void WatchOtherAndUpdate <OA, OS, OT>(IStatefulActor <OA, OS, OT> other, TState?whileIn = null)
     where OS : struct
 => WatchOtherWhileInState(other, (s, t) => true, UpdateStates, whileIn);