コード例 #1
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;
            }
コード例 #2
0
        public Task <ISendEndpoint> GetPublishSendEndpoint <T>()
            where T : class
        {
            LogContext.SetCurrentIfNull(_logContext);

            return(_receiveEndpoint.GetPublishSendEndpoint <T>());
        }
コード例 #3
0
        public Task StopAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            LogContext.SetCurrentIfNull(_logContext);

            if (_busHandle == null)
            {
                LogContext.Warning?.Log("Failed to stop bus: {Address} ({Reason})", Address, "Not Started");
                return(TaskUtil.Completed);
            }

            return(_busHandle.StopAsync(cancellationToken));
        }
コード例 #4
0
        ConnectHandle IConsumePipeConnector.ConnectConsumePipe <T>(IPipe <ConsumeContext <T> > pipe, ConnectPipeOptions options)
        {
            LogContext.SetCurrentIfNull(_logContext);

            var handle = _consumePipe.ConnectConsumePipe(pipe, options);

            if (_busHandle != null && !_receiveEndpoint.Started.IsCompletedSuccessfully())
            {
                TaskUtil.Await(_receiveEndpoint.Started);
            }

            return(handle);
        }
コード例 #5
0
        ConnectHandle IRequestPipeConnector.ConnectRequestPipe <T>(Guid requestId, IPipe <ConsumeContext <T> > pipe)
        {
            LogContext.SetCurrentIfNull(_logContext);

            var handle = _consumePipe.ConnectRequestPipe(requestId, pipe);

            if (_busHandle != null && !_receiveEndpoint.Started.IsCompletedSuccessfully())
            {
                TaskUtil.Await(_receiveEndpoint.Started);
            }

            return(handle);
        }
コード例 #6
0
        public async Task StopAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            LogContext.SetCurrentIfNull(_logContext);

            if (_busHandle == null)
            {
                LogContext.Warning?.Log("Failed to stop bus: {Address} ({Reason})", Address, "Not Started");
                return;
            }

            await _busHandle.StopAsync(cancellationToken).ConfigureAwait(false);

            _busHandle = null;
        }
コード例 #7
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;
            }
コード例 #8
0
        ConnectHandle IEndpointConfigurationObserverConnector.ConnectEndpointConfigurationObserver(IEndpointConfigurationObserver observer)
        {
            LogContext.SetCurrentIfNull(_logContext);

            return(_host.ConnectEndpointConfigurationObserver(observer));
        }
コード例 #9
0
        public ConnectHandle ConnectSendObserver(ISendObserver observer)
        {
            LogContext.SetCurrentIfNull(_logContext);

            return(_host.ConnectSendObserver(observer));
        }
コード例 #10
0
        ConnectHandle IReceiveEndpointObserverConnector.ConnectReceiveEndpointObserver(IReceiveEndpointObserver observer)
        {
            LogContext.SetCurrentIfNull(_logContext);

            return(_host.ConnectReceiveEndpointObserver(observer));
        }
コード例 #11
0
        public async Task <BusHandle> StartAsync(CancellationToken cancellationToken)
        {
            LogContext.SetCurrentIfNull(_logContext);

            if (_busHandle != null)
            {
                LogContext.Warning?.Log("StartAsync called, but the bus was already started: {Address} ({Reason})", Address, "Already Started");
                return(_busHandle);
            }

            await _busObservable.PreStart(this).ConfigureAwait(false);

            Handle busHandle = null;

            CancellationTokenSource tokenSource = null;

            try
            {
                if (cancellationToken == default)
                {
                    tokenSource       = new CancellationTokenSource(TimeSpan.FromSeconds(60));
                    cancellationToken = tokenSource.Token;
                }

                var hostHandle = _host.Start(cancellationToken);

                busHandle = new Handle(_host, hostHandle, this, _busObservable, _logContext);

                try
                {
                    await busHandle.Ready.OrCanceled(cancellationToken).ConfigureAwait(false);
                }
                catch (OperationCanceledException exception) when(exception.CancellationToken == cancellationToken)
                {
                    try
                    {
                        await busHandle.StopAsync(TimeSpan.FromSeconds(30)).ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        LogContext.Warning?.Log(ex, "Bus start faulted, and failed to stop host");
                    }

                    await busHandle.Ready.ConfigureAwait(false);
                }

                await _busObservable.PostStart(this, busHandle.Ready).ConfigureAwait(false);

                _busHandle = busHandle;

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

                return(_busHandle);
            }
            catch (Exception ex)
            {
                try
                {
                    if (busHandle != null)
                    {
                        LogContext.Debug?.Log(ex, "Bus start faulted, stopping host");

                        await busHandle.StopAsync(cancellationToken).ConfigureAwait(false);
                    }
                }
                catch (OperationCanceledException)
                {
                }
                catch (Exception stopException)
                {
                    LogContext.Warning?.Log(stopException, "Bus start faulted, and failed to stop host");
                }

                await _busObservable.StartFaulted(this, ex).ConfigureAwait(false);

                throw;
            }
            finally
            {
                tokenSource?.Dispose();
            }
        }
コード例 #12
0
        Task <ISendEndpoint> ISendEndpointProvider.GetSendEndpoint(Uri address)
        {
            LogContext.SetCurrentIfNull(_logContext);

            return(_receiveEndpoint.GetSendEndpoint(address));
        }
コード例 #13
0
        Task IPublishEndpoint.Publish <T>(object values, IPipe <PublishContext> publishPipe, CancellationToken cancellationToken)
        {
            LogContext.SetCurrentIfNull(_logContext);

            return(_publishEndpoint.Publish <T>(values, publishPipe, cancellationToken));
        }
コード例 #14
0
        Task IPublishEndpoint.Publish(object message, Type messageType, IPipe <PublishContext> publishPipe, CancellationToken cancellationToken)
        {
            LogContext.SetCurrentIfNull(_logContext);

            return(_publishEndpoint.Publish(message, messageType, publishPipe, cancellationToken));
        }
コード例 #15
0
        Task IPublishEndpoint.Publish(object message, CancellationToken cancellationToken)
        {
            LogContext.SetCurrentIfNull(_logContext);

            return(_publishEndpoint.Publish(message, cancellationToken));
        }
コード例 #16
0
        Task IPublishEndpoint.Publish <T>(T message, IPipe <PublishContext <T> > publishPipe, CancellationToken cancellationToken)
        {
            LogContext.SetCurrentIfNull(_logContext);

            return(_publishEndpoint.Publish(message, publishPipe, cancellationToken));
        }
コード例 #17
0
        ConnectHandle IConsumeMessageObserverConnector.ConnectConsumeMessageObserver <T>(IConsumeMessageObserver <T> observer)
        {
            LogContext.SetCurrentIfNull(_logContext);

            return(_host.ConnectConsumeMessageObserver(observer));
        }