Esempio n. 1
0
        public override async Task <HostHandle> Start()
        {
            var handlesReady = new TaskCompletionSource <HostReceiveEndpointHandle[]>();
            var hostStarted  = new TaskCompletionSource <bool>();

            IPipe <HttpHostContext> connectionPipe = Pipe.ExecuteAsync <HttpHostContext>(async context =>
            {
                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Connection established to {0}", Settings.Host);
                }

                try
                {
                    await handlesReady.Task.ConfigureAwait(false);

                    await context.Start(context.CancellationToken).ConfigureAwait(false);

                    hostStarted.TrySetResult(true);

                    await Completed.ConfigureAwait(false);
                }
                catch (OperationCanceledException ex)
                {
                    hostStarted.TrySetException(ex);
                }
                catch (Exception ex)
                {
                    hostStarted.TrySetException(ex);
                    throw;
                }
            });

            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting connection to {0}", Settings.Host);
            }

            var connectionTask = HttpHostContextSupervisor.Send(connectionPipe, Stopping);

            HostReceiveEndpointHandle[] handles = ReceiveEndpoints.StartEndpoints();

            var hostHandle = new Handle(handles, this, _httpHostContextSupervisor, connectionTask);

            await hostHandle.Ready.ConfigureAwait(false);

            handlesReady.TrySetResult(handles);

            await hostStarted.Task.ConfigureAwait(false);

            return(hostHandle);
        }
Esempio n. 2
0
        public async Task <HostHandle> Start()
        {
            if (_handle != null)
            {
                throw new MassTransitException($"The host was already started: {_settings}");
            }

            HostReceiveEndpointHandle[] handles = ReceiveEndpoints.StartEndpoints();

            _handle = new Handle(handles, this, ConnectionCache);

            return(_handle);
        }
Esempio n. 3
0
        public override async Task <HostHandle> Start(CancellationToken cancellationToken)
        {
            LogContext.Debug?.Log("Starting host: {HostAddress}", _hostConfiguration.HostAddress);

            DefaultLogContext = LogContext.Current;
            SendLogContext    = LogContext.Current.CreateLogContext(LogCategoryName.Transport.Send);
            ReceiveLogContext = LogContext.Current.CreateLogContext(LogCategoryName.Transport.Receive);

            var handlesReady = TaskUtil.GetTask <HostReceiveEndpointHandle[]>();
            var hostStarted  = TaskUtil.GetTask <bool>();

            IPipe <HttpHostContext> connectionPipe = Pipe.ExecuteAsync <HttpHostContext>(async context =>
            {
                try
                {
                    await handlesReady.Task.ConfigureAwait(false);

                    await context.Start(context.CancellationToken).ConfigureAwait(false);

                    hostStarted.TrySetResult(true);

                    await Completed.ConfigureAwait(false);
                }
                catch (OperationCanceledException ex)
                {
                    hostStarted.TrySetException(ex);
                }
                catch (Exception ex)
                {
                    hostStarted.TrySetException(ex);
                    throw;
                }
            });

            var connectionTask = HttpHostContextSupervisor.Send(connectionPipe, Stopping);

            HostReceiveEndpointHandle[] handles = ReceiveEndpoints.StartEndpoints(cancellationToken);

            HostHandle hostHandle = new StartHostHandle(this, handles, GetAgentHandles());

            await hostHandle.Ready.ConfigureAwait(false);

            handlesReady.TrySetResult(handles);

            await hostStarted.Task.ConfigureAwait(false);

            return(hostHandle);
        }
Esempio n. 4
0
        public HostHandle Start(CancellationToken cancellationToken)
        {
            if (_handle != null)
            {
                LogContext.Warning?.Log("Start called, but the host was already started: {Address} ({Reason})", _hostConfiguration.HostAddress,
                                        "Already Started");

                return(_handle);
            }

            LogContext.SetCurrentIfNull(_hostConfiguration.LogContext);

            LogContext.Debug?.Log("Starting host: {HostAddress}", _hostConfiguration.HostAddress);

            HostReceiveEndpointHandle[] handles = ReceiveEndpoints.StartEndpoints(cancellationToken);

            HostRiderHandle[] riders = _riderCollection.StartRiders(cancellationToken);

            _handle = new StartHostHandle(this, handles, riders);

            return(_handle);
        }