-
Notifications
You must be signed in to change notification settings - Fork 581
Update AutorecoveringConnection to call ShutdownListeners before reco… #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
src/main/java/com/rabbitmq/client/RecoverableConnection.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// The contents of this file are subject to the Mozilla Public License | ||
// Version 1.1 (the "License"); you may not use this file except in | ||
// compliance with the License. You may obtain a copy of the License | ||
// at http://www.mozilla.org/MPL/ | ||
// | ||
// Software distributed under the License is distributed on an "AS IS" | ||
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | ||
// the License for the specific language governing rights and | ||
// limitations under the License. | ||
// | ||
// The Original Code is RabbitMQ. | ||
// | ||
// The Initial Developer of the Original Code is GoPivotal, Inc. | ||
// Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. | ||
// | ||
|
||
package com.rabbitmq.client; | ||
/** | ||
* Convenience interface which combines a Connection and Recoverable together. | ||
* | ||
* @see Connection | ||
* @see Recoverable | ||
* | ||
*/ | ||
public interface RecoverableConnection extends Connection, Recoverable { } |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/rabbitmq/client/RecoverableShutdownSignalException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.rabbitmq.client; | ||
|
||
public class RecoverableShutdownSignalException extends ShutdownSignalException { | ||
|
||
/** Default for non-checking. */ | ||
private static final long serialVersionUID = 1L; | ||
|
||
private final boolean _recoveryToBeAttempted; | ||
|
||
public RecoverableShutdownSignalException(boolean hardError, boolean initiatedByApplication, Method reason, | ||
Object ref) { | ||
this(hardError, initiatedByApplication, reason, ref, "", null, false); | ||
} | ||
|
||
/** | ||
* Construct a RecoverableShutdownSignalException from the arguments. | ||
* @param hardError the relevant hard error | ||
* @param initiatedByApplication if the shutdown was client-initiated | ||
* @param reason AMQP method describing the exception reason | ||
* @param ref Reference to Connection or Channel that fired the signal | ||
* @param messagePrefix prefix to add to exception message | ||
*/ | ||
public RecoverableShutdownSignalException(boolean hardError, | ||
boolean initiatedByApplication, | ||
Method reason, Object ref, String messagePrefix, Throwable cause) | ||
{ | ||
this(hardError, initiatedByApplication, reason, ref, messagePrefix, cause, false); | ||
} | ||
|
||
public RecoverableShutdownSignalException(ShutdownSignalException sse, boolean recoveryToBeAttempted) { | ||
this(sse.isHardError(), sse.isInitiatedByApplication(), sse.getReason(), sse.getReference(), sse.getMessagePrefix(), sse.getCause(), recoveryToBeAttempted); | ||
} | ||
|
||
public RecoverableShutdownSignalException(boolean hardError, | ||
boolean initiatedByApplication, | ||
Method reason, Object ref, String messagePrefix, Throwable cause, boolean recoveryToBeAttempted) | ||
{ | ||
super(hardError, initiatedByApplication, reason, ref, messagePrefix, cause); | ||
this._recoveryToBeAttempted = recoveryToBeAttempted; | ||
} | ||
|
||
public boolean isRecoveryToBeAttempted() { | ||
return _recoveryToBeAttempted; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/main/java/com/rabbitmq/client/impl/ForwardingShutdownNotifier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// The contents of this file are subject to the Mozilla Public License | ||
// Version 1.1 (the "License"); you may not use this file except in | ||
// compliance with the License. You may obtain a copy of the License | ||
// at http://www.mozilla.org/MPL/ | ||
// | ||
// Software distributed under the License is distributed on an "AS IS" | ||
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | ||
// the License for the specific language governing rights and | ||
// limitations under the License. | ||
// | ||
// The Original Code is RabbitMQ. | ||
// | ||
// The Initial Developer of the Original Code is GoPivotal, Inc. | ||
// Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved. | ||
// | ||
|
||
|
||
package com.rabbitmq.client.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.rabbitmq.client.ShutdownListener; | ||
import com.rabbitmq.client.ShutdownNotifier; | ||
import com.rabbitmq.client.ShutdownSignalException; | ||
|
||
/** | ||
* A class that manages {@link ShutdownListener}s and remembers the reason for a shutdown. Both | ||
* {@link com.rabbitmq.client.Channel Channel}s and {@link com.rabbitmq.client.Connection | ||
* Connection}s have shutdown listeners. | ||
* | ||
* The ForwardingShutdownNotifier will only notify listeners when notifyListeners is called, | ||
* and may be called multiple times. | ||
* | ||
* This notifier will always report that it is open. | ||
*/ | ||
public class ForwardingShutdownNotifier implements ShutdownNotifier { | ||
|
||
/** Monitor for shutdown listeners and shutdownCause */ | ||
private final Object monitor = new Object(); | ||
|
||
/** List of all shutdown listeners associated with the component */ | ||
private final List<ShutdownListener> shutdownListeners = new ArrayList<ShutdownListener>(); | ||
|
||
private volatile ShutdownSignalException lastShutdownCause = null; | ||
|
||
public void addShutdownListener(ShutdownListener listener) | ||
{ | ||
synchronized(this.monitor) { | ||
this.shutdownListeners.add(listener); | ||
} | ||
} | ||
|
||
/** | ||
* Returns the last close reason notified to listeners. | ||
*/ | ||
public ShutdownSignalException getCloseReason() { | ||
synchronized(this.monitor) { | ||
return this.lastShutdownCause; | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* Do not call this directly, use notifyListeners(cause) | ||
*/ | ||
public void notifyListeners() | ||
{ | ||
|
||
} | ||
|
||
public void removeShutdownListener(ShutdownListener listener) | ||
{ | ||
synchronized(this.monitor) { | ||
this.shutdownListeners.remove(listener); | ||
} | ||
} | ||
|
||
/** Always reports open */ | ||
public boolean isOpen() { | ||
return true; | ||
} | ||
|
||
/** | ||
* Notifies the registered listeners of this cause. | ||
* @param sse | ||
*/ | ||
public void notifyListeners(final ShutdownSignalException sse) { | ||
ShutdownListener[] sdls = null; | ||
synchronized(this.monitor) { | ||
sdls = this.shutdownListeners | ||
.toArray(new ShutdownListener[this.shutdownListeners.size()]); | ||
this.lastShutdownCause = sse; | ||
} | ||
for (ShutdownListener l: sdls) { | ||
try { | ||
l.shutdownCompleted(sse); | ||
} catch (Exception e) { | ||
// FIXME: proper logging | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it non-obvious how the (user-provided) hooks are recovered.