From ef38f5589ddb40171902662301baa2151f945c8f Mon Sep 17 00:00:00 2001 From: David Fowler Date: Tue, 13 Oct 2015 03:46:34 -0700 Subject: [PATCH] React to hosting changes to IApplicationLifetime --- .../Infrastructure/KestrelThread.cs | 10 +++---- .../ServerFactory.cs | 9 +++--- .../ServiceContext.cs | 6 ++-- .../ShutdownNotImplemented.cs | 28 +++++++++++++++++-- .../TestServiceContext.cs | 2 +- 5 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index 3c72d00581..b989f2762b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -1,14 +1,14 @@ // 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. -using Microsoft.AspNet.Server.Kestrel.Networking; using System; using System.Collections.Generic; using System.Runtime.ExceptionServices; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.Dnx.Runtime; +using Microsoft.AspNet.Server.Kestrel.Networking; using Microsoft.Extensions.Logging; namespace Microsoft.AspNet.Server.Kestrel @@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Server.Kestrel { private static Action _objectCallbackAdapter = (callback, state) => ((Action)callback).Invoke(state); private KestrelEngine _engine; - private readonly IApplicationShutdown _appShutdown; + private readonly IApplicationLifetime _appLifetime; private Thread _thread; private UvLoopHandle _loop; private UvAsyncHandle _post; @@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Server.Kestrel public KestrelThread(KestrelEngine engine) { _engine = engine; - _appShutdown = engine.AppShutdown; + _appLifetime = engine.AppLifetime; _log = engine.Log; _loop = new UvLoopHandle(_log); _post = new UvAsyncHandle(_log); @@ -232,7 +232,7 @@ namespace Microsoft.AspNet.Server.Kestrel _closeError = ExceptionDispatchInfo.Capture(ex); // Request shutdown so we can rethrow this exception // in Stop which should be observable. - _appShutdown.RequestShutdown(); + _appLifetime.RequestShutdown(); } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs index c804e4c233..2abaf71ecf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerFactory.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Hosting.Server; using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Server.Features; @@ -20,13 +21,13 @@ namespace Microsoft.AspNet.Server.Kestrel public class ServerFactory : IServerFactory { private readonly ILibraryManager _libraryManager; - private readonly IApplicationShutdown _appShutdownService; + private readonly IApplicationLifetime _appLifetime; private readonly ILogger _logger; - public ServerFactory(ILibraryManager libraryManager, IApplicationShutdown appShutdownService, ILoggerFactory loggerFactory) + public ServerFactory(ILibraryManager libraryManager, IApplicationLifetime appLifetime, ILoggerFactory loggerFactory) { _libraryManager = libraryManager; - _appShutdownService = appShutdownService; + _appLifetime = appLifetime; _logger = loggerFactory.CreateLogger("Microsoft.AspNet.Server.Kestrel"); } @@ -57,7 +58,7 @@ namespace Microsoft.AspNet.Server.Kestrel var dateHeaderValueManager = new DateHeaderValueManager(); var engine = new KestrelEngine(_libraryManager, new ServiceContext { - AppShutdown = _appShutdownService, + AppLifetime = _appLifetime, Log = new KestrelTrace(_logger), DateHeaderValueManager = dateHeaderValueManager, ConnectionFilter = information.ConnectionFilter diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs index 317cfcf274..b777101539 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServiceContext.cs @@ -1,10 +1,10 @@ // 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. +using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Server.Kestrel.Filter; using Microsoft.AspNet.Server.Kestrel.Http; using Microsoft.AspNet.Server.Kestrel.Infrastructure; -using Microsoft.Dnx.Runtime; namespace Microsoft.AspNet.Server.Kestrel { @@ -17,14 +17,14 @@ namespace Microsoft.AspNet.Server.Kestrel public ServiceContext(ServiceContext context) { - AppShutdown = context.AppShutdown; + AppLifetime = context.AppLifetime; Memory = context.Memory; Log = context.Log; DateHeaderValueManager = context.DateHeaderValueManager; ConnectionFilter = context.ConnectionFilter; } - public IApplicationShutdown AppShutdown { get; set; } + public IApplicationLifetime AppLifetime { get; set; } public IMemoryPool Memory { get; set; } diff --git a/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs b/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs index 5d32828583..4e7b084e93 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/ShutdownNotImplemented.cs @@ -3,12 +3,36 @@ using System; using System.Threading; -using Microsoft.Dnx.Runtime; +using Microsoft.AspNet.Hosting; 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 { get diff --git a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs index 51fe80d8a9..64f2018fdb 100644 --- a/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs +++ b/test/Microsoft.AspNet.Server.KestrelTests/TestServiceContext.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNet.Server.KestrelTests { public TestServiceContext() { - AppShutdown = new ShutdownNotImplemented(); + AppLifetime = new ShutdownNotImplemented(); Log = new TestKestrelTrace(); DateHeaderValueManager = new TestDateHeaderValueManager(); }