TopologyListener interface proto

Change-Id: I31bf5739a11d608f470eee2e785cc9a4ad687a25
diff --git a/src/main/java/net/onrc/onos/core/topology/ITopologyListener2.java b/src/main/java/net/onrc/onos/core/topology/ITopologyListener2.java
new file mode 100644
index 0000000..9478599
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/topology/ITopologyListener2.java
@@ -0,0 +1,22 @@
+package net.onrc.onos.core.topology;
+
+import java.util.List;
+
+import net.onrc.onos.api.batchoperation.BatchOperationEntry;
+import net.onrc.onos.core.topology.TopologyBatchOperation.Operator;
+
+// FIXME replace ITopologyListener
+/**
+ * Topology event listener interface.
+ */
+public interface ITopologyListener2 {
+
+    /**
+     * Topology event handler.
+     *
+     * @param updated Topology after applying changes
+     * @param changes topology events
+     */
+    public void topologyEvent(ImmutableTopology updated,
+            List<BatchOperationEntry<Operator, TopologyBatchTarget>> changes);
+}
diff --git a/src/main/java/net/onrc/onos/core/topology/ImmutableTopology.java b/src/main/java/net/onrc/onos/core/topology/ImmutableTopology.java
new file mode 100644
index 0000000..0f7ab96
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/topology/ImmutableTopology.java
@@ -0,0 +1,216 @@
+package net.onrc.onos.core.topology;
+
+import java.util.Collection;
+
+import net.floodlightcontroller.util.MACAddress;
+import net.onrc.onos.core.util.Dpid;
+import net.onrc.onos.core.util.PortNumber;
+import net.onrc.onos.core.util.SwitchPort;
+
+/**
+ * ImmutableTopology.
+ */
+public interface ImmutableTopology {
+
+    /**
+     * Gets the switch for a given switch DPID.
+     *
+     * @param dpid the switch dpid.
+     * @return the switch if found, otherwise null.
+     */
+    public Switch getSwitch(Dpid dpid);
+
+    /**
+     * Gets all switches in the network.
+     *
+     * @return all switches in the network.
+     */
+    public Iterable<Switch> getSwitches();
+
+    /**
+     * Gets the port on a switch.
+     *
+     * @param dpid   the switch DPID.
+     * @param portNumber the switch port number.
+     * @return the switch port if found, otherwise null.
+     */
+    public Port getPort(Dpid dpid, PortNumber portNumber);
+
+    /**
+     * Gets the port on a switch.
+     *
+     * @param port port identifier
+     * @return the switch port if found, otherwise null.
+     */
+    public Port getPort(SwitchPort port);
+
+    /**
+     * Gets all ports on a switch specified.
+     *
+     * @param dpid Switch dpid
+     * @return ports.
+     */
+    public Collection<Port> getPorts(Dpid dpid);
+
+    /**
+     * Gets the outgoing link from a switch port.
+     * <p/>
+     * FIXME As a temporary workaround, it will look for type "packet" and
+     * returns it if found, else return whichever link is found first.
+     *
+     * @param dpid   the switch DPID.
+     * @param portNumber the switch port number.
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getOutgoingLink(Dpid dpid, PortNumber portNumber);
+
+    /**
+     * Gets the outgoing link from a switch port.
+     *
+     * @param dpid   the switch DPID.
+     * @param portNumber the switch port number.
+     * @param type   type of the link
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getOutgoingLink(Dpid dpid, PortNumber portNumber, String type);
+
+    /**
+     * Gets the outgoing link from a switch port.
+     * <p/>
+     * FIXME As a temporary workaround, it will look for type "packet" and
+     * returns it if found, else return whichever link is found first.
+     *
+     * @param port port identifier
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getOutgoingLink(SwitchPort port);
+
+    /**
+     * Gets the outgoing link from a switch port.
+     *
+     * @param port port identifier
+     * @param type type of the link
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getOutgoingLink(SwitchPort port, String type);
+
+    /**
+     * Gets all the outgoing link from a switch port.
+     *
+     * @param port port identifier
+     * @return outgoing links
+     */
+    public Collection<Link> getOutgoingLinks(SwitchPort port);
+
+    /**
+     * Gets the incoming link to a switch port.
+     * <p/>
+     * FIXME As a temporary workaround, it will look for type "packet" and
+     * returns it if found, else return whichever link is found first.
+     *
+     * @param dpid   the switch DPID.
+     * @param portNumber the switch port number.
+     * @return the incoming link if found, otherwise null.
+     */
+    public Link getIncomingLink(Dpid dpid, PortNumber portNumber);
+
+    /**
+     * Gets the incoming link to a switch port.
+     * <p/>
+     * FIXME As a temporary workaround, it will look for type "packet" and
+     * returns it if found, else return whichever link is found first.
+     *
+     * @param dpid   the switch DPID.
+     * @param portNumber the switch port number.
+     * @param type type of the link
+     * @return the incoming link if found, otherwise null.
+     */
+    public Link getIncomingLink(Dpid dpid, PortNumber portNumber, String type);
+
+    /**
+     * Gets the incoming link to a switch port.
+     * <p/>
+     * FIXME As a temporary workaround, it will look for type "packet" and
+     * returns it if found, else return whichever link is found first.
+     *
+     * @param port port identifier
+     * @return the incoming link if found, otherwise null.
+     */
+    public Link getIncomingLink(SwitchPort port);
+
+    /**
+     * Gets the incoming link to a switch port.
+     *
+     * @param port port identifier
+     * @param type type of the link
+     * @return the incoming link if found, otherwise null.
+     */
+    public Link getIncomingLink(SwitchPort port, String type);
+
+    /**
+     * Gets all the incoming link from a switch port.
+     *
+     * @param port port identifier
+     * @return incoming links
+     */
+    public Collection<Link> getIncomingLinks(SwitchPort port);
+
+    /**
+     * Gets the outgoing link from a switch and a port to another switch and
+     * a port.
+     *
+     * @param srcDpid   the source switch DPID.
+     * @param srcPortNumber the source switch port number.
+     * @param dstDpid   the destination switch DPID.
+     * @param dstPortNumber the destination switch port number.
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getLink(Dpid srcDpid, PortNumber srcPortNumber,
+                        Dpid dstDpid, PortNumber dstPortNumber);
+
+    /**
+     * Gets the outgoing link from a switch and a port to another switch and
+     * a port.
+     *
+     * @param srcDpid   the source switch DPID.
+     * @param srcPortNumber the source switch port number.
+     * @param dstDpid   the destination switch DPID.
+     * @param dstPortNumber the destination switch port number.
+     * @param type      type of the link
+     * @return the outgoing link if found, otherwise null.
+     */
+    public Link getLink(Dpid srcDpid, PortNumber srcPortNumber,
+                        Dpid dstDpid, PortNumber dstPortNumber,
+                        String type);
+
+    /**
+     * Gets all links in the network.
+     * <p/>
+     *
+     * @return all links in the network.
+     */
+    public Iterable<Link> getLinks();
+
+    /**
+     * Gets the network device for a given MAC address.
+     *
+     * @param address the MAC address to use.
+     * @return the network device for the MAC address if found, otherwise null.
+     */
+    public Host getHostByMac(MACAddress address);
+
+    /**
+     * Gets all devices in the network.
+     *
+     * @return all devices in the network
+     */
+    public Iterable<Host> getHosts();
+
+    /**
+     * Gets all devices on specified port.
+     *
+     * @param port port which the device is attached
+     * @return all devices attached to the port.
+     */
+    public Collection<Host> getHosts(SwitchPort port);
+}
diff --git a/src/main/java/net/onrc/onos/core/topology/Topology.java b/src/main/java/net/onrc/onos/core/topology/Topology.java
index 4e1b61e..464f463 100644
--- a/src/main/java/net/onrc/onos/core/topology/Topology.java
+++ b/src/main/java/net/onrc/onos/core/topology/Topology.java
@@ -1,12 +1,6 @@
 package net.onrc.onos.core.topology;
 
