Example #1
0
            /// <summary>
            /// Sets the counter to a value atomically.
            /// </summary>
            public override int Exchange(int value)
            {
                var op = this.Context.Runtime.GetExecutingOperation <ActorOperation>();

                this.Context.SendEvent(this.CounterActor, SharedCounterEvent.SetEvent(op.Actor.Id, value));
                var response = op.Actor.ReceiveEventAsync(typeof(SharedCounterResponseEvent)).Result;

                return((response as SharedCounterResponseEvent).Value);
            }
Example #2
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Mock"/> class.
            /// </summary>
            internal Mock(int value, ActorExecutionContext.Mock context)
                : base(value)
            {
                this.Context      = context;
                this.CounterActor = context.CreateActor(typeof(SharedCounterActor));
                var op = context.Runtime.GetExecutingOperation <ActorOperation>();

                context.SendEvent(this.CounterActor, SharedCounterEvent.SetEvent(op.Actor.Id, value));
                op.Actor.ReceiveEventAsync(typeof(SharedCounterResponseEvent)).Wait();
            }
Example #3
0
            /// <summary>
            /// Initializes a new instance of the <see cref="Mock"/> class.
            /// </summary>
            internal Mock(int value, ControlledRuntime runtime)
                : base(value)
            {
                this.Runtime      = runtime;
                this.CounterActor = this.Runtime.CreateActor(typeof(SharedCounterActor));
                var op = this.Runtime.Scheduler.GetExecutingOperation <ActorOperation>();

                this.Runtime.SendEvent(this.CounterActor, SharedCounterEvent.SetEvent(op.Actor.Id, value));
                op.Actor.ReceiveEventAsync(typeof(SharedCounterResponseEvent)).Wait();
            }