React to hosting changes to IApplicationLifetime

This commit is contained in:
David Fowler 2015-10-13 03:46:34 -07:00
parent dcdf778bcc
commit ef38f5589d
5 changed files with 40 additions and 15 deletions

View File

@ -1,14 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Server.Kestrel.Networking;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.ExceptionServices; using System.Runtime.ExceptionServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.Dnx.Runtime; using Microsoft.AspNet.Server.Kestrel.Networking;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Microsoft.AspNet.Server.Kestrel namespace Microsoft.AspNet.Server.Kestrel
@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel
{ {
private static Action<object, object> _objectCallbackAdapter = (callback, state) => ((Action<object>)callback).Invoke(state); private static Action<object, object> _objectCallbackAdapter = (callback, state) => ((Action<object>)callback).Invoke(state);
private KestrelEngine _engine; private KestrelEngine _engine;
private readonly IApplicationShutdown _appShutdown; private readonly IApplicationLifetime _appLifetime;
private Thread _thread; private Thread _thread;
private UvLoopHandle _loop; private UvLoopHandle _loop;
private UvAsyncHandle _post; private UvAsyncHandle _post;
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel
public KestrelThread(KestrelEngine engine) public KestrelThread(KestrelEngine engine)
{ {
_engine = engine; _engine = engine;
_appShutdown = engine.AppShutdown; _appLifetime = engine.AppLifetime;
_log = engine.Log; _log = engine.Log;
_loop = new UvLoopHandle(_log); _loop = new UvLoopHandle(_log);
_post = new UvAsyncHandle(_log); _post = new UvAsyncHandle(_log);
@ -232,7 +232,7 @@ namespace Microsoft.AspNet.Server.Kestrel
_closeError = ExceptionDispatchInfo.Capture(ex); _closeError = ExceptionDispatchInfo.Capture(ex);
// Request shutdown so we can rethrow this exception // Request shutdown so we can rethrow this exception
// in Stop which should be observable. // in Stop which should be observable.
_appShutdown.RequestShutdown(); _appLifetime.RequestShutdown();
} }
} }

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Hosting.Server;
using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Server.Features; using Microsoft.AspNet.Server.Features;
@ -20,13 +21,13 @@ namespace Microsoft.AspNet.Server.Kestrel
public class ServerFactory : IServerFactory public class ServerFactory : IServerFactory
{ {
private readonly ILibraryManager _libraryManager; private readonly ILibraryManager _libraryManager;
private readonly IApplicationShutdown _appShutdownService; private readonly IApplicationLifetime _appLifetime;
private readonly ILogger _logger; private readonly ILogger _logger;
public ServerFactory(ILibraryManager libraryManager, IApplicationShutdown appShutdownService, ILoggerFactory loggerFactory) public ServerFactory(ILibraryManager libraryManager, IApplicationLifetime appLifetime, ILoggerFactory loggerFactory)
{ {
_libraryManager = libraryManager; _libraryManager = libraryManager;
_appShutdownService = appShutdownService; _appLifetime = appLifetime;
_logger = loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"); _logger = loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel");
} }
@ -57,7 +58,7 @@ namespace Microsoft.AspNet.Server.Kestrel
var dateHeaderValueManager = new DateHeaderValueManager(); var dateHeaderValueManager = new DateHeaderValueManager();
var engine = new KestrelEngine(_libraryManager, new ServiceContext var engine = new KestrelEngine(_libraryManager, new ServiceContext
{ {
AppShutdown = _appShutdownService, AppLifetime = _appLifetime,
Log = new KestrelTrace(_logger), Log = new KestrelTrace(_logger),
DateHeaderValueManager = dateHeaderValueManager, DateHeaderValueManager = dateHeaderValueManager,
ConnectionFilter = information.ConnectionFilter ConnectionFilter = information.ConnectionFilter

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Filter;
using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Http;
using Microsoft.AspNet.Server.Kestrel.Infrastructure; using Microsoft.AspNet.Server.Kestrel.Infrastructure;
using Microsoft.Dnx.Runtime;
namespace Microsoft.AspNet.Server.Kestrel namespace Microsoft.AspNet.Server.Kestrel
{ {
@ -17,14 +17,14 @@ namespace Microsoft.AspNet.Server.Kestrel
public ServiceContext(ServiceContext context) public ServiceContext(ServiceContext context)
{ {
AppShutdown = context.AppShutdown; AppLifetime = context.AppLifetime;
Memory = context.Memory; Memory = context.Memory;
Log = context.Log; Log = context.Log;
DateHeaderValueManager = context.DateHeaderValueManager; DateHeaderValueManager = context.DateHeaderValueManager;
ConnectionFilter = context.ConnectionFilter; ConnectionFilter = context.ConnectionFilter;
} }
public IApplicationShutdown AppShutdown { get; set; } public IApplicationLifetime AppLifetime { get; set; }
public IMemoryPool Memory { get; set; } public IMemoryPool Memory { get; set; }

View File

@ -3,12 +3,36 @@
using System; using System;
using System.Threading; using System.Threading;
using Microsoft.Dnx.Runtime; using Microsoft.AspNet.Hosting;
namespace Microsoft.AspNet.Server.KestrelTests namespace Microsoft.AspNet.Server.KestrelTests
{ {
public class ShutdownNotImplemented : IApplicationShutdown public class ShutdownNotImplemented : IApplicationLifetime
{ {
public CancellationToken ApplicationStarted
{
get
{
throw new NotImplementedException();
}
}
public CancellationToken ApplicationStopped
{
get
{
throw new NotImplementedException();
}
}
public CancellationToken ApplicationStopping
{
get
{
throw new NotImplementedException();
}
}
public CancellationToken ShutdownRequested public CancellationToken ShutdownRequested
{ {
get get

View File

@ -6,7 +6,7 @@ namespace Microsoft.AspNet.Server.KestrelTests
{ {
public TestServiceContext() public TestServiceContext()
{ {
AppShutdown = new ShutdownNotImplemented(); AppLifetime = new ShutdownNotImplemented();
Log = new TestKestrelTrace(); Log = new TestKestrelTrace();
DateHeaderValueManager = new TestDateHeaderValueManager(); DateHeaderValueManager = new TestDateHeaderValueManager();
} }