-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AXON-335 : Prevent CommandGateway.sendAndWait() from hanging indefini…
…tely in certain specific cases
- Loading branch information
1 parent
6d45d27
commit cd59915
Showing
7 changed files
with
414 additions
and
86 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...amework/commandhandling/distributed/jgroups/CommandResponseProcessingFailedException.java
This file contains 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,46 @@ | ||
/* | ||
* Copyright (c) 2010-2015. Axon Framework | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.axonframework.commandhandling.distributed.jgroups; | ||
|
||
import org.axonframework.common.AxonException; | ||
|
||
/** | ||
* Exception indicating that a failure occured during processing of a command response. Typically this would imply an unserializable command response / exception message | ||
* | ||
* @author Srideep Prasad | ||
*/ | ||
|
||
public class CommandResponseProcessingFailedException extends AxonException{ | ||
|
||
/** | ||
* Initializes the exception using the given <code>message</code>. | ||
* | ||
* @param message The message describing the exception | ||
*/ | ||
public CommandResponseProcessingFailedException(String message) { | ||
super(message); | ||
} | ||
|
||
/** | ||
* Initializes the exception using the given <code>message</code> and <code>cause</code>. | ||
* | ||
* @param message The message describing the exception | ||
* @param cause The underlying cause of the exception | ||
*/ | ||
public CommandResponseProcessingFailedException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
This file contains 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
53 changes: 53 additions & 0 deletions
53
...ork/commandhandling/distributed/jgroups/support/callbacks/MemberAwareCommandCallback.java
This file contains 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,53 @@ | ||
/* | ||
* Copyright (c) 2010-2015. Axon Framework | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.axonframework.commandhandling.distributed.jgroups.support.callbacks; | ||
|
||
|
||
import org.axonframework.commandhandling.CommandCallback; | ||
import org.jgroups.Address; | ||
import org.jgroups.View; | ||
|
||
/** | ||
* Internal class used used by JGroupsConnector. For internal use only. Pulled outside to allow for seamless unit testing | ||
* | ||
* @author Allard Buijze | ||
* @since 2.0 | ||
*/ | ||
public class MemberAwareCommandCallback<R> implements CommandCallback<R> { | ||
|
||
private final Address dest; | ||
private final CommandCallback<R> callback; | ||
|
||
public MemberAwareCommandCallback(Address dest, CommandCallback<R> callback) { | ||
this.dest = dest; | ||
this.callback = callback; | ||
} | ||
|
||
public boolean isMemberLive(View currentView) { | ||
return currentView.containsMember(dest); | ||
} | ||
|
||
@Override | ||
public void onSuccess(R result) { | ||
callback.onSuccess(result); | ||
} | ||
|
||
@Override | ||
public void onFailure(Throwable cause) { | ||
callback.onFailure(cause); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...axonframework/commandhandling/distributed/jgroups/support/callbacks/ReplyingCallback.java
This file contains 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,78 @@ | ||
/* | ||
* Copyright (c) 2010-2015. Axon Framework | ||
* | ||
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.axonframework.commandhandling.distributed.jgroups.support.callbacks; | ||
|
||
import org.axonframework.commandhandling.CommandCallback; | ||
import org.axonframework.commandhandling.CommandMessage; | ||
import org.axonframework.commandhandling.distributed.jgroups.CommandResponseProcessingFailedException; | ||
import org.axonframework.commandhandling.distributed.jgroups.ReplyMessage; | ||
import org.axonframework.serializer.Serializer; | ||
import org.jgroups.JChannel; | ||
import org.jgroups.Message; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Internal class used used by JGroupsConnector. For internal use only. Pulled outside to allow for seamless unit testing | ||
* | ||
* @author Allard Buijze | ||
* @since 2.0 | ||
*/ | ||
public class ReplyingCallback implements CommandCallback<Object> { | ||
|
||
private final Message msg; | ||
private final CommandMessage commandMessage; | ||
private final JChannel channel; | ||
private final Serializer serializer; | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ReplyingCallback.class); | ||
|
||
public ReplyingCallback(JChannel channel, Message msg, CommandMessage commandMessage, Serializer serializer) { | ||
this.msg = msg; | ||
this.commandMessage = commandMessage; | ||
this.channel = channel; | ||
this.serializer = serializer; | ||
} | ||
|
||
@Override | ||
public void onSuccess(Object result) { | ||
try { | ||
channel.send(msg.getSrc(), new ReplyMessage(commandMessage.getIdentifier(), | ||
result, | ||
null, serializer)); | ||
} catch (Exception e) { | ||
logger.error("Unable to send reply to command [name: {}, id: {}]. ", | ||
new Object[]{commandMessage.getCommandName(), | ||
commandMessage.getIdentifier(), | ||
e}); | ||
throw new CommandResponseProcessingFailedException(String.format("An error occurred while attempting to process command response of type : %s, Exception Message: %s", result.getClass().getName(), e.getMessage()),e); | ||
} | ||
} | ||
|
||
@Override | ||
public void onFailure(Throwable cause) { | ||
try { | ||
channel.send(msg.getSrc(), new ReplyMessage(commandMessage.getIdentifier(), | ||
null, | ||
cause, serializer)); | ||
} catch (Exception e) { | ||
logger.error("Unable to send reply:", e); | ||
//Not capturing the causative exception while throwing - the causative exception may not be serializable and this may cause the commandbus to hangup. | ||
throw new CommandResponseProcessingFailedException(String.format("An error occurred while attempting to process command exception response of type : %s, Exception Message:: %s", e.getClass().getName(), e.getMessage())); | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.