Handle more specific BindException and IOException
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / example / messages / KeyValue.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.cluster.example.messages;
10
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;
15
16 import java.io.Serializable;
17 import java.util.HashMap;
18 import java.util.Map;
19
20 public class KeyValue extends Payload implements Serializable {
21     private static final long serialVersionUID = 1L;
22     private String key;
23     private String value;
24
25     public KeyValue() {
26     }
27
28     public KeyValue(String key, String value){
29         this.key = key;
30         this.value = value;
31     }
32
33     public String getKey() {
34         return key;
35     }
36
37     public String getValue() {
38         return value;
39     }
40
41     public void setKey(String key) {
42         this.key = key;
43     }
44
45     public void setValue(String value) {
46         this.value = value;
47     }
48
49     @Override public String toString() {
50         return "KeyValue{" +
51             "key='" + key + '\'' +
52             ", value='" + value + '\'' +
53             '}';
54     }
55
56     // override this method to return  the protobuff related extension fields and their values
57     @Override public Map<GeneratedMessage.GeneratedExtension, String> encode() {
58         Map<GeneratedMessage.GeneratedExtension, String> map = new HashMap<>();
59         map.put(KeyValueMessages.key, getKey());
60         map.put(KeyValueMessages.value, getValue());
61         return map;
62     }
63
64     // override this method to assign the values from protobuff
65     @Override public Payload decode(
66         AppendEntriesMessages.AppendEntries.ReplicatedLogEntry.Payload payloadProtoBuff) {
67         String key = payloadProtoBuff.getExtension(KeyValueMessages.key);
68         String value = payloadProtoBuff.getExtension(KeyValueMessages.value);
69         this.setKey(key);
70         this.setValue(value);
71         return this;
72     }
73
74 }