2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.cluster.example.messages;
11 import com.google.protobuf.GeneratedMessage;
12 import org.opendaylight.controller.protobuff.messages.cluster.example.KeyValueMessages;
13 import org.opendaylight.controller.cluster.raft.protobuff.client.messages.Payload;
14 import org.opendaylight.controller.protobuff.messages.cluster.raft.AppendEntriesMessages;
16 import java.io.Serializable;
17 import java.util.HashMap;
20 public class KeyValue extends Payload implements Serializable {
27 public KeyValue(String key, String value){
32 public String getKey() {
36 public String getValue() {
40 public void setKey(String key) {
44 public void setValue(String value) {
48 @Override public String toString() {
50 "key='" + key + '\'' +
51 ", value='" + value + '\'' +
55 // override this method to return the protobuff related extension fields and their values
56 @Override public Map<GeneratedMessage.GeneratedExtension, String> encode() {
57 Map<GeneratedMessage.GeneratedExtension, String> map = new HashMap<>();
58 map.put(KeyValueMessages.key, getKey());
59 map.put(KeyValueMessages.value, getValue());
63 // override this method to assign the values from protobuff
64 @Override public Payload decode(
65 AppendEntriesMessages.AppendEntries.ReplicatedLogEntry.Payload payloadProtoBuff) {
66 String key = payloadProtoBuff.getExtension(KeyValueMessages.key);
67 String value = payloadProtoBuff.getExtension(KeyValueMessages.value);