Esempio n. 1
0
            public async Task <IDisposable> SubscribeAsync(LeaseObserver <T> observer)
            {
                if (!this.observers.Contains(observer))
                {
                    this.observers.Add(observer);

                    foreach (var lease in this.partitionManager.currentlyOwnedShards.Values)
                    {
                        try
                        {
                            await observer.OnLeaseAquiredAsync(lease);
                        }
                        catch (Exception ex)
                        {
                            // Eat any exceptions during notification of observers
                            this.partitionManager.settings.Logger.PartitionManagerError(
                                partitionManager.accountName,
                                partitionManager.taskHub,
                                partitionManager.workerName,
                                lease.PartitionId,
                                $"Failed during notification of observers of {this.partitionManager.leaseManager} lease: {ex.ToString()}");
                        }
                    }
                }

                return(new Unsubscriber(this.observers, observer));
            }
Esempio n. 2
0
        public Task <IDisposable> SubscribeAsync(
            Func <T, Task> leaseAquiredDelegate,
            Func <T, CloseReason, Task> leaseReleasedDelegate)
        {
            var leaseObserver = new LeaseObserver <T>(leaseAquiredDelegate, leaseReleasedDelegate);

            return(this.leaseObserverManager.SubscribeAsync(leaseObserver));
        }
Esempio n. 3
0
 internal Unsubscriber(List <LeaseObserver <T> > observers, LeaseObserver <T> observer)
 {
     this._observers = observers;
     this._observer  = observer;
 }