X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-akka-raft%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fexample%2Fmessages%2FKeyValue.java;h=2eb4189eac911d7ecb773137bfcfc652b523564b;hb=2d62916cb1f4b4045f4fc38fbd313f8339f9ac67;hp=00cc09ae3004316f35ed35398ae930832192a236;hpb=02bdbc1c781abc0b0b1d12dbfc1a19c316bebb98;p=controller.git diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/messages/KeyValue.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/messages/KeyValue.java index 00cc09ae30..2eb4189eac 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/messages/KeyValue.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/example/messages/KeyValue.java @@ -8,11 +8,21 @@ package org.opendaylight.controller.cluster.example.messages; +import com.google.protobuf.GeneratedMessage; import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; +import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload; +import org.opendaylight.controller.protobuff.messages.cluster.example.KeyValueMessages; +import org.opendaylight.controller.protobuff.messages.cluster.raft.AppendEntriesMessages; -public class KeyValue implements Serializable{ - private final String key; - private final String value; +public class KeyValue extends Payload implements Serializable { + private static final long serialVersionUID = 1L; + private String key; + private String value; + + public KeyValue() { + } public KeyValue(String key, String value){ this.key = key; @@ -27,10 +37,42 @@ public class KeyValue implements Serializable{ return value; } + public void setKey(String key) { + this.key = key; + } + + public void setValue(String value) { + this.value = value; + } + @Override public String toString() { return "KeyValue{" + "key='" + key + '\'' + ", value='" + value + '\'' + '}'; } + + // override this method to return the protobuff related extension fields and their values + @Override public Map, String> encode() { + Map, String> map = new HashMap<>(); + map.put(KeyValueMessages.key, getKey()); + map.put(KeyValueMessages.value, getValue()); + return map; + } + + // override this method to assign the values from protobuff + @Override public Payload decode( + AppendEntriesMessages.AppendEntries.ReplicatedLogEntry.Payload payloadProtoBuff) { + String key = payloadProtoBuff.getExtension(KeyValueMessages.key); + String value = payloadProtoBuff.getExtension(KeyValueMessages.value); + this.setKey(key); + this.setValue(value); + return this; + } + + @Override + public int size() { + return this.value.length() + this.key.length(); + } + }