Prevent extra peformance hit by fillInStackTrace() when create a new annotated connect exception.
Motivation: To make it easier to debug connect exceptions we create new exceptions which also contain the remote address. For this we basically created a new instance and call setStackTrace(...). When doing this we pay an extra penality because it calls fillInStackTrace() when calling the super constructor. Modifications: Create special sub-classes of Exceptions that override the fillInStackTrace() method and so eliminate the overhead. Result: Less overhead when "annotate" connect exceptions.
This commit is contained in:
parent
2d111e0980
commit
8ce7e73e78
@ -939,17 +939,13 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
*/
|
||||
protected final Throwable annotateConnectException(Throwable cause, SocketAddress remoteAddress) {
|
||||
if (cause instanceof ConnectException) {
|
||||
Throwable newT = new ConnectException(cause.getMessage() + ": " + remoteAddress);
|
||||
newT.setStackTrace(cause.getStackTrace());
|
||||
cause = newT;
|
||||
} else if (cause instanceof NoRouteToHostException) {
|
||||
Throwable newT = new NoRouteToHostException(cause.getMessage() + ": " + remoteAddress);
|
||||
newT.setStackTrace(cause.getStackTrace());
|
||||
cause = newT;
|
||||
} else if (cause instanceof SocketException) {
|
||||
Throwable newT = new SocketException(cause.getMessage() + ": " + remoteAddress);
|
||||
newT.setStackTrace(cause.getStackTrace());
|
||||
cause = newT;
|
||||
return new AnnotatedConnectException((ConnectException) cause, remoteAddress);
|
||||
}
|
||||
if (cause instanceof NoRouteToHostException) {
|
||||
return new AnnotatedNoRouteToHostException((NoRouteToHostException) cause, remoteAddress);
|
||||
}
|
||||
if (cause instanceof SocketException) {
|
||||
return new AnnotatedSocketException((SocketException) cause, remoteAddress);
|
||||
}
|
||||
|
||||
return cause;
|
||||
@ -1062,4 +1058,49 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
||||
return super.trySuccess();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class AnnotatedConnectException extends ConnectException {
|
||||
|
||||
private static final long serialVersionUID = 3901958112696433556L;
|
||||
|
||||
AnnotatedConnectException(ConnectException exception, SocketAddress remoteAddress) {
|
||||
super(exception.getMessage() + ": " + remoteAddress);
|
||||
setStackTrace(exception.getStackTrace());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class AnnotatedNoRouteToHostException extends NoRouteToHostException {
|
||||
|
||||
private static final long serialVersionUID = -6801433937592080623L;
|
||||
|
||||
AnnotatedNoRouteToHostException(NoRouteToHostException exception, SocketAddress remoteAddress) {
|
||||
super(exception.getMessage() + ": " + remoteAddress);
|
||||
setStackTrace(exception.getStackTrace());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class AnnotatedSocketException extends SocketException {
|
||||
|
||||
private static final long serialVersionUID = 3896743275010454039L;
|
||||
|
||||
AnnotatedSocketException(SocketException exception, SocketAddress remoteAddress) {
|
||||
super(exception.getMessage() + ": " + remoteAddress);
|
||||
setStackTrace(exception.getStackTrace());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user