serializers for roles
Change-Id: I97a5a433be66ec3a95300d863fd790af4582b9ea
Showing
4 changed files
with
60 additions
and
3 deletions
core/store/serializers/src/main/java/org/onlab/onos/store/serializers/MastershipRoleSerializer.java
0 → 100644
| 1 | +package org.onlab.onos.store.serializers; | ||
| 2 | + | ||
| 3 | +import org.onlab.onos.net.MastershipRole; | ||
| 4 | + | ||
| 5 | +import com.esotericsoftware.kryo.Kryo; | ||
| 6 | +import com.esotericsoftware.kryo.Serializer; | ||
| 7 | +import com.esotericsoftware.kryo.io.Input; | ||
| 8 | +import com.esotericsoftware.kryo.io.Output; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * Kryo Serializer for {@link org.onlab.onos.net.MastershipRole}. | ||
| 12 | + */ | ||
| 13 | +public class MastershipRoleSerializer extends Serializer<MastershipRole> { | ||
| 14 | + | ||
| 15 | + @Override | ||
| 16 | + public MastershipRole read(Kryo kryo, Input input, Class<MastershipRole> type) { | ||
| 17 | + final String role = kryo.readObject(input, String.class); | ||
| 18 | + return MastershipRole.valueOf(role); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public void write(Kryo kryo, Output output, MastershipRole object) { | ||
| 23 | + kryo.writeObject(output, object.toString()); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | +} |
core/store/serializers/src/main/java/org/onlab/onos/store/serializers/MastershipTermSerializer.java
0 → 100644
| 1 | +package org.onlab.onos.store.serializers; | ||
| 2 | + | ||
| 3 | +import org.onlab.onos.cluster.MastershipTerm; | ||
| 4 | +import org.onlab.onos.cluster.NodeId; | ||
| 5 | + | ||
| 6 | +import com.esotericsoftware.kryo.Kryo; | ||
| 7 | +import com.esotericsoftware.kryo.Serializer; | ||
| 8 | +import com.esotericsoftware.kryo.io.Input; | ||
| 9 | +import com.esotericsoftware.kryo.io.Output; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * Kryo Serializer for {@link org.onlab.onos.cluster.MastershipTerm}. | ||
| 13 | + */ | ||
| 14 | +public class MastershipTermSerializer extends Serializer<MastershipTerm> { | ||
| 15 | + | ||
| 16 | + @Override | ||
| 17 | + public MastershipTerm read(Kryo kryo, Input input, Class<MastershipTerm> type) { | ||
| 18 | + final NodeId node = new NodeId(kryo.readObject(input, String.class)); | ||
| 19 | + final int term = input.readInt(); | ||
| 20 | + return MastershipTerm.of(node, term); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + @Override | ||
| 24 | + public void write(Kryo kryo, Output output, MastershipTerm object) { | ||
| 25 | + output.writeString(object.master().toString()); | ||
| 26 | + output.writeInt(object.termNumber()); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | +} |
| ... | @@ -12,6 +12,7 @@ import org.junit.After; | ... | @@ -12,6 +12,7 @@ import org.junit.After; |
| 12 | import org.junit.Before; | 12 | import org.junit.Before; |
| 13 | import org.junit.BeforeClass; | 13 | import org.junit.BeforeClass; |
| 14 | import org.junit.Test; | 14 | import org.junit.Test; |
| 15 | +import org.onlab.onos.cluster.MastershipTerm; | ||
| 15 | import org.onlab.onos.cluster.NodeId; | 16 | import org.onlab.onos.cluster.NodeId; |
| 16 | import org.onlab.onos.net.ConnectPoint; | 17 | import org.onlab.onos.net.ConnectPoint; |
| 17 | import org.onlab.onos.net.DefaultDevice; | 18 | import org.onlab.onos.net.DefaultDevice; |
| ... | @@ -21,6 +22,7 @@ import org.onlab.onos.net.Device; | ... | @@ -21,6 +22,7 @@ import org.onlab.onos.net.Device; |
| 21 | import org.onlab.onos.net.DeviceId; | 22 | import org.onlab.onos.net.DeviceId; |
| 22 | import org.onlab.onos.net.Link; | 23 | import org.onlab.onos.net.Link; |
| 23 | import org.onlab.onos.net.LinkKey; | 24 | import org.onlab.onos.net.LinkKey; |
| 25 | +import org.onlab.onos.net.MastershipRole; | ||
| 24 | import org.onlab.onos.net.PortNumber; | 26 | import org.onlab.onos.net.PortNumber; |
| 25 | import org.onlab.onos.net.provider.ProviderId; | 27 | import org.onlab.onos.net.provider.ProviderId; |
| 26 | import org.onlab.packet.IpPrefix; | 28 | import org.onlab.packet.IpPrefix; |
| ... | @@ -81,6 +83,9 @@ public class KryoSerializerTests { | ... | @@ -81,6 +83,9 @@ public class KryoSerializerTests { |
| 81 | .register(DefaultDevice.class) | 83 | .register(DefaultDevice.class) |
| 82 | 84 | ||
| 83 | .register(URI.class, new URISerializer()) | 85 | .register(URI.class, new URISerializer()) |
| 86 | + | ||
| 87 | + .register(MastershipRole.class, new MastershipRoleSerializer()) | ||
| 88 | + .register(MastershipTerm.class, new MastershipTermSerializer()) | ||
| 84 | .build(); | 89 | .build(); |
| 85 | } | 90 | } |
| 86 | 91 | ... | ... |
| ... | @@ -9,7 +9,6 @@ import org.junit.Test; | ... | @@ -9,7 +9,6 @@ import org.junit.Test; |
| 9 | import org.onlab.onos.cluster.MastershipTerm; | 9 | import org.onlab.onos.cluster.MastershipTerm; |
| 10 | import org.onlab.onos.cluster.NodeId; | 10 | import org.onlab.onos.cluster.NodeId; |
| 11 | import org.onlab.onos.net.DeviceId; | 11 | import org.onlab.onos.net.DeviceId; |
| 12 | -import org.onlab.onos.net.provider.ProviderId; | ||
| 13 | 12 | ||
| 14 | import com.google.common.collect.Sets; | 13 | import com.google.common.collect.Sets; |
| 15 | 14 | ||
| ... | @@ -24,8 +23,6 @@ import static org.onlab.onos.cluster.MastershipEvent.Type.*; | ... | @@ -24,8 +23,6 @@ import static org.onlab.onos.cluster.MastershipEvent.Type.*; |
| 24 | */ | 23 | */ |
| 25 | public class SimpleMastershipStoreTest { | 24 | public class SimpleMastershipStoreTest { |
| 26 | 25 | ||
| 27 | - private static final ProviderId PID = new ProviderId("of", "foo"); | ||
| 28 | - | ||
| 29 | private static final DeviceId DID1 = DeviceId.deviceId("of:01"); | 26 | private static final DeviceId DID1 = DeviceId.deviceId("of:01"); |
| 30 | private static final DeviceId DID2 = DeviceId.deviceId("of:02"); | 27 | private static final DeviceId DID2 = DeviceId.deviceId("of:02"); |
| 31 | private static final DeviceId DID3 = DeviceId.deviceId("of:03"); | 28 | private static final DeviceId DID3 = DeviceId.deviceId("of:03"); | ... | ... |
-
Please register or login to post a comment