26
26
using Microsoft . AspNetCore . Hosting ;
27
27
using Microsoft . AspNetCore . Server . Kestrel . Core ;
28
28
using Microsoft . Extensions . DependencyInjection ;
29
+ using Microsoft . Extensions . Hosting ;
29
30
using Microsoft . Extensions . Logging ;
30
31
31
32
namespace BenchmarkWorkerWebsite
@@ -42,7 +43,7 @@ public static IServerRunner CreateStarted(ServerConfig config, ILogger logger)
42
43
{
43
44
logger . LogInformation ( "ServerConfig: {0}" , config ) ;
44
45
45
- var webHostBuilder = WebHost . CreateDefaultBuilder ( ) ;
46
+ var hostBuilder = Host . CreateDefaultBuilder ( ) ;
46
47
47
48
if ( config . AsyncServerThreads != 0 )
48
49
{
@@ -69,36 +70,39 @@ public static IServerRunner CreateStarted(ServerConfig config, ILogger logger)
69
70
logger . LogWarning ( "Grpc.AspNetCore server doesn't support autoselecting of listening port. Setting port explictly to " + port ) ;
70
71
}
71
72
72
- webHostBuilder . ConfigureKestrel ( ( context , options ) =>
73
+ hostBuilder . ConfigureWebHostDefaults ( webHostBuilder =>
73
74
{
74
- options . ListenAnyIP ( port , listenOptions =>
75
+ webHostBuilder . ConfigureKestrel ( ( context , options ) =>
75
76
{
76
- // TODO(jtattermusch): use TLS if config.SecurityParams != null
77
- listenOptions . Protocols = HttpProtocols . Http2 ;
77
+ options . ListenAnyIP ( port , listenOptions =>
78
+ {
79
+ // TODO(jtattermusch): use TLS if config.SecurityParams != null
80
+ listenOptions . Protocols = HttpProtocols . Http2 ;
81
+ } ) ;
78
82
} ) ;
79
- } ) ;
80
83
81
- if ( config . ServerType == ServerType . AsyncServer )
82
- {
83
- GrpcPreconditions . CheckArgument ( config . PayloadConfig == null ,
84
- "ServerConfig.PayloadConfig shouldn't be set for BenchmarkService based server." ) ;
85
- webHostBuilder . UseStartup < BenchmarkServiceStartup > ( ) ;
86
- }
87
- else if ( config . ServerType == ServerType . AsyncGenericServer )
88
- {
89
- var genericService = new GenericServiceImpl ( config . PayloadConfig . BytebufParams . RespSize ) ;
90
- // TODO(jtattermusch): use startup with given generic service
91
- throw new ArgumentException ( "Generice service is not yet implemented." ) ;
92
- }
93
- else
94
- {
95
- throw new ArgumentException ( "Unsupported ServerType" ) ;
96
- }
84
+ if ( config . ServerType == ServerType . AsyncServer )
85
+ {
86
+ GrpcPreconditions . CheckArgument ( config . PayloadConfig == null ,
87
+ "ServerConfig.PayloadConfig shouldn't be set for BenchmarkService based server." ) ;
88
+ webHostBuilder . UseStartup < BenchmarkServiceStartup > ( ) ;
89
+ }
90
+ else if ( config . ServerType == ServerType . AsyncGenericServer )
91
+ {
92
+ var genericService = new GenericServiceImpl ( config . PayloadConfig . BytebufParams . RespSize ) ;
93
+ // TODO(jtattermusch): use startup with given generic service
94
+ throw new ArgumentException ( "Generice service is not yet implemented." ) ;
95
+ }
96
+ else
97
+ {
98
+ throw new ArgumentException ( "Unsupported ServerType" ) ;
99
+ }
100
+ } ) ;
97
101
98
102
// Don't log requests handled by the benchmarking service
99
- webHostBuilder . ConfigureLogging ( logging => logging . SetMinimumLevel ( LogLevel . Warning ) ) ;
103
+ hostBuilder . ConfigureLogging ( logging => logging . SetMinimumLevel ( LogLevel . Warning ) ) ;
100
104
101
- var webHost = webHostBuilder . Build ( ) ;
105
+ var webHost = hostBuilder . Build ( ) ;
102
106
webHost . Start ( ) ;
103
107
return new ServerRunnerImpl ( webHost , logger , port ) ;
104
108
}
@@ -150,14 +154,14 @@ await requestStream.ForEachAsync(async request =>
150
154
/// </summary>
151
155
public class ServerRunnerImpl : IServerRunner
152
156
{
153
- readonly IWebHost webHost ;
157
+ readonly IHost host ;
154
158
readonly ILogger logger ;
155
159
readonly int boundPort ;
156
160
readonly TimeStats timeStats = new TimeStats ( ) ;
157
161
158
- public ServerRunnerImpl ( IWebHost webHost , ILogger logger , int boundPort )
162
+ public ServerRunnerImpl ( IHost host , ILogger logger , int boundPort )
159
163
{
160
- this . webHost = webHost ;
164
+ this . host = host ;
161
165
this . logger = logger ;
162
166
this . boundPort = boundPort ;
163
167
}
@@ -189,7 +193,7 @@ public ServerStats GetStats(bool reset)
189
193
/// <returns>Task that finishes when server has shutdown.</returns>
190
194
public Task StopAsync ( )
191
195
{
192
- return webHost . StopAsync ( ) ;
196
+ return host . StopAsync ( ) ;
193
197
}
194
198
}
195
199
}
0 commit comments