Skip to content

Commit 61289ab

Browse files
committed
make ShutdownSignalException.reason a Method
...rather than a Method, or a Command, or an Exception, or a String, or a unicorn Also, make AlreadyClosedException really be a ShutdownSignalException, containing the same information.
1 parent fb57269 commit 61289ab

File tree

5 files changed

+31
-28
lines changed

5 files changed

+31
-28
lines changed

src/com/rabbitmq/client/AlreadyClosedException.java

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

28-
public AlreadyClosedException(String s, Object ref)
28+
public AlreadyClosedException(ShutdownSignalException sse)
2929
{
30-
super(true, true, s, ref);
30+
super(sse.isHardError(),
31+
sse.isInitiatedByApplication(),
32+
sse.getReason(),
33+
sse.getReference());
3134
}
3235
}

src/com/rabbitmq/client/ShutdownSignalException.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class ShutdownSignalException extends RuntimeException implements Sensibl
4141
private final boolean _initiatedByApplication;
4242

4343
/** Possible explanation */
44-
private final Object _reason;
44+
private final Method _reason;
4545

4646
/** Either Channel or Connection instance, depending on _hardError */
4747
private final Object _ref;
@@ -50,12 +50,12 @@ public class ShutdownSignalException extends RuntimeException implements Sensibl
5050
* Construct a ShutdownSignalException from the arguments.
5151
* @param hardError the relevant hard error
5252
* @param initiatedByApplication if the shutdown was client-initiated
53-
* @param reason Object describing the origin of the exception
53+
* @param reason AMQP method describing the exception reason
5454
* @param ref Reference to Connection or Channel that fired the signal
5555
*/
5656
public ShutdownSignalException(boolean hardError,
5757
boolean initiatedByApplication,
58-
Object reason, Object ref)
58+
Method reason, Object ref)
5959
{
6060
super((initiatedByApplication
6161
? ("clean " + (hardError ? "connection" : "channel") + " shutdown")
@@ -77,8 +77,8 @@ public ShutdownSignalException(boolean hardError,
7777
*/
7878
public boolean isInitiatedByApplication() { return _initiatedByApplication; }
7979

80-
/** @return the reason object, if any */
81-
public Object getReason() { return _reason; }
80+
/** @return the reason, if any */
81+
public Method getReason() { return _reason; }
8282

8383
/** @return Reference to Connection or Channel object that fired the signal **/
8484
public Object getReference() { return _ref; }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void ensureIsOpen()
187187
throws AlreadyClosedException
188188
{
189189
if (!isOpen()) {
190-
throw new AlreadyClosedException("Attempt to use closed channel", this);
190+
throw new AlreadyClosedException(getCloseReason());
191191
}
192192
}
193193

@@ -262,7 +262,7 @@ public void processShutdownSignal(ShutdownSignalException signal,
262262
synchronized (_channelMutex) {
263263
if (!setShutdownCauseIfOpen(signal)) {
264264
if (!ignoreClosed)
265-
throw new AlreadyClosedException("Attempt to use closed channel", this);
265+
throw new AlreadyClosedException(getCloseReason());
266266
}
267267

268268
_channelMutex.notifyAll();

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private final void ensureIsOpen()
163163
throws AlreadyClosedException
164164
{
165165
if (!isOpen()) {
166-
throw new AlreadyClosedException("Attempt to use closed connection", this);
166+
throw new AlreadyClosedException(getCloseReason());
167167
}
168168
}
169169

@@ -310,14 +310,11 @@ public void start()
310310
response = sm.handleChallenge(challenge, this.username, this.password);
311311
}
312312
} catch (ShutdownSignalException e) {
313-
Object shutdownReason = e.getReason();
314-
if (shutdownReason instanceof AMQCommand) {
315-
Method shutdownMethod = ((AMQCommand) shutdownReason).getMethod();
316-
if (shutdownMethod instanceof AMQP.Connection.Close) {
317-
AMQP.Connection.Close shutdownClose = (AMQP.Connection.Close) shutdownMethod;
318-
if (shutdownClose.getReplyCode() == AMQP.ACCESS_REFUSED) {
319-
throw new AuthenticationFailureException(shutdownClose.getReplyText());
320-
}
313+
Method shutdownMethod = e.getReason();
314+
if (shutdownMethod instanceof AMQP.Connection.Close) {
315+
AMQP.Connection.Close shutdownClose = (AMQP.Connection.Close) shutdownMethod;
316+
if (shutdownClose.getReplyCode() == AMQP.ACCESS_REFUSED) {
317+
throw new AuthenticationFailureException(shutdownClose.getReplyText());
321318
}
322319
}
323320
throw new PossibleAuthenticationFailureException(e);
@@ -532,11 +529,11 @@ private class MainLoop extends Thread {
532529
}
533530
} catch (EOFException ex) {
534531
if (!_brokerInitiatedShutdown)
535-
shutdown(ex, false, ex, true);
532+
shutdown(null, false, ex, true);
536533
} catch (Throwable ex) {
537534
_exceptionHandler.handleUnexpectedConnectionDriverException(AMQConnection.this,
538535
ex);
539-
shutdown(ex, false, ex, true);
536+
shutdown(null, false, ex, true);
540537
} finally {
541538
// Finally, shut down our underlying data connection.
542539
_frameHandler.close();
@@ -629,7 +626,7 @@ public boolean processControlCommand(Command c) throws IOException
629626
}
630627

631628
public void handleConnectionClose(Command closeCommand) {
632-
ShutdownSignalException sse = shutdown(closeCommand, false, null, _inConnectionNegotiation);
629+
ShutdownSignalException sse = shutdown(closeCommand.getMethod(), false, null, _inConnectionNegotiation);
633630
try {
634631
_channel0.quiescingTransmit(new AMQP.Connection.CloseOk.Builder().build());
635632
} catch (IOException _) { } // ignore
@@ -662,13 +659,13 @@ public SocketCloseWait(ShutdownSignalException sse) {
662659
* built from the argument, and stops this connection from accepting further work from the
663660
* application. {@link com.rabbitmq.client.ShutdownListener ShutdownListener}s for the
664661
* connection are notified when the main loop terminates.
665-
* @param reason object being shutdown
662+
* @param reason description of reason for the exception
666663
* @param initiatedByApplication true if caused by a client command
667664
* @param cause trigger exception which caused shutdown
668665
* @param notifyRpc true if outstanding rpc should be informed of shutdown
669666
* @return a shutdown signal built using the given arguments
670667
*/
671-
public ShutdownSignalException shutdown(Object reason,
668+
public ShutdownSignalException shutdown(Method reason,
672669
boolean initiatedByApplication,
673670
Throwable cause,
674671
boolean notifyRpc)
@@ -678,7 +675,7 @@ public ShutdownSignalException shutdown(Object reason,
678675
return sse;
679676
}
680677

681-
private ShutdownSignalException startShutdown(Object reason,
678+
private ShutdownSignalException startShutdown(Method reason,
682679
boolean initiatedByApplication,
683680
Throwable cause,
684681
boolean notifyRpc)
@@ -688,7 +685,7 @@ private ShutdownSignalException startShutdown(Object reason,
688685
sse.initCause(cause);
689686
if (!setShutdownCauseIfOpen(sse)) {
690687
if (initiatedByApplication)
691-
throw new AlreadyClosedException("Attempt to use closed connection", this);
688+
throw new AlreadyClosedException(getCloseReason());
692689
}
693690

694691
// stop any heartbeating
@@ -811,8 +808,11 @@ public AMQCommand transformReply(AMQCommand command) {
811808
_channel0.quiescingTransmit(reason);
812809
}
813810
} catch (TimeoutException tte) {
814-
if (!abort)
815-
throw new ShutdownSignalException(true, true, tte, this);
811+
if (!abort) {
812+
ShutdownSignalException sse = new ShutdownSignalException(true, true, null, this);
813+
sse.initCause(cause);
814+
throw sse;
815+
}
816816
} catch (ShutdownSignalException sse) {
817817
if (!abort)
818818
throw sse;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ private void callConfirmListeners(@SuppressWarnings("unused") Command command, B
477477
private void asyncShutdown(Command command) throws IOException {
478478
ShutdownSignalException signal = new ShutdownSignalException(false,
479479
false,
480-
command,
480+
command.getMethod(),
481481
this);
482482
synchronized (_channelMutex) {
483483
try {

0 commit comments

Comments
 (0)