Skip to content

Commit d349844

Browse files
author
Simon MacMullen
committed
Merge bug26099
2 parents 5e9fe95 + 44bba4b commit d349844

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

src/com/rabbitmq/client/AlreadyClosedException.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,21 @@ public class AlreadyClosedException extends ShutdownSignalException {
2525
/** Default for suppressing warnings without version check. */
2626
private static final long serialVersionUID = 1L;
2727

28-
public AlreadyClosedException(ShutdownSignalException sse)
29-
{
28+
public AlreadyClosedException(ShutdownSignalException sse) {
29+
this(sse, null);
30+
}
31+
32+
public AlreadyClosedException(ShutdownSignalException sse, Throwable cause) {
3033
super(sse.isHardError(),
3134
sse.isInitiatedByApplication(),
3235
sse.getReason(),
3336
sse.getReference(),
34-
(sse.isHardError() ? "connection" : "channel" + " is already closed due to previous "));
37+
composeMessagePrefix(sse),
38+
((cause == null) ? sse.getCause() : cause));
39+
}
40+
41+
private static String composeMessagePrefix(ShutdownSignalException sse) {
42+
String connectionOrChannel = sse.isHardError() ? "connection " : "channel ";
43+
return connectionOrChannel + "is already closed due to ";
3544
}
3645
}

src/com/rabbitmq/client/ShutdownSignalException.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public ShutdownSignalException(boolean hardError,
5757
boolean initiatedByApplication,
5858
Method reason, Object ref)
5959
{
60-
this(hardError, initiatedByApplication, reason, ref, "");
60+
this(hardError, initiatedByApplication, reason, ref, "", null);
6161
}
6262

6363
/**
@@ -70,19 +70,33 @@ public ShutdownSignalException(boolean hardError,
7070
*/
7171
public ShutdownSignalException(boolean hardError,
7272
boolean initiatedByApplication,
73-
Method reason, Object ref, String messagePrefix)
73+
Method reason, Object ref, String messagePrefix, Throwable cause)
7474
{
75-
super(messagePrefix + (initiatedByApplication
76-
? ("clean " + (hardError ? "connection" : "channel") + " shutdown")
77-
: ((hardError ? "connection" : "channel") + " error"))
78-
+ "; reason: " + reason);
75+
super(composeMessage(hardError, initiatedByApplication, reason, messagePrefix, cause));
7976
this._hardError = hardError;
8077
this._initiatedByApplication = initiatedByApplication;
8178
this._reason = reason;
8279
// Depending on hardError what we got is either Connection or Channel reference
8380
this._ref = ref;
8481
}
8582

83+
private static String composeMessage(boolean hardError, boolean initiatedByApplication,
84+
Method reason, String messagePrefix, Throwable cause) {
85+
final String connectionOrChannel = hardError ? "connection" : "channel";
86+
final String appInitiated = "clean " + connectionOrChannel + " shutdown";
87+
final String nonAppInitiated = connectionOrChannel + " error";
88+
final String explanation = initiatedByApplication ? appInitiated : nonAppInitiated;
89+
90+
StringBuilder result = new StringBuilder(messagePrefix).append(explanation);
91+
if(reason != null) {
92+
result.append("; protocol method: ").append(reason);
93+
}
94+
if(cause != null) {
95+
result.append("; cause: ").append(cause);
96+
}
97+
return result.toString();
98+
}
99+
86100
/** @return true if this signals a connection error, or false if a channel error */
87101
public boolean isHardError() { return _hardError; }
88102

src/com/rabbitmq/client/impl/AMQConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ private ShutdownSignalException startShutdown(Method reason,
717717
sse.initCause(cause);
718718
if (!setShutdownCauseIfOpen(sse)) {
719719
if (initiatedByApplication)
720-
throw new AlreadyClosedException(getCloseReason());
720+
throw new AlreadyClosedException(getCloseReason(), cause);
721721
}
722722

723723
// stop any heartbeating

0 commit comments

Comments
 (0)