Пример #1
0
        public Task HandleMessageAsync(IAsyncBusEntity sender, VersionCumulativeUpdateNotification <T> notification)
        {
            _log.LogInformation($"Librarian actor #{FactoryInstanceId} of factory '{FactoryId}' received notification of type '{notification.GetType()}' from async bus entity '{sender.EntityId}'");
            _log.LogVerbose($"VersionCumulativeUpdate: base=#{notification.CumulativeUpdate.BaseVersionNumber}, version=#{notification.VersionNumber}, cumulativeUpdate='{notification.CumulativeUpdate.GetType()}'");

            _updates.AddOrUpdate(notification.CumulativeUpdate.BaseVersionNumber,
                                 v => new Dictionary <long, ICumulativeUpdate <T> > {
                { notification.FactoryInstanceId, notification.CumulativeUpdate }
            },
                                 d => { d.Add(notification.FactoryInstanceId, notification.CumulativeUpdate); return(d); });

            return(Task.FromResult(0));
        }
Пример #2
0
        public async Task <Tuple <long, Task <long> > > PromoteNewVersion(IAsyncBusEntity bus, long baseVersionNumber)
        {
            var versionAccumulator = _versions.AddOrUpdate(Interlocked.Increment(ref _versionNumber), v => new SingleVersionAccumulator(v, baseVersionNumber), a => a.ConfirmVersion(baseVersionNumber));

            _log.LogVerbose($"Vendor actor instance #{FactoryInstanceId} of factory '{FactoryId}' promote new version #{versionAccumulator.VersionNumber} for base #{baseVersionNumber}");

            await bus.PublishMessageAsync(new VersionConfirmNotification(FactoryId, FactoryInstanceId, versionAccumulator.VersionNumber, baseVersionNumber));

            return(new Tuple <long, Task <long> >(versionAccumulator.VersionNumber, versionAccumulator.ConfirmTask));
        }
Пример #3
0
 public static T Get <T>(this ISuperSonicCollection <T> collection, long index, T defaultValue = default(T)) where T : class
 {
     return(collection.AddOrUpdate(index, x => defaultValue, x => x));
 }
Пример #4
0
        public static T AddOrUpdate <T>(this ISuperSonicCollection <T> collection, long index, Func <long, T> createFunc, Func <T, T> updateFunc) where T : class
        {
            T old;

            return(collection.AddOrUpdate(index, createFunc, updateFunc, out old));
        }
Пример #5
0
 public virtual Snapshot <T> UpdateSnapshot(ICumulativeUpdate <T> update, long newVersionNumber, out Snapshot <T> current)
 {
     return(_snapshots.AddOrUpdate(update.BaseVersionNumber, LoadSnapshot, s => s.ApplyUpdate(newVersionNumber, update), out current));
 }