minor changes to RoleValue
Change-Id: Id870843c53549439e88ada40e8b2ef5513b8e4b7
Showing
2 changed files
with
8 additions
and
7 deletions
| 1 | package org.onlab.onos.store.mastership.impl; | 1 | package org.onlab.onos.store.mastership.impl; |
| 2 | 2 | ||
| 3 | import java.util.Collections; | 3 | import java.util.Collections; |
| 4 | -import java.util.HashMap; | 4 | +import java.util.EnumMap; |
| 5 | import java.util.LinkedList; | 5 | import java.util.LinkedList; |
| 6 | import java.util.List; | 6 | import java.util.List; |
| 7 | import java.util.Map; | 7 | import java.util.Map; |
| ... | @@ -17,9 +17,9 @@ import com.google.common.base.MoreObjects.ToStringHelper; | ... | @@ -17,9 +17,9 @@ import com.google.common.base.MoreObjects.ToStringHelper; |
| 17 | * A structure that holds node mastership roles associated with a | 17 | * A structure that holds node mastership roles associated with a |
| 18 | * {@link DeviceId}. This structure needs to be locked through IMap. | 18 | * {@link DeviceId}. This structure needs to be locked through IMap. |
| 19 | */ | 19 | */ |
| 20 | -public class RoleValue { | 20 | +final class RoleValue { |
| 21 | 21 | ||
| 22 | - protected Map<MastershipRole, List<NodeId>> value = new HashMap<>(); | 22 | + protected final Map<MastershipRole, List<NodeId>> value = new EnumMap<>(MastershipRole.class); |
| 23 | 23 | ||
| 24 | public RoleValue() { | 24 | public RoleValue() { |
| 25 | value.put(MastershipRole.MASTER, new LinkedList<NodeId>()); | 25 | value.put(MastershipRole.MASTER, new LinkedList<NodeId>()); |
| ... | @@ -27,7 +27,8 @@ public class RoleValue { | ... | @@ -27,7 +27,8 @@ public class RoleValue { |
| 27 | value.put(MastershipRole.NONE, new LinkedList<NodeId>()); | 27 | value.put(MastershipRole.NONE, new LinkedList<NodeId>()); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | - public Map<MastershipRole, List<NodeId>> value() { | 30 | + // exposing internals for serialization purpose only |
| 31 | + Map<MastershipRole, List<NodeId>> value() { | ||
| 31 | return Collections.unmodifiableMap(value); | 32 | return Collections.unmodifiableMap(value); |
| 32 | } | 33 | } |
| 33 | 34 | ... | ... |
| ... | @@ -35,10 +35,10 @@ public class RoleValueSerializer extends Serializer<RoleValue> { | ... | @@ -35,10 +35,10 @@ public class RoleValueSerializer extends Serializer<RoleValue> { |
| 35 | 35 | ||
| 36 | @Override | 36 | @Override |
| 37 | public void write(Kryo kryo, Output output, RoleValue type) { | 37 | public void write(Kryo kryo, Output output, RoleValue type) { |
| 38 | - output.writeInt(type.value().size()); | 38 | + final Map<MastershipRole, List<NodeId>> map = type.value(); |
| 39 | + output.writeInt(map.size()); | ||
| 39 | 40 | ||
| 40 | - for (Map.Entry<MastershipRole, List<NodeId>> el : | 41 | + for (Map.Entry<MastershipRole, List<NodeId>> el : map.entrySet()) { |
| 41 | - type.value().entrySet()) { | ||
| 42 | output.writeInt(el.getKey().ordinal()); | 42 | output.writeInt(el.getKey().ordinal()); |
| 43 | 43 | ||
| 44 | List<NodeId> nodes = el.getValue(); | 44 | List<NodeId> nodes = el.getValue(); | ... | ... |
-
Please register or login to post a comment