Skip to content

Commit 03961ca

Browse files
merge heads
2 parents 14f8518 + df183d3 commit 03961ca

File tree

7 files changed

+33
-43
lines changed

7 files changed

+33
-43
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
@@ -164,7 +164,7 @@ private final void ensureIsOpen()
164164
throws AlreadyClosedException
165165
{
166166
if (!isOpen()) {
167-
throw new AlreadyClosedException("Attempt to use closed connection", this);
167+
throw new AlreadyClosedException(getCloseReason());
168168
}
169169
}
170170

@@ -312,14 +312,11 @@ public void start()
312312
response = sm.handleChallenge(challenge, this.username, this.password);
313313
}
314314
} catch (ShutdownSignalException e) {
315-
Object shutdownReason = e.getReason();
316-
if (shutdownReason instanceof AMQCommand) {
317-
Method shutdownMethod = ((AMQCommand) shutdownReason).getMethod();
318-
if (shutdownMethod instanceof AMQP.Connection.Close) {
319-
AMQP.Connection.Close shutdownClose = (AMQP.Connection.Close) shutdownMethod;
320-
if (shutdownClose.getReplyCode() == AMQP.ACCESS_REFUSED) {
321-
throw new AuthenticationFailureException(shutdownClose.getReplyText());
322-
}
315+
Method shutdownMethod = e.getReason();
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());
323320
}
324321
}
325322
throw new PossibleAuthenticationFailureException(e);
@@ -534,11 +531,11 @@ private class MainLoop extends Thread {
534531
}
535532
} catch (EOFException ex) {
536533
if (!_brokerInitiatedShutdown)
537-
shutdown(ex, false, ex, true);
534+
shutdown(null, false, ex, true);
538535
} catch (Throwable ex) {
539536
_exceptionHandler.handleUnexpectedConnectionDriverException(AMQConnection.this,
540537
ex);
541-
shutdown(ex, false, ex, true);
538+
shutdown(null, false, ex, true);
542539
} finally {
543540
// Finally, shut down our underlying data connection.
544541
_frameHandler.close();
@@ -631,7 +628,7 @@ public boolean processControlCommand(Command c) throws IOException
631628
}
632629

633630
public void handleConnectionClose(Command closeCommand) {
634-
ShutdownSignalException sse = shutdown(closeCommand, false, null, _inConnectionNegotiation);
631+
ShutdownSignalException sse = shutdown(closeCommand.getMethod(), false, null, _inConnectionNegotiation);
635632
try {
636633
_channel0.quiescingTransmit(new AMQP.Connection.CloseOk.Builder().build());
637634
} catch (IOException _) { } // ignore
@@ -664,13 +661,13 @@ public SocketCloseWait(ShutdownSignalException sse) {
664661
* built from the argument, and stops this connection from accepting further work from the
665662
* application. {@link com.rabbitmq.client.ShutdownListener ShutdownListener}s for the
666663
* connection are notified when the main loop terminates.
667-
* @param reason object being shutdown
664+
* @param reason description of reason for the exception
668665
* @param initiatedByApplication true if caused by a client command
669666
* @param cause trigger exception which caused shutdown
670667
* @param notifyRpc true if outstanding rpc should be informed of shutdown
671668
* @return a shutdown signal built using the given arguments
672669
*/
673-
public ShutdownSignalException shutdown(Object reason,
670+
public ShutdownSignalException shutdown(Method reason,
674671
boolean initiatedByApplication,
675672
Throwable cause,
676673
boolean notifyRpc)
@@ -680,7 +677,7 @@ public ShutdownSignalException shutdown(Object reason,
680677
return sse;
681678
}
682679

683-
private ShutdownSignalException startShutdown(Object reason,
680+
private ShutdownSignalException startShutdown(Method reason,
684681
boolean initiatedByApplication,
685682
Throwable cause,
686683
boolean notifyRpc)
@@ -690,7 +687,7 @@ private ShutdownSignalException startShutdown(Object reason,
690687
sse.initCause(cause);
691688
if (!setShutdownCauseIfOpen(sse)) {
692689
if (initiatedByApplication)
693-
throw new AlreadyClosedException("Attempt to use closed connection", this);
690+
throw new AlreadyClosedException(getCloseReason());
694691
}
695692

696693
// stop any heartbeating
@@ -813,8 +810,11 @@ public AMQCommand transformReply(AMQCommand command) {
813810
_channel0.quiescingTransmit(reason);
814811
}
815812
} catch (TimeoutException tte) {
816-
if (!abort)
817-
throw new ShutdownSignalException(true, true, tte, this);
813+
if (!abort) {
814+
ShutdownSignalException sse = new ShutdownSignalException(true, true, null, this);
815+
sse.initCause(cause);
816+
throw sse;
817+
}
818818
} catch (ShutdownSignalException sse) {
819819
if (!abort)
820820
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/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)