Use named exceptions in ChannelPool implementations (#10721)

Motivation:

I was collecting stats for failed promises with a FixedChannelPool and I was bucketing by stats using cause.getSimpleName(). After #9152 was released, the introduction of the anonymous classes make getSimpleName() return "" causing confusion.

Modification:

Use named classes in the ChannelPool implementations. I made them private, but I can change that if you think otherwise.

Result:

The SimpleChannelPool fails the promises with a ChannelPoolFullException. The FixedChannelPool fails the promises with an AcquireTimeoutException. Also AcquireTimeoutException is more specific than just a plain TimeoutException, which is also useful for troubleshooting. If you want different class names, please advise.
This commit is contained in:
James Yuzawa 2020-10-23 08:29:37 -04:00 committed by GitHub
parent ee4164ab8f
commit 726944146b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 15 deletions

View File

@ -194,15 +194,7 @@ public class FixedChannelPool extends SimpleChannelPool {
@Override @Override
public void onTimeout(AcquireTask task) { public void onTimeout(AcquireTask task) {
// Fail the promise as we timed out. // Fail the promise as we timed out.
task.promise.setFailure(new TimeoutException( task.promise.setFailure(new AcquireTimeoutException());
"Acquire operation took longer then configured maximum time") {
// Suppress a warning since the method doesn't need synchronization
@Override
public Throwable fillInStackTrace() { // lgtm[java/non-sync-override]
return this;
}
});
} }
}; };
break; break;
@ -514,4 +506,17 @@ public class FixedChannelPool extends SimpleChannelPool {
return GlobalEventExecutor.INSTANCE.newSucceededFuture(null); return GlobalEventExecutor.INSTANCE.newSucceededFuture(null);
} }
private static final class AcquireTimeoutException extends TimeoutException {
private AcquireTimeoutException() {
super("Acquire operation took longer then configured maximum time");
}
// Suppress a warning since the method doesn't need synchronization
@Override
public Throwable fillInStackTrace() { // lgtm[java/non-sync-override]
return this;
}
}
} }

View File

@ -350,12 +350,7 @@ public class SimpleChannelPool implements ChannelPool {
handler.channelReleased(channel); handler.channelReleased(channel);
promise.setSuccess(null); promise.setSuccess(null);
} else { } else {
closeAndFail(channel, new IllegalStateException("ChannelPool full") { closeAndFail(channel, new ChannelPoolFullException(), promise);
@Override
public Throwable fillInStackTrace() {
return this;
}
}, promise);
} }
} }
@ -418,4 +413,17 @@ public class SimpleChannelPool implements ChannelPool {
} }
}); });
} }
private static final class ChannelPoolFullException extends IllegalStateException {
private ChannelPoolFullException() {
super("ChannelPool full");
}
// Suppress a warning since the method doesn't need synchronization
@Override
public Throwable fillInStackTrace() { // lgtm[java/non-sync-override]
return this;
}
}
} }