use of net.morimekta.providence.thrift.io.FramedBufferInputStream in project providence by morimekta.
the class NonblockingSocketClientHandler method handleReadResponses.
private void handleReadResponses(SocketChannel channel, PService service) {
while (this.channel == channel && channel.isOpen()) {
FramedBufferInputStream in = new FramedBufferInputStream(channel);
try {
in.nextFrame();
PServiceCall reply = serializer.deserialize(in, service);
if (reply.getType() == PServiceCallType.CALL || reply.getType() == PServiceCallType.ONEWAY) {
throw new PApplicationException("Reply with invalid call type: " + reply.getType(), PApplicationExceptionType.INVALID_MESSAGE_TYPE);
}
CompletableFuture<PServiceCall> future = responseFutures.get(reply.getSequence());
if (future == null) {
// The item response timed out.
LOGGER.debug("No future for sequence ID " + reply.getSequence());
continue;
}
responseFutures.remove(reply.getSequence());
future.complete(reply);
} catch (Exception e) {
if (!channel.isOpen()) {
// If the channel is closed. Should not trigger on disconnected.
break;
}
LOGGER.error("Exception in channel response reading", e);
}
}
if (responseFutures.size() > 0) {
LOGGER.warn("Channel closed with {} unfinished calls", responseFutures.size());
responseFutures.forEach((s, f) -> f.completeExceptionally(new IOException("Channel closed")));
responseFutures.clear();
}
}
Aggregations