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/Host.java b/src/main/java/net/onrc/onos/core/topology/Host.java
index 05849c5..4e0c2e4 100644
--- a/src/main/java/net/onrc/onos/core/topology/Host.java
+++ b/src/main/java/net/onrc/onos/core/topology/Host.java
@@ -33,7 +33,7 @@
     public Iterable<Port> getAttachmentPoints();
 
     /**
-     * Gest the Host last seen time.
+     * Gets the Host last seen time.
      * <p/>
      *
      * @return the Host last seen time. (UTC in ms)
diff --git a/src/main/java/net/onrc/onos/core/topology/HostEvent.java b/src/main/java/net/onrc/onos/core/topology/HostEvent.java
index ebaf688..1c64939 100644
--- a/src/main/java/net/onrc/onos/core/topology/HostEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/HostEvent.java
@@ -11,6 +11,7 @@
 import net.onrc.onos.core.topology.web.serializers.HostEventSerializer;
 import net.onrc.onos.core.util.SwitchPort;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import org.codehaus.jackson.map.annotate.JsonSerialize;
 
 /**
@@ -42,11 +43,13 @@
         mac = null;
     }
 
+    /**
+     * Creates the Host object.
+     *
+     * @param mac the MAC address to identify the host
+     */
     public HostEvent(MACAddress mac) {
-        if (mac == null) {
-            throw new IllegalArgumentException("Host mac cannot be null");
-        }
-        this.mac = mac;
+        this.mac = checkNotNull(mac);
         this.attachmentPoints = new LinkedList<>();
     }
 
diff --git a/src/main/java/net/onrc/onos/core/topology/HostImpl.java b/src/main/java/net/onrc/onos/core/topology/HostImpl.java
index 289e1e0..7370be0 100644
--- a/src/main/java/net/onrc/onos/core/topology/HostImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/HostImpl.java
@@ -3,7 +3,7 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.lang.Validate;
+import static com.google.common.base.Preconditions.checkNotNull;
 
 import net.floodlightcontroller.util.MACAddress;
 import net.onrc.onos.core.util.SwitchPort;
@@ -25,8 +25,7 @@
      */
     HostImpl(TopologyInternal topology, MACAddress mac) {
         super(topology);
-        Validate.notNull(mac);
-        this.id = mac;
+        this.id = checkNotNull(mac);
     }
 
     @Override
diff --git a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
index 00b4b90..f7ae6d3 100644
--- a/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/LinkEvent.java
@@ -9,7 +9,7 @@
 import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.SwitchPort;
 
-import org.apache.commons.lang.Validate;
+import static com.google.common.base.Preconditions.checkNotNull;
 import org.codehaus.jackson.map.annotate.JsonSerialize;
 
 /**
@@ -42,9 +42,7 @@
      * @param id link tuple to identify this link
      */
     public LinkEvent(LinkTuple id) {
-        Validate.notNull(id);
-
-        this.id = id;
+        this.id = checkNotNull(id);
     }
 
     /**
@@ -74,19 +72,6 @@
     }
 
     /**
-     * Creates the Link object.
-     *
-     * @param srcDpid source switch DPID
-     * @param srcPortNo source port number
-     * @param dstDpid destination switch DPID
-     * @param dstPortNo destination port number
-     */
-    public LinkEvent(Dpid srcDpid, PortNumber srcPortNo,
-                     Dpid dstDpid, PortNumber dstPortNo) {
-        this(new LinkTuple(srcDpid, srcPortNo, dstDpid, dstPortNo));
-    }
-
-    /**
      * Gets a {@link LinkTuple} that identifies this link.
      *
      * @return a LinkTuple representing the Port
diff --git a/src/main/java/net/onrc/onos/core/topology/LinkImpl.java b/src/main/java/net/onrc/onos/core/topology/LinkImpl.java
index 5886c8e..ee60d2d 100644
--- a/src/main/java/net/onrc/onos/core/topology/LinkImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/LinkImpl.java
@@ -4,7 +4,7 @@
 
 import net.onrc.onos.core.util.LinkTuple;
 
-import org.apache.commons.lang.Validate;
+import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
  * Handler to Link object stored in In-memory Topology snapshot.
@@ -23,8 +23,7 @@
      */
     LinkImpl(TopologyInternal topology, LinkTuple linkTuple) {
         super(topology);
-        Validate.notNull(linkTuple);
-        this.id = linkTuple;
+        this.id = checkNotNull(linkTuple);
     }
 
     @Override
