@@ -66,6 +66,7 @@ public final class RpcResolver implements Resolver {
66
66
private final LinkedBlockingQueue <StreamResponseModel <EventStreamResponse >> incomingQueue ;
67
67
private final Consumer <FlagdProviderEvent > onProviderEvent ;
68
68
private final ServiceStub stub ;
69
+ private final ServiceBlockingStub blockingStub ;
69
70
70
71
/**
71
72
* Resolves flag values using
@@ -82,9 +83,11 @@ public RpcResolver(
82
83
this .strategy = ResolveFactory .getStrategy (options );
83
84
this .options = options ;
84
85
incomingQueue = new LinkedBlockingQueue <>(QUEUE_SIZE );
85
- this .connector = new ChannelConnector <>(options , ServiceGrpc :: newBlockingStub , onProviderEvent );
86
+ this .connector = new ChannelConnector <>(options , onProviderEvent );
86
87
this .onProviderEvent = onProviderEvent ;
87
88
this .stub = ServiceGrpc .newStub (this .connector .getChannel ()).withWaitForReady ();
89
+ this .blockingStub =
90
+ ServiceGrpc .newBlockingStub (this .connector .getChannel ()).withWaitForReady ();
88
91
}
89
92
90
93
// testing only
@@ -93,6 +96,7 @@ protected RpcResolver(
93
96
final Cache cache ,
94
97
final Consumer <FlagdProviderEvent > onProviderEvent ,
95
98
ServiceStub mockStub ,
99
+ ServiceBlockingStub mockBlockingStub ,
96
100
ChannelConnector <ServiceStub , ServiceBlockingStub > connector ) {
97
101
this .cache = cache ;
98
102
this .strategy = ResolveFactory .getStrategy (options );
@@ -101,6 +105,7 @@ protected RpcResolver(
101
105
this .connector = connector ;
102
106
this .onProviderEvent = onProviderEvent ;
103
107
this .stub = mockStub ;
108
+ this .blockingStub = mockBlockingStub ;
104
109
}
105
110
106
111
/**
@@ -145,15 +150,15 @@ public void onError() {
145
150
public ProviderEvaluation <Boolean > booleanEvaluation (String key , Boolean defaultValue , EvaluationContext ctx ) {
146
151
ResolveBooleanRequest request = ResolveBooleanRequest .newBuilder ().buildPartial ();
147
152
148
- return resolve (key , ctx , request , getResolver ()::resolveBoolean , null );
153
+ return resolve (key , ctx , request , getBlockingStub ()::resolveBoolean , null );
149
154
}
150
155
151
156
/**
152
157
* String evaluation from grpc resolver.
153
158
*/
154
159
public ProviderEvaluation <String > stringEvaluation (String key , String defaultValue , EvaluationContext ctx ) {
155
160
ResolveStringRequest request = ResolveStringRequest .newBuilder ().buildPartial ();
156
- return resolve (key , ctx , request , getResolver ()::resolveString , null );
161
+ return resolve (key , ctx , request , getBlockingStub ()::resolveString , null );
157
162
}
158
163
159
164
/**
@@ -162,7 +167,7 @@ public ProviderEvaluation<String> stringEvaluation(String key, String defaultVal
162
167
public ProviderEvaluation <Double > doubleEvaluation (String key , Double defaultValue , EvaluationContext ctx ) {
163
168
ResolveFloatRequest request = ResolveFloatRequest .newBuilder ().buildPartial ();
164
169
165
- return resolve (key , ctx , request , getResolver ()::resolveFloat , null );
170
+ return resolve (key , ctx , request , getBlockingStub ()::resolveFloat , null );
166
171
}
167
172
168
173
/**
@@ -172,11 +177,17 @@ public ProviderEvaluation<Integer> integerEvaluation(String key, Integer default
172
177
173
178
ResolveIntRequest request = ResolveIntRequest .newBuilder ().buildPartial ();
174
179
175
- return resolve (key , ctx , request , getResolver ()::resolveInt , (Object value ) -> ((Long ) value ).intValue ());
180
+ return resolve (key , ctx , request , getBlockingStub ()::resolveInt , (Object value ) -> ((Long ) value ).intValue ());
176
181
}
177
182
178
- private ServiceGrpc .ServiceBlockingStub getResolver () {
179
- return connector .getBlockingStub ().withDeadlineAfter (options .getDeadline (), TimeUnit .MILLISECONDS );
183
+ private ServiceGrpc .ServiceBlockingStub getBlockingStub () {
184
+ ServiceBlockingStub localStub = blockingStub ;
185
+
186
+ if (options .getDeadline () > 0 ) {
187
+ localStub = localStub .withDeadlineAfter (options .getDeadline (), TimeUnit .MILLISECONDS );
188
+ }
189
+
190
+ return localStub ;
180
191
}
181
192
182
193
/**
@@ -190,7 +201,7 @@ public ProviderEvaluation<Value> objectEvaluation(String key, Value defaultValue
190
201
key ,
191
202
ctx ,
192
203
request ,
193
- getResolver ()::resolveObject ,
204
+ getBlockingStub ()::resolveObject ,
194
205
(Object value ) -> convertObjectResponse ((com .google .protobuf .Struct ) value ));
195
206
}
196
207
@@ -321,11 +332,11 @@ private void observeEventStream() throws InterruptedException {
321
332
log .info ("Initializing event stream observer" );
322
333
323
334
// outer loop for re-issuing the stream request
335
+ // "waitForReady" on the channel, plus our retry policy slow this loop down in error conditions
324
336
while (!shutdown .get ()) {
325
337
326
338
log .debug ("Initializing event stream request" );
327
339
restartStream ();
328
-
329
340
// inner loop for handling messages
330
341
while (!shutdown .get ()) {
331
342
final StreamResponseModel <EventStreamResponse > taken = incomingQueue .take ();
0 commit comments