Hi folks,
I am pretty noob with gRpc and trying to make bidirectional streaming work
with ListenableFutures.
My code is as follows:
RequestService requestService = MoreExecutors.*listeningDecorator*(
MyExecutor) ;
ResponseService responseService = MoreExecutors.*listeningDecorator*
(MyExecutor) ;
@Override
public StreamObserver<Request> ingestEventsStreaming(StreamObserver<
Response> responseObserver) {
return new StreamObserver<Request>() {
@Override
public void onNext(Request request) {
ListenableFuture<IngestionResponse> listenableFuture =
requestService.submit( new RequestHandlerTask(config));
listenableFuture.addListener(new Runnable() {
@Override
public void run() {
try {
responseObserver.onNext(listenableFuture.get());
} catch (InterruptedException e) {
LOG.error("Interrupted", e);
} catch (ExecutionException e) {
LOG.error("Exception in task", e.getCause());
}
} }, responseService);
}
@Override
public void onError(Throwable t) {
LOG.warn(“Request Failed");
}
@Override
public void onCompleted() {
responseObserver.onCompleted();
}
};
}
Above code throws following exception:
Exception in thread "pool-3-thread-1" Exception in thread "pool-3-thread-3"
java.lang.IllegalStateException: call is closed
at com.google.common.base.Preconditions.checkState(Preconditions.java:510)
at io.grpc.internal.ServerCallImpl.sendHeaders(ServerCallImpl.java:89)
at
io.grpc.stub.ServerCalls$ServerCallStreamObserverImpl.onNext(ServerCalls.java:338)
at
com.paloaltonetworks.apollo2.ingestion.frontend.server.FrontendServer$FrontendService$1$1.run(FrontendServer.java:160)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
It seems that adding listener fails the code.
May I know if I am doing anything wrong ? Any help will be much appreciated.
Thanks,
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/1ae15b1d-c7fc-46d8-affa-c13d10fa0af3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.