@@ -32,48 +32,11 @@ public extension SmokeHTTP1Server {
3232 InitializerType. SelectorType. DefaultOperationDelegateType. RequestHeadType == SmokeHTTP1RequestHead ,
3333 InitializerType. SelectorType. DefaultOperationDelegateType. ResponseHandlerType ==
3434 StandardHTTP1ResponseHandler < SmokeInvocationContext < InitializerType . SelectorType . DefaultOperationDelegateType . InvocationReportingType > > {
35- let eventLoopGroup =
36- MultiThreadedEventLoopGroup ( numberOfThreads: System . coreCount)
37-
38- let initalizer : InitializerType
39- do {
40- initalizer = try factory ( eventLoopGroup. next ( ) )
41- } catch {
42- let logger = Logger . init ( label: " application.initialization " )
43-
44- logger. error ( " Unable to initialize application from factory due to error - \( error) . " )
45-
46- return
35+ func wrappedFactory( eventLoopGroup: EventLoopGroup ) throws -> InitializerType {
36+ return try factory ( eventLoopGroup. next ( ) )
4737 }
4838
49- // initialize the logger after instatiating the initializer
50- let logger = Logger . init ( label: " application.initialization " )
51-
52- let handler = OperationServerHTTP1RequestHandler < InitializerType . SelectorType , TraceContextType > (
53- handlerSelector: initalizer. handlerSelector,
54- context: initalizer. getInvocationContext ( ) , serverName: initalizer. serverName,
55- reportingConfiguration: initalizer. reportingConfiguration)
56- let server = StandardSmokeHTTP1Server ( handler: handler,
57- port: initalizer. port,
58- invocationStrategy: initalizer. invocationStrategy,
59- defaultLogger: initalizer. defaultLogger,
60- eventLoopProvider: initalizer. eventLoopProvider,
61- shutdownOnSignal: initalizer. shutdownOnSignal)
62- do {
63- try server. start ( )
64-
65- try server. waitUntilShutdownAndThen {
66- do {
67- try initalizer. onShutdown ( )
68-
69- try eventLoopGroup. syncShutdownGracefully ( )
70- } catch {
71- logger. error ( " Unable to shutdown cleanly: ' \( error) ' " )
72- }
73- }
74- } catch {
75- logger. error ( " Unable to start Operations Server: ' \( error) ' " )
76- }
39+ runAsOperationServer ( wrappedFactory)
7740 }
7841
7942 static func runAsOperationServer< InitializerType: SmokeServerPerInvocationContextInitializer , TraceContextType> (
@@ -82,47 +45,110 @@ public extension SmokeHTTP1Server {
8245 InitializerType. SelectorType. DefaultOperationDelegateType. RequestHeadType == SmokeHTTP1RequestHead ,
8346 InitializerType. SelectorType. DefaultOperationDelegateType. ResponseHandlerType ==
8447 StandardHTTP1ResponseHandler < SmokeInvocationContext < InitializerType . SelectorType . DefaultOperationDelegateType . InvocationReportingType > > {
85- let eventLoopGroup =
86- MultiThreadedEventLoopGroup ( numberOfThreads: System . coreCount)
87-
88- let initalizer : InitializerType
89- do {
90- initalizer = try factory ( eventLoopGroup. next ( ) )
91- } catch {
92- let logger = Logger . init ( label: " application.initialization " )
93-
94- logger. error ( " Unable to initialize application from factory due to error - \( error) . " )
95-
96- return
48+ func wrappedFactory( eventLoopGroup: EventLoopGroup ) throws -> InitializerType {
49+ return try factory ( eventLoopGroup. next ( ) )
9750 }
9851
99- // initialize the logger after instatiating the initializer
100- let logger = Logger . init ( label: " application.initialization " )
101-
102- let handler = OperationServerHTTP1RequestHandler < InitializerType . SelectorType , TraceContextType > (
103- handlerSelector: initalizer. handlerSelector,
104- contextProvider: initalizer. getInvocationContext, serverName: initalizer. serverName,
105- reportingConfiguration: initalizer. reportingConfiguration)
106- let server = StandardSmokeHTTP1Server ( handler: handler,
107- port: initalizer. port,
108- invocationStrategy: initalizer. invocationStrategy,
109- defaultLogger: initalizer. defaultLogger,
110- eventLoopProvider: initalizer. eventLoopProvider,
111- shutdownOnSignal: initalizer. shutdownOnSignal)
112- do {
113- try server. start ( )
114-
115- try server. waitUntilShutdownAndThen {
116- do {
117- try initalizer. onShutdown ( )
118-
119- try eventLoopGroup. syncShutdownGracefully ( )
120- } catch {
121- logger. error ( " Unable to shutdown cleanly: ' \( error) ' " )
122- }
123- }
124- } catch {
125- logger. error ( " Unable to start Operations Server: ' \( error) ' " )
126- }
52+ runAsOperationServer ( wrappedFactory)
12753 }
54+
55+ static func runAsOperationServer< InitializerType: SmokeServerStaticContextInitializer , TraceContextType> (
56+ _ factory: @escaping ( EventLoopGroup ) throws -> InitializerType )
57+ where InitializerType. SelectorType. DefaultOperationDelegateType. InvocationReportingType == SmokeServerInvocationReporting < TraceContextType > ,
58+ InitializerType. SelectorType. DefaultOperationDelegateType. RequestHeadType == SmokeHTTP1RequestHead ,
59+ InitializerType. SelectorType. DefaultOperationDelegateType. ResponseHandlerType ==
60+ StandardHTTP1ResponseHandler < SmokeInvocationContext < InitializerType . SelectorType . DefaultOperationDelegateType . InvocationReportingType > > {
61+ let eventLoopGroup =
62+ MultiThreadedEventLoopGroup ( numberOfThreads: System . coreCount)
63+
64+ let initalizer : InitializerType
65+ do {
66+ initalizer = try factory ( eventLoopGroup)
67+ } catch {
68+ let logger = Logger . init ( label: " application.initialization " )
69+
70+ logger. error ( " Unable to initialize application from factory due to error - \( error) . " )
71+
72+ return
73+ }
74+
75+ // initialize the logger after instatiating the initializer
76+ let logger = Logger . init ( label: " application.initialization " )
77+
78+ let handler = OperationServerHTTP1RequestHandler < InitializerType . SelectorType , TraceContextType > (
79+ handlerSelector: initalizer. handlerSelector,
80+ context: initalizer. getInvocationContext ( ) , serverName: initalizer. serverName,
81+ reportingConfiguration: initalizer. reportingConfiguration)
82+ let server = StandardSmokeHTTP1Server ( handler: handler,
83+ port: initalizer. port,
84+ invocationStrategy: initalizer. invocationStrategy,
85+ defaultLogger: initalizer. defaultLogger,
86+ eventLoopProvider: initalizer. eventLoopProvider,
87+ shutdownOnSignal: initalizer. shutdownOnSignal)
88+ do {
89+ try server. start ( )
90+
91+ try server. waitUntilShutdownAndThen {
92+ do {
93+ try initalizer. onShutdown ( )
94+
95+ try eventLoopGroup. syncShutdownGracefully ( )
96+ } catch {
97+ logger. error ( " Unable to shutdown cleanly: ' \( error) ' " )
98+ }
99+ }
100+ } catch {
101+ logger. error ( " Unable to start Operations Server: ' \( error) ' " )
102+ }
103+ }
104+
105+ static func runAsOperationServer< InitializerType: SmokeServerPerInvocationContextInitializer , TraceContextType> (
106+ _ factory: @escaping ( EventLoopGroup ) throws -> InitializerType )
107+ where InitializerType. SelectorType. DefaultOperationDelegateType. InvocationReportingType == SmokeServerInvocationReporting < TraceContextType > ,
108+ InitializerType. SelectorType. DefaultOperationDelegateType. RequestHeadType == SmokeHTTP1RequestHead ,
109+ InitializerType. SelectorType. DefaultOperationDelegateType. ResponseHandlerType ==
110+ StandardHTTP1ResponseHandler < SmokeInvocationContext < InitializerType . SelectorType . DefaultOperationDelegateType . InvocationReportingType > > {
111+ let eventLoopGroup =
112+ MultiThreadedEventLoopGroup ( numberOfThreads: System . coreCount)
113+
114+ let initalizer : InitializerType
115+ do {
116+ initalizer = try factory ( eventLoopGroup)
117+ } catch {
118+ let logger = Logger . init ( label: " application.initialization " )
119+
120+ logger. error ( " Unable to initialize application from factory due to error - \( error) . " )
121+
122+ return
123+ }
124+
125+ // initialize the logger after instatiating the initializer
126+ let logger = Logger . init ( label: " application.initialization " )
127+
128+ let handler = OperationServerHTTP1RequestHandler < InitializerType . SelectorType , TraceContextType > (
129+ handlerSelector: initalizer. handlerSelector,
130+ contextProvider: initalizer. getInvocationContext, serverName: initalizer. serverName,
131+ reportingConfiguration: initalizer. reportingConfiguration)
132+ let server = StandardSmokeHTTP1Server ( handler: handler,
133+ port: initalizer. port,
134+ invocationStrategy: initalizer. invocationStrategy,
135+ defaultLogger: initalizer. defaultLogger,
136+ eventLoopProvider: initalizer. eventLoopProvider,
137+ shutdownOnSignal: initalizer. shutdownOnSignal)
138+ do {
139+ try server. start ( )
140+
141+ try server. waitUntilShutdownAndThen {
142+ do {
143+ try initalizer. onShutdown ( )
144+
145+ try eventLoopGroup. syncShutdownGracefully ( )
146+ } catch {
147+ logger. error ( " Unable to shutdown cleanly: ' \( error) ' " )
148+ }
149+ }
150+ } catch {
151+ logger. error ( " Unable to start Operations Server: ' \( error) ' " )
152+ }
153+ }
128154}
0 commit comments