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/test/java/net/onrc/onos/core/util/serializers/KryoFactoryTest.java b/src/test/java/net/onrc/onos/core/util/serializers/KryoFactoryTest.java
index 9431cfe..712a50f 100644
--- a/src/test/java/net/onrc/onos/core/util/serializers/KryoFactoryTest.java
+++ b/src/test/java/net/onrc/onos/core/util/serializers/KryoFactoryTest.java
@@ -46,6 +46,7 @@
     private static final Dpid DPID_B = new Dpid(Long.MAX_VALUE);
     private static final PortNumber PORT_NO_A = new PortNumber((short) 42);
     private static final PortNumber PORT_NO_B = new PortNumber((short) 65534);
+    private static final String ONOS_INSTANCE_NAME = "ONOS-Instance-Test";
 
     private static final double SEC_IN_NANO = 1000 * 1000 * 1000.0;
 
@@ -172,7 +173,8 @@
         // To be more strict, we should be checking serialized byte[].
         { // CHECKSTYLE IGNORE THIS LINE
             HostEvent obj = new HostEvent(MACAddress.valueOf(0x12345678));
-            obj.createStringAttribute(TopologyElement.TYPE, TopologyElement.TYPE_PACKET_LAYER);
+            obj.createStringAttribute(TopologyElement.TYPE,
+                                      TopologyElement.TYPE_PACKET_LAYER);
             obj.addAttachmentPoint(new SwitchPort(DPID_A, PORT_NO_A));
             // avoid using System.currentTimeMillis() var-int size may change
             obj.setLastSeenTime(392860800000L);
@@ -184,8 +186,10 @@
         }
 
         { // CHECKSTYLE IGNORE THIS LINE
-            LinkEvent obj = new LinkEvent(DPID_A, PORT_NO_A, DPID_B, PORT_NO_B);
-            obj.createStringAttribute(TopologyElement.TYPE, TopologyElement.TYPE_PACKET_LAYER);
+            LinkEvent obj = new LinkEvent(new SwitchPort(DPID_A, PORT_NO_A),
+                                          new SwitchPort(DPID_B, PORT_NO_B));
+            obj.createStringAttribute(TopologyElement.TYPE,
+                                      TopologyElement.TYPE_PACKET_LAYER);
             obj.freeze();
             Result result = benchType(obj, EqualityCheck.EQUALS);
             results.add(result);
@@ -195,7 +199,8 @@
 
         { // CHECKSTYLE IGNORE THIS LINE
             PortEvent obj = new PortEvent(DPID_A, PORT_NO_A);
-            obj.createStringAttribute(TopologyElement.TYPE, TopologyElement.TYPE_PACKET_LAYER);
+            obj.createStringAttribute(TopologyElement.TYPE,
+                                      TopologyElement.TYPE_PACKET_LAYER);
             obj.freeze();
             Result result = benchType(obj, EqualityCheck.EQUALS);
             results.add(result);
@@ -205,7 +210,8 @@
 
         { // CHECKSTYLE IGNORE THIS LINE
             SwitchEvent obj = new SwitchEvent(DPID_A);
-            obj.createStringAttribute(TopologyElement.TYPE, TopologyElement.TYPE_PACKET_LAYER);
+            obj.createStringAttribute(TopologyElement.TYPE,
+                                      TopologyElement.TYPE_PACKET_LAYER);
             obj.freeze();
             Result result = benchType(obj, EqualityCheck.EQUALS);
             results.add(result);
@@ -215,23 +221,27 @@
 
         { // CHECKSTYLE IGNORE THIS LINE
             SwitchEvent evt = new SwitchEvent(DPID_A);
-            evt.createStringAttribute(TopologyElement.TYPE, TopologyElement.TYPE_PACKET_LAYER);
+            evt.createStringAttribute(TopologyElement.TYPE,
+                                      TopologyElement.TYPE_PACKET_LAYER);
             evt.freeze();
+            OnosInstanceId onosInstanceId =
+                new OnosInstanceId(ONOS_INSTANCE_NAME);
 
             // using the back door to access package-scoped constructor
             Constructor<TopologyEvent> swConst
-                = TopologyEvent.class.getDeclaredConstructor(SwitchEvent.class);
+                = TopologyEvent.class.getDeclaredConstructor(SwitchEvent.class,
+                        OnosInstanceId.class);
             swConst.setAccessible(true);
-            TopologyEvent obj = swConst.newInstance(evt);
+            TopologyEvent obj = swConst.newInstance(evt, onosInstanceId);
 
             Result result = benchType(obj, EqualityCheck.TO_STRING);
             results.add(result);
             // update me if serialized form is expected to change
-            assertEquals(27, result.size);
+            assertEquals(47, result.size);
         }
 
         { // CHECKSTYLE IGNORE THIS LINE
-            OnosInstanceId id = new OnosInstanceId("Some_Instance_Name");
+            OnosInstanceId id = new OnosInstanceId(ONOS_INSTANCE_NAME);
 
             Result result = benchType(id, EqualityCheck.EQUALS);
             results.add(result);