diff --git a/src/main/java/net/onrc/onos/core/topology/MastershipEvent.java b/src/main/java/net/onrc/onos/core/topology/MastershipEvent.java
index 5668e2f..8106a39 100644
--- a/src/main/java/net/onrc/onos/core/topology/MastershipEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/MastershipEvent.java
@@ -9,7 +9,7 @@
 import net.onrc.onos.core.util.Dpid;
 import net.onrc.onos.core.util.OnosInstanceId;
 
-import org.apache.commons.lang.Validate;
+import static com.google.common.base.Preconditions.checkNotNull;
 import org.codehaus.jackson.map.annotate.JsonSerialize;
 
 /**
@@ -45,11 +45,8 @@
      */
     public MastershipEvent(Dpid dpid, OnosInstanceId onosInstanceId,
                            Role role) {
-        Validate.notNull(dpid);
-        Validate.notNull(onosInstanceId);
-
-        this.dpid = dpid;
-        this.onosInstanceId = onosInstanceId;
+        this.dpid = checkNotNull(dpid);
+        this.onosInstanceId = checkNotNull(onosInstanceId);
         this.role = role;
     }
 
diff --git a/src/main/java/net/onrc/onos/core/topology/PortEvent.java b/src/main/java/net/onrc/onos/core/topology/PortEvent.java
index 305f4aa..0fa5a7e 100644
--- a/src/main/java/net/onrc/onos/core/topology/PortEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/PortEvent.java
@@ -5,7 +5,7 @@
 import net.onrc.onos.core.util.PortNumber;
 import net.onrc.onos.core.util.SwitchPort;
 
-import org.apache.commons.lang.Validate;
+import static com.google.common.base.Preconditions.checkNotNull;
 import org.codehaus.jackson.map.annotate.JsonSerialize;
 
 import java.nio.ByteBuffer;
