- final ChannelFuture future = channel.writeAndFlush(netconfMessage);
- if (delayedEncoder != null) {
- replaceMessageEncoder(delayedEncoder);
- delayedEncoder = null;
- }
-
- return future;
+ // From: https://github.com/netty/netty/issues/3887
+ // Netty can provide "ordering" in the following situations:
+ // 1. You are doing all writes from the EventLoop thread; OR
+ // 2. You are doing no writes from the EventLoop thread (i.e. all writes are being done in other thread(s)).
+ //
+ // Restconf writes to a netconf mountpoint execute multiple messages
+ // and one of these was executed from a restconf thread thus breaking ordering so
+ // we need to execute all messages from an EventLoop thread.
+ final DefaultChannelPromise proxyFuture = new DefaultChannelPromise(channel);
+ channel.eventLoop().execute(new Runnable() {
+ @Override
+ public void run() {
+ final ChannelFuture future = channel.writeAndFlush(netconfMessage);
+ future.addListener(new FutureListener<Void>() {
+ @Override
+ public void operationComplete(Future<Void> future) throws Exception {
+ if (future.isSuccess()) {
+ proxyFuture.setSuccess();
+ } else {
+ proxyFuture.setFailure(future.cause());
+ }
+ }
+ });
+ if (delayedEncoder != null) {
+ replaceMessageEncoder(delayedEncoder);
+ delayedEncoder = null;
+ }
+ }
+ });
+
+ return proxyFuture;