Committed by
Brian O'Connor
Generalize the MultiValuedTimestamp.
Change-Id: I691730d59f440778856afd0e4808ba775eccba0a
Showing
3 changed files
with
35 additions
and
31 deletions
... | @@ -15,17 +15,6 @@ | ... | @@ -15,17 +15,6 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.net.device.impl; | 16 | package org.onosproject.net.device.impl; |
17 | 17 | ||
18 | -import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | -import static org.onosproject.net.MastershipRole.*; | ||
20 | -import static org.onlab.util.Tools.namedThreads; | ||
21 | -import static org.slf4j.LoggerFactory.getLogger; | ||
22 | - | ||
23 | -import java.util.List; | ||
24 | -import java.util.concurrent.Executors; | ||
25 | -import java.util.concurrent.ScheduledExecutorService; | ||
26 | -import java.util.concurrent.TimeUnit; | ||
27 | - | ||
28 | - | ||
29 | import com.google.common.collect.Lists; | 18 | import com.google.common.collect.Lists; |
30 | import org.apache.felix.scr.annotations.Activate; | 19 | import org.apache.felix.scr.annotations.Activate; |
31 | import org.apache.felix.scr.annotations.Component; | 20 | import org.apache.felix.scr.annotations.Component; |
... | @@ -65,6 +54,18 @@ import org.onosproject.net.provider.AbstractProviderRegistry; | ... | @@ -65,6 +54,18 @@ import org.onosproject.net.provider.AbstractProviderRegistry; |
65 | import org.onosproject.net.provider.AbstractProviderService; | 54 | import org.onosproject.net.provider.AbstractProviderService; |
66 | import org.slf4j.Logger; | 55 | import org.slf4j.Logger; |
67 | 56 | ||
57 | +import java.util.List; | ||
58 | +import java.util.concurrent.Executors; | ||
59 | +import java.util.concurrent.ScheduledExecutorService; | ||
60 | +import java.util.concurrent.TimeUnit; | ||
61 | + | ||
62 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
63 | +import static org.onlab.util.Tools.namedThreads; | ||
64 | +import static org.onosproject.net.MastershipRole.MASTER; | ||
65 | +import static org.onosproject.net.MastershipRole.NONE; | ||
66 | +import static org.onosproject.net.MastershipRole.STANDBY; | ||
67 | +import static org.slf4j.LoggerFactory.getLogger; | ||
68 | + | ||
68 | /** | 69 | /** |
69 | * Provides implementation of the device SB & NB APIs. | 70 | * Provides implementation of the device SB & NB APIs. |
70 | */ | 71 | */ |
... | @@ -234,7 +235,7 @@ public class DeviceManager | ... | @@ -234,7 +235,7 @@ public class DeviceManager |
234 | log.debug("Checking mastership"); | 235 | log.debug("Checking mastership"); |
235 | for (Device device : getDevices()) { | 236 | for (Device device : getDevices()) { |
236 | final DeviceId deviceId = device.id(); | 237 | final DeviceId deviceId = device.id(); |
237 | - log.debug("Checking device {}", deviceId); | 238 | + log.trace("Checking device {}", deviceId); |
238 | 239 | ||
239 | if (!isReachable(deviceId)) { | 240 | if (!isReachable(deviceId)) { |
240 | continue; | 241 | continue; | ... | ... |
... | @@ -22,26 +22,28 @@ import org.onosproject.store.Timestamp; | ... | @@ -22,26 +22,28 @@ import org.onosproject.store.Timestamp; |
22 | import java.util.Objects; | 22 | import java.util.Objects; |
23 | 23 | ||
24 | import static com.google.common.base.Preconditions.checkArgument; | 24 | import static com.google.common.base.Preconditions.checkArgument; |
25 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
25 | 26 | ||
26 | /** | 27 | /** |
27 | - * A logical timestamp that derives its value from two input values. Value1 | 28 | + * A logical timestamp that derives its value from two input values. The first |
28 | - * always takes precedence over value2 when comparing timestamps. | 29 | + * value always takes precedence over the second value when comparing timestamps. |
29 | */ | 30 | */ |
30 | -public class MultiValuedTimestamp implements Timestamp { | 31 | +public class MultiValuedTimestamp<T extends Comparable<T>, U extends Comparable<U>> |
32 | + implements Timestamp { | ||
31 | 33 | ||
32 | - private final Timestamp timestamp; | 34 | + private final T value1; |
33 | - private final long value2; | 35 | + private final U value2; |
34 | 36 | ||
35 | /** | 37 | /** |
36 | * Creates a new timestamp based on two values. The first value has higher | 38 | * Creates a new timestamp based on two values. The first value has higher |
37 | * precedence than the second when comparing timestamps. | 39 | * precedence than the second when comparing timestamps. |
38 | * | 40 | * |
39 | - * @param timestamp first value | 41 | + * @param value1 first value |
40 | * @param value2 second value | 42 | * @param value2 second value |
41 | */ | 43 | */ |
42 | - public MultiValuedTimestamp(Timestamp timestamp, long value2) { | 44 | + public MultiValuedTimestamp(T value1, U value2) { |
43 | - this.timestamp = timestamp; | 45 | + this.value1 = checkNotNull(value1); |
44 | - this.value2 = value2; | 46 | + this.value2 = checkNotNull(value2); |
45 | } | 47 | } |
46 | 48 | ||
47 | @Override | 49 | @Override |
... | @@ -51,14 +53,14 @@ public class MultiValuedTimestamp implements Timestamp { | ... | @@ -51,14 +53,14 @@ public class MultiValuedTimestamp implements Timestamp { |
51 | MultiValuedTimestamp that = (MultiValuedTimestamp) o; | 53 | MultiValuedTimestamp that = (MultiValuedTimestamp) o; |
52 | 54 | ||
53 | return ComparisonChain.start() | 55 | return ComparisonChain.start() |
54 | - .compare(this.timestamp, that.timestamp) | 56 | + .compare(this.value1, that.value1) |
55 | .compare(this.value2, that.value2) | 57 | .compare(this.value2, that.value2) |
56 | .result(); | 58 | .result(); |
57 | } | 59 | } |
58 | 60 | ||
59 | @Override | 61 | @Override |
60 | public int hashCode() { | 62 | public int hashCode() { |
61 | - return Objects.hash(timestamp, value2); | 63 | + return Objects.hash(value1, value2); |
62 | } | 64 | } |
63 | 65 | ||
64 | @Override | 66 | @Override |
... | @@ -70,14 +72,14 @@ public class MultiValuedTimestamp implements Timestamp { | ... | @@ -70,14 +72,14 @@ public class MultiValuedTimestamp implements Timestamp { |
70 | return false; | 72 | return false; |
71 | } | 73 | } |
72 | MultiValuedTimestamp that = (MultiValuedTimestamp) obj; | 74 | MultiValuedTimestamp that = (MultiValuedTimestamp) obj; |
73 | - return Objects.equals(this.timestamp, that.timestamp) && | 75 | + return Objects.equals(this.value1, that.value1) && |
74 | Objects.equals(this.value2, that.value2); | 76 | Objects.equals(this.value2, that.value2); |
75 | } | 77 | } |
76 | 78 | ||
77 | @Override | 79 | @Override |
78 | public String toString() { | 80 | public String toString() { |
79 | return MoreObjects.toStringHelper(getClass()) | 81 | return MoreObjects.toStringHelper(getClass()) |
80 | - .add("timestamp", timestamp) | 82 | + .add("value1", value1) |
81 | .add("value2", value2) | 83 | .add("value2", value2) |
82 | .toString(); | 84 | .toString(); |
83 | } | 85 | } |
... | @@ -87,8 +89,8 @@ public class MultiValuedTimestamp implements Timestamp { | ... | @@ -87,8 +89,8 @@ public class MultiValuedTimestamp implements Timestamp { |
87 | * | 89 | * |
88 | * @return first value | 90 | * @return first value |
89 | */ | 91 | */ |
90 | - public Timestamp timestamp() { | 92 | + public T value1() { |
91 | - return timestamp; | 93 | + return value1; |
92 | } | 94 | } |
93 | 95 | ||
94 | /** | 96 | /** |
... | @@ -96,14 +98,14 @@ public class MultiValuedTimestamp implements Timestamp { | ... | @@ -96,14 +98,14 @@ public class MultiValuedTimestamp implements Timestamp { |
96 | * | 98 | * |
97 | * @return second value | 99 | * @return second value |
98 | */ | 100 | */ |
99 | - public long sequenceNumber() { | 101 | + public U value2() { |
100 | return value2; | 102 | return value2; |
101 | } | 103 | } |
102 | 104 | ||
103 | // Default constructor for serialization | 105 | // Default constructor for serialization |
104 | @SuppressWarnings("unused") | 106 | @SuppressWarnings("unused") |
105 | private MultiValuedTimestamp() { | 107 | private MultiValuedTimestamp() { |
106 | - this.timestamp = null; | 108 | + this.value1 = null; |
107 | - this.value2 = -1; | 109 | + this.value2 = null; |
108 | } | 110 | } |
109 | } | 111 | } | ... | ... |
... | @@ -31,6 +31,7 @@ public class IntentDataLogicalClockManager<K> implements ClockService<K, IntentD | ... | @@ -31,6 +31,7 @@ public class IntentDataLogicalClockManager<K> implements ClockService<K, IntentD |
31 | 31 | ||
32 | @Override | 32 | @Override |
33 | public Timestamp getTimestamp(K key, IntentData intentData) { | 33 | public Timestamp getTimestamp(K key, IntentData intentData) { |
34 | - return new MultiValuedTimestamp(intentData.version(), sequenceNumber.getAndIncrement()); | 34 | + return new MultiValuedTimestamp<>(intentData.version(), |
35 | + sequenceNumber.getAndIncrement()); | ||
35 | } | 36 | } |
36 | } | 37 | } | ... | ... |
-
Please register or login to post a comment