public IPipeContextAgent <ClientContext> CreateContext(ISupervisor supervisor) { var client = new HttpClient(); ClientContext clientContext = new HttpClientContext(client, _receivePipe, supervisor.Stopped); return(supervisor.AddContext(clientContext)); }
IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor) { Task <ConnectionContext> context = Task.FromResult(CreateConnectionContext(supervisor)); IPipeContextAgent <ConnectionContext> contextHandle = supervisor.AddContext(context); return(contextHandle); }
IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor) { var context = Task.Run(() => CreateConnection(supervisor), supervisor.Stopping); IPipeContextAgent <ConnectionContext> contextHandle = supervisor.AddContext(context); return(contextHandle); }
IPipeContextAgent <MessagingFactoryContext> IPipeContextFactory <MessagingFactoryContext> .CreateContext(ISupervisor supervisor) { var context = Task.Factory.StartNew(() => CreateConnection(supervisor), supervisor.Stopping, TaskCreationOptions.None, TaskScheduler.Default) .Unwrap(); IPipeContextAgent <MessagingFactoryContext> contextHandle = supervisor.AddContext(context); return(contextHandle); }
IPipeContextAgent <HttpHostContext> IPipeContextFactory <HttpHostContext> .CreateContext(ISupervisor supervisor) { HttpHostContext hostContext = new KestrelHttpHostContext(_configuration, supervisor.Stopped); hostContext.GetOrAddPayload(() => _configuration); IPipeContextAgent <HttpHostContext> contextHandle = supervisor.AddContext(hostContext); return(contextHandle); }
public IPipeContextAgent <SimpleContext> CreateContext(ISupervisor supervisor) { var context = new SimpleContextImpl() { Value = Interlocked.Increment(ref _id).ToString() }; IPipeContextAgent <SimpleContext> contextHandle = supervisor.AddContext <SimpleContext>(context); void SimpleContextOnInvalid(object sender, EventArgs args) => contextHandle.DisposeAsync(); context.OnInvalid += SimpleContextOnInvalid; return(contextHandle); }
IPipeContextAgent <HttpHostContext> IPipeContextFactory <HttpHostContext> .CreateContext(ISupervisor supervisor) { if (_log.IsDebugEnabled) { _log.DebugFormat("Created: {0}", _configuration.HostAddress); } HttpHostContext hostContext = new KestrelHttpHostContext(_configuration, supervisor.Stopped); hostContext.GetOrAddPayload(() => _configuration); IPipeContextAgent <HttpHostContext> contextHandle = supervisor.AddContext(hostContext); return(contextHandle); }
IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor) { var context = Task.Run(() => CreateConnection(supervisor), supervisor.Stopping); IPipeContextAgent <ConnectionContext> contextHandle = supervisor.AddContext(context); void HandleConnectionException(Exception exception) { contextHandle.Stop($"Connection Exception: {exception}"); } context.ContinueWith(task => { task.Result.Connection.ExceptionListener += HandleConnectionException; contextHandle.Completed.ContinueWith(_ => task.Result.Connection.ExceptionListener -= HandleConnectionException); }, TaskContinuationOptions.OnlyOnRanToCompletion); return(contextHandle); }
IPipeContextAgent <HttpHostContext> IPipeContextFactory <HttpHostContext> .CreateContext(ISupervisor supervisor) { if (_log.IsDebugEnabled) { _log.DebugFormat("Connecting: {0}", _settings.Description); } if (_log.IsDebugEnabled) { _log.DebugFormat("Connected: {0} (address: {1}, local: {2}", _settings.Description, _settings.Host, _settings.Port); } HttpHostContext hostContext = new KestrelHttpHostContext(_settings, supervisor.Stopped); hostContext.GetOrAddPayload(() => _settings); IPipeContextAgent <HttpHostContext> contextHandle = supervisor.AddContext(hostContext); return(contextHandle); }
IPipeContextAgent <ConnectionContext> IPipeContextFactory <ConnectionContext> .CreateContext(ISupervisor supervisor) { Task <ConnectionContext> context = Task.Run(() => CreateConnection(supervisor), supervisor.Stopped); IPipeContextAgent <ConnectionContext> contextHandle = supervisor.AddContext(context); void HandleShutdown(object sender, ShutdownEventArgs args) { if (args.Initiator != ShutdownInitiator.Application) { contextHandle.Stop(args.ReplyText); } } context.ContinueWith(task => { task.Result.Connection.ConnectionShutdown += HandleShutdown; contextHandle.Completed.ContinueWith(_ => task.Result.Connection.ConnectionShutdown -= HandleShutdown); }, TaskContinuationOptions.OnlyOnRanToCompletion); return(contextHandle); }