use of io.grpc.Context.CancellationListener in project grpc-java by grpc.
the class ClientXdsClientV3Test method createLrsService.
@Override
protected BindableService createLrsService() {
return new LoadReportingServiceImplBase() {
@Override
public StreamObserver<LoadStatsRequest> streamLoadStats(StreamObserver<LoadStatsResponse> responseObserver) {
assertThat(lrsEnded.get()).isTrue();
lrsEnded.set(false);
@SuppressWarnings("unchecked") StreamObserver<LoadStatsRequest> requestObserver = mock(StreamObserver.class);
LrsRpcCall call = new LrsRpcCallV3(requestObserver, responseObserver);
Context.current().addListener(new CancellationListener() {
@Override
public void cancelled(Context context) {
lrsEnded.set(true);
}
}, MoreExecutors.directExecutor());
loadReportCalls.offer(call);
return requestObserver;
}
};
}
use of io.grpc.Context.CancellationListener in project grpc-java by grpc.
the class HealthServiceImpl method watch.
@Override
public void watch(HealthCheckRequest request, final StreamObserver<HealthCheckResponse> responseObserver) {
final String service = request.getService();
synchronized (watchLock) {
ServingStatus status = statusMap.get(service);
responseObserver.onNext(getResponseForWatch(status));
IdentityHashMap<StreamObserver<HealthCheckResponse>, Boolean> serviceWatchers = watchers.get(service);
if (serviceWatchers == null) {
serviceWatchers = new IdentityHashMap<>();
watchers.put(service, serviceWatchers);
}
serviceWatchers.put(responseObserver, Boolean.TRUE);
}
Context.current().addListener(new CancellationListener() {
@Override
public // Called when the client has closed the stream
void cancelled(Context context) {
synchronized (watchLock) {
IdentityHashMap<StreamObserver<HealthCheckResponse>, Boolean> serviceWatchers = watchers.get(service);
if (serviceWatchers != null) {
serviceWatchers.remove(responseObserver);
if (serviceWatchers.isEmpty()) {
watchers.remove(service);
}
}
}
}
}, MoreExecutors.directExecutor());
}
use of io.grpc.Context.CancellationListener in project grpc-java by grpc.
the class ClientXdsClientV2Test method createAdsService.
@Override
protected BindableService createAdsService() {
return new AggregatedDiscoveryServiceImplBase() {
@Override
public StreamObserver<DiscoveryRequest> streamAggregatedResources(final StreamObserver<DiscoveryResponse> responseObserver) {
// ensure previous call was ended
assertThat(adsEnded.get()).isTrue();
adsEnded.set(false);
@SuppressWarnings("unchecked") StreamObserver<DiscoveryRequest> requestObserver = mock(StreamObserver.class);
DiscoveryRpcCall call = new DiscoveryRpcCallV2(requestObserver, responseObserver);
resourceDiscoveryCalls.offer(call);
Context.current().addListener(new CancellationListener() {
@Override
public void cancelled(Context context) {
adsEnded.set(true);
}
}, MoreExecutors.directExecutor());
return requestObserver;
}
};
}
use of io.grpc.Context.CancellationListener in project grpc-java by grpc.
the class ClientXdsClientV2Test method createLrsService.
@Override
protected BindableService createLrsService() {
return new LoadReportingServiceImplBase() {
@Override
public StreamObserver<LoadStatsRequest> streamLoadStats(StreamObserver<LoadStatsResponse> responseObserver) {
assertThat(lrsEnded.get()).isTrue();
lrsEnded.set(false);
@SuppressWarnings("unchecked") StreamObserver<LoadStatsRequest> requestObserver = mock(StreamObserver.class);
LrsRpcCall call = new LrsRpcCallV2(requestObserver, responseObserver);
Context.current().addListener(new CancellationListener() {
@Override
public void cancelled(Context context) {
lrsEnded.set(true);
}
}, MoreExecutors.directExecutor());
loadReportCalls.offer(call);
return requestObserver;
}
};
}
use of io.grpc.Context.CancellationListener in project grpc-java by grpc.
the class ClientXdsClientV3Test method createAdsService.
@Override
protected BindableService createAdsService() {
return new AggregatedDiscoveryServiceImplBase() {
@Override
public StreamObserver<DiscoveryRequest> streamAggregatedResources(final StreamObserver<DiscoveryResponse> responseObserver) {
// ensure previous call was ended
assertThat(adsEnded.get()).isTrue();
adsEnded.set(false);
@SuppressWarnings("unchecked") StreamObserver<DiscoveryRequest> requestObserver = mock(StreamObserver.class);
DiscoveryRpcCall call = new DiscoveryRpcCallV3(requestObserver, responseObserver);
resourceDiscoveryCalls.offer(call);
Context.current().addListener(new CancellationListener() {
@Override
public void cancelled(Context context) {
adsEnded.set(true);
}
}, MoreExecutors.directExecutor());
return requestObserver;
}
};
}
Aggregations