public async Task StopAsync(CancellationToken cancellationToken = new CancellationToken())
            {
                if (_stopped)
                {
                    return;
                }

                await _busObserver.PreStop(_bus).ConfigureAwait(false);

                try
                {
                    foreach (var observerHandle in _observerHandles)
                    {
                        observerHandle.Disconnect();
                    }

                    await Task.WhenAll(_endpointHandles.Select(x => x.Stop(cancellationToken))).ConfigureAwait(false);

                    await Task.WhenAll(_hostHandles.Select(x => x.Stop(cancellationToken))).ConfigureAwait(false);

                    await _busObserver.PostStop(_bus).ConfigureAwait(false);
                }
                catch (Exception exception)
                {
                    await _busObserver.StopFaulted(_bus, exception).ConfigureAwait(false);

                    throw;
                }

                _stopped = true;
            }
示例#2
0
            public async Task StopAsync(CancellationToken cancellationToken)
            {
                if (_stopped)
                {
                    return;
                }

                await _busObserver.PreStop(_bus).ConfigureAwait(false);

                try
                {
                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Stopping hosts...");
                    }

                    await Task.WhenAll(_hostHandles.Select(x => x.Stop(cancellationToken))).ConfigureAwait(false);

                    await _busObserver.PostStop(_bus).ConfigureAwait(false);
                }
                catch (Exception exception)
                {
                    await _busObserver.StopFaulted(_bus, exception).ConfigureAwait(false);

                    throw;
                }

                _stopped = true;
            }
示例#3
0
            public async Task StopAsync(CancellationToken cancellationToken)
            {
                LogContext.SetCurrentIfNull(_logContext);

                if (_stopped)
                {
                    return;
                }

                await _busObserver.PreStop(_bus).ConfigureAwait(false);

                try
                {
                    await _hostHandle.Stop(cancellationToken).ConfigureAwait(false);

                    await _busObserver.PostStop(_bus).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                }
                catch (Exception exception)
                {
                    await _busObserver.StopFaulted(_bus, exception).ConfigureAwait(false);

                    LogContext.Warning?.Log(exception, "Bus stop faulted: {HostAddress}", _host.Address);

                    throw;
                }

                LogContext.Info?.Log("Bus stopped: {HostAddress}", _host.Address);

                _stopped = true;
            }
示例#4
0
            public void Stop(CancellationToken cancellationToken)
            {
                if (_stopped)
                {
                    return;
                }

                TaskUtil.Await(() => _busObserver.PreStop(_bus), cancellationToken);

                try
                {
                    foreach (var observerHandle in _observerHandles)
                    {
                        observerHandle.Disconnect();
                    }

                    TaskUtil.Await(() => Task.WhenAll(_endpointHandles.Select(x => x.Stop(cancellationToken))), cancellationToken);

                    TaskUtil.Await(() => Task.WhenAll(_hostHandles.Select(x => x.Stop(cancellationToken))), cancellationToken);

                    TaskUtil.Await(() => _busObserver.PostStop(_bus), cancellationToken);
                }
                catch (Exception exception)
                {
                    TaskUtil.Await(() => _busObserver.StopFaulted(_bus, exception), cancellationToken);

                    throw;
                }

                _stopped = true;
            }
示例#5
0
            public async Task StopAsync(CancellationToken cancellationToken)
            {
                LogContext.SetCurrentIfNull(_logContext);

                if (_stopped)
                {
                    return;
                }

                await _busObserver.PreStop(_bus).ConfigureAwait(false);

                try
                {
                    var hostAddress = _hostHandle.Ready.IsCompletedSuccessfully()
                        ? _hostHandle.Ready.GetAwaiter().GetResult().HostAddress
                        : new Uri(_bus.Address.GetLeftPart(UriPartial.Authority));

                    LogContext.Debug?.Log("Stopping host: {HostAddress}", hostAddress);

                    await _hostHandle.Stop(cancellationToken).ConfigureAwait(false);

                    await _busObserver.PostStop(_bus).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                }
                catch (Exception exception)
                {
                    await _busObserver.StopFaulted(_bus, exception).ConfigureAwait(false);

                    LogContext.Warning?.Log(exception, "Bus stop faulted");

                    throw;
                }

                _stopped = true;
            }