Task IReceiveEndpointObserver.Ready(ReceiveEndpointReady ready) { _handle.Disconnect(); _registration.Dispose(); return(_ready.TrySetResultOnThreadPool(ready)); }
/// <summary> /// Subscribes a message handler to the bus, which is disconnected after the message /// is received. /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="filter">A filter that only completes the task if filter is true</param> /// <returns>An awaitable task completed when the message is received</returns> public Task <ConsumeContext <T> > SubscribeHandler <T>(Func <ConsumeContext <T>, bool> filter) where T : class { TaskCompletionSource <ConsumeContext <T> > source = TaskUtil.GetTask <ConsumeContext <T> >(); ConnectHandle handler = null; handler = Bus.ConnectHandler <T>(async context => { if (filter(context)) { handler.Disconnect(); source.SetResult(context); } }); TestCancelledTask.ContinueWith(x => { handler.Disconnect(); source.TrySetCanceled(); }, TaskContinuationOptions.OnlyOnCanceled); return(source.Task); }
Task IReceiveEndpointObserver.Ready(ReceiveEndpointReady ready) { _ready.TrySetResult(ready); _handle.Disconnect(); return(TaskUtil.Completed); }
public Task SetReady(ReceiveEndpointReady ready) { _handle.Disconnect(); _registration.Dispose(); _ready.TrySetResult(ready); return(Util.TaskUtil.Completed); }
public static Task <ConsumeContext <T> > SubscribeHandler <T>(this IBus bus, TimeSpan?timeout = null, CancellationToken cancelToken = default) where T : class { if (bus == null) { throw new ArgumentNullException(nameof(bus)); } if (timeout.HasValue && timeout < Timeout.InfiniteTimeSpan) { throw new ArgumentOutOfRangeException(nameof(timeout)); } ConnectHandle handler = null; var cts = CancellationTokenSource.CreateLinkedTokenSource(cancelToken); var lnkCancelToken = cts.Token; var tcs = new TaskCompletionSource <ConsumeContext <T> >(); if (timeout.HasValue && timeout.Value != Timeout.InfiniteTimeSpan) { cts.CancelAfter((new TimeSpan[] { timeout.Value, TimeSpan.FromMilliseconds(1000) }).Max()); } handler = bus.ConnectHandler <T>(context => { cts.Dispose(); if (tcs.TrySetResult(context)) { handler.Disconnect(); } return(Task.CompletedTask); }); if (!tcs.Task.IsCompleted) { lnkCancelToken.Register(() => { cts.Dispose(); if (tcs.TrySetCanceled()) { handler.Disconnect(); } }); } return(tcs.Task); }
public Task PostStop(IBus bus) { _handle?.Disconnect(); _handle = null; return(TaskUtil.Completed); }
public virtual async Task Stop() { try { _receiveEndpointObserver?.Disconnect(); _receiveEndpointObserver = null; _busSendObserver?.Disconnect(); _busSendObserver = null; _inputQueueSendObserver?.Disconnect(); _inputQueueSendObserver = null; _busPublishObserver?.Disconnect(); _busPublishObserver = null; _busConsumeObserver?.Disconnect(); _busConsumeObserver = null; using (var tokenSource = new CancellationTokenSource(TestTimeout)) { await(_busHandle?.StopAsync(tokenSource.Token) ?? TaskUtil.Completed).ConfigureAwait(false); } } catch (Exception ex) { _log.Error("Bus Stop Failed: ", ex); throw; } finally { _busHandle = null; _bus = null; } }
public void Dispose() { Log.Info("Start Dispose DataBus"); _receiveHandle.Disconnect(); _receiveHandle.Dispose(); _consumeHandle.Disconnect(); _consumeHandle.Dispose(); _busControl.Stop(); Log.Info("DataBus Disposed"); }
public void Disconnect() { _handle.Disconnect(); async Task DisposeConsumerFactory() { await _factory.DisposeAsync().ConfigureAwait(false); } Task.Run(DisposeConsumerFactory); }
async Task ReceiveTransportHandle.Stop(CancellationToken cancellationToken) { LogContext.SetCurrentIfNull(_transport._context.LogContext); await _transport.Stop("Stop", cancellationToken).ConfigureAwait(false); _consumerHandle.Disconnect(); var completed = new ReceiveTransportCompletedEvent(_transport._inputAddress, _transport._dispatcher.GetDeliveryMetrics()); await _transport._context.TransportObservers.Completed(completed).ConfigureAwait(false); }
/// <summary> /// Subscribes a message handler to the bus, which is disconnected after the message /// is received. /// </summary> /// <typeparam name="T">The message type</typeparam> /// <returns>An awaitable task completed when the message is received</returns> protected Task <ConsumeContext <T> > SubscribeHandler <T>() where T : class { var source = new TaskCompletionSource <ConsumeContext <T> >(); ConnectHandle handler = null; handler = Bus.ConnectHandler <T>(async context => { source.SetResult(context); handler.Disconnect(); }); TestCancelledTask.ContinueWith(x => { source.TrySetCanceled(); handler.Disconnect(); }, TaskContinuationOptions.OnlyOnCanceled); return(source.Task); }
protected override async Task StopAgent(StopContext context) { LogContext.SetCurrentIfNull(_context.LogContext); var metrics = _dispatcher.GetMetrics(); var completed = new ReceiveTransportCompletedEvent(_context.InputAddress, metrics); await _context.TransportObservers.Completed(completed).ConfigureAwait(false); LogContext.Debug?.Log("Consumer completed {InputAddress}: {DeliveryCount} received, {ConcurrentDeliveryCount} concurrent", _context.InputAddress, metrics.DeliveryCount, metrics.ConcurrentDeliveryCount); _consumerHandle.Disconnect(); await base.StopAgent(context).ConfigureAwait(false); }
async Task ReceiveTransportHandle.Stop(CancellationToken cancellationToken) { LogContext.SetCurrentIfNull(_transport._context.LogContext); await _transport.Stop("Stop", cancellationToken).ConfigureAwait(false); _consumerHandle.Disconnect(); var metrics = _transport._dispatcher.GetMetrics(); var completed = new ReceiveTransportCompletedEvent(_transport._inputAddress, metrics); await _transport._context.TransportObservers.Completed(completed).ConfigureAwait(false); LogContext.Debug?.Log("Consumer completed {InputAddress}: {DeliveryCount} received, {ConcurrentDeliveryCount} concurrent", _transport._inputAddress, metrics.DeliveryCount, metrics.ConcurrentDeliveryCount); }
public async Task Should_remain_in_order() { var values = new List <int>(); var observable = new AsyncObservable <List <int> >(); ConnectHandle observer = observable.Connect(values); for (int i = 0; i < 10000; i++) { int index = i; observable.Notify(async x => x.Add(index)); } observer.Disconnect(); Assert.AreEqual(10000, values.Count); Assert.IsTrue(values.SequenceEqual(Enumerable.Range(0, 10000).Select(x => x).ToList())); }
public Observer(IReceiveEndpointObserverConnector endpoint, CancellationToken cancellationToken) { _cancellationToken = cancellationToken; _ready = TaskUtil.GetTask <ReceiveEndpointReady>(); if (cancellationToken.CanBeCanceled) { _registration = cancellationToken.Register(() => { if (_faulted != null) { _handle?.Disconnect(); _ready.TrySetExceptionOnThreadPool(_faulted.Exception); } _registration.Dispose(); }); } _handle = endpoint.ConnectReceiveEndpointObserver(this); }
public EndpointHandle(ReceiveEndpoint endpoint, IReceiveTransport transport, StartObserver startObserver, CancellationToken cancellationToken) { _endpoint = endpoint; _transport = transport; _cancellationToken = cancellationToken; _ready = Util.TaskUtil.GetTask <ReceiveEndpointReady>(); if (cancellationToken.CanBeCanceled) { _registration = cancellationToken.Register(() => { if (_faulted != null) { _handle?.Disconnect(); _ready.TrySetException(_faulted.Exception); } _registration.Dispose(); }); } _handle = startObserver.ConnectEndpointHandle(this); }
public void Disconnect() { _handle.Disconnect(); }
public void SeparatePublishFromSendTopology() { _publishToSendTopologyHandle?.Disconnect(); }
public void Disconnect() { _registration.Dispose(); _handle.Disconnect(); }
Task IReceiveEndpointObserver.Ready(ReceiveEndpointReady ready) { _handle.Disconnect(); return(Task.Factory.StartNew(() => _ready.TrySetResult(ready), CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default)); }