Gather topology element info to TopologyImpl

- Moved all the self-contained topology elements (*Event) to
  TopologyImpl. (ONOS-1651)
  Now {Switch, Port, Link, Host}Impl is just a handler attached to
  TopologyImpl.
- BugFix: TopologyManager.addHost(HostEvent)
  HostEvent could be pushed to reorder queue multiple times,
  if multiple attachment point was given.
- BugFix: TopologyManager.{addLink, removePort}
  Properly handle if Host attachment point was removed as side-effect.
- BugFix: Copy HostEvent#lastSeenTime
- BugFix: Event instance notified to listeners (api*Events) should be
  the event which was/will be in the replica. (TopologyManager)
- Added/Modified debug log in TopologyManager so that log will be in
  same format for each event type.
  "{Added, Update, Removed} <Self-contained>"
- Removed backdoor method and use TestUtils instead.

Change-Id: If053d6f11f39574a188e7a52cb6194114f8afe5d
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 935b3c5..4e0da5e 100644
--- a/src/main/java/net/onrc/onos/core/topology/PortImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/PortImpl.java
@@ -10,61 +10,35 @@
 import net.onrc.onos.core.util.SwitchPort;
 
 /**
- * Port Object stored in In-memory Topology.
+ * Handler to Port object stored in In-memory Topology snapshot.
  * <p/>
- * TODO REMOVE following design memo: This object itself may hold the DBObject,
- * but this Object itself will not issue any read/write to the DataStore.
  */
 public class PortImpl extends TopologyObject implements Port {
 
-    //////////////////////////////////////////////////////
-    /// Topology element attributes
-    ///  - any changes made here needs to be replicated.
-    //////////////////////////////////////////////////////
-    private PortEvent portObj;
+    private final SwitchPort id;
 
 
     /**
-     * Creates a Port object based on {@link PortEvent}.
-     *
-     * @param topology Topology instance this object belongs to
-     * @param scPort self contained {@link PortEvent}
-     */
-    public PortImpl(Topology topology, PortEvent scPort) {
-        super(topology);
-        Validate.notNull(scPort);
-
-        // TODO should we assume portObj is already frozen before this call
-        //      or expect attribute update will happen after .
-        if (scPort.isFrozen()) {
-            this.portObj = scPort;
-        } else {
-            this.portObj = new PortEvent(scPort);
-            this.portObj.freeze();
-        }
-    }
-
-    /**
-     * Creates a Port object with empty attributes.
+     * Creates a Port handler object.
      *
      * @param topology Topology instance this object belongs to
      * @param switchPort SwitchPort
      */
-    public PortImpl(Topology topology, SwitchPort switchPort) {
-        this(topology, new PortEvent(switchPort).freeze());
+    PortImpl(TopologyInternal topology, SwitchPort switchPort) {
+        super(topology);
+        Validate.notNull(switchPort);
+        this.id = switchPort;
     }
 
     /**
-     * Creates a Port object with empty attributes.
+     * Creates a Port handler object.
      *
      * @param topology Topology instance this object belongs to
      * @param dpid DPID
      * @param number PortNumber
      */
-    public PortImpl(Topology topology, Dpid dpid, PortNumber number) {
+    PortImpl(TopologyInternal topology, Dpid dpid, PortNumber number) {
         this(topology, new SwitchPort(dpid, number));
-        Validate.notNull(dpid);
-        Validate.notNull(number);
     }
 
     @Override
@@ -79,7 +53,7 @@
 
     @Override
     public SwitchPort asSwitchPort() {
-        return portObj.getSwitchPort();
+        return id;
     }
 
     @Override
@@ -87,12 +61,6 @@
         return getStringAttribute(PortEvent.DESCRIPTION, "");
     }
 
-    void setDescription(String description) {
-//        portObj.createStringAttribute(attr, value);
-        // TODO implement using attributes
-        throw new UnsupportedOperationException("Not implemented yet");
-    }
-
     @Override
     public Long getHardwareAddress() {
         // TODO implement using attributes?
@@ -170,7 +138,7 @@
     }
 
     @Override
-    public Iterable<Host> getHosts() {
+    public Collection<Host> getHosts() {
         topology.acquireReadLock();
         try {
             return topology.getHosts(this.asSwitchPort());
@@ -179,21 +147,9 @@
         }
     }
 
-    void replaceStringAttributes(PortEvent updated) {
-        Validate.isTrue(this.asSwitchPort().equals(updated.getSwitchPort()),
-                "Wrong PortEvent given.");
-
-        // XXX simply replacing whole self-contained object for now
-        if (updated.isFrozen()) {
-            this.portObj = updated;
-        } else {
-            this.portObj = new PortEvent(updated).freeze();
-        }
-    }
-
     @Override
     public String getStringAttribute(String attr) {
-        return portObj.getStringAttribute(attr);
+        return this.topology.getPortEvent(id).getStringAttribute(attr);
     }
 
     @Override
@@ -208,7 +164,7 @@
 
     @Override
     public Map<String, String> getAllStringAttributes() {
-        return portObj.getAllStringAttributes();
+        return this.topology.getPortEvent(id).getAllStringAttributes();
     }
 
     @Override