44
44
import io .quarkus .arc .Arc ;
45
45
import io .quarkus .arc .InstanceHandle ;
46
46
import io .quarkus .arc .Subclass ;
47
+ import io .quarkus .arc .runtime .BeanContainer ;
47
48
import io .quarkus .grpc .api .ServerBuilderCustomizer ;
48
49
import io .quarkus .grpc .auth .GrpcSecurityInterceptor ;
49
50
import io .quarkus .grpc .reflection .service .ReflectionServiceV1 ;
@@ -121,18 +122,15 @@ public void handle(RoutingContext event) {
121
122
}
122
123
}
123
124
124
- public void initializeGrpcServer (RuntimeValue <Vertx > vertxSupplier ,
125
+ public void initializeGrpcServer (boolean hasNoBindableServiceBeans , BeanContainer beanContainer ,
126
+ RuntimeValue <Vertx > vertxSupplier ,
125
127
RuntimeValue <Router > routerSupplier ,
126
128
GrpcConfiguration cfg ,
127
129
ShutdownContext shutdown ,
128
130
Map <String , List <String >> blockingMethodsPerService ,
129
131
Map <String , List <String >> virtualMethodsPerService ,
130
132
LaunchMode launchMode , boolean securityPresent , Map <Integer , Handler <RoutingContext >> securityHandlers ) {
131
- GrpcContainer grpcContainer = Arc .container ().instance (GrpcContainer .class ).get ();
132
- if (grpcContainer == null ) {
133
- throw new IllegalStateException ("gRPC not initialized, GrpcContainer not found" );
134
- }
135
- if (hasNoServices (grpcContainer .getServices ()) && LaunchMode .current () != LaunchMode .DEVELOPMENT ) {
133
+ if (hasNoBindableServiceBeans && LaunchMode .current () != LaunchMode .DEVELOPMENT ) {
136
134
LOGGER .error ("Unable to find beans exposing the `BindableService` interface - not starting the gRPC server" );
137
135
return ; // OK?
138
136
}
@@ -152,20 +150,23 @@ public void initializeGrpcServer(RuntimeValue<Vertx> vertxSupplier,
152
150
// start single server, not in a verticle, regardless of the configuration.instances
153
151
// for reason unknown to me, verticles occasionally get undeployed on dev mode reload
154
152
if (GrpcServerReloader .getServer () != null || (provider != null && provider .serverAlreadyExists ())) {
155
- devModeReload (grpcContainer , vertx , configuration , provider , blockingMethodsPerService ,
153
+ devModeReload (beanContainer .beanInstance (GrpcContainer .class ), vertx , configuration , provider ,
154
+ blockingMethodsPerService ,
156
155
virtualMethodsPerService , shutdown );
157
156
} else {
158
- devModeStart (grpcContainer , vertx , configuration , provider , blockingMethodsPerService ,
157
+ devModeStart (beanContainer .beanInstance (GrpcContainer .class ), vertx , configuration , provider ,
158
+ blockingMethodsPerService ,
159
159
virtualMethodsPerService , shutdown ,
160
160
launchMode );
161
161
}
162
162
} else {
163
- prodStart (grpcContainer , vertx , configuration , provider , blockingMethodsPerService , virtualMethodsPerService ,
163
+ prodStart (beanContainer .beanInstance (GrpcContainer .class ), vertx , configuration , provider ,
164
+ blockingMethodsPerService , virtualMethodsPerService ,
164
165
launchMode );
165
166
}
166
167
} else {
167
168
buildGrpcServer (vertx , configuration , routerSupplier , shutdown , blockingMethodsPerService , virtualMethodsPerService ,
168
- grpcContainer , launchMode , securityPresent , securityHandlers );
169
+ beanContainer . beanInstance ( GrpcContainer . class ) , launchMode , securityPresent , securityHandlers );
169
170
}
170
171
}
171
172
0 commit comments