blob: fe312835c39ae230259429066a939e8321e45b1b [file] [log] [blame]
Jonathan Harte37e4e22014-05-13 19:12:02 -07001package net.onrc.onos.core.topology;
2
Pavlin Radoslavova5637c02014-07-30 15:55:11 -07003import static com.google.common.base.Preconditions.checkNotNull;
Yuta HIGUCHIbf0a8712014-06-30 18:59:46 -07004
Jonathan Harte37e4e22014-05-13 19:12:02 -07005
Yuta HIGUCHIc45e0b62014-06-24 22:34:20 -07006/**
7 * Base class for Topology Objects.
8 */
Yuta HIGUCHI692e68e2014-07-09 18:08:02 -07009public abstract class TopologyObject implements ITopologyElement {
Jonathan Harte37e4e22014-05-13 19:12:02 -070010
Yuta HIGUCHIc45e0b62014-06-24 22:34:20 -070011 /**
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070012 * Topology snapshot this object belongs to.
Yuta HIGUCHIc45e0b62014-06-24 22:34:20 -070013 */
Yuta HIGUCHI9e6223d2014-08-26 00:01:32 -070014 protected volatile BaseInternalTopology topology;
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070015
16 // XXX Updater to be used once we implement snapshot update.
17 // Should it be static or not.
18 // static: Low memory consumption, but higher contention on atomic update
19 // non-static: Updater per instance, but less chance of contention
20// private static final AtomicReferenceFieldUpdater<TopologyObject, TopologyImpl>
21// TOPOLOGY_UPDATER =
22// AtomicReferenceFieldUpdater.newUpdater(
23// TopologyObject.class, TopologyImpl.class, "topology");
Jonathan Harte37e4e22014-05-13 19:12:02 -070024
Yuta HIGUCHIc45e0b62014-06-24 22:34:20 -070025 /**
26 * Constructor.
27 *
28 * @param topology Topology instance this object belongs to
29 */
Yuta HIGUCHI9e6223d2014-08-26 00:01:32 -070030 protected TopologyObject(BaseInternalTopology topology) {
Pavlin Radoslavova5637c02014-07-30 15:55:11 -070031 this.topology = checkNotNull(topology);
Jonathan Harte37e4e22014-05-13 19:12:02 -070032 }
33
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070034 // TODO Add method to replace topology snapshot
35 // - Request TopologyManager for latest TopologyImpl and swap?
36 // - Make caller specify TopologyImpl instance?
Yuta HIGUCHI8b389a72014-07-18 13:50:00 -070037
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -070038
39 /**
40 * Returns the type of topology object.
41 *
42 * @return the type of the topology object
43 */
Yuta HIGUCHI692e68e2014-07-09 18:08:02 -070044 @Override
Praseed Balakrishnan57ed8432014-06-26 11:49:56 -070045 public abstract String getType();
Jonathan Harte37e4e22014-05-13 19:12:02 -070046}