BUG-3771: Use sync on FutureChannels intead of await 39/29539/2
authorClaudio D. Gasparini <cgaspari@cisco.com>
Wed, 11 Nov 2015 09:46:12 +0000 (10:46 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 12 Nov 2015 00:02:50 +0000 (00:02 +0000)
"Await" waits until future has finished and throw execution
if thread was interrupted."Sync"" instead waits for this
future until it is done, and re throws the cause of
the failure if this future failed.
When closing the module, first we ensure that channel
has been closed and if it didn't fail we proceed
with next closures.

Change-Id: I1240d6fdb6986b8c30251206d8027db7b1a987fa
Signed-off-by: Claudio D. Gasparini <cgaspari@cisco.com>
pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/PCEPTopologyProvider.java

index e5999cd3bf39de23a6ce11fab76f9a6d43763cca..e53c899f4756f316274469b98bc88a45c735e624 100644 (file)
@@ -11,7 +11,6 @@ import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelFutureListener;
 import java.net.InetSocketAddress;
 import java.util.concurrent.ExecutionException;
 import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
@@ -76,29 +75,27 @@ public final class PCEPTopologyProvider extends DefaultTopologyReference impleme
 
     @Override
     public void close() throws InterruptedException {
-        LOG.debug("Closing server channel {}", this.channel);
-
-        this.channel.close().addListener(new ChannelFutureListener() {
-            @Override
-            public void operationComplete(final ChannelFuture f) {
-                LOG.debug("Server channel {} closed", f.channel());
+        try {
+            this.channel.close().sync();
+            LOG.debug("Server channel {} closed", this.channel);
+        } catch (InterruptedException e) {
+            LOG.error("Failed to close channel {}", this.channel, e);
+        }
 
-                try {
-                    PCEPTopologyProvider.this.network.close();
-                } catch (final Exception e) {
-                    LOG.error("Failed to unregister network-level RPCs", e);
-                }
-                try {
-                    PCEPTopologyProvider.this.element.close();
-                } catch (final Exception e) {
-                    LOG.error("Failed to unregister element-level RPCs", e);
-                }
-                try {
-                    PCEPTopologyProvider.this.manager.close();
-                } catch (final Exception e) {
-                    LOG.error("Failed to shutdown session manager", e);
-                }
-            }
-        }).await();
+        try {
+            PCEPTopologyProvider.this.network.close();
+        } catch (final Exception e) {
+            LOG.error("Failed to unregister network-level RPCs", e);
+        }
+        try {
+            PCEPTopologyProvider.this.element.close();
+        } catch (final Exception e) {
+            LOG.error("Failed to unregister element-level RPCs", e);
+        }
+        try {
+            PCEPTopologyProvider.this.manager.close();
+        } catch (final Exception e) {
+            LOG.error("Failed to shutdown session manager", e);
+        }
     }
 }