Skip to content

Commit 28de277

Browse files
committed
Merge bug16247 into default
2 parents c60e2e9 + 59a9618 commit 28de277

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

src/com/rabbitmq/client/AlreadyClosedException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* which was already closed
66
*/
77
public class AlreadyClosedException extends ShutdownSignalException {
8-
public AlreadyClosedException(String s)
8+
public AlreadyClosedException(String s, Object ref)
99
{
10-
super(true, true, s);
10+
super(true, true, s, ref);
1111
}
1212
}

src/com/rabbitmq/client/RpcClient.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ public byte[] primitiveCall(AMQP.BasicProperties props, byte[] message)
190190
ShutdownSignalException wrapper =
191191
new ShutdownSignalException(sig.isHardError(),
192192
sig.isInitiatedByApplication(),
193-
sig.getReason());
193+
sig.getReason(),
194+
sig.getReference());
194195
wrapper.initCause(sig);
195196
throw wrapper;
196197
} else {

src/com/rabbitmq/client/ShutdownSignalException.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
/**
2828
* Encapsulates a shutdown condition for a connection to an AMQP broker.
29+
* Depending on HardError when calling
30+
* {@link com.rabbitmq.client.ShutdownSignalException#getReference()} we will
31+
* either get a reference to the Connection or Channel instance that fired
32+
* this exception.
2933
*/
3034

3135
public class ShutdownSignalException extends RuntimeException {
@@ -42,19 +46,25 @@ public class ShutdownSignalException extends RuntimeException {
4246
/** Possible explanation */
4347
private final Object _reason;
4448

49+
/** Either Channel or Connection instance, depending on _hardError */
50+
private final Object _ref;
51+
4552
/**
4653
* Construct a ShutdownSignalException from the arguments.
4754
* @param hardError the relevant hard error
4855
* @param initiatedByApplication if the shutdown was client-initiated
4956
* @param reason Object describing the origin of the exception
57+
* @param ref Reference to Connection or Channel that fired the signal
5058
*/
5159
public ShutdownSignalException(boolean hardError,
5260
boolean initiatedByApplication,
53-
Object reason)
61+
Object reason, Object ref)
5462
{
5563
this._hardError = hardError;
5664
this._initiatedByApplication = initiatedByApplication;
5765
this._reason = reason;
66+
// Depending on hardError what we got is either Connection or Channel reference
67+
this._ref = ref;
5868
}
5969

6070
/** @return true if this signals a connection error, or false if a channel error */
@@ -68,6 +78,9 @@ public ShutdownSignalException(boolean hardError,
6878

6979
/** @return the reason object, if any */
7080
public Object getReason() { return _reason; }
81+
82+
/** @return Reference to Connection or Channel object that fired the signal **/
83+
public Object getReference() { return _ref; }
7184

7285
public String toString() {
7386
return super.toString() + " (" +

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void ensureIsOpen()
173173
throws AlreadyClosedException
174174
{
175175
if (!isOpen()) {
176-
throw new AlreadyClosedException("Attempt to use closed channel");
176+
throw new AlreadyClosedException("Attempt to use closed channel", this);
177177
}
178178
}
179179

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void ensureIsOpen()
107107
throws AlreadyClosedException
108108
{
109109
if (!isOpen()) {
110-
throw new AlreadyClosedException("Attempt to use closed connection");
110+
throw new AlreadyClosedException("Attempt to use closed connection", this);
111111
}
112112
}
113113

@@ -565,7 +565,7 @@ public void shutdown(Object reason,
565565
ensureIsOpen(); // invariant: we should never be shut down more than once per instance
566566
_shutdownCause = new ShutdownSignalException(true,
567567
initiatedByApplication,
568-
reason);
568+
reason, this);
569569
}
570570
if (cause != null) {
571571
_shutdownCause.initCause(cause);
@@ -611,4 +611,4 @@ public void close(int closeCode,
611611
@Override public String toString() {
612612
return "amqp://" + _params.getUserName() + "@" + getHost() + ":" + getPort() + _params.getVirtualHost();
613613
}
614-
}
614+
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ public void releaseChannelNumber() {
222222
releaseChannelNumber();
223223
ShutdownSignalException signal = new ShutdownSignalException(false,
224224
false,
225-
command);
225+
command,
226+
this);
226227
processShutdownSignal(signal);
227228
notifyListeners();
228229
return true;
@@ -274,13 +275,13 @@ public void close(int closeCode,
274275
Channel.Close reason = new Channel.Close(closeCode, closeMessage, 0, 0);
275276
ShutdownSignalException signal = new ShutdownSignalException(false,
276277
initiatedByApplication,
277-
reason);
278+
reason,
279+
this);
278280
if (cause != null) {
279281
signal.initCause(cause);
280282
}
281-
282283
processShutdownSignal(signal);
283-
284+
284285
// Now that we're in quiescing state, send channel.close and
285286
// wait for the reply. Note that we can't use regular old rpc
286287
// or exnWrappingRpc here, since _isOpen is false. We use

0 commit comments

Comments
 (0)