@@ -45,8 +45,7 @@
      * @param switchPort SwitchPort to identify this port
      */
     public PortEvent(SwitchPort switchPort) {
-        Validate.notNull(switchPort);
-        this.id = switchPort;
+        this.id = checkNotNull(switchPort);
     }
 
     /**
@@ -132,8 +131,8 @@
     public static final int PORTID_BYTES = SwitchEvent.SWITCHID_BYTES + 2 + 8;
 
     public static ByteBuffer getPortID(Dpid dpid, PortNumber number) {
-        Validate.notNull(dpid);
-        Validate.notNull(number);
+        checkNotNull(dpid);
+        checkNotNull(number);
         return getPortID(dpid.value(), number.value());
     }
 
@@ -156,5 +155,4 @@
     public ByteBuffer getIDasByteBuffer() {
         return getPortID(getDpid(), getPortNumber());
     }
-
 }
diff --git a/src/main/java/net/onrc/onos/core/topology/PortImpl.java b/src/main/java/net/onrc/onos/core/topology/PortImpl.java
index 3f4cdfb..5067049 100644
--- a/src/main/java/net/onrc/onos/core/topology/PortImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/PortImpl.java
@@ -3,7 +3,7 @@
 import java.util.Collection;
 import java.util.Map;
 
-import org.apache.commons.lang.Validate;
+import static com.google.common.base.Preconditions.checkNotNull;
 
 import net.onrc.onos.core.util.Dpid;
 import net.onrc.onos.core.util.PortNumber;
@@ -26,8 +26,7 @@
      */
     PortImpl(TopologyInternal topology, SwitchPort switchPort) {
         super(topology);
-        Validate.notNull(switchPort);
-        this.id = switchPort;
+        this.id = checkNotNull(switchPort);
     }
 
     /**
diff --git a/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java b/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java
index fdc4b84..f724fae 100644
--- a/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/SwitchEvent.java
@@ -6,8 +6,8 @@
 import java.nio.ByteBuffer;
 import java.util.Objects;
 
+import static com.google.common.base.Preconditions.checkNotNull;
 import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.apache.commons.lang.Validate;
 
 /**
  * Self-contained Switch Object.
@@ -34,8 +34,7 @@
      * @param dpid Dpid to identify this switch
      */
     public SwitchEvent(Dpid dpid) {
-        Validate.notNull(dpid);
-        this.dpid = dpid;
+        this.dpid = checkNotNull(dpid);
     }
 
     /**
diff --git a/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java b/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java
index e0e02d5..29df7b8 100644
--- a/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/SwitchImpl.java
@@ -11,7 +11,7 @@
 import net.onrc.onos.core.util.Dpid;
 import net.onrc.onos.core.util.PortNumber;
 
-import org.apache.commons.lang.Validate;
+import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
  * Handler to Switch object stored in In-memory Topology snapshot.
@@ -31,8 +31,7 @@
      */
     SwitchImpl(TopologyInternal topology, Dpid dpid) {
         super(topology);
-        Validate.notNull(dpid);
-        this.id = dpid;
+        this.id = checkNotNull(dpid);
     }
 
     @Override
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyElement.java b/src/main/java/net/onrc/onos/core/topology/TopologyElement.java
index bb32958..f169456 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyElement.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyElement.java
@@ -6,7 +6,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 
-import org.apache.commons.lang.Validate;
+import static com.google.common.base.Preconditions.checkNotNull;
 
 /**
  * Base class for Topology Elements.
@@ -150,7 +150,7 @@
         if (isFrozen) {
             throw new IllegalStateException("Tried to modify frozen object: " + this);
         }
-        Validate.notNull(value, "attribute value cannot be null");
+        checkNotNull(value, "attribute value cannot be null");
 
         return this.stringAttributes.putIfAbsent(attr, value) == null;
     }
@@ -160,7 +160,7 @@
         if (isFrozen) {
             throw new IllegalStateException("Tried to modify frozen object: " + this);
         }
-        Validate.notNull(value, "attribute value cannot be null");
+        checkNotNull(value, "attribute value cannot be null");
 
         return this.stringAttributes.replace(attr, oldValue, value);
     }
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();
         }
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
index e733c68..10fa6be 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
@@ -273,11 +273,11 @@
             //
             for (EventEntry<TopologyEvent> event : events) {
                 TopologyEvent topologyEvent = event.eventData();
-                SwitchEvent switchEvent = topologyEvent.switchEvent;
-                PortEvent portEvent = topologyEvent.portEvent;
-                LinkEvent linkEvent = topologyEvent.linkEvent;
-                HostEvent hostEvent = topologyEvent.hostEvent;
-                MastershipEvent mastershipEvent = topologyEvent.mastershipEvent;
+                SwitchEvent switchEvent = topologyEvent.getSwitchEvent();
+                PortEvent portEvent = topologyEvent.getPortEvent();
+                LinkEvent linkEvent = topologyEvent.getLinkEvent();
+                HostEvent hostEvent = topologyEvent.getHostEvent();
+                MastershipEvent mastershipEvent = topologyEvent.getMastershipEvent();
 
                 //
                 // Extract the events
@@ -625,13 +625,17 @@
         if (datastore.addSwitch(switchEvent, portEvents)) {
             log.debug("Sending add switch: {}", switchEvent);
             // Send out notification
-            TopologyEvent topologyEvent = new TopologyEvent(switchEvent);
+            TopologyEvent topologyEvent =
+                new TopologyEvent(switchEvent,
+                                  registryService.getOnosInstanceId());
             eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
 
             // Send out notification for each port
             for (PortEvent portEvent : portEvents) {
                 log.debug("Sending add port: {}", portEvent);
-                topologyEvent = new TopologyEvent(portEvent);
+                topologyEvent =
+                    new TopologyEvent(portEvent,
+                                      registryService.getOnosInstanceId());
                 eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
             }
 
@@ -737,7 +741,9 @@
         if (datastore.addPort(portEvent)) {
             log.debug("Sending add port: {}", portEvent);
             // Send out notification
-            TopologyEvent topologyEvent = new TopologyEvent(portEvent);
+            TopologyEvent topologyEvent =
+                new TopologyEvent(portEvent,
+                                  registryService.getOnosInstanceId());
             eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
 
             // Store the new Port Event in the local cache
@@ -817,7 +823,9 @@
         if (datastore.addLink(linkEvent)) {
             log.debug("Sending add link: {}", linkEvent);
             // Send out notification
-            TopologyEvent topologyEvent = new TopologyEvent(linkEvent);
+            TopologyEvent topologyEvent =
+                new TopologyEvent(linkEvent,
+                                  registryService.getOnosInstanceId());
             eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
 
             // Store the new Link Event in the local cache
@@ -864,7 +872,9 @@
     public void putHostDiscoveryEvent(HostEvent hostEvent) {
         if (datastore.addHost(hostEvent)) {
             // Send out notification
-            TopologyEvent topologyEvent = new TopologyEvent(hostEvent);
+            TopologyEvent topologyEvent =
+                new TopologyEvent(hostEvent,
+                                  registryService.getOnosInstanceId());
             eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
             log.debug("Put the host info into the cache of the topology. mac {}", hostEvent.getMac());
 
@@ -921,7 +931,9 @@
     @Override
     public void putSwitchMastershipEvent(MastershipEvent mastershipEvent) {
         // Send out notification
-        TopologyEvent topologyEvent = new TopologyEvent(mastershipEvent);
+        TopologyEvent topologyEvent =
+            new TopologyEvent(mastershipEvent,
+                              registryService.getOnosInstanceId());
         eventChannel.addEntry(topologyEvent.getID(), topologyEvent);
     }
 
@@ -1363,8 +1375,15 @@
                 continue;
             }
 
+            //
+            // TODO: Using the local ONOS Instance ID below is incorrect.
+            // Currently, this code is not used, and it might go away in the
+            // future.
+            //
             SwitchEvent switchEvent = new SwitchEvent(new Dpid(sw.getDpid()));
-            TopologyEvent topologyEvent = new TopologyEvent(switchEvent);
+            TopologyEvent topologyEvent =
+                new TopologyEvent(switchEvent,
+                                  registryService.getOnosInstanceId());
             EventEntry<TopologyEvent> eventEntry =
                     new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
                             topologyEvent);
@@ -1377,30 +1396,49 @@
                 continue;
             }
 
-            PortEvent portEvent = new PortEvent(
-                    new Dpid(p.getDpid()),
-                    new PortNumber(p.getNumber().shortValue()));
-            TopologyEvent topologyEvent = new TopologyEvent(portEvent);
+            //
+            // TODO: Using the local ONOS Instance ID below is incorrect.
+            // Currently, this code is not used, and it might go away in the
+            // future.
+            //
+            PortEvent portEvent =
+                new PortEvent(new Dpid(p.getDpid()),
+                              new PortNumber(p.getNumber().shortValue()));
+            TopologyEvent topologyEvent =
+                new TopologyEvent(portEvent,
+                                  registryService.getOnosInstanceId());
             EventEntry<TopologyEvent> eventEntry =
                     new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
                             topologyEvent);
             collection.add(eventEntry);
         }
 
-         for (KVDevice d : KVDevice.getAllDevices()) {
-              HostEvent devEvent = new HostEvent(MACAddress.valueOf(d.getMac()));
-              for (byte[] portId : d.getAllPortIds()) {
-                  devEvent.addAttachmentPoint(
-                          new SwitchPort(KVPort.getDpidFromKey(portId),
-                                  KVPort.getNumberFromKey(portId)));
-              }
-         }
+        for (KVDevice d : KVDevice.getAllDevices()) {
+            //
+            // TODO: Using the local ONOS Instance ID below is incorrect.
+            // Currently, this code is not used, and it might go away in the
+            // future.
+            //
+            HostEvent devEvent = new HostEvent(MACAddress.valueOf(d.getMac()));
+            for (byte[] portId : d.getAllPortIds()) {
+                devEvent.addAttachmentPoint(
+                        new SwitchPort(KVPort.getDpidFromKey(portId),
+                        KVPort.getNumberFromKey(portId)));
+            }
+        }
 
         for (KVLink l : KVLink.getAllLinks()) {
+            //
+            // TODO: Using the local ONOS Instance ID below is incorrect.
+            // Currently, this code is not used, and it might go away in the
+            // future.
+            //
             LinkEvent linkEvent = new LinkEvent(
-                    new SwitchPort(l.getSrc().dpid, l.getSrc().number),
-                    new SwitchPort(l.getDst().dpid, l.getDst().number));
-            TopologyEvent topologyEvent = new TopologyEvent(linkEvent);
+                        new SwitchPort(l.getSrc().dpid, l.getSrc().number),
+                        new SwitchPort(l.getDst().dpid, l.getDst().number));
+            TopologyEvent topologyEvent =
+                new TopologyEvent(linkEvent,
+                                  registryService.getOnosInstanceId());
             EventEntry<TopologyEvent> eventEntry =
                     new EventEntry<TopologyEvent>(EventEntry.Type.ENTRY_ADD,
                             topologyEvent);
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyObject.java b/src/main/java/net/onrc/onos/core/topology/TopologyObject.java
index 445c2d8..b83c99b 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyObject.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyObject.java
@@ -1,6 +1,6 @@
 package net.onrc.onos.core.topology;
 
-import org.apache.commons.lang.Validate;
+import static com.google.common.base.Preconditions.checkNotNull;
 
 
 /**
@@ -28,8 +28,7 @@
      * @param topology Topology instance this object belongs to
      */
     protected TopologyObject(TopologyInternal topology) {
-        Validate.notNull(topology);
-        this.topology = topology;
+        this.topology = checkNotNull(topology);
     }
 
     // TODO Add method to replace topology snapshot