Work toward ONOS-1451: Separate Event Key space per instance

Misc changes and cleanup (Step 3):

* Enabled the usage of ONOS Instance ID inside class TopologyEvent
  - Added the ONOS Instance ID as part of the TopologyEvent key
  - Use the ONOS Instance ID inside method toString() and equals()
  - Also, added new method TopologyEvent.getIDasByteBuffer()

* Added support for Mastership Events inside class TopologyEvents,
  including the JSON output.
  NOTE: For now the JSON output for the Topology object itself doesn't
  contain the corresponding Mastership info. The need for
  adding such info is TBD.

* Added new class TopologyEventFilter that will perform the filtering
  if incoming events. For now the internal logic of this filter is empty.

* Reordered some of the MastershipEvent-related code right before the
  SwitchEvent-related code so it is more consistent.

Change-Id: I940c4686b776f5136a10c25bc49278b69c548fc5
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyEvents.java b/src/main/java/net/onrc/onos/core/topology/TopologyEvents.java
index 1de3caf..543c1cb 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyEvents.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyEvents.java
@@ -15,10 +15,10 @@
  * <p/>
  * (b) The processing order of the "removed" events should be:
  * removedHostEvents, removedLinkEvents, removedPortEvents,
- * removedSwitchEvents
+ * removedSwitchEvents, removedMastershipEvents
  * <p/>
  * (c) The processing order of the "added" events should be:
- * addedSwitchEvents, addedPortEvents, addedLinkEvents,
+ * addedMastershipEvents, addedSwitchEvents, addedPortEvents, addedLinkEvents,
  * addedHostEvents
  * <p/>
  * The above ordering guarantees that removing a port for example
@@ -30,6 +30,8 @@
  */
 @JsonSerialize(using = TopologyEventsSerializer.class)
 public final class TopologyEvents {
+    private final Collection<MastershipEvent> addedMastershipEvents;
+    private final Collection<MastershipEvent> removedMastershipEvents;
     private final Collection<SwitchEvent> addedSwitchEvents;
     private final Collection<SwitchEvent> removedSwitchEvents;
     private final Collection<PortEvent> addedPortEvents;
@@ -42,6 +44,8 @@
     /**
      * Constructor.
      *
+     * @param addedMastershipEvents the collection of added Mastership Events.
+     * @param removedMastershipEvents the collection of removed Mastership Events.
      * @param addedSwitchEvents the collection of added Switch Events.
      * @param removedSwitchEvents the collection of removed Switch Events.
      * @param addedPortEvents the collection of added Port Events.
@@ -52,7 +56,9 @@
      * @param removedHostEvents the collection of removed Host Events.
      */
     // CHECKSTYLE:OFF suppress the warning about too many parameters
-    public TopologyEvents(Collection<SwitchEvent> addedSwitchEvents,
+    public TopologyEvents(Collection<MastershipEvent> addedMastershipEvents,
+                          Collection<MastershipEvent> removedMastershipEvents,
+                          Collection<SwitchEvent> addedSwitchEvents,
                           Collection<SwitchEvent> removedSwitchEvents,
                           Collection<PortEvent> addedPortEvents,
                           Collection<PortEvent> removedPortEvents,
@@ -61,6 +67,10 @@
                           Collection<HostEvent> addedHostEvents,
                           Collection<HostEvent> removedHostEvents) {
         // CHECKSTYLE:ON
+        this.addedMastershipEvents =
+            Collections.unmodifiableCollection(addedMastershipEvents);
+        this.removedMastershipEvents =
+            Collections.unmodifiableCollection(removedMastershipEvents);
         this.addedSwitchEvents =
             Collections.unmodifiableCollection(addedSwitchEvents);
         this.removedSwitchEvents =
@@ -80,6 +90,24 @@
     }
 
     /**
+     * Gets the collection of added Mastership Events.
+     *
+     * @return the collection of added Mastership Events.
+     */
+    public Collection<MastershipEvent> getAddedMastershipEvents() {
+        return addedMastershipEvents;
+    }
+
+    /**
+     * Gets the collection of removed Mastership Events.
+     *
+     * @return the collection of removed Mastership Events.
+     */
+    public Collection<MastershipEvent> getRemovedMastershipEvents() {
+        return removedMastershipEvents;
+    }
+
+    /**
      * Gets the collection of added Switch Events.
      *
      * @return the collection of added Switch Events.