Skip to content

Commit 241910f

Browse files
author
Simon MacMullen
committed
Merge bug25999
2 parents 9b95d4a + 03961ca commit 241910f

File tree

8 files changed

+34
-44
lines changed

8 files changed

+34
-44
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
@@ -170,7 +170,7 @@ private final void ensureIsOpen()
170170
throws AlreadyClosedException
171171
{
172172
if (!isOpen()) {
173-
throw new AlreadyClosedException("Attempt to use closed connection", this);
173+
throw new AlreadyClosedException(getCloseReason());
174174
}
175175
}
176176

@@ -331,14 +331,11 @@ public void start()
331331
response = sm.handleChallenge(challenge, this.username, this.password);
332332
}
333333
} catch (ShutdownSignalException e) {
334-
Object shutdownReason = e.getReason();
335-
if (shutdownReason instanceof AMQCommand) {
336-
Method shutdownMethod = ((AMQCommand) shutdownReason).getMethod();
337-
if (shutdownMethod instanceof AMQP.Connection.Close) {
338-
AMQP.Connection.Close shutdownClose = (AMQP.Connection.Close) shutdownMethod;
339-
if (shutdownClose.getReplyCode() == AMQP.ACCESS_REFUSED) {
340-
throw new AuthenticationFailureException(shutdownClose.getReplyText());
341-
}
334+
Method shutdownMethod = e.getReason();
335+
if (shutdownMethod instanceof AMQP.Connection.Close) {
336+
AMQP.Connection.Close shutdownClose = (AMQP.Connection.Close) shutdownMethod;
337+
if (shutdownClose.getReplyCode() == AMQP.ACCESS_REFUSED) {
338+
throw new AuthenticationFailureException(shutdownClose.getReplyText());
342339
}
343340
}
344341
throw new PossibleAuthenticationFailureException(e);
@@ -563,11 +560,11 @@ private class MainLoop implements Runnable {
563560
}
564561
} catch (EOFException ex) {
565562
if (!_brokerInitiatedShutdown)
566-
shutdown(ex, false, ex, true);
563+
shutdown(null, false, ex, true);
567564
} catch (Throwable ex) {
568565
_exceptionHandler.handleUnexpectedConnectionDriverException(AMQConnection.this,
569566
ex);
570-
shutdown(ex, false, ex, true);
567+
shutdown(null, false, ex, true);
571568
} finally {
572569
// Finally, shut down our underlying data connection.
573570
_frameHandler.close();
@@ -660,7 +657,7 @@ public boolean processControlCommand(Command c) throws IOException
660657
}
661658

662659
public void handleConnectionClose(Command closeCommand) {
663-
ShutdownSignalException sse = shutdown(closeCommand, false, null, _inConnectionNegotiation);
660+
ShutdownSignalException sse = shutdown(closeCommand.getMethod(), false, null, _inConnectionNegotiation);
664661
try {
665662
_channel0.quiescingTransmit(new AMQP.Connection.CloseOk.Builder().build());
666663
} catch (IOException _) { } // ignore
@@ -694,13 +691,13 @@ public SocketCloseWait(ShutdownSignalException sse) {
694691
* built from the argument, and stops this connection from accepting further work from the
695692
* application. {@link com.rabbitmq.client.ShutdownListener ShutdownListener}s for the
696693
* connection are notified when the main loop terminates.
697-
* @param reason object being shutdown
694+
* @param reason description of reason for the exception
698695
* @param initiatedByApplication true if caused by a client command
699696
* @param cause trigger exception which caused shutdown
700697
* @param notifyRpc true if outstanding rpc should be informed of shutdown
701698
* @return a shutdown signal built using the given arguments
702699
*/
703-
public ShutdownSignalException shutdown(Object reason,
700+
public ShutdownSignalException shutdown(Method reason,
704701
boolean initiatedByApplication,
705702
Throwable cause,
706703
boolean notifyRpc)
@@ -710,7 +707,7 @@ public ShutdownSignalException shutdown(Object reason,
710707
return sse;
711708
}
712709

713-
private ShutdownSignalException startShutdown(Object reason,
710+
private ShutdownSignalException startShutdown(Method reason,
714711
boolean initiatedByApplication,
715712
Throwable cause,
716713
boolean notifyRpc)
@@ -720,7 +717,7 @@ private ShutdownSignalException startShutdown(Object reason,
720717
sse.initCause(cause);
721718
if (!setShutdownCauseIfOpen(sse)) {
722719
if (initiatedByApplication)
723-
throw new AlreadyClosedException("Attempt to use closed connection", this);
720+
throw new AlreadyClosedException(getCloseReason());
724721
}
725722

726723
// stop any heartbeating
@@ -843,8 +840,11 @@ public AMQCommand transformReply(AMQCommand command) {
843840
_channel0.quiescingTransmit(reason);
844841
}
845842
} catch (TimeoutException tte) {
846-
if (!abort)
847-
throw new ShutdownSignalException(true, true, tte, this);
843+
if (!abort) {
844+
ShutdownSignalException sse = new ShutdownSignalException(true, true, null, this);
845+
sse.initCause(cause);
846+
throw sse;
847+
}
848848
} catch (ShutdownSignalException sse) {
849849
if (!abort)
850850
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 {

test/src/com/rabbitmq/client/test/BrokerTestCase.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,8 @@ public void checkShutdownSignal(int expectedCode, IOException ioe) {
129129
checkShutdownSignal(expectedCode, sse);
130130
}
131131

132-
public void checkShutdownSignal(int expectedCode, AlreadyClosedException ace) {
133-
ShutdownNotifierComponent snc = (ShutdownNotifierComponent) ace.getReference();
134-
ShutdownSignalException sse = snc.getCloseReason();
135-
checkShutdownSignal(expectedCode, sse);
136-
}
137-
138132
public void checkShutdownSignal(int expectedCode, ShutdownSignalException sse) {
139-
Object reason = sse.getReason();
140-
Method method;
141-
if (reason instanceof Command) {
142-
method = ((Command) reason).getMethod();
143-
} else {
144-
method = (Method) reason;
145-
}
133+
Method method = sse.getReason();
146134
channel = null;
147135
if (sse.isHardError()) {
148136
connection = null;

test/src/com/rabbitmq/client/test/functional/ExceptionHandling.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public void testNullExceptionHandler() {
5757
}
5858

5959
private void wait(CountDownLatch latch) throws InterruptedException {
60-
latch.await(30, TimeUnit.MINUTES);
60+
latch.await(1800, TimeUnit.SECONDS);
6161
}
6262
}

test/src/com/rabbitmq/examples/perf/MulticastParams.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ private static boolean exists(Connection connection, Checker checker) throws IOE
237237
}
238238
catch (IOException e) {
239239
ShutdownSignalException sse = (ShutdownSignalException) e.getCause();
240-
Command closeCommand = (Command) sse.getReason();
241240
if (!sse.isHardError()) {
242-
AMQP.Channel.Close closeMethod = (AMQP.Channel.Close) closeCommand.getMethod();
241+
AMQP.Channel.Close closeMethod = (AMQP.Channel.Close) sse.getReason();
243242
if (closeMethod.getReplyCode() == AMQP.NOT_FOUND) {
244243
return false;
245244
}

0 commit comments

Comments
 (0)