Inheritance: IOwinHostCache, IProbeSite
Exemple #1
0
        public HttpHost(HttpHostSettings hostSettings)
        {
            _settings = hostSettings;

            //exception Filter
            ReceiveEndpoints = new ReceiveEndpointCollection();

            //connection retry policy

            _supervisor = new TaskSupervisor($"{TypeMetadataCache<HttpHost>.ShortName} - {Settings.Host}");

            _owinHostCache = new OwinHostCache(Settings, _supervisor);
        }
Exemple #2
0
        public async Task <HostHandle> Start()
        {
            TaskCompletionSource <HostReceiveEndpointHandle[]> handlesReady = new TaskCompletionSource <HostReceiveEndpointHandle[]>();
            TaskCompletionSource <bool> hostStarted = new TaskCompletionSource <bool>();

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

                try
                {
                    var endpointHandles = await handlesReady.Task.ConfigureAwait(false);

                    context.StartHost();

                    hostStarted.TrySetResult(true);

                    //Wait until someone shuts down the bus - Parked thread.
                    await _supervisor.StopRequested.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 = OwinHostCache.Send(connectionPipe, _supervisor.StoppingToken);

            HostReceiveEndpointHandle[] handles = ReceiveEndpoints.StartEndpoints();

            handlesReady.TrySetResult(handles);

            await hostStarted.Task.ConfigureAwait(false);

            return(new Handle(connectionTask, handles, _supervisor, this));
        }