use of net.morimekta.providence.util.ServiceCallInstrumentation.NS_IN_MILLIS in project providence by morimekta.
the class SocketServer method process.
@SuppressWarnings("unchecked")
private void process(long startTime, Socket socket) {
try (Socket ignore = socket;
BufferedInputStream in = new BufferedInputStream(socket.getInputStream());
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
IOMessageReader reader = new IOMessageReader(in, serializer);
IOMessageWriter writer = new IOMessageWriter(out, serializer)) {
while (socket.isConnected()) {
AtomicReference<PServiceCall> callRef = new AtomicReference<>();
AtomicReference<PServiceCall> responseRef = new AtomicReference<>();
try {
DefaultProcessorHandler handler = new DefaultProcessorHandler(new WrappedProcessor(processor, (c, p) -> {
callRef.set(c);
responseRef.set(p.handleCall(c));
return responseRef.get();
}));
handler.process(reader, writer);
out.flush();
long endTime = System.nanoTime();
double duration = ((double) (endTime - startTime)) / NS_IN_MILLIS;
try {
instrumentation.onComplete(duration, callRef.get(), responseRef.get());
} catch (Throwable th) {
LOGGER.error("Exception in service instrumentation", th);
}
} catch (IOException e) {
long endTime = System.nanoTime();
double duration = ((double) (endTime - startTime)) / NS_IN_MILLIS;
try {
instrumentation.onTransportException(e, duration, callRef.get(), responseRef.get());
} catch (Throwable th) {
LOGGER.error("Exception in service instrumentation", th);
}
throw new UncheckedIOException(e.getMessage(), e);
}
in.mark(1);
if (in.read() < 0) {
return;
}
in.reset();
startTime = System.nanoTime();
}
} catch (IOException e) {
throw new UncheckedIOException(e.getMessage(), e);
}
}
Aggregations