-import java.util.Collection;
-
-import net.floodlightcontroller.util.MACAddress;
 import net.onrc.onos.core.topology.web.serializers.TopologySerializer;
-import net.onrc.onos.core.util.Dpid;
-import net.onrc.onos.core.util.PortNumber;
-import net.onrc.onos.core.util.SwitchPort;
 
 import org.codehaus.jackson.map.annotate.JsonSerialize;
 
@@ -16,210 +10,7 @@
  * only the discovery modules to be allowed to modify the topology.
  */
 @JsonSerialize(using = TopologySerializer.class)
-public interface Topology {
-
-    /**
-     * Gets the switch for a given switch DPID.
-     *
-     * @param dpid the switch dpid.
-     * @return the switch if found, otherwise null.
-     */
-    public Switch getSwitch(Dpid dpid);
-
-    /**
-     * Gets all switches in the network.
-     *
-     * @return all switches in the network.
-     */
-    public Iterable<Switch> getSwitches();
-
-    /**
-     * Gets the port on a switch.
-     *
-     * @param dpid   the switch DPID.
-     * @param portNumber the switch port number.
-     * @return the switch port if found, otherwise null.
-     */
-    public Port getPort(Dpid dpid, PortNumber portNumber);
-
-    /**
-     * Gets the port on a switch.
-     *
-     * @param port port identifier
-     * @return the switch port if found, otherwise null.
-     */
-    public Port getPort(SwitchPort port);
-
-    /**
-     * Gets all ports on a switch specified.
-     *
-     * @param dpid Switch dpid
-     * @return ports.
-     */
-    public Collection<Port> getPorts(Dpid dpid);
-
-    /**
-     * Gets the outgoing link from a switch port.
-     * <p/>
-     * FIXME As a temporary workaround, it will look for type "packet" and
-     * returns it if found, else return whichever link is found first.
-     *
-     * @param dpid   the switch DPID.
-     * @param portNumber the switch port number.
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getOutgoingLink(Dpid dpid, PortNumber portNumber);
-
-    /**
-     * Gets the outgoing link from a switch port.
-     *
-     * @param dpid   the switch DPID.
-     * @param portNumber the switch port number.
-     * @param type   type of the link
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getOutgoingLink(Dpid dpid, PortNumber portNumber, String type);
-
-    /**
-     * Gets the outgoing link from a switch port.
-     * <p/>
-     * FIXME As a temporary workaround, it will look for type "packet" and
-     * returns it if found, else return whichever link is found first.
-     *
-     * @param port port identifier
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getOutgoingLink(SwitchPort port);
-
-    /**
-     * Gets the outgoing link from a switch port.
-     *
-     * @param port port identifier
-     * @param type type of the link
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getOutgoingLink(SwitchPort port, String type);
-
-    /**
-     * Gets all the outgoing link from a switch port.
-     *
-     * @param port port identifier
-     * @return outgoing links
-     */
-    public Collection<Link> getOutgoingLinks(SwitchPort port);
-
-    /**
-     * Gets the incoming link to a switch port.
-     * <p/>
-     * FIXME As a temporary workaround, it will look for type "packet" and
-     * returns it if found, else return whichever link is found first.
-     *
-     * @param dpid   the switch DPID.
-     * @param portNumber the switch port number.
-     * @return the incoming link if found, otherwise null.
-     */
-    public Link getIncomingLink(Dpid dpid, PortNumber portNumber);
-
-    /**
-     * Gets the incoming link to a switch port.
-     * <p/>
-     * FIXME As a temporary workaround, it will look for type "packet" and
-     * returns it if found, else return whichever link is found first.
-     *
-     * @param dpid   the switch DPID.
-     * @param portNumber the switch port number.
-     * @param type type of the link
-     * @return the incoming link if found, otherwise null.
-     */
-    public Link getIncomingLink(Dpid dpid, PortNumber portNumber, String type);
-
-
-    /**
-     * Gets the incoming link to a switch port.
-     * <p/>
-     * FIXME As a temporary workaround, it will look for type "packet" and
-     * returns it if found, else return whichever link is found first.
-     *
-     * @param port port identifier
-     * @return the incoming link if found, otherwise null.
-     */
-    public Link getIncomingLink(SwitchPort port);
-
-    /**
-     * Gets the incoming link to a switch port.
-     *
-     * @param port port identifier
-     * @param type type of the link
-     * @return the incoming link if found, otherwise null.
-     */
-    public Link getIncomingLink(SwitchPort port, String type);
-
-    /**
-     * Gets all the incoming link from a switch port.
-     *
-     * @param port port identifier
-     * @return incoming links
-     */
-    public Collection<Link> getIncomingLinks(SwitchPort port);
-
-    /**
-     * Gets the outgoing link from a switch and a port to another switch and
-     * a port.
-     *
-     * @param srcDpid   the source switch DPID.
-     * @param srcPortNumber the source switch port number.
-     * @param dstDpid   the destination switch DPID.
-     * @param dstPortNumber the destination switch port number.
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getLink(Dpid srcDpid, PortNumber srcPortNumber,
-                        Dpid dstDpid, PortNumber dstPortNumber);
-
-    /**
-     * Gets the outgoing link from a switch and a port to another switch and
-     * a port.
-     *
-     * @param srcDpid   the source switch DPID.
-     * @param srcPortNumber the source switch port number.
-     * @param dstDpid   the destination switch DPID.
-     * @param dstPortNumber the destination switch port number.
-     * @param type      type of the link
-     * @return the outgoing link if found, otherwise null.
-     */
-    public Link getLink(Dpid srcDpid, PortNumber srcPortNumber,
-                        Dpid dstDpid, PortNumber dstPortNumber,
-                        String type);
-
-    /**
-     * Gets all links in the network.
-     * <p/>
-     *
-     * @return all links in the network.
-     */
-    public Iterable<Link> getLinks();
-
-    /**
-     * Gets the network device for a given MAC address.
-     *
-     * @param address the MAC address to use.
-     * @return the network device for the MAC address if found, otherwise null.
-     */
-    public Host getHostByMac(MACAddress address);
-
-    /**
-     * Gets all devices in the network.
-     *
-     * @return all devices in the network
-     */
-    public Iterable<Host> getHosts();
-
-    /**
-     * Gets all devices on specified port.
-     *
-     * @param port port which the device is attached
-     * @return all devices attached to the port.
-     */
-    public Collection<Host> getHosts(SwitchPort port);
+public interface Topology extends ImmutableTopology {
 
     /**
      * Acquire a read lock on the entire topology. The topology will not
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyBatchOperation.java b/src/main/java/net/onrc/onos/core/topology/TopologyBatchOperation.java
index 2292b5b..f05e9d0 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyBatchOperation.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyBatchOperation.java
@@ -7,7 +7,8 @@
  * A list of topology operations.
  */
 public class TopologyBatchOperation extends
-        BatchOperation<BatchOperationEntry<TopologyBatchOperation.Operator, ?>> {
+        BatchOperation<BatchOperationEntry<TopologyBatchOperation.Operator, TopologyBatchTarget>> {
+
     /**
      * The topology operations' operators.
      */
@@ -27,27 +28,25 @@
      * Adds an add-TopologyEvent operation.
      *
      * @param topologyEvent the Topology Event to be added
-     * @return the TopologyBatchOperation object if succeeded, null otherwise
+     * @return the TopologyBatchOperation object
      */
     public TopologyBatchOperation addAddTopologyOperation(
                                         TopologyEvent topologyEvent) {
-        return (null == super.addOperation(
-                new BatchOperationEntry<Operator, TopologyEvent>(
-                                        Operator.ADD, topologyEvent)))
-                ? null : this;
+        return (TopologyBatchOperation) addOperation(
+                new BatchOperationEntry<Operator, TopologyBatchTarget>(
+                                        Operator.ADD, topologyEvent));
     }
 
     /**
      * Adds a remove-TopologyEvent operation.
      *
      * @param topologyEvent the Topology Event to be removed
-     * @return the TopologyBatchOperation object if succeeded, null otherwise
+     * @return the TopologyBatchOperation object
      */
     public TopologyBatchOperation addRemoveTopologyOperation(
                                         TopologyEvent topologyEvent) {
-        return (null == super.addOperation(
-                new BatchOperationEntry<Operator, TopologyEvent>(
-                                        Operator.REMOVE, topologyEvent)))
-                ? null : this;
+        return (TopologyBatchOperation) addOperation(
+                new BatchOperationEntry<Operator, TopologyBatchTarget>(
+                                        Operator.REMOVE, topologyEvent));
     }
 }
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyBatchTarget.java b/src/main/java/net/onrc/onos/core/topology/TopologyBatchTarget.java
new file mode 100644
index 0000000..76adef9
--- /dev/null
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyBatchTarget.java
@@ -0,0 +1,10 @@
+package net.onrc.onos.core.topology;
+
+import net.onrc.onos.api.batchoperation.BatchOperationTarget;
+
+/**
+ * Tag interface for TopologyBatchOperation targets.
+ */
+public interface TopologyBatchTarget extends BatchOperationTarget {
+
+}
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 a71bbf7..c86bcc6 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyEvent.java
@@ -4,7 +4,6 @@
 import java.nio.charset.StandardCharsets;
 import java.util.Objects;
 
-import net.onrc.onos.api.batchoperation.BatchOperationTarget;
 import net.onrc.onos.core.util.Dpid;
 import net.onrc.onos.core.util.OnosInstanceId;
 
@@ -19,7 +18,7 @@
  * TODO: This class should become immutable after its internals and usage
  * are finalized.
  */
-public final class TopologyEvent implements BatchOperationTarget {
+public final class TopologyEvent implements TopologyBatchTarget {
     private final Type eventType;
     private final TopologyElement<?> event;
     private final OnosInstanceId onosInstanceId;   // The ONOS Instance ID