Committed by
Gerrit Code Review
Replace ECMap with ConsistentMap in UiExtensionManager
Change-Id: Ibe7e98611e755fe4c3123bd7f27cdab79677a761
Showing
1 changed file
with
20 additions
and
20 deletions
... | @@ -32,20 +32,20 @@ import com.google.common.collect.ImmutableMap; | ... | @@ -32,20 +32,20 @@ import com.google.common.collect.ImmutableMap; |
32 | import com.google.common.collect.ImmutableSet; | 32 | import com.google.common.collect.ImmutableSet; |
33 | import com.google.common.collect.Lists; | 33 | import com.google.common.collect.Lists; |
34 | import com.google.common.collect.Maps; | 34 | import com.google.common.collect.Maps; |
35 | + | ||
35 | import org.apache.felix.scr.annotations.Activate; | 36 | import org.apache.felix.scr.annotations.Activate; |
36 | import org.apache.felix.scr.annotations.Component; | 37 | import org.apache.felix.scr.annotations.Component; |
37 | import org.apache.felix.scr.annotations.Deactivate; | 38 | import org.apache.felix.scr.annotations.Deactivate; |
38 | import org.apache.felix.scr.annotations.Reference; | 39 | import org.apache.felix.scr.annotations.Reference; |
39 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 40 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
40 | import org.apache.felix.scr.annotations.Service; | 41 | import org.apache.felix.scr.annotations.Service; |
41 | -import org.onlab.util.KryoNamespace; | ||
42 | import org.onosproject.mastership.MastershipService; | 42 | import org.onosproject.mastership.MastershipService; |
43 | import org.onosproject.store.serializers.KryoNamespaces; | 43 | import org.onosproject.store.serializers.KryoNamespaces; |
44 | -import org.onosproject.store.service.EventuallyConsistentMap; | 44 | +import org.onosproject.store.service.ConsistentMap; |
45 | -import org.onosproject.store.service.EventuallyConsistentMapEvent; | 45 | +import org.onosproject.store.service.MapEvent; |
46 | -import org.onosproject.store.service.EventuallyConsistentMapListener; | 46 | +import org.onosproject.store.service.MapEventListener; |
47 | +import org.onosproject.store.service.Serializer; | ||
47 | import org.onosproject.store.service.StorageService; | 48 | import org.onosproject.store.service.StorageService; |
48 | -import org.onosproject.store.service.WallClockTimestamp; | ||
49 | import org.onosproject.ui.UiExtension; | 49 | import org.onosproject.ui.UiExtension; |
50 | import org.onosproject.ui.UiExtensionService; | 50 | import org.onosproject.ui.UiExtensionService; |
51 | import org.onosproject.ui.UiMessageHandlerFactory; | 51 | import org.onosproject.ui.UiMessageHandlerFactory; |
... | @@ -79,7 +79,7 @@ public class UiExtensionManager | ... | @@ -79,7 +79,7 @@ public class UiExtensionManager |
79 | 79 | ||
80 | private static final ClassLoader CL = UiExtensionManager.class.getClassLoader(); | 80 | private static final ClassLoader CL = UiExtensionManager.class.getClassLoader(); |
81 | 81 | ||
82 | - private static final String ONOS_USER_PREFERENCES = "onos-user-preferences"; | 82 | + private static final String ONOS_USER_PREFERENCES = "onos-ui-user-preferences"; |
83 | private static final String CORE = "core"; | 83 | private static final String CORE = "core"; |
84 | private static final String GUI_ADDED = "guiAdded"; | 84 | private static final String GUI_ADDED = "guiAdded"; |
85 | private static final String GUI_REMOVED = "guiRemoved"; | 85 | private static final String GUI_REMOVED = "guiRemoved"; |
... | @@ -107,8 +107,9 @@ public class UiExtensionManager | ... | @@ -107,8 +107,9 @@ public class UiExtensionManager |
107 | protected StorageService storageService; | 107 | protected StorageService storageService; |
108 | 108 | ||
109 | // User preferences | 109 | // User preferences |
110 | - private EventuallyConsistentMap<String, ObjectNode> prefs; | 110 | + private ConsistentMap<String, ObjectNode> prefsConsistentMap; |
111 | - private final EventuallyConsistentMapListener<String, ObjectNode> prefsListener = | 111 | + private Map<String, ObjectNode> prefs; |
112 | + private final MapEventListener<String, ObjectNode> prefsListener = | ||
112 | new InternalPrefsListener(); | 113 | new InternalPrefsListener(); |
113 | 114 | ||
114 | private final ObjectMapper mapper = new ObjectMapper(); | 115 | private final ObjectMapper mapper = new ObjectMapper(); |
... | @@ -167,28 +168,27 @@ public class UiExtensionManager | ... | @@ -167,28 +168,27 @@ public class UiExtensionManager |
167 | 168 | ||
168 | @Activate | 169 | @Activate |
169 | public void activate() { | 170 | public void activate() { |
170 | - KryoNamespace.Builder kryoBuilder = new KryoNamespace.Builder() | 171 | + Serializer serializer = Serializer.using(KryoNamespaces.API, |
171 | - .register(KryoNamespaces.API) | 172 | + ObjectNode.class, ArrayNode.class, |
172 | - .register(ObjectNode.class, ArrayNode.class, | ||
173 | JsonNodeFactory.class, LinkedHashMap.class, | 173 | JsonNodeFactory.class, LinkedHashMap.class, |
174 | TextNode.class, BooleanNode.class, | 174 | TextNode.class, BooleanNode.class, |
175 | LongNode.class, DoubleNode.class, ShortNode.class, | 175 | LongNode.class, DoubleNode.class, ShortNode.class, |
176 | IntNode.class, NullNode.class); | 176 | IntNode.class, NullNode.class); |
177 | 177 | ||
178 | - prefs = storageService.<String, ObjectNode>eventuallyConsistentMapBuilder() | 178 | + prefsConsistentMap = storageService.<String, ObjectNode>consistentMapBuilder() |
179 | .withName(ONOS_USER_PREFERENCES) | 179 | .withName(ONOS_USER_PREFERENCES) |
180 | - .withSerializer(kryoBuilder) | 180 | + .withSerializer(serializer) |
181 | - .withTimestampProvider((k, v) -> new WallClockTimestamp()) | 181 | + .withRelaxedReadConsistency() |
182 | - .withPersistence() | ||
183 | .build(); | 182 | .build(); |
184 | - prefs.addListener(prefsListener); | 183 | + prefsConsistentMap.addListener(prefsListener); |
184 | + prefs = prefsConsistentMap.asJavaMap(); | ||
185 | register(core); | 185 | register(core); |
186 | log.info("Started"); | 186 | log.info("Started"); |
187 | } | 187 | } |
188 | 188 | ||
189 | @Deactivate | 189 | @Deactivate |
190 | public void deactivate() { | 190 | public void deactivate() { |
191 | - prefs.removeListener(prefsListener); | 191 | + prefsConsistentMap.removeListener(prefsListener); |
192 | UiWebSocketServlet.closeAll(); | 192 | UiWebSocketServlet.closeAll(); |
193 | unregister(core); | 193 | unregister(core); |
194 | log.info("Stopped"); | 194 | log.info("Stopped"); |
... | @@ -283,11 +283,11 @@ public class UiExtensionManager | ... | @@ -283,11 +283,11 @@ public class UiExtensionManager |
283 | 283 | ||
284 | // Auxiliary listener to preference map events. | 284 | // Auxiliary listener to preference map events. |
285 | private class InternalPrefsListener | 285 | private class InternalPrefsListener |
286 | - implements EventuallyConsistentMapListener<String, ObjectNode> { | 286 | + implements MapEventListener<String, ObjectNode> { |
287 | @Override | 287 | @Override |
288 | - public void event(EventuallyConsistentMapEvent<String, ObjectNode> event) { | 288 | + public void event(MapEvent<String, ObjectNode> event) { |
289 | String userName = userName(event.key()); | 289 | String userName = userName(event.key()); |
290 | - if (event.type() == EventuallyConsistentMapEvent.Type.PUT) { | 290 | + if (event.type() == MapEvent.Type.INSERT || event.type() == MapEvent.Type.UPDATE) { |
291 | UiWebSocketServlet.sendToUser(userName, UPDATE_PREFS, jsonPrefs()); | 291 | UiWebSocketServlet.sendToUser(userName, UPDATE_PREFS, jsonPrefs()); |
292 | } | 292 | } |
293 | } | 293 | } | ... | ... |
-
Please register or login to post a comment