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; }
public Task <ISendEndpoint> GetPublishSendEndpoint <T>() where T : class { LogContext.SetCurrentIfNull(_logContext); return(_receiveEndpoint.GetPublishSendEndpoint <T>()); }
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)); }
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); }
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); }
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; }
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; }
ConnectHandle IEndpointConfigurationObserverConnector.ConnectEndpointConfigurationObserver(IEndpointConfigurationObserver observer) { LogContext.SetCurrentIfNull(_logContext); return(_host.ConnectEndpointConfigurationObserver(observer)); }
public ConnectHandle ConnectSendObserver(ISendObserver observer) { LogContext.SetCurrentIfNull(_logContext); return(_host.ConnectSendObserver(observer)); }
ConnectHandle IReceiveEndpointObserverConnector.ConnectReceiveEndpointObserver(IReceiveEndpointObserver observer) { LogContext.SetCurrentIfNull(_logContext); return(_host.ConnectReceiveEndpointObserver(observer)); }
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(); } }
Task <ISendEndpoint> ISendEndpointProvider.GetSendEndpoint(Uri address) { LogContext.SetCurrentIfNull(_logContext); return(_receiveEndpoint.GetSendEndpoint(address)); }
Task IPublishEndpoint.Publish <T>(object values, IPipe <PublishContext> publishPipe, CancellationToken cancellationToken) { LogContext.SetCurrentIfNull(_logContext); return(_publishEndpoint.Publish <T>(values, publishPipe, cancellationToken)); }
Task IPublishEndpoint.Publish(object message, Type messageType, IPipe <PublishContext> publishPipe, CancellationToken cancellationToken) { LogContext.SetCurrentIfNull(_logContext); return(_publishEndpoint.Publish(message, messageType, publishPipe, cancellationToken)); }
Task IPublishEndpoint.Publish(object message, CancellationToken cancellationToken) { LogContext.SetCurrentIfNull(_logContext); return(_publishEndpoint.Publish(message, cancellationToken)); }
Task IPublishEndpoint.Publish <T>(T message, IPipe <PublishContext <T> > publishPipe, CancellationToken cancellationToken) { LogContext.SetCurrentIfNull(_logContext); return(_publishEndpoint.Publish(message, publishPipe, cancellationToken)); }
ConnectHandle IConsumeMessageObserverConnector.ConnectConsumeMessageObserver <T>(IConsumeMessageObserver <T> observer) { LogContext.SetCurrentIfNull(_logContext); return(_host.ConnectConsumeMessageObserver(observer)); }