GossipDeviceStore: Notifying applications of latest topology events received from peers
Showing
2 changed files
with
24 additions
and
5 deletions
| 1 | package org.onlab.onos.store; | 1 | package org.onlab.onos.store; |
| 2 | 2 | ||
| 3 | +import java.util.List; | ||
| 4 | + | ||
| 3 | import org.onlab.onos.event.Event; | 5 | import org.onlab.onos.event.Event; |
| 4 | 6 | ||
| 5 | import static com.google.common.base.Preconditions.checkState; | 7 | import static com.google.common.base.Preconditions.checkState; |
| ... | @@ -41,4 +43,15 @@ public class AbstractStore<E extends Event, D extends StoreDelegate<E>> | ... | @@ -41,4 +43,15 @@ public class AbstractStore<E extends Event, D extends StoreDelegate<E>> |
| 41 | delegate.notify(event); | 43 | delegate.notify(event); |
| 42 | } | 44 | } |
| 43 | } | 45 | } |
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * Notifies the delegate with the specified list of events. | ||
| 49 | + * | ||
| 50 | + * @param events list of events to delegate | ||
| 51 | + */ | ||
| 52 | + protected void notifyDelegate(List<E> events) { | ||
| 53 | + for (E event: events) { | ||
| 54 | + notifyDelegate(event); | ||
| 55 | + } | ||
| 56 | + } | ||
| 44 | } | 57 | } | ... | ... |
| ... | @@ -870,6 +870,12 @@ public class GossipDeviceStore | ... | @@ -870,6 +870,12 @@ public class GossipDeviceStore |
| 870 | clusterCommunicator.broadcast(message); | 870 | clusterCommunicator.broadcast(message); |
| 871 | } | 871 | } |
| 872 | 872 | ||
| 873 | + private void notifyDelegateIfNotNull(DeviceEvent event) { | ||
| 874 | + if (event != null) { | ||
| 875 | + notifyDelegate(event); | ||
| 876 | + } | ||
| 877 | + } | ||
| 878 | + | ||
| 873 | private class InternalDeviceEventListener implements ClusterMessageHandler { | 879 | private class InternalDeviceEventListener implements ClusterMessageHandler { |
| 874 | @Override | 880 | @Override |
| 875 | public void handle(ClusterMessage message) { | 881 | public void handle(ClusterMessage message) { |
| ... | @@ -881,7 +887,7 @@ public class GossipDeviceStore | ... | @@ -881,7 +887,7 @@ public class GossipDeviceStore |
| 881 | DeviceId deviceId = event.deviceId(); | 887 | DeviceId deviceId = event.deviceId(); |
| 882 | Timestamped<DeviceDescription> deviceDescription = event.deviceDescription(); | 888 | Timestamped<DeviceDescription> deviceDescription = event.deviceDescription(); |
| 883 | 889 | ||
| 884 | - createOrUpdateDeviceInternal(providerId, deviceId, deviceDescription); | 890 | + notifyDelegateIfNotNull(createOrUpdateDeviceInternal(providerId, deviceId, deviceDescription)); |
| 885 | } | 891 | } |
| 886 | } | 892 | } |
| 887 | 893 | ||
| ... | @@ -895,7 +901,7 @@ public class GossipDeviceStore | ... | @@ -895,7 +901,7 @@ public class GossipDeviceStore |
| 895 | DeviceId deviceId = event.deviceId(); | 901 | DeviceId deviceId = event.deviceId(); |
| 896 | Timestamp timestamp = event.timestamp(); | 902 | Timestamp timestamp = event.timestamp(); |
| 897 | 903 | ||
| 898 | - markOfflineInternal(deviceId, timestamp); | 904 | + notifyDelegateIfNotNull(markOfflineInternal(deviceId, timestamp)); |
| 899 | } | 905 | } |
| 900 | } | 906 | } |
| 901 | 907 | ||
| ... | @@ -909,7 +915,7 @@ public class GossipDeviceStore | ... | @@ -909,7 +915,7 @@ public class GossipDeviceStore |
| 909 | DeviceId deviceId = event.deviceId(); | 915 | DeviceId deviceId = event.deviceId(); |
| 910 | Timestamp timestamp = event.timestamp(); | 916 | Timestamp timestamp = event.timestamp(); |
| 911 | 917 | ||
| 912 | - removeDeviceInternal(deviceId, timestamp); | 918 | + notifyDelegateIfNotNull(removeDeviceInternal(deviceId, timestamp)); |
| 913 | } | 919 | } |
| 914 | } | 920 | } |
| 915 | 921 | ||
| ... | @@ -924,7 +930,7 @@ public class GossipDeviceStore | ... | @@ -924,7 +930,7 @@ public class GossipDeviceStore |
| 924 | DeviceId deviceId = event.deviceId(); | 930 | DeviceId deviceId = event.deviceId(); |
| 925 | Timestamped<List<PortDescription>> portDescriptions = event.portDescriptions(); | 931 | Timestamped<List<PortDescription>> portDescriptions = event.portDescriptions(); |
| 926 | 932 | ||
| 927 | - updatePortsInternal(providerId, deviceId, portDescriptions); | 933 | + notifyDelegate(updatePortsInternal(providerId, deviceId, portDescriptions)); |
| 928 | } | 934 | } |
| 929 | } | 935 | } |
| 930 | 936 | ||
| ... | @@ -939,7 +945,7 @@ public class GossipDeviceStore | ... | @@ -939,7 +945,7 @@ public class GossipDeviceStore |
| 939 | DeviceId deviceId = event.deviceId(); | 945 | DeviceId deviceId = event.deviceId(); |
| 940 | Timestamped<PortDescription> portDescription = event.portDescription(); | 946 | Timestamped<PortDescription> portDescription = event.portDescription(); |
| 941 | 947 | ||
| 942 | - updatePortStatusInternal(providerId, deviceId, portDescription); | 948 | + notifyDelegateIfNotNull(updatePortStatusInternal(providerId, deviceId, portDescription)); |
| 943 | } | 949 | } |
| 944 | } | 950 | } |
| 945 | } | 951 | } | ... | ... |
-
Please register or login to post a comment