Skip to content

Introduced shouldRecordStats explaining variable in the onMessage method to clarify the intent behind conditional checks for recording statistics. #1105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/main/java/io/nats/service/EndpointContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class EndpointContext {
private final Connection conn;
private final ServiceEndpoint se;
private final ServiceMessageHandler handler;
private final boolean recordStats;
private final boolean shouldRecordStats;
private final String qGroup;

private final boolean internalDispatcher;
Expand All @@ -35,7 +35,7 @@ class EndpointContext {
this.conn = conn;
this.se = se;
handler = se.getHandler();
this.recordStats = !internalEndpoint;
this.shouldRecordStats = !internalEndpoint;
qGroup = internalEndpoint ? null : se.getQueueGroup();

if (se.getDispatcher() == null) {
Expand Down Expand Up @@ -64,27 +64,32 @@ public void onMessage(Message msg) throws InterruptedException {
long start = System.nanoTime();
ServiceMessage smsg = new ServiceMessage(msg);
try {
if (recordStats) {
if (shouldRecordStats) {
numRequests.incrementAndGet();
}
handler.onMessage(smsg);
}
catch (Throwable t) {
if (recordStats) {
numErrors.incrementAndGet();
lastError = t.toString();
if (shouldRecordStats) {
handleServiceMessageError(smsg, t);
}
try {
smsg.respondStandardError(conn, lastError, 500);
} catch (RuntimeException ignore) {}
}
finally {
if (recordStats) {
if (shouldRecordStats) {
processingTime.addAndGet(System.nanoTime() - start);
}
}
}

private void handleServiceMessageError(ServiceMessage smsg, Throwable t) {
numErrors.incrementAndGet();
lastError = t.toString();
try {
smsg.respondStandardError(conn, lastError, 500);
} catch (RuntimeException ignore) {}
}


EndpointStats getEndpointStats() {
return new EndpointStats(
se.getEndpoint().getName(),
Expand Down