Refactoring to move code to right locations. Attempt at breaking dependency cycles.
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipListener.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipListener.java
deleted file mode 100644
index 71d65be..0000000
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipListener.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.onlab.onos.cluster;
-
-import org.onlab.onos.event.EventListener;
-
-/**
- * Entity capable of receiving device mastership-related events.
- */
-public interface MastershipListener extends EventListener<MastershipEvent> {
-}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipStoreDelegate.java b/core/api/src/main/java/org/onlab/onos/cluster/MastershipStoreDelegate.java
deleted file mode 100644
index b4d923c..0000000
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipStoreDelegate.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.onlab.onos.cluster;
-
-import org.onlab.onos.store.StoreDelegate;
-
-/**
- * Mastership store delegate abstraction.
- */
-public interface MastershipStoreDelegate extends StoreDelegate<MastershipEvent> {
-}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipAdminService.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipAdminService.java
similarity index 78%
rename from core/api/src/main/java/org/onlab/onos/cluster/MastershipAdminService.java
rename to core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipAdminService.java
index 907b3f8..78c9c39 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipAdminService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipAdminService.java
@@ -1,12 +1,13 @@
-package org.onlab.onos.cluster;
+package org.onlab.onos.net.device;
+import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
/**
* Service for administering the inventory of device masterships.
*/
-public interface MastershipAdminService {
+public interface DeviceMastershipAdminService {
/**
* Applies the current mastership role for the specified device.
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipEvent.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipEvent.java
similarity index 78%
rename from core/api/src/main/java/org/onlab/onos/cluster/MastershipEvent.java
rename to core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipEvent.java
index 15811fb..1232d9c 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipEvent.java
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipEvent.java
@@ -1,12 +1,13 @@
-package org.onlab.onos.cluster;
+package org.onlab.onos.net.device;
+import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.event.AbstractEvent;
import org.onlab.onos.net.DeviceId;
/**
* Describes a device mastership event.
*/
-public class MastershipEvent extends AbstractEvent<MastershipEvent.Type, DeviceId> {
+public class DeviceMastershipEvent extends AbstractEvent<DeviceMastershipEvent.Type, DeviceId> {
//do we worry about explicitly setting slaves/equals? probably not,
//to keep it simple
@@ -30,7 +31,7 @@
* @param device event device subject
* @param master master ID subject
*/
- public MastershipEvent(Type type, DeviceId device, NodeId master) {
+ public DeviceMastershipEvent(Type type, DeviceId device, NodeId master) {
super(type, device);
this.master = master;
}
@@ -44,7 +45,7 @@
* @param master master ID subject
* @param time occurrence time
*/
- public MastershipEvent(Type type, DeviceId device, NodeId master, long time) {
+ public DeviceMastershipEvent(Type type, DeviceId device, NodeId master, long time) {
super(type, device, time);
this.master = master;
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipListener.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipListener.java
new file mode 100644
index 0000000..0c7c8d9
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipListener.java
@@ -0,0 +1,9 @@
+package org.onlab.onos.net.device;
+
+import org.onlab.onos.event.EventListener;
+
+/**
+ * Entity capable of receiving device mastership-related events.
+ */
+public interface DeviceMastershipListener extends EventListener<DeviceMastershipEvent> {
+}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipService.java
similarity index 88%
rename from core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
rename to core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipService.java
index 51b6f6a..a44abfd 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipService.java
@@ -1,7 +1,8 @@
-package org.onlab.onos.cluster;
+package org.onlab.onos.net.device;
import java.util.Set;
+import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
@@ -11,7 +12,7 @@
* determining mastership, but is not responsible for actually applying it
* to the devices; this falls on the device service.
*/
-public interface MastershipService {
+public interface DeviceMastershipService {
/**
* Returns the role of the local node for the specified device, without
@@ -62,20 +63,20 @@
*
* @return the MastershipTermService for this mastership manager
*/
- MastershipTermService requestTermService();
+ DeviceMastershipTermService requestTermService();
/**
* Adds the specified mastership change listener.
*
* @param listener the mastership listener
*/
- void addListener(MastershipListener listener);
+ void addListener(DeviceMastershipListener listener);
/**
* Removes the specified mastership change listener.
*
* @param listener the mastership listener
*/
- void removeListener(MastershipListener listener);
+ void removeListener(DeviceMastershipListener listener);
}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStore.java
similarity index 84%
rename from core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
rename to core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStore.java
index dc5603f..ee9b253 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipStore.java
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStore.java
@@ -1,7 +1,8 @@
-package org.onlab.onos.cluster;
+package org.onlab.onos.net.device;
import java.util.Set;
+import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.store.Store;
@@ -10,7 +11,7 @@
* Manages inventory of mastership roles for devices, across controller
* instances; not intended for direct use.
*/
-public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> {
+public interface DeviceMastershipStore extends Store<DeviceMastershipEvent, DeviceMastershipStoreDelegate> {
// three things to map: NodeId, DeviceId, MastershipRole
@@ -54,7 +55,7 @@
* @param deviceId device identifier
* @return a mastership event
*/
- MastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
+ DeviceMastershipEvent setMaster(NodeId nodeId, DeviceId deviceId);
/**
* Returns the current master and number of past mastership hand-offs
@@ -63,7 +64,7 @@
* @param deviceId the device identifier
* @return the current master's ID and the term value for device, or null
*/
- MastershipTerm getTermFor(DeviceId deviceId);
+ DeviceMastershipTerm getTermFor(DeviceId deviceId);
/**
* Sets a controller instance's mastership role to STANDBY for a device.
@@ -74,7 +75,7 @@
* @param deviceId device to revoke mastership role for
* @return a mastership event
*/
- MastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
+ DeviceMastershipEvent setStandby(NodeId nodeId, DeviceId deviceId);
/**
* Allows a controller instance to give up its current role for a device.
@@ -85,6 +86,6 @@
* @param deviceId device to revoke mastership role for
* @return a mastership event
*/
- MastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
+ DeviceMastershipEvent relinquishRole(NodeId nodeId, DeviceId deviceId);
}
diff --git a/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStoreDelegate.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStoreDelegate.java
new file mode 100644
index 0000000..f654d85
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipStoreDelegate.java
@@ -0,0 +1,9 @@
+package org.onlab.onos.net.device;
+
+import org.onlab.onos.store.StoreDelegate;
+
+/**
+ * DeviceMastership store delegate abstraction.
+ */
+public interface DeviceMastershipStoreDelegate extends StoreDelegate<DeviceMastershipEvent> {
+}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTerm.java
similarity index 64%
rename from core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java
rename to core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTerm.java
index 71d08f2..f05a3d2 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipTerm.java
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTerm.java
@@ -1,19 +1,21 @@
-package org.onlab.onos.cluster;
+package org.onlab.onos.net.device;
import java.util.Objects;
-public final class MastershipTerm {
+import org.onlab.onos.cluster.NodeId;
+
+public final class DeviceMastershipTerm {
private final NodeId master;
private final int termNumber;
- private MastershipTerm(NodeId master, int term) {
+ private DeviceMastershipTerm(NodeId master, int term) {
this.master = master;
this.termNumber = term;
}
- public static MastershipTerm of(NodeId master, int term) {
- return new MastershipTerm(master, term);
+ public static DeviceMastershipTerm of(NodeId master, int term) {
+ return new DeviceMastershipTerm(master, term);
}
public NodeId master() {
@@ -34,8 +36,8 @@
if (this == other) {
return true;
}
- if (other instanceof MastershipTerm) {
- MastershipTerm that = (MastershipTerm) other;
+ if (other instanceof DeviceMastershipTerm) {
+ DeviceMastershipTerm that = (DeviceMastershipTerm) other;
if (!this.master.equals(that.master)) {
return false;
}
diff --git a/core/api/src/main/java/org/onlab/onos/cluster/MastershipTermService.java b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTermService.java
similarity index 74%
rename from core/api/src/main/java/org/onlab/onos/cluster/MastershipTermService.java
rename to core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTermService.java
index b03ed81..7a0c063 100644
--- a/core/api/src/main/java/org/onlab/onos/cluster/MastershipTermService.java
+++ b/core/api/src/main/java/org/onlab/onos/net/device/DeviceMastershipTermService.java
@@ -1,4 +1,4 @@
-package org.onlab.onos.cluster;
+package org.onlab.onos.net.device;
import org.onlab.onos.net.DeviceId;
@@ -6,7 +6,7 @@
/**
* Service to obtain mastership term information.
*/
-public interface MastershipTermService {
+public interface DeviceMastershipTermService {
// TBD: manage/increment per device mastership change
// or increment on any change
@@ -16,5 +16,5 @@
* @param deviceId the identifier of the device
* @return current master's term.
*/
- MastershipTerm getMastershipTerm(DeviceId deviceId);
+ DeviceMastershipTerm getMastershipTerm(DeviceId deviceId);
}
diff --git a/core/api/src/main/java/org/onlab/onos/store/ClockProviderService.java b/core/api/src/main/java/org/onlab/onos/store/ClockProviderService.java
index a5f81c7..fff6d15 100644
--- a/core/api/src/main/java/org/onlab/onos/store/ClockProviderService.java
+++ b/core/api/src/main/java/org/onlab/onos/store/ClockProviderService.java
@@ -1,7 +1,7 @@
package org.onlab.onos.store;
-import org.onlab.onos.cluster.MastershipTerm;
import org.onlab.onos.net.DeviceId;
+import org.onlab.onos.net.device.DeviceMastershipTerm;
//TODO: Consider renaming to DeviceClockProviderService?
/**
@@ -16,5 +16,5 @@
* @param deviceId device identifier.
* @param term mastership term.
*/
- public void setMastershipTerm(DeviceId deviceId, MastershipTerm term);
+ public void setMastershipTerm(DeviceId deviceId, DeviceMastershipTerm term);
}
diff --git a/core/api/src/main/java/org/onlab/onos/store/Timestamped.java b/core/api/src/main/java/org/onlab/onos/store/Timestamped.java
new file mode 100644
index 0000000..9de7b0d
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/store/Timestamped.java
@@ -0,0 +1,87 @@
+package org.onlab.onos.store;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Objects;
+
+import com.google.common.base.MoreObjects;
+
+/**
+ * Wrapper class to store Timestamped value.
+ * @param <T>
+ */
+public final class Timestamped<T> {
+
+ private final Timestamp timestamp;
+ private final T value;
+
+ /**
+ * Creates a time stamped value.
+ *
+ * @param value to be timestamp
+ * @param timestamp the timestamp
+ */
+ public Timestamped(T value, Timestamp timestamp) {
+ this.value = checkNotNull(value);
+ this.timestamp = checkNotNull(timestamp);
+ }
+
+ /**
+ * Returns the value.
+ * @return value
+ */
+ public T value() {
+ return value;
+ }
+
+ /**
+ * Returns the time stamp.
+ * @return time stamp
+ */
+ public Timestamp timestamp() {
+ return timestamp;
+ }
+
+ /**
+ * Tests if this timestamped value is newer than the other.
+ *
+ * @param other timestamped value
+ * @return true if this instance is newer.
+ */
+ public boolean isNewer(Timestamped<T> other) {
+ return this.timestamp.compareTo(checkNotNull(other).timestamp()) > 0;
+ }
+
+ @Override
+ public int hashCode() {
+ return timestamp.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof Timestamped)) {
+ return false;
+ }
+ @SuppressWarnings("unchecked")
+ Timestamped<T> that = (Timestamped<T>) obj;
+ return Objects.equals(this.timestamp, that.timestamp);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .add("timestamp", timestamp)
+ .add("value", value)
+ .toString();
+ }
+
+ // Default constructor for serialization
+ @Deprecated
+ private Timestamped() {
+ this.value = null;
+ this.timestamp = null;
+ }
+}
diff --git a/core/api/src/main/java/org/onlab/onos/store/VersionedValue.java b/core/api/src/main/java/org/onlab/onos/store/VersionedValue.java
new file mode 100644
index 0000000..70602f6
--- /dev/null
+++ b/core/api/src/main/java/org/onlab/onos/store/VersionedValue.java
@@ -0,0 +1,76 @@
+package org.onlab.onos.store;
+
+import java.util.Objects;
+
+/**
+ * Wrapper class for a entity that is versioned
+ * and can either be up or down.
+ *
+ * @param <T> type of the value.
+ */
+public class VersionedValue<T> {
+ private final T entity;
+ private final Timestamp timestamp;
+ private final boolean isUp;
+
+ public VersionedValue(T entity, boolean isUp, Timestamp timestamp) {
+ this.entity = entity;
+ this.isUp = isUp;
+ this.timestamp = timestamp;
+ }
+
+ /**
+ * Returns the value.
+ * @return value.
+ */
+ public T entity() {
+ return entity;
+ }
+
+ /**
+ * Tells whether the entity is up or down.
+ * @return true if up, false otherwise.
+ */
+ public boolean isUp() {
+ return isUp;
+ }
+
+ /**
+ * Returns the timestamp (version) associated with this entity.
+ * @return timestamp.
+ */
+ public Timestamp timestamp() {
+ return timestamp;
+ }
+
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(entity, timestamp, isUp);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ @SuppressWarnings("unchecked")
+ VersionedValue<T> that = (VersionedValue<T>) obj;
+ return Objects.equals(this.entity, that.entity) &&
+ Objects.equals(this.timestamp, that.timestamp) &&
+ Objects.equals(this.isUp, that.isUp);
+ }
+
+ // Default constructor for serializer
+ protected VersionedValue() {
+ this.entity = null;
+ this.isUp = false;
+ this.timestamp = null;
+ }
+}