public Task RegisterProcessorFactoryAsync(Lease lease, ICheckpointManager checkpointManager, IEventProcessorFactory eventProcessorFactory, EventProcessorOptions processorOptions) { base.ThrowIfDisposed(); if (lease == null) { throw Fx.Exception.ArgumentNull("lease"); } if (checkpointManager == null) { throw Fx.Exception.ArgumentNull("checkpointManager"); } if (eventProcessorFactory == null) { throw Fx.Exception.ArgumentNull("eventProcessorFactory"); } if (processorOptions == null) { throw Fx.Exception.ArgumentNull("processorOptions"); } EventProcessorLifecycleManager eventProcessorLifecycleManager = null; if (this.handlers.TryGetValue(lease, out eventProcessorLifecycleManager)) { ExceptionTrace exception = Fx.Exception; string eventProcessorAlreadyRegistered = Resources.EventProcessorAlreadyRegistered; object[] partitionId = new object[] { lease.PartitionId }; throw exception.AsError(new InvalidOperationException(Microsoft.ServiceBus.SR.GetString(eventProcessorAlreadyRegistered, partitionId)), null); } eventProcessorLifecycleManager = new EventProcessorLifecycleManager(this, lease, checkpointManager, processorOptions); if (!this.handlers.TryAdd(lease, eventProcessorLifecycleManager)) { return(TaskHelpers.GetCompletedTask <object>(null)); } return(eventProcessorLifecycleManager.RegisterProcessorFactoryAsync(eventProcessorFactory)); }
public EventDataPumpAsyncResult(EventProcessorLifecycleManager lifeCycleManager, EventHubReceiver receiver, PartitionContext context, AsyncCallback callback, object state) : base(TimeSpan.MaxValue, callback, state) { this.context = context; this.lifeCycleManager = lifeCycleManager; this.receiver = receiver; this.trackingContext = TrackingContext.GetInstance(Guid.NewGuid(), this.receiver.Name); base.Start(); }
protected override IEnumerator <IteratorAsyncResult <EventProcessorLifecycleManager.EventProcessorInitializeAsyncResult> .AsyncStep> GetAsyncSteps() { object obj; Func <Task <EventHubReceiver> > func = null; if (!string.IsNullOrWhiteSpace(this.startingOffset)) { func = () => this.lifeCycleManager.eventHubConsumer.CreateReceiverAsync(this.partitionId, this.startingOffset, this.epoch); } else { Func <string, object> initialOffsetProvider = this.lifeCycleManager.processorOptions.InitialOffsetProvider; obj = (initialOffsetProvider != null ? initialOffsetProvider(this.lease.PartitionId) : null); object obj1 = obj; if (obj1 != null) { string str = obj1 as string; if (str == null) { DateTime?nullable = (DateTime?)(obj1 as DateTime?); if (!nullable.HasValue) { throw Fx.Exception.AsError(new InvalidOperationException(SRClient.InitialOffsetProviderReturnTypeNotSupported(obj1.GetType().ToString())), null); } func = () => this.lifeCycleManager.eventHubConsumer.CreateReceiverAsync(this.partitionId, nullable.Value, this.epoch); } else { func = () => this.lifeCycleManager.eventHubConsumer.CreateReceiverAsync(this.partitionId, str, this.epoch); } } else { func = () => this.lifeCycleManager.eventHubConsumer.CreateReceiverAsync(this.partitionId, "-1", this.epoch); } } yield return(base.CallTask((EventProcessorLifecycleManager.EventProcessorInitializeAsyncResult thisPtr, TimeSpan t) => func().Then <EventHubReceiver>((EventHubReceiver receiver) => { thisPtr.partitionContext = thisPtr.lifeCycleManager.InitializeManager(receiver); thisPtr.receiver = receiver; return thisPtr.lifeCycleManager.processor.OpenAsync(thisPtr.partitionContext); }), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); TaskCompletionSource <object> taskCompletionSource = new TaskCompletionSource <object>(); try { EventProcessorLifecycleManager eventProcessorLifecycleManager = this.lifeCycleManager; EventHubReceiver eventHubReceiver = this.receiver; PartitionContext partitionContext = this.partitionContext; EventProcessorLifecycleManager.EventDataPumpAsyncResult.Begin(eventProcessorLifecycleManager, eventHubReceiver, partitionContext, (IAsyncResult ar) => taskCompletionSource.TrySetResult(null), null); } catch (Exception exception) { Environment.FailFast(exception.ToString()); } this.lifeCycleManager.dispatchTask = taskCompletionSource.Task; }
public void UnregisterProcessor(Lease lease, CloseReason reason) { EventProcessorLifecycleManager eventProcessorLifecycleManager = null; if (this.handlers.TryRemove(lease, out eventProcessorLifecycleManager)) { eventProcessorLifecycleManager.UnregisterProcessorAsync(reason).Wait(); } }
public EventProcessorShutdownAsyncResult(EventProcessorLifecycleManager lifeCycleManager, EventHubReceiver receiver, IEventProcessor processor, PartitionContext context, CloseReason reason, Task dispatchTask, AsyncCallback callback, object state) : base(TimeSpan.MaxValue, callback, state) { this.lifeCycleManager = lifeCycleManager; this.receiver = receiver; this.processor = processor; this.context = context; this.reason = reason; this.dispatchTask = dispatchTask; base.Start(); }
public Task UnregisterProcessorAsync(Lease lease, CloseReason reason) { EventProcessorLifecycleManager eventProcessorLifecycleManager = null; if (!this.handlers.TryRemove(lease, out eventProcessorLifecycleManager)) { return(TaskHelpers.GetCompletedTask <object>(null)); } return(eventProcessorLifecycleManager.UnregisterProcessorAsync(reason)); }
public EventProcessorInitializeAsyncResult(EventProcessorLifecycleManager lifeCycleManager, Lease lease, AsyncCallback callback, object state) : base(TimeSpan.MaxValue, callback, state) { this.lifeCycleManager = lifeCycleManager; this.lease = lease; this.trackingContext = TrackingContext.GetInstance(Guid.NewGuid(), lease.PartitionId); this.partitionId = lease.PartitionId; this.startingOffset = lease.Offset; this.epoch = lease.Epoch; EventProcessorLifecycleManager.EventProcessorInitializeAsyncResult eventProcessorInitializeAsyncResult = this; eventProcessorInitializeAsyncResult.OnCompleting = (Action <AsyncResult, Exception>)Delegate.Combine(eventProcessorInitializeAsyncResult.OnCompleting, EventProcessorLifecycleManager.EventProcessorInitializeAsyncResult.OnFinallyDelegate); base.Start(); }
public static IAsyncResult Begin(EventProcessorLifecycleManager lifeCycleManager, EventHubReceiver receiver, IEventProcessor processor, PartitionContext context, CloseReason reason, Task dispatchTask, AsyncCallback callback, object state) { return(new EventProcessorLifecycleManager.EventProcessorShutdownAsyncResult(lifeCycleManager, receiver, processor, context, reason, dispatchTask, callback, state)); }
public static IAsyncResult Begin(EventProcessorLifecycleManager lifeCycleManager, Lease lease, AsyncCallback callback, object state) { return(new EventProcessorLifecycleManager.EventProcessorInitializeAsyncResult(lifeCycleManager, lease, callback, state)); }
public static IAsyncResult Begin(EventProcessorLifecycleManager lifeCycleManager, EventHubReceiver receiver, PartitionContext context, AsyncCallback callback, object state) { return(new EventProcessorLifecycleManager.EventDataPumpAsyncResult(lifeCycleManager, receiver, context, callback, state)); }