/// <summary>Ctor.</summary> /// <param name="currentVersion">current version and value</param> /// <param name="priorVersion">prior version and value</param> public CurrentValue( VersionedValue<T> currentVersion, VersionedValue<T> priorVersion) { this.currentVersion = currentVersion; this.priorVersion = priorVersion; }
private VersionedValue CreateAndPushNewInstance() { var instance = new VersionedValue(m_stackOfValues.Count + 1, m_constructor()); m_stackOfValues.Push(instance); return(instance); }
private Task FulfillAsync() { _sumValue = _sumValue.NextVersion(_leftValue.Value + _rightValue.Value); _wait.SetResult(_sumValue); _wait = new TaskCompletionSource <VersionedValue <int> >(); return(Task.CompletedTask); }
private VersionedValue CreateAndPushNewInstance() { Contract.Ensures(Contract.Result <VersionedValue>().Version == CurrentVersion); var instance = new VersionedValue(m_stackOfValues.Count + 1, m_constructor()); m_stackOfValues.Push(instance); return(instance); }
private Task FulfillAsync() { _sumValue = _sumValue.NextVersion(_leftValue.Value + _rightValue.Value); _logger.LogInformation( "{@Time}: {@GrainType} {@GrainKey} updated sum value to {@Value} with version {@Version}", DateTime.Now.TimeOfDay, GrainType, GrainKey, _sumValue.Value, _sumValue.Version); _wait.SetResult(_sumValue); _wait = new TaskCompletionSource <VersionedValue <int> >(); return(Task.CompletedTask); }
public override Task OnActivateAsync() { // initialize the state _state = new VersionedValue <int>(0, 0); // initialize the polling wait handle _wait = new TaskCompletionSource <VersionedValue <int> >(); return(base.OnActivateAsync()); }
public override async Task OnActivateAsync() { // hydrate the cache with whatever value is available right now _cache = await GrainFactory.GetGrain <IProducerGrain>(GrainKey).GetAsync(); // start polling _pollTimer = RegisterTimer(_ => PollAsync(), null, TimeSpan.Zero, TimeSpan.FromMilliseconds(1)); await base.OnActivateAsync(); }
public override Task OnActivateAsync() { // initialize the state _state = VersionedValue <OrdersStats> .None.NextVersion(new OrdersStats()); // initialize the polling wait handle _wait = new TaskCompletionSource <VersionedValue <OrdersStats> >(); return(base.OnActivateAsync()); }
public override async Task OnActivateAsync() { // derive the source grains to aggregate from the grain key var parts = GrainKey.Split('|'); _leftGrain = GrainFactory.GetGrain <IProducerGrain>(parts[0]); _rightGrain = GrainFactory.GetGrain <IProducerGrain>(parts[1]); // get the starting values as they are now before starting to long poll _leftValue = await _leftGrain.GetAsync(); _rightValue = await _rightGrain.GetAsync(); await FulfillAsync(); // start long polling the left grain _leftPoll = await RegisterReactivePollAsync( null, // dont initialize for this one () => _leftGrain.LongPollAsync(_leftValue.Version), result => result.IsValid, apply => { _leftValue = apply; _logger.LogInformation( "{@Time}: {@GrainType} {@GrainKey} updated left value to {@Value} with version {@Version}", DateTime.Now.TimeOfDay, GrainType, GrainKey, _leftValue.Value, _leftValue.Version); return(FulfillAsync()); }, failed => { _logger.LogWarning("The reactive poll timed out by returning a 'none' response before Orleans could break the promise."); return(Task.CompletedTask); }); // start long polling the right grain _rightPoll = await RegisterReactivePollAsync( null, // dont initialize for this one () => _rightGrain.LongPollAsync(_rightValue.Version), result => result.IsValid, apply => { _rightValue = apply; _logger.LogInformation( "{@Time}: {@GrainType} {@GrainKey} updated right value to {@Value} with version {@Version}", DateTime.Now.TimeOfDay, GrainType, GrainKey, _rightValue.Value, _rightValue.Version); return(FulfillAsync()); }, failed => { _logger.LogWarning("The reactive poll timed out by returning a 'none' response before Orleans could break the promise."); return(Task.CompletedTask); }); await base.OnActivateAsync(); }
private async Task LongPollRightAsync() { try { _rightValue = await _rightGrain.LongPollAsync(_rightValue.Version); await FulfillAsync(); } catch (TimeoutException) { } }
private async Task LongPollLeftAsync() { try { _leftValue = await _leftGrain.LongPollAsync(_leftValue.Version); await FulfillAsync(); } catch (TimeoutException) { } }
private async Task PollAsync() { try { _cache = await GrainFactory.GetGrain <IProducerGrain>(GrainKey).LongPollAsync(_cache.Version); } catch (TimeoutException error) { _logger.LogDebug(error, "{@GrainType} {@GrainKey} long polling broken. Polling again..."); } }
/// <exception cref="System.Exception"/> private void IncrSharedCount(SharedCount sharedCount) { while (true) { // Loop until we successfully increment the counter VersionedValue <int> versionedValue = sharedCount.GetVersionedValue(); if (sharedCount.TrySetCount(versionedValue, versionedValue.GetValue() + 1)) { break; } } }
public Task UpdateValue(OrdersStats value) { // update the state _state = _state.NextVersion(value); _logger.LogInformation("{@GrainType} {@GrainKey} updated value to {@Value} with version {@Version}", GrainType, GrainKey, _state.Value, _state.Version); // fulfill waiting promises _wait.SetResult(_state); _wait = new TaskCompletionSource <VersionedValue <OrdersStats> >(); return(Task.CompletedTask); }
private Task IncrementAsync(int increment) { // update the state _state = _state.NextVersion(_state.Value + increment); _logger.LogInformation("{@GrainType} {@GrainKey} updated value to {@Value} with version {@Version}", GrainType, GrainKey, _state.Value, _state.Version); // fulfill waiting promises _wait.SetResult(_state); _wait = new TaskCompletionSource <VersionedValue <int> >(); return(Task.CompletedTask); }
public override async Task OnActivateAsync() { // derive the source grains to aggregate from the grain key var parts = GrainKey.Split('|'); _leftGrain = GrainFactory.GetGrain <IProducerGrain>(parts[0]); _rightGrain = GrainFactory.GetGrain <IProducerGrain>(parts[1]); // get the starting values as they are now _leftValue = await _leftGrain.GetAsync(); _rightValue = await _rightGrain.GetAsync(); await FulfillAsync(); // start long polling _leftPollTimer = RegisterTimer(_ => LongPollLeftAsync(), null, TimeSpan.Zero, TimeSpan.FromMilliseconds(1)); _rightPollTimer = RegisterTimer(_ => LongPollRightAsync(), null, TimeSpan.Zero, TimeSpan.FromMilliseconds(1)); await base.OnActivateAsync(); }
public override async Task OnActivateAsync() { // start long polling _poll = await RegisterReactivePollAsync( () => GrainFactory.GetGrain <IOrdersStatsProducer>(GrainKey).GetAsync(), () => GrainFactory.GetGrain <IOrdersStatsProducer>(GrainKey).LongPollStatsAsync(_cache.Version), result => result.IsValid, apply => { _cache = apply; _logger.LogInformation( "{@Time}: {@GrainType} {@GrainKey} updated value to {@Value}", DateTime.Now.TimeOfDay, GrainType, GrainKey, _cache.Value); return(Task.CompletedTask); }, failed => { _logger.LogWarning("The reactive poll timed out by returning a 'none' response before Orleans could break the promise."); return(Task.CompletedTask); }); await base.OnActivateAsync(); }
/// <summary> /// Constructor /// </summary> /// <param name="factory">logger factory</param> public RCService(ILoggerFactory factory) { _logger = factory.CreateLogger <RCService <T> >(); _value = VersionedValue <T> .None.NextVersion(default);