Preventing NPEs in stores via notifyDelegate

Change-Id: I1c4b83c6a03b1f69a3ea1329724a7208d47cefa4
diff --git a/core/store/dist/src/main/java/org/onosproject/store/cfg/DistributedComponentConfigStore.java b/core/store/dist/src/main/java/org/onosproject/store/cfg/DistributedComponentConfigStore.java
index 08c7dd7..12fad4fb 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/cfg/DistributedComponentConfigStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/cfg/DistributedComponentConfigStore.java
@@ -101,9 +101,9 @@
             String[] keys = event.key().split(SEP);
             if (event.type() == INSERT || event.type() == UPDATE) {
                 String value = event.newValue().value();
-                delegate.notify(new ComponentConfigEvent(PROPERTY_SET, keys[0], keys[1], value));
+                notifyDelegate(new ComponentConfigEvent(PROPERTY_SET, keys[0], keys[1], value));
             } else if (event.type() == REMOVE) {
-                delegate.notify(new ComponentConfigEvent(PROPERTY_UNSET, keys[0], keys[1], null));
+                notifyDelegate(new ComponentConfigEvent(PROPERTY_UNSET, keys[0], keys[1], null));
             }
         }
     }
diff --git a/core/store/dist/src/main/java/org/onosproject/store/device/impl/ECDeviceStore.java b/core/store/dist/src/main/java/org/onosproject/store/device/impl/ECDeviceStore.java
index c64fa0a..5776515 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/device/impl/ECDeviceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/device/impl/ECDeviceStore.java
@@ -844,7 +844,7 @@
             if (event.type() == PUT) {
                 Device device = devices.get(event.key());
                 if (device != null) {
-                    delegate.notify(new DeviceEvent(PORT_STATS_UPDATED, device));
+                    notifyDelegate(new DeviceEvent(PORT_STATS_UPDATED, device));
                 }
             }
         }
diff --git a/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java b/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
index faf7e50..c81d7ab 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java
@@ -1823,7 +1823,7 @@
             if (event.type() == PUT) {
                 Device device = devices.get(event.key());
                 if (device != null) {
-                    delegate.notify(new DeviceEvent(PORT_STATS_UPDATED, device));
+                    notifyDelegate(new DeviceEvent(PORT_STATS_UPDATED, device));
                 }
             }
         }
diff --git a/incubator/store/src/main/java/org/onosproject/incubator/store/mcast/impl/DistributedMcastStore.java b/incubator/store/src/main/java/org/onosproject/incubator/store/mcast/impl/DistributedMcastStore.java
index d007bb2..a1d00b2 100644
--- a/incubator/store/src/main/java/org/onosproject/incubator/store/mcast/impl/DistributedMcastStore.java
+++ b/incubator/store/src/main/java/org/onosproject/incubator/store/mcast/impl/DistributedMcastStore.java
@@ -25,7 +25,6 @@
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.mcast.McastEvent;
 import org.onosproject.net.mcast.McastRoute;
-import org.onosproject.net.mcast.McastRouteInfo;
 import org.onosproject.net.mcast.McastStore;
 import org.onosproject.net.mcast.McastStoreDelegate;
 import org.onosproject.store.AbstractStore;
@@ -39,6 +38,7 @@
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicReference;
 
+import static org.onosproject.net.mcast.McastRouteInfo.mcastRouteInfo;
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
@@ -96,14 +96,14 @@
         switch (operation) {
             case ADD:
                 if (mcastRoutes.putIfAbsent(route, MulticastData.empty()) == null) {
-                    delegate.notify(new McastEvent(McastEvent.Type.ROUTE_ADDED,
-                                                   McastRouteInfo.mcastRouteInfo(route)));
+                    notifyDelegate(new McastEvent(McastEvent.Type.ROUTE_ADDED,
+                                                  mcastRouteInfo(route)));
                 }
                 break;
             case REMOVE:
                 if (mcastRoutes.remove(route) != null) {
-                    delegate.notify(new McastEvent(McastEvent.Type.ROUTE_REMOVED,
-                                                   McastRouteInfo.mcastRouteInfo(route)));
+                    notifyDelegate(new McastEvent(McastEvent.Type.ROUTE_REMOVED,
+                                                  mcastRouteInfo(route)));
                 }
                 break;
             default:
@@ -124,10 +124,10 @@
 
 
         if (data != null) {
-            delegate.notify(new McastEvent(McastEvent.Type.SOURCE_ADDED,
-                                           McastRouteInfo.mcastRouteInfo(route,
-                                                                         data.sinks(),
-                                                                         source)));
+            notifyDelegate(new McastEvent(McastEvent.Type.SOURCE_ADDED,
+                                          mcastRouteInfo(route,
+                                                         data.sinks(),
+                                                         source)));
         }
 
     }
@@ -157,19 +157,16 @@
         if (data != null) {
             switch (operation) {
                 case ADD:
-                    delegate.notify(new McastEvent(
-                            McastEvent.Type.SINK_ADDED,
-                            McastRouteInfo.mcastRouteInfo(route,
-                                                          sink,
-                                                          data.source())));
+                    notifyDelegate(new McastEvent(McastEvent.Type.SINK_ADDED,
+                                                  mcastRouteInfo(route, sink,
+                                                                 data.source())));
                     break;
                 case REMOVE:
                     if (data != null) {
-                        delegate.notify(new McastEvent(
-                                McastEvent.Type.SINK_REMOVED,
-                                McastRouteInfo.mcastRouteInfo(route,
-                                                              sink,
-                                                              data.source())));
+                        notifyDelegate(new McastEvent(McastEvent.Type.SINK_REMOVED,
+                                                      mcastRouteInfo(route,
+                                                                     sink,
+                                                                     data.source())));
                     }
                     break;
                 default: