Fix shutdown crash if link pruner runs after services are shut down

Change-Id: I7eb3dc9ed19b1a20182d34f8e25df151e32f572f
diff --git a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
index 7459ce2..69449b3 100644
--- a/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
+++ b/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LldpLinkProvider.java
@@ -142,6 +142,8 @@
 
     private ScheduledExecutorService executor;
 
+    private boolean shuttingDown = false;
+
     // TODO: Add sanity checking for the configurable params based on the delays
     private static final long DEVICE_SYNC_DELAY = 5;
     private static final long LINK_PRUNER_DELAY = 3;
@@ -238,6 +240,7 @@
 
     @Activate
     public void activate(ComponentContext context) {
+        shuttingDown = false;
         cfgService.registerProperties(getClass());
         appId = coreService.registerApplication(PROVIDER_NAME);
 
@@ -265,6 +268,7 @@
 
     @Deactivate
     public void deactivate() {
+        shuttingDown = true;
         cfgRegistry.removeListener(cfgListener);
         factories.forEach(cfgRegistry::unregisterConfigFactory);
 
@@ -352,7 +356,6 @@
         deviceService.removeListener(deviceListener);
         packetService.removeProcessor(packetProcessor);
 
-
         if (executor != null) {
             executor.shutdownNow();
         }
@@ -690,7 +693,13 @@
 
             } catch (Exception e) {
                 // Catch all exceptions to avoid task being suppressed
-                log.error("Exception thrown during link pruning process", e);
+                if (!shuttingDown) {
+                    // Error condition
+                    log.error("Exception thrown during link pruning process", e);
+                } else {
+                    // Provider is shutting down, the error can be ignored
+                    log.trace("Shutting down, ignoring error", e);
+                }
             }
         }