/// <summary> /// Gets the current value of the shared counter. /// </summary> public override int GetValue() { var op = this.Context.Runtime.GetExecutingOperation <ActorOperation>(); this.Context.SendEvent(this.CounterActor, SharedCounterEvent.GetEvent(op.Actor.Id)); var response = op.Actor.ReceiveEventAsync(typeof(SharedCounterResponseEvent)).Result; return((response as SharedCounterResponseEvent).Value); }
/// <summary> /// Sets the counter to a value atomically if it is equal to a given value. /// </summary> public override int CompareExchange(int value, int comparand) { var op = this.Context.Runtime.GetExecutingOperation <ActorOperation>(); this.Context.SendEvent(this.CounterActor, SharedCounterEvent.CompareExchangeEvent(op.Actor.Id, value, comparand)); var response = op.Actor.ReceiveEventAsync(typeof(SharedCounterResponseEvent)).Result; return((response as SharedCounterResponseEvent).Value); }
/// <summary> /// Adds a value to the counter atomically. /// </summary> public override int Add(int value) { var op = this.Context.Scheduler.GetExecutingOperation <ActorOperation>(); this.Context.SendEvent(this.CounterActor, SharedCounterEvent.AddEvent(op.Actor.Id, value)); var response = op.Actor.ReceiveEventAsync(typeof(SharedCounterResponseEvent)).Result; return((response as SharedCounterResponseEvent).Value); }
/// <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(); }
/// <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(); }
/// <summary> /// Decrements the shared counter. /// </summary> public override void Decrement() => this.Context.SendEvent(this.CounterActor, SharedCounterEvent.DecrementEvent());
/// <summary> /// Increments the shared counter. /// </summary> public override void Increment() => this.Runtime.SendEvent(this.CounterActor, SharedCounterEvent.IncrementEvent());