Beispiel #1
0
        public HttpHost(HttpHostSettings hostSettings, IHostTopology topology)
        {
            _settings = hostSettings;
            Topology  = topology;

            ReceiveEndpoints = new ReceiveEndpointCollection();

            _httpHostCache = new HttpHostCache(Settings);
        }
Beispiel #2
0
        public 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
                {
                    HostReceiveEndpointHandle[] endpointHandles = 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 = HttpHostCache.Send(connectionPipe, Stopping);

            HostReceiveEndpointHandle[] handles = ReceiveEndpoints.StartEndpoints();

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

            await hostHandle.Ready.ConfigureAwait(false);

            handlesReady.TrySetResult(handles);

            await hostStarted.Task.ConfigureAwait(false);

            return(hostHandle);
        }