Bug2268: Deprecate legacy Payload classes
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / main / java / org / opendaylight / controller / cluster / raft / protobuff / client / messages / Payload.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.raft.protobuff.client.messages;
10
11
12 import com.google.protobuf.GeneratedMessage;
13 import java.util.Map;
14 import org.opendaylight.controller.protobuff.messages.cluster.raft.AppendEntriesMessages;
15
16 /**
17  * An instance of a Payload class is meant to be used as the Payload for
18  * AppendEntries.
19  * <p>
20  *
21  * When an actor which is derived from RaftActor attempts to persistData it
22  * must pass an instance of the Payload class. Similarly when state needs to
23  * be applied to the derived RaftActor it will be passed an instance of the
24  * Payload class.
25  * <p>
26  *
27  * To define your own payload do the following,
28  * <ol>
29  *     <li>Create your own protocol buffer message which extends the AppendEntries Payload</li>
30  *     <li>Extend this Payload class</li>
31  *     <li>Implement encode</li>
32  *     <li>Implement decode</li>
33  * </ol>
34  *
35  * Your own protocol buffer message can be create like so, <br/>
36  * <pre>
37  * {@code
38  *
39  * import "AppendEntriesMessages.proto";
40  *
41  * package org.opendaylight.controller.cluster.raft;
42  *
43  * option java_package = "org.opendaylight.controller.cluster.raft.protobuff.messages";
44  * option java_outer_classname = "MockPayloadMessages";
45  *
46  * extend AppendEntries.ReplicatedLogEntry.Payload {
47  *      optional string value = 2;
48  * }
49  * }
50  * </pre>
51  *
52  */
53 public abstract class Payload {
54
55     public String getClientPayloadClassName() {
56         return this.getClass().getName();
57     }
58
59     /**
60      * Encode the payload data as a protocol buffer extension.
61      * <p>
62      * TODO: Add more meat in here
63      * @param <T>
64      * @return Map of <GeneratedMessage.GeneratedExtension, T>
65      */
66     @Deprecated
67     public abstract <T extends Object> Map<GeneratedMessage.GeneratedExtension, T> encode();
68
69     /**
70      * Decode the protocol buffer payload into a specific Payload as defined
71      * by the class extending RaftActor
72      *
73      * @param payload The payload in protocol buffer format
74      * @return
75      */
76     @Deprecated
77     public abstract Payload decode(
78         AppendEntriesMessages.AppendEntries.ReplicatedLogEntry.Payload payload);
79
80     public abstract int size();
81 }