X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fsal-netconf-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fsal%2Fconnect%2Fnetconf%2FNetconfDevice.java;h=ca821798b1f724536fb3e46fa91329dc0becde13;hb=c262d7912fba8fed542860f527dc173977d022dd;hp=4ffafe55b29528219898f0c3ba2df8847f40d803;hpb=c7190c8cced3b56410e6cf57d637be1accd2c1d0;p=netconf.git diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java index 4ffafe55b2..ca821798b1 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/NetconfDevice.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -116,6 +117,8 @@ public class NetconfDevice private final EventExecutor eventExecutor; private final NetconfNodeAugmentedOptional nodeOptional; + @GuardedBy("this") + private ListenableFuture> schemaFuturesList; @GuardedBy("this") private boolean connected = false; @@ -151,8 +154,8 @@ public class NetconfDevice } @Override - public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities, - final NetconfDeviceCommunicator listener) { + public synchronized void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities, + final NetconfDeviceCommunicator listener) { // SchemaContext setup has to be performed in a dedicated thread since // we are in a netty thread in this method // Yang models are being downloaded in this method and it would cause a @@ -178,6 +181,7 @@ public class NetconfDevice // Potentially acquire mount point list and interpret it final ListenableFuture futureContext = Futures.transformAsync(futureSchema, schemaContext -> createMountPointContext(schemaContext, baseSchema, listener), processingExecutor); + schemaFuturesList = Futures.allAsList(sourceResolverFuture, futureSchema, futureContext); Futures.addCallback(futureContext, new FutureCallback() { @Override @@ -188,8 +192,12 @@ public class NetconfDevice @Override public void onFailure(final Throwable cause) { - LOG.warn("{}: Unexpected error resolving device sources", id, cause); + if (cause instanceof CancellationException) { + LOG.warn("{}: Device communicator was tear down since the schema setup started", id); + return; + } + LOG.warn("{}: Unexpected error resolving device sources", id, cause); // No more sources, fail or try to reconnect if (cause instanceof EmptySchemaContextException) { if (nodeOptional != null && nodeOptional.getIgnoreMissingSchemaSources().getAllowed()) { @@ -342,10 +350,14 @@ public class NetconfDevice } @Override - public void onRemoteSessionDown() { + public synchronized void onRemoteSessionDown() { setConnected(false); + if (schemaFuturesList != null && !schemaFuturesList.isDone()) { + if (!schemaFuturesList.cancel(true)) { + LOG.warn("The cleanup of Schema Futures for device {} was unsuccessful.", id); + } + } notificationHandler.onRemoteSchemaDown(); - salFacade.onDeviceDisconnected(); sourceRegistrations.forEach(SchemaSourceRegistration::close); sourceRegistrations.clear();