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

Misc changes and cleanup (Step 2):
 * Added OnosInstanceId field to class TopologyEvent. For now it is
   just assigned, but is not used.

 * Minor refactoring of class TopologyEvent so it will be easier to make it
   immutable after its its internals and usage are inalized.

 * Modified the signature of method PathIntentMap.getIntentsByLink()
   to use LinkTuple for the lookup instead of LinkEvent.

 * Replaced (only inside onos/core/topology) the usage of Apache's
   Validate with Google's Preconditions for null-checking and assignment.

   With Apache's Validate we have to use two statements:
    Validate.notNull(foo);
    this.foo = foo;

   With Google's Preconditions we can do it with a single statement:
    this.foo = checkNotNull(foo);

   NOTE: Apache's commons-lang version 3.x adds Google's semantics.
   In the future, we need to decide (across all ONOS code) whether
   to use Google's Preconditions or Apache's Validate 3.x

 * Removed one of the LinkEvent convenience constructors, because it is used
   only in 1-2 places in the unit tests, and nowhere in the main code.

 * Few other (minor) cleanup changes

Change-Id: I05dae593ae1244a0af23515e7c73911f21275479
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java b/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
index cdae99c..df38b5e 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
@@ -2,6 +2,9 @@
 
 import java.util.Objects;
 
+import net.onrc.onos.core.util.OnosInstanceId;
+
+import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
  * Self-contained Topology event Object
@@ -9,63 +12,149 @@
  * TODO: For now the topology event contains one of the following events:
  * Switch, Port, Link, Host, Switch Mastership. In the future it will contain
  * multiple events in a single transaction.
+ * TODO: This class should become immutable after its internals and usage
+ * are finalized.
  */
-public class TopologyEvent {
-    SwitchEvent switchEvent = null;             // Set for Switch event
-    PortEvent portEvent = null;                 // Set for Port event
-    LinkEvent linkEvent = null;                 // Set for Link event
-    HostEvent hostEvent = null;                 // Set for Host event
-    MastershipEvent mastershipEvent = null;     // Set for Mastership event
+public final class TopologyEvent {
+    private final SwitchEvent switchEvent;      // Set for Switch event
+    private final PortEvent portEvent;          // Set for Port event
+    private final LinkEvent linkEvent;          // Set for Link event
+    private final HostEvent hostEvent;          // Set for Host event
+    private final MastershipEvent mastershipEvent; // Set for Mastership event
+    private final OnosInstanceId onosInstanceId;   // The ONOS Instance ID
 
     /**
-     * Default constructor.
+     * Default constructor for serializer.
      */
-    public TopologyEvent() {
+    @Deprecated
+    protected TopologyEvent() {
+        switchEvent = null;
+        portEvent = null;
+        linkEvent = null;
+        hostEvent = null;
+        mastershipEvent = null;
+        onosInstanceId = null;
     }
 
     /**
      * Constructor for given Switch event.
      *
      * @param switchEvent the Switch event to use.
+     * @param onosInstanceId the ONOS Instance ID that originates the event.
      */
-    TopologyEvent(SwitchEvent switchEvent) {
-        this.switchEvent = switchEvent;
+    TopologyEvent(SwitchEvent switchEvent, OnosInstanceId onosInstanceId) {
+        this.switchEvent = checkNotNull(switchEvent);
+        this.portEvent = null;
+        this.linkEvent = null;
+        this.hostEvent = null;
+        this.mastershipEvent = null;
+        this.onosInstanceId = checkNotNull(onosInstanceId);
     }
 
     /**
      * Constructor for given Port event.
      *
      * @param portEvent the Port event to use.
+     * @param onosInstanceId the ONOS Instance ID that originates the event.
      */
-    TopologyEvent(PortEvent portEvent) {
-        this.portEvent = portEvent;
+    TopologyEvent(PortEvent portEvent, OnosInstanceId onosInstanceId) {
+        this.switchEvent = null;
+        this.portEvent = checkNotNull(portEvent);
+        this.linkEvent = null;
+        this.hostEvent = null;
+        this.mastershipEvent = null;
+        this.onosInstanceId = checkNotNull(onosInstanceId);
     }
 
     /**
      * Constructor for given Link event.
      *
      * @param linkEvent the Link event to use.
+     * @param onosInstanceId the ONOS Instance ID that originates the event.
      */
-    TopologyEvent(LinkEvent linkEvent) {
-        this.linkEvent = linkEvent;
+    TopologyEvent(LinkEvent linkEvent, OnosInstanceId onosInstanceId) {
+        this.switchEvent = null;
+        this.portEvent = null;
+        this.linkEvent = checkNotNull(linkEvent);
+        this.hostEvent = null;
+        this.mastershipEvent = null;
+        this.onosInstanceId = checkNotNull(onosInstanceId);
     }
 
     /**
      * Constructor for given Host event.
      *
      * @param hostEvent the Host event to use.
+     * @param onosInstanceId the ONOS Instance ID that originates the event.
      */
-    TopologyEvent(HostEvent hostEvent) {
-        this.hostEvent = hostEvent;
+    TopologyEvent(HostEvent hostEvent, OnosInstanceId onosInstanceId) {
+        this.switchEvent = null;
+        this.portEvent = null;
+        this.linkEvent = null;
+        this.hostEvent = checkNotNull(hostEvent);
+        this.mastershipEvent = null;
+        this.onosInstanceId = checkNotNull(onosInstanceId);
     }
 
     /**
      * Constructor for given Switch Mastership event.
      *
      * @param mastershipEvent the Switch Mastership event to use.
+     * @param onosInstanceId the ONOS Instance ID that originates the event.
      */
-    TopologyEvent(MastershipEvent mastershipEvent) {
-        this.mastershipEvent = mastershipEvent;
+    TopologyEvent(MastershipEvent mastershipEvent,
+                  OnosInstanceId onosInstanceId) {
+        this.switchEvent = null;
+        this.portEvent = null;
+        this.linkEvent = null;
+        this.hostEvent = null;
+        this.mastershipEvent = checkNotNull(mastershipEvent);
+        this.onosInstanceId = checkNotNull(onosInstanceId);
+    }
+
+    /**
+     * Gets the Switch event.
+     *
+     * @return the Switch event.
+     */
+    public SwitchEvent getSwitchEvent() {
+        return switchEvent;
+    }
+
+    /**
+     * Gets the Port event.
+     *
+     * @return the Port event.
+     */
+    public PortEvent getPortEvent() {
+        return portEvent;
+    }
+
+    /**
+     * Gets the Link event.
+     *
+     * @return the Link event.
+     */
+    public LinkEvent getLinkEvent() {
+        return linkEvent;
+    }
+
+    /**
+     * Gets the Host event.
+     *
+     * @return the Host event.
+     */
+    public HostEvent getHostEvent() {
+        return hostEvent;
+    }
+
+    /**
+     * Gets the Mastership event.
+     *
+     * @return the Mastership event.
+     */
+    public MastershipEvent getMastershipEvent() {
+        return mastershipEvent;
     }
 
     /**
@@ -88,6 +177,7 @@
         }
 
         TopologyEvent other = (TopologyEvent) obj;
+        // TODO: For now the onosInstanceId is not used
         return Objects.equals(switchEvent, other.switchEvent) &&
                 Objects.equals(portEvent, other.portEvent) &&
                 Objects.equals(linkEvent, other.linkEvent) &&
@@ -97,6 +187,7 @@
 
     @Override
     public int hashCode() {
+        // TODO: For now the onosInstanceId is not used
         return Objects.hash(switchEvent, portEvent, linkEvent, hostEvent,
                             mastershipEvent);
     }
@@ -108,6 +199,7 @@
      */
     @Override
     public String toString() {
+        // TODO: For now the onosInstanceId is not used
         if (switchEvent != null) {
             return switchEvent.toString();
         }
@@ -132,6 +224,7 @@
      * @return the Topology event ID.
      */
     public byte[] getID() {
+        // TODO: For now the onosInstanceId is not used
         if (switchEvent != null) {
             return switchEvent.getID();
         }