Madan Jampani

Removed ClockService<K, V> and replaced its usage with a BiFunction<K, V, Timestamp>

Change-Id: Ide8d979f9361f1aff6727a83733747f4512ef8ff
...@@ -55,7 +55,6 @@ import org.onosproject.store.service.EventuallyConsistentMap; ...@@ -55,7 +55,6 @@ import org.onosproject.store.service.EventuallyConsistentMap;
55 import org.onosproject.store.service.EventuallyConsistentMapBuilder; 55 import org.onosproject.store.service.EventuallyConsistentMapBuilder;
56 import org.onosproject.store.service.StorageService; 56 import org.onosproject.store.service.StorageService;
57 import org.onosproject.store.service.WallClockTimestamp; 57 import org.onosproject.store.service.WallClockTimestamp;
58 -import org.onosproject.store.service.WallclockClockManager;
59 import org.slf4j.Logger; 58 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory; 59 import org.slf4j.LoggerFactory;
61 60
...@@ -171,7 +170,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -171,7 +170,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
171 nsNextObjStore = nsNextObjMapBuilder 170 nsNextObjStore = nsNextObjMapBuilder
172 .withName("nsnextobjectivestore") 171 .withName("nsnextobjectivestore")
173 .withSerializer(kryoBuilder) 172 .withSerializer(kryoBuilder)
174 - .withClockService(new WallclockClockManager<>()) 173 + .withTimestampProvider((k, v) -> new WallClockTimestamp())
175 .build(); 174 .build();
176 log.trace("Current size {}", nsNextObjStore.size()); 175 log.trace("Current size {}", nsNextObjStore.size());
177 176
...@@ -181,7 +180,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -181,7 +180,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
181 tunnelStore = tunnelMapBuilder 180 tunnelStore = tunnelMapBuilder
182 .withName("tunnelstore") 181 .withName("tunnelstore")
183 .withSerializer(kryoBuilder) 182 .withSerializer(kryoBuilder)
184 - .withClockService(new WallclockClockManager<>()) 183 + .withTimestampProvider((k, v) -> new WallClockTimestamp())
185 .build(); 184 .build();
186 185
187 EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder = 186 EventuallyConsistentMapBuilder<String, Policy> policyMapBuilder =
...@@ -190,7 +189,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { ...@@ -190,7 +189,7 @@ public class SegmentRoutingManager implements SegmentRoutingService {
190 policyStore = policyMapBuilder 189 policyStore = policyMapBuilder
191 .withName("policystore") 190 .withName("policystore")
192 .withSerializer(kryoBuilder) 191 .withSerializer(kryoBuilder)
193 - .withClockService(new WallclockClockManager<>()) 192 + .withTimestampProvider((k, v) -> new WallClockTimestamp())
194 .build(); 193 .build();
195 194
196 networkConfigService.init(); 195 networkConfigService.init();
......
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.store.service;
17 -
18 -import org.onosproject.store.Timestamp;
19 -
20 -/**
21 - * Clock service that can generate timestamps based off of two input objects.
22 - * Implementations are free to only take one or none of the objects into account
23 - * when generating timestamps.
24 - */
25 -public interface ClockService<T, U> {
26 -
27 - /**
28 - * Gets a new timestamp for the given objects.
29 - *
30 - * @param object1 First object to use when generating timestamps
31 - * @param object2 Second object to use when generating timestamps
32 - * @return the new timestamp
33 - */
34 - Timestamp getTimestamp(T object1, U object2);
35 -}
...@@ -114,7 +114,7 @@ public interface EventuallyConsistentMap<K, V> { ...@@ -114,7 +114,7 @@ public interface EventuallyConsistentMap<K, V> {
114 * Removes the given key-value mapping from the map, if it exists. 114 * Removes the given key-value mapping from the map, if it exists.
115 * <p> 115 * <p>
116 * This actually means remove any values up to and including the timestamp 116 * This actually means remove any values up to and including the timestamp
117 - * given by {@link org.onosproject.store.service.ClockService#getTimestamp(Object, Object)}. 117 + * given by the map's timestampProvider.
118 * Any mappings that produce an earlier timestamp than this given key-value 118 * Any mappings that produce an earlier timestamp than this given key-value
119 * pair will be removed, and any mappings that produce a later timestamp 119 * pair will be removed, and any mappings that produce a later timestamp
120 * will supersede this remove. 120 * will supersede this remove.
......
...@@ -18,6 +18,7 @@ package org.onosproject.store.service; ...@@ -18,6 +18,7 @@ package org.onosproject.store.service;
18 18
19 import org.onlab.util.KryoNamespace; 19 import org.onlab.util.KryoNamespace;
20 import org.onosproject.cluster.NodeId; 20 import org.onosproject.cluster.NodeId;
21 +import org.onosproject.store.Timestamp;
21 22
22 import java.util.Collection; 23 import java.util.Collection;
23 import java.util.concurrent.ExecutorService; 24 import java.util.concurrent.ExecutorService;
...@@ -66,10 +67,10 @@ public interface EventuallyConsistentMapBuilder<K, V> { ...@@ -66,10 +67,10 @@ public interface EventuallyConsistentMapBuilder<K, V> {
66 KryoNamespace.Builder serializerBuilder); 67 KryoNamespace.Builder serializerBuilder);
67 68
68 /** 69 /**
69 - * Sets the clock service to use for generating timestamps for map updates. 70 + * Sets the function to use for generating timestamps for map updates.
70 * <p> 71 * <p>
71 - * The client must provide an {@link org.onosproject.store.service.ClockService} 72 + * The client must provide an {@code BiFunction<K, V, Timestamp>}
72 - * which can generate timestamps for a given key. The clock service is free 73 + * which can generate timestamps for a given key. The function is free
73 * to generate timestamps however it wishes, however these timestamps will 74 * to generate timestamps however it wishes, however these timestamps will
74 * be used to serialize updates to the map so they must be strict enough 75 * be used to serialize updates to the map so they must be strict enough
75 * to ensure updates are properly ordered for the use case (i.e. in some 76 * to ensure updates are properly ordered for the use case (i.e. in some
...@@ -80,11 +81,11 @@ public interface EventuallyConsistentMapBuilder<K, V> { ...@@ -80,11 +81,11 @@ public interface EventuallyConsistentMapBuilder<K, V> {
80 * Note: This is a mandatory parameter. 81 * Note: This is a mandatory parameter.
81 * </p> 82 * </p>
82 * 83 *
83 - * @param clockService clock service 84 + * @param timestampProvider provides a new timestamp
84 * @return this EventuallyConsistentMapBuilder 85 * @return this EventuallyConsistentMapBuilder
85 */ 86 */
86 - EventuallyConsistentMapBuilder<K, V> withClockService( 87 + EventuallyConsistentMapBuilder<K, V> withTimestampProvider(
87 - ClockService<K, V> clockService); 88 + BiFunction<K, V, Timestamp> timestampProvider);
88 89
89 /** 90 /**
90 * Sets the executor to use for processing events coming in from peers. 91 * Sets the executor to use for processing events coming in from peers.
......
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.store.service;
17 -
18 -import org.onosproject.store.Timestamp;
19 -
20 -/**
21 - * A clock service which hands out wallclock-based timestamps.
22 - */
23 -public class WallclockClockManager<T, U> implements ClockService<T, U> {
24 - @Override
25 - public Timestamp getTimestamp(T object1, U object2) {
26 - return new WallClockTimestamp();
27 - }
28 -}
...@@ -133,13 +133,13 @@ public class GossipApplicationStore extends ApplicationArchive ...@@ -133,13 +133,13 @@ public class GossipApplicationStore extends ApplicationArchive
133 apps = storageService.<ApplicationId, Application>eventuallyConsistentMapBuilder() 133 apps = storageService.<ApplicationId, Application>eventuallyConsistentMapBuilder()
134 .withName("apps") 134 .withName("apps")
135 .withSerializer(serializer) 135 .withSerializer(serializer)
136 - .withClockService((k, v) -> clockService.getTimestamp()) 136 + .withTimestampProvider((k, v) -> clockService.getTimestamp())
137 .build(); 137 .build();
138 138
139 states = storageService.<Application, InternalState>eventuallyConsistentMapBuilder() 139 states = storageService.<Application, InternalState>eventuallyConsistentMapBuilder()
140 .withName("app-states") 140 .withName("app-states")
141 .withSerializer(serializer) 141 .withSerializer(serializer)
142 - .withClockService((k, v) -> clockService.getTimestamp()) 142 + .withTimestampProvider((k, v) -> clockService.getTimestamp())
143 .build(); 143 .build();
144 144
145 states.addListener(new InternalAppStatesListener()); 145 states.addListener(new InternalAppStatesListener());
...@@ -147,7 +147,7 @@ public class GossipApplicationStore extends ApplicationArchive ...@@ -147,7 +147,7 @@ public class GossipApplicationStore extends ApplicationArchive
147 permissions = storageService.<Application, Set<Permission>>eventuallyConsistentMapBuilder() 147 permissions = storageService.<Application, Set<Permission>>eventuallyConsistentMapBuilder()
148 .withName("app-permissions") 148 .withName("app-permissions")
149 .withSerializer(serializer) 149 .withSerializer(serializer)
150 - .withClockService((k, v) -> clockService.getTimestamp()) 150 + .withTimestampProvider((k, v) -> clockService.getTimestamp())
151 .build(); 151 .build();
152 152
153 log.info("Started"); 153 log.info("Started");
......
...@@ -70,7 +70,7 @@ public class GossipComponentConfigStore ...@@ -70,7 +70,7 @@ public class GossipComponentConfigStore
70 properties = storageService.<String, String>eventuallyConsistentMapBuilder() 70 properties = storageService.<String, String>eventuallyConsistentMapBuilder()
71 .withName("cfg") 71 .withName("cfg")
72 .withSerializer(serializer) 72 .withSerializer(serializer)
73 - .withClockService((k, v) -> clockService.getTimestamp()) 73 + .withTimestampProvider((k, v) -> clockService.getTimestamp())
74 .build(); 74 .build();
75 75
76 properties.addListener(new InternalPropertiesListener()); 76 properties.addListener(new InternalPropertiesListener());
......
...@@ -78,7 +78,6 @@ import org.onosproject.store.service.EventuallyConsistentMapListener; ...@@ -78,7 +78,6 @@ import org.onosproject.store.service.EventuallyConsistentMapListener;
78 import org.onosproject.store.service.MultiValuedTimestamp; 78 import org.onosproject.store.service.MultiValuedTimestamp;
79 import org.onosproject.store.service.StorageService; 79 import org.onosproject.store.service.StorageService;
80 import org.onosproject.store.service.WallClockTimestamp; 80 import org.onosproject.store.service.WallClockTimestamp;
81 -import org.onosproject.store.service.WallclockClockManager;
82 import org.slf4j.Logger; 81 import org.slf4j.Logger;
83 82
84 import java.io.IOException; 83 import java.io.IOException;
...@@ -244,7 +243,7 @@ public class GossipDeviceStore ...@@ -244,7 +243,7 @@ public class GossipDeviceStore
244 .withName("port-stats") 243 .withName("port-stats")
245 .withSerializer(deviceDataSerializer) 244 .withSerializer(deviceDataSerializer)
246 .withAntiEntropyPeriod(5, TimeUnit.SECONDS) 245 .withAntiEntropyPeriod(5, TimeUnit.SECONDS)
247 - .withClockService(new WallclockClockManager<>()) 246 + .withTimestampProvider((k, v) -> new WallClockTimestamp())
248 .withTombstonesDisabled() 247 .withTombstonesDisabled()
249 .build(); 248 .build();
250 devicePortStats.addListener(portStatsListener); 249 devicePortStats.addListener(portStatsListener);
......
...@@ -18,8 +18,8 @@ package org.onosproject.store.ecmap; ...@@ -18,8 +18,8 @@ package org.onosproject.store.ecmap;
18 import org.onlab.util.KryoNamespace; 18 import org.onlab.util.KryoNamespace;
19 import org.onosproject.cluster.ClusterService; 19 import org.onosproject.cluster.ClusterService;
20 import org.onosproject.cluster.NodeId; 20 import org.onosproject.cluster.NodeId;
21 +import org.onosproject.store.Timestamp;
21 import org.onosproject.store.cluster.messaging.ClusterCommunicationService; 22 import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
22 -import org.onosproject.store.service.ClockService;
23 import org.onosproject.store.service.EventuallyConsistentMap; 23 import org.onosproject.store.service.EventuallyConsistentMap;
24 import org.onosproject.store.service.EventuallyConsistentMapBuilder; 24 import org.onosproject.store.service.EventuallyConsistentMapBuilder;
25 25
...@@ -45,7 +45,7 @@ public class EventuallyConsistentMapBuilderImpl<K, V> ...@@ -45,7 +45,7 @@ public class EventuallyConsistentMapBuilderImpl<K, V>
45 private ExecutorService eventExecutor; 45 private ExecutorService eventExecutor;
46 private ExecutorService communicationExecutor; 46 private ExecutorService communicationExecutor;
47 private ScheduledExecutorService backgroundExecutor; 47 private ScheduledExecutorService backgroundExecutor;
48 - private ClockService<K, V> clockService; 48 + private BiFunction<K, V, Timestamp> timestampProvider;
49 private BiFunction<K, V, Collection<NodeId>> peerUpdateFunction; 49 private BiFunction<K, V, Collection<NodeId>> peerUpdateFunction;
50 private boolean tombstonesDisabled = false; 50 private boolean tombstonesDisabled = false;
51 private long antiEntropyPeriod = 5; 51 private long antiEntropyPeriod = 5;
...@@ -79,9 +79,9 @@ public class EventuallyConsistentMapBuilderImpl<K, V> ...@@ -79,9 +79,9 @@ public class EventuallyConsistentMapBuilderImpl<K, V>
79 } 79 }
80 80
81 @Override 81 @Override
82 - public EventuallyConsistentMapBuilder<K, V> withClockService( 82 + public EventuallyConsistentMapBuilder<K, V> withTimestampProvider(
83 - ClockService<K, V> clockService) { 83 + BiFunction<K, V, Timestamp> timestampProvider) {
84 - this.clockService = checkNotNull(clockService); 84 + this.timestampProvider = checkNotNull(timestampProvider);
85 return this; 85 return this;
86 } 86 }
87 87
...@@ -141,13 +141,13 @@ public class EventuallyConsistentMapBuilderImpl<K, V> ...@@ -141,13 +141,13 @@ public class EventuallyConsistentMapBuilderImpl<K, V>
141 public EventuallyConsistentMap<K, V> build() { 141 public EventuallyConsistentMap<K, V> build() {
142 checkNotNull(name, "name is a mandatory parameter"); 142 checkNotNull(name, "name is a mandatory parameter");
143 checkNotNull(serializerBuilder, "serializerBuilder is a mandatory parameter"); 143 checkNotNull(serializerBuilder, "serializerBuilder is a mandatory parameter");
144 - checkNotNull(clockService, "clockService is a mandatory parameter"); 144 + checkNotNull(timestampProvider, "timestampProvider is a mandatory parameter");
145 145
146 return new EventuallyConsistentMapImpl<>(name, 146 return new EventuallyConsistentMapImpl<>(name,
147 clusterService, 147 clusterService,
148 clusterCommunicator, 148 clusterCommunicator,
149 serializerBuilder, 149 serializerBuilder,
150 - clockService, 150 + timestampProvider,
151 peerUpdateFunction, 151 peerUpdateFunction,
152 eventExecutor, 152 eventExecutor,
153 communicationExecutor, 153 communicationExecutor,
......
...@@ -37,7 +37,6 @@ import org.onosproject.store.impl.LogicalTimestamp; ...@@ -37,7 +37,6 @@ import org.onosproject.store.impl.LogicalTimestamp;
37 import org.onosproject.store.impl.Timestamped; 37 import org.onosproject.store.impl.Timestamped;
38 import org.onosproject.store.service.WallClockTimestamp; 38 import org.onosproject.store.service.WallClockTimestamp;
39 import org.onosproject.store.serializers.KryoSerializer; 39 import org.onosproject.store.serializers.KryoSerializer;
40 -import org.onosproject.store.service.ClockService;
41 import org.onosproject.store.service.EventuallyConsistentMap; 40 import org.onosproject.store.service.EventuallyConsistentMap;
42 import org.onosproject.store.service.EventuallyConsistentMapEvent; 41 import org.onosproject.store.service.EventuallyConsistentMapEvent;
43 import org.onosproject.store.service.EventuallyConsistentMapListener; 42 import org.onosproject.store.service.EventuallyConsistentMapListener;
...@@ -84,7 +83,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -84,7 +83,7 @@ public class EventuallyConsistentMapImpl<K, V>
84 private final ClusterCommunicationService clusterCommunicator; 83 private final ClusterCommunicationService clusterCommunicator;
85 private final KryoSerializer serializer; 84 private final KryoSerializer serializer;
86 85
87 - private final ClockService<K, V> clockService; 86 + private final BiFunction<K, V, Timestamp> timestampProvider;
88 87
89 private final MessageSubject updateMessageSubject; 88 private final MessageSubject updateMessageSubject;
90 private final MessageSubject antiEntropyAdvertisementSubject; 89 private final MessageSubject antiEntropyAdvertisementSubject;
...@@ -130,8 +129,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -130,8 +129,7 @@ public class EventuallyConsistentMapImpl<K, V>
130 * @param clusterCommunicator the cluster communications service 129 * @param clusterCommunicator the cluster communications service
131 * @param serializerBuilder a Kryo namespace builder that can serialize 130 * @param serializerBuilder a Kryo namespace builder that can serialize
132 * both K and V 131 * both K and V
133 - * @param clockService a clock service able to generate timestamps 132 + * @param timestampProvider provider of timestamps for K and V
134 - * for K and V
135 * @param peerUpdateFunction function that provides a set of nodes to immediately 133 * @param peerUpdateFunction function that provides a set of nodes to immediately
136 * update to when there writes to the map 134 * update to when there writes to the map
137 * @param eventExecutor executor to use for processing incoming 135 * @param eventExecutor executor to use for processing incoming
...@@ -150,7 +148,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -150,7 +148,7 @@ public class EventuallyConsistentMapImpl<K, V>
150 ClusterService clusterService, 148 ClusterService clusterService,
151 ClusterCommunicationService clusterCommunicator, 149 ClusterCommunicationService clusterCommunicator,
152 KryoNamespace.Builder serializerBuilder, 150 KryoNamespace.Builder serializerBuilder,
153 - ClockService<K, V> clockService, 151 + BiFunction<K, V, Timestamp> timestampProvider,
154 BiFunction<K, V, Collection<NodeId>> peerUpdateFunction, 152 BiFunction<K, V, Collection<NodeId>> peerUpdateFunction,
155 ExecutorService eventExecutor, 153 ExecutorService eventExecutor,
156 ExecutorService communicationExecutor, 154 ExecutorService communicationExecutor,
...@@ -170,7 +168,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -170,7 +168,7 @@ public class EventuallyConsistentMapImpl<K, V>
170 168
171 this.serializer = createSerializer(serializerBuilder); 169 this.serializer = createSerializer(serializerBuilder);
172 170
173 - this.clockService = clockService; 171 + this.timestampProvider = timestampProvider;
174 172
175 if (peerUpdateFunction != null) { 173 if (peerUpdateFunction != null) {
176 this.peerUpdateFunction = peerUpdateFunction; 174 this.peerUpdateFunction = peerUpdateFunction;
...@@ -302,7 +300,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -302,7 +300,7 @@ public class EventuallyConsistentMapImpl<K, V>
302 checkNotNull(key, ERROR_NULL_KEY); 300 checkNotNull(key, ERROR_NULL_KEY);
303 checkNotNull(value, ERROR_NULL_VALUE); 301 checkNotNull(value, ERROR_NULL_VALUE);
304 302
305 - Timestamp timestamp = clockService.getTimestamp(key, value); 303 + Timestamp timestamp = timestampProvider.apply(key, value);
306 304
307 if (putInternal(key, value, timestamp)) { 305 if (putInternal(key, value, timestamp)) {
308 notifyPeers(new PutEntry<>(key, value, timestamp), 306 notifyPeers(new PutEntry<>(key, value, timestamp),
...@@ -354,7 +352,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -354,7 +352,7 @@ public class EventuallyConsistentMapImpl<K, V>
354 checkNotNull(key, ERROR_NULL_KEY); 352 checkNotNull(key, ERROR_NULL_KEY);
355 353
356 // TODO prevent calls here if value is important for timestamp 354 // TODO prevent calls here if value is important for timestamp
357 - Timestamp timestamp = clockService.getTimestamp(key, null); 355 + Timestamp timestamp = timestampProvider.apply(key, null);
358 356
359 if (removeInternal(key, timestamp)) { 357 if (removeInternal(key, timestamp)) {
360 notifyPeers(new RemoveEntry<>(key, timestamp), 358 notifyPeers(new RemoveEntry<>(key, timestamp),
...@@ -412,7 +410,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -412,7 +410,7 @@ public class EventuallyConsistentMapImpl<K, V>
412 checkNotNull(key, ERROR_NULL_KEY); 410 checkNotNull(key, ERROR_NULL_KEY);
413 checkNotNull(value, ERROR_NULL_VALUE); 411 checkNotNull(value, ERROR_NULL_VALUE);
414 412
415 - Timestamp timestamp = clockService.getTimestamp(key, value); 413 + Timestamp timestamp = timestampProvider.apply(key, value);
416 414
417 if (removeInternal(key, timestamp)) { 415 if (removeInternal(key, timestamp)) {
418 notifyPeers(new RemoveEntry<>(key, timestamp), 416 notifyPeers(new RemoveEntry<>(key, timestamp),
......
...@@ -59,7 +59,6 @@ import org.onosproject.net.group.GroupStoreDelegate; ...@@ -59,7 +59,6 @@ import org.onosproject.net.group.GroupStoreDelegate;
59 import org.onosproject.net.group.StoredGroupBucketEntry; 59 import org.onosproject.net.group.StoredGroupBucketEntry;
60 import org.onosproject.net.group.StoredGroupEntry; 60 import org.onosproject.net.group.StoredGroupEntry;
61 import org.onosproject.store.AbstractStore; 61 import org.onosproject.store.AbstractStore;
62 -import org.onosproject.store.Timestamp;
63 import org.onosproject.store.cluster.messaging.ClusterCommunicationService; 62 import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
64 import org.onosproject.store.cluster.messaging.ClusterMessage; 63 import org.onosproject.store.cluster.messaging.ClusterMessage;
65 import org.onosproject.store.cluster.messaging.ClusterMessageHandler; 64 import org.onosproject.store.cluster.messaging.ClusterMessageHandler;
...@@ -67,7 +66,6 @@ import org.onosproject.store.service.MultiValuedTimestamp; ...@@ -67,7 +66,6 @@ import org.onosproject.store.service.MultiValuedTimestamp;
67 import org.onosproject.store.serializers.DeviceIdSerializer; 66 import org.onosproject.store.serializers.DeviceIdSerializer;
68 import org.onosproject.store.serializers.KryoNamespaces; 67 import org.onosproject.store.serializers.KryoNamespaces;
69 import org.onosproject.store.serializers.URISerializer; 68 import org.onosproject.store.serializers.URISerializer;
70 -import org.onosproject.store.service.ClockService;
71 import org.onosproject.store.service.EventuallyConsistentMap; 69 import org.onosproject.store.service.EventuallyConsistentMap;
72 import org.onosproject.store.service.EventuallyConsistentMapBuilder; 70 import org.onosproject.store.service.EventuallyConsistentMapBuilder;
73 import org.onosproject.store.service.EventuallyConsistentMapEvent; 71 import org.onosproject.store.service.EventuallyConsistentMapEvent;
...@@ -142,6 +140,8 @@ public class DistributedGroupStore ...@@ -142,6 +140,8 @@ public class DistributedGroupStore
142 140
143 private KryoNamespace.Builder kryoBuilder = null; 141 private KryoNamespace.Builder kryoBuilder = null;
144 142
143 + private final AtomicLong sequenceNumber = new AtomicLong(0);
144 +
145 @Activate 145 @Activate
146 public void activate() { 146 public void activate() {
147 kryoBuilder = new KryoNamespace.Builder() 147 kryoBuilder = new KryoNamespace.Builder()
...@@ -210,7 +210,8 @@ public class DistributedGroupStore ...@@ -210,7 +210,8 @@ public class DistributedGroupStore
210 groupStoreEntriesByKey = keyMapBuilder 210 groupStoreEntriesByKey = keyMapBuilder
211 .withName("groupstorekeymap") 211 .withName("groupstorekeymap")
212 .withSerializer(kryoBuilder) 212 .withSerializer(kryoBuilder)
213 - .withClockService(new GroupStoreLogicalClockManager<>()) 213 + .withTimestampProvider((k, v) -> new MultiValuedTimestamp<>(System.currentTimeMillis(),
214 + sequenceNumber.getAndIncrement()))
214 .build(); 215 .build();
215 groupStoreEntriesByKey.addListener(new GroupStoreKeyMapListener()); 216 groupStoreEntriesByKey.addListener(new GroupStoreKeyMapListener());
216 log.debug("Current size of groupstorekeymap:{}", 217 log.debug("Current size of groupstorekeymap:{}",
...@@ -223,7 +224,8 @@ public class DistributedGroupStore ...@@ -223,7 +224,8 @@ public class DistributedGroupStore
223 auditPendingReqQueue = auditMapBuilder 224 auditPendingReqQueue = auditMapBuilder
224 .withName("pendinggroupkeymap") 225 .withName("pendinggroupkeymap")
225 .withSerializer(kryoBuilder) 226 .withSerializer(kryoBuilder)
226 - .withClockService(new GroupStoreLogicalClockManager<>()) 227 + .withTimestampProvider((k, v) -> new MultiValuedTimestamp<>(System.currentTimeMillis(),
228 + sequenceNumber.getAndIncrement()))
227 .build(); 229 .build();
228 log.debug("Current size of pendinggroupkeymap:{}", 230 log.debug("Current size of pendinggroupkeymap:{}",
229 auditPendingReqQueue.size()); 231 auditPendingReqQueue.size());
...@@ -909,21 +911,6 @@ public class DistributedGroupStore ...@@ -909,21 +911,6 @@ public class DistributedGroupStore
909 } 911 }
910 912
911 /** 913 /**
912 - * ClockService that generates wallclock based timestamps.
913 - */
914 - private class GroupStoreLogicalClockManager<T, U>
915 - implements ClockService<T, U> {
916 -
917 - private final AtomicLong sequenceNumber = new AtomicLong(0);
918 -
919 - @Override
920 - public Timestamp getTimestamp(T t1, U u1) {
921 - return new MultiValuedTimestamp<>(System.currentTimeMillis(),
922 - sequenceNumber.getAndIncrement());
923 - }
924 - }
925 -
926 - /**
927 * Map handler to receive any events when the group key map is updated. 914 * Map handler to receive any events when the group key map is updated.
928 */ 915 */
929 private class GroupStoreKeyMapListener implements 916 private class GroupStoreKeyMapListener implements
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.store.intent.impl; 16 package org.onosproject.store.intent.impl;
17 17
18 import com.google.common.collect.ImmutableList; 18 import com.google.common.collect.ImmutableList;
19 +
19 import org.apache.commons.lang.math.RandomUtils; 20 import org.apache.commons.lang.math.RandomUtils;
20 import org.apache.felix.scr.annotations.Activate; 21 import org.apache.felix.scr.annotations.Activate;
21 import org.apache.felix.scr.annotations.Component; 22 import org.apache.felix.scr.annotations.Component;
...@@ -48,6 +49,7 @@ import org.slf4j.Logger; ...@@ -48,6 +49,7 @@ import org.slf4j.Logger;
48 import java.util.Collection; 49 import java.util.Collection;
49 import java.util.List; 50 import java.util.List;
50 import java.util.Objects; 51 import java.util.Objects;
52 +import java.util.concurrent.atomic.AtomicLong;
51 import java.util.stream.Collectors; 53 import java.util.stream.Collectors;
52 54
53 import static com.google.common.base.Preconditions.checkNotNull; 55 import static com.google.common.base.Preconditions.checkNotNull;
...@@ -83,6 +85,8 @@ public class GossipIntentStore ...@@ -83,6 +85,8 @@ public class GossipIntentStore
83 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 85 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
84 protected PartitionService partitionService; 86 protected PartitionService partitionService;
85 87
88 + private final AtomicLong sequenceNumber = new AtomicLong(0);
89 +
86 @Activate 90 @Activate
87 public void activate() { 91 public void activate() {
88 KryoNamespace.Builder intentSerializer = KryoNamespace.newBuilder() 92 KryoNamespace.Builder intentSerializer = KryoNamespace.newBuilder()
...@@ -94,14 +98,17 @@ public class GossipIntentStore ...@@ -94,14 +98,17 @@ public class GossipIntentStore
94 currentMap = storageService.<Key, IntentData>eventuallyConsistentMapBuilder() 98 currentMap = storageService.<Key, IntentData>eventuallyConsistentMapBuilder()
95 .withName("intent-current") 99 .withName("intent-current")
96 .withSerializer(intentSerializer) 100 .withSerializer(intentSerializer)
97 - .withClockService(new IntentDataLogicalClockManager<>()) 101 + .withTimestampProvider((key, intentData) ->
102 + new MultiValuedTimestamp<>(intentData.version(),
103 + sequenceNumber.getAndIncrement()))
98 .withPeerUpdateFunction((key, intentData) -> getPeerNodes(key, intentData)) 104 .withPeerUpdateFunction((key, intentData) -> getPeerNodes(key, intentData))
99 .build(); 105 .build();
100 106
101 pendingMap = storageService.<Key, IntentData>eventuallyConsistentMapBuilder() 107 pendingMap = storageService.<Key, IntentData>eventuallyConsistentMapBuilder()
102 .withName("intent-pending") 108 .withName("intent-pending")
103 .withSerializer(intentSerializer) 109 .withSerializer(intentSerializer)
104 - .withClockService(new IntentDataClockManager<>()) 110 + .withTimestampProvider((key, intentData) -> new MultiValuedTimestamp<>(intentData.version(),
111 + System.nanoTime()))
105 .withPeerUpdateFunction((key, intentData) -> getPeerNodes(key, intentData)) 112 .withPeerUpdateFunction((key, intentData) -> getPeerNodes(key, intentData))
106 .build(); 113 .build();
107 114
......
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.store.intent.impl;
17 -
18 -import org.onosproject.net.intent.IntentData;
19 -import org.onosproject.store.Timestamp;
20 -import org.onosproject.store.service.ClockService;
21 -import org.onosproject.store.service.MultiValuedTimestamp;
22 -
23 -/**
24 - * ClockService that uses IntentData versions as timestamps.
25 - */
26 -public class IntentDataClockManager<K> implements ClockService<K, IntentData> {
27 - @Override
28 - public Timestamp getTimestamp(K key, IntentData intentData) {
29 - return new MultiValuedTimestamp<>(intentData.version(), System.nanoTime());
30 - }
31 -}
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.store.intent.impl;
17 -
18 -import org.onosproject.net.intent.IntentData;
19 -import org.onosproject.store.Timestamp;
20 -import org.onosproject.store.service.ClockService;
21 -import org.onosproject.store.service.MultiValuedTimestamp;
22 -
23 -import java.util.concurrent.atomic.AtomicLong;
24 -
25 -/**
26 - * ClockService that generates logical timestamps based on IntentData versions.
27 - */
28 -public class IntentDataLogicalClockManager<K> implements ClockService<K, IntentData> {
29 -
30 - private final AtomicLong sequenceNumber = new AtomicLong(0);
31 -
32 - @Override
33 - public Timestamp getTimestamp(K key, IntentData intentData) {
34 - return new MultiValuedTimestamp<>(intentData.version(),
35 - sequenceNumber.getAndIncrement());
36 - }
37 -}
...@@ -35,7 +35,6 @@ import org.onosproject.store.cluster.messaging.ClusterCommunicationService; ...@@ -35,7 +35,6 @@ import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
35 import org.onosproject.store.cluster.messaging.ClusterMessage; 35 import org.onosproject.store.cluster.messaging.ClusterMessage;
36 import org.onosproject.store.cluster.messaging.ClusterMessageHandler; 36 import org.onosproject.store.cluster.messaging.ClusterMessageHandler;
37 import org.onosproject.store.cluster.messaging.MessageSubject; 37 import org.onosproject.store.cluster.messaging.MessageSubject;
38 -import org.onosproject.store.service.ClockService;
39 import org.onosproject.store.impl.LogicalTimestamp; 38 import org.onosproject.store.impl.LogicalTimestamp;
40 import org.onosproject.store.service.WallClockTimestamp; 39 import org.onosproject.store.service.WallClockTimestamp;
41 import org.onosproject.store.serializers.KryoNamespaces; 40 import org.onosproject.store.serializers.KryoNamespaces;
...@@ -148,7 +147,7 @@ public class EventuallyConsistentMapImplTest { ...@@ -148,7 +147,7 @@ public class EventuallyConsistentMapImplTest {
148 clusterService, clusterCommunicator) 147 clusterService, clusterCommunicator)
149 .withName(MAP_NAME) 148 .withName(MAP_NAME)
150 .withSerializer(serializer) 149 .withSerializer(serializer)
151 - .withClockService(clockService) 150 + .withTimestampProvider((k, v) -> clockService.getTimestamp(k, v))
152 .withCommunicationExecutor(MoreExecutors.newDirectExecutorService()) 151 .withCommunicationExecutor(MoreExecutors.newDirectExecutorService())
153 .build(); 152 .build();
154 153
...@@ -805,12 +804,11 @@ public class EventuallyConsistentMapImplTest { ...@@ -805,12 +804,11 @@ public class EventuallyConsistentMapImplTest {
805 * @param <T> Type that the clock service will give out timestamps for 804 * @param <T> Type that the clock service will give out timestamps for
806 * @param <U> Second type that the clock service will give out values for 805 * @param <U> Second type that the clock service will give out values for
807 */ 806 */
808 - private class SequentialClockService<T, U> implements ClockService<T, U> { 807 + private class SequentialClockService<T, U> {
809 808
810 private static final long INITIAL_VALUE = 1; 809 private static final long INITIAL_VALUE = 1;
811 private final AtomicLong counter = new AtomicLong(INITIAL_VALUE); 810 private final AtomicLong counter = new AtomicLong(INITIAL_VALUE);
812 811
813 - @Override
814 public Timestamp getTimestamp(T object, U object2) { 812 public Timestamp getTimestamp(T object, U object2) {
815 return new TestTimestamp(counter.getAndIncrement()); 813 return new TestTimestamp(counter.getAndIncrement());
816 } 814 }
......
...@@ -57,7 +57,7 @@ import org.onosproject.store.serializers.KryoNamespaces; ...@@ -57,7 +57,7 @@ import org.onosproject.store.serializers.KryoNamespaces;
57 import org.onosproject.store.service.EventuallyConsistentMap; 57 import org.onosproject.store.service.EventuallyConsistentMap;
58 import org.onosproject.store.service.MultiValuedTimestamp; 58 import org.onosproject.store.service.MultiValuedTimestamp;
59 import org.onosproject.store.service.StorageService; 59 import org.onosproject.store.service.StorageService;
60 -import org.onosproject.store.service.WallclockClockManager; 60 +import org.onosproject.store.service.WallClockTimestamp;
61 import org.slf4j.Logger; 61 import org.slf4j.Logger;
62 62
63 import com.google.common.base.MoreObjects; 63 import com.google.common.base.MoreObjects;
...@@ -114,23 +114,23 @@ public class DistributedTunnelStore ...@@ -114,23 +114,23 @@ public class DistributedTunnelStore
114 tunnelIdAsKeyStore = storageService 114 tunnelIdAsKeyStore = storageService
115 .<TunnelId, Tunnel>eventuallyConsistentMapBuilder() 115 .<TunnelId, Tunnel>eventuallyConsistentMapBuilder()
116 .withName("all_tunnel").withSerializer(serializer) 116 .withName("all_tunnel").withSerializer(serializer)
117 - .withClockService(new WallclockClockManager<>()).build(); 117 + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
118 tunnelNameAsKeyStore = storageService 118 tunnelNameAsKeyStore = storageService
119 .<TunnelName, Set<TunnelId>>eventuallyConsistentMapBuilder() 119 .<TunnelName, Set<TunnelId>>eventuallyConsistentMapBuilder()
120 .withName("tunnel_name_tunnel").withSerializer(serializer) 120 .withName("tunnel_name_tunnel").withSerializer(serializer)
121 - .withClockService(new WallclockClockManager<>()).build(); 121 + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
122 srcAndDstKeyStore = storageService 122 srcAndDstKeyStore = storageService
123 .<TunnelKey, Set<TunnelId>>eventuallyConsistentMapBuilder() 123 .<TunnelKey, Set<TunnelId>>eventuallyConsistentMapBuilder()
124 .withName("src_dst_tunnel").withSerializer(serializer) 124 .withName("src_dst_tunnel").withSerializer(serializer)
125 - .withClockService(new WallclockClockManager<>()).build(); 125 + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
126 typeKeyStore = storageService 126 typeKeyStore = storageService
127 .<Tunnel.Type, Set<TunnelId>>eventuallyConsistentMapBuilder() 127 .<Tunnel.Type, Set<TunnelId>>eventuallyConsistentMapBuilder()
128 .withName("type_tunnel").withSerializer(serializer) 128 .withName("type_tunnel").withSerializer(serializer)
129 - .withClockService(new WallclockClockManager<>()).build(); 129 + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
130 orderRelationship = storageService 130 orderRelationship = storageService
131 .<ApplicationId, Set<TunnelSubscription>>eventuallyConsistentMapBuilder() 131 .<ApplicationId, Set<TunnelSubscription>>eventuallyConsistentMapBuilder()
132 .withName("type_tunnel").withSerializer(serializer) 132 .withName("type_tunnel").withSerializer(serializer)
133 - .withClockService(new WallclockClockManager<>()).build(); 133 + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build();
134 idGenerator = coreService.getIdGenerator(runnelOpTopoic); 134 idGenerator = coreService.getIdGenerator(runnelOpTopoic);
135 log.info("Started"); 135 log.info("Started");
136 } 136 }
......