* @return the operation result
* @throws IOException for any error
*/
public ModelNode executeAwaitConnectionClosed(final ModelNode operation) throws IOException {
final DomainTestClient client = internalGetOrCreateClient();
final Channel channel = client.getChannel();
if( null == channel )
throw new IllegalStateException("Didn't get a remoting channel from the DomainTestClient.");
final Connection ref = channel.getConnection();
ModelNode result = new ModelNode();
try {
result = client.execute(operation);
// IN case the operation wasn't successful, don't bother waiting
if(! "success".equals(result.get("outcome").asString())) {
return result;
}
} catch(Exception e) {
if(e instanceof IOException) {
final Throwable cause = e.getCause();
if(cause instanceof ExecutionException) {
// ignore, this might happen if the channel gets closed before we got the response
} else {
throw (IOException) e;
}
} else {
throw new RuntimeException(e);
}
}
try {
if(channel != null) {
// Wait for the channel to close
channel.awaitClosed();
}
// Wait for the connection to be closed
connection.awaitConnectionClosed(ref);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();