blob: dd29f24faeadba3a4c3c80554aca497384596744 [file] [log] [blame]
tom1d416c52014-09-29 20:55:24 -07001package org.onlab.onos.store.cluster.messaging;
2
Madan Jampani8a895092014-10-17 16:55:50 -07003import java.io.IOException;
4
Madan Jampani890bc352014-10-01 22:35:29 -07005import org.onlab.onos.cluster.NodeId;
tom1d416c52014-09-29 20:55:24 -07006
Yuta HIGUCHI971addc2014-10-07 23:23:17 -07007// TODO: Should payload type be ByteBuffer?
tom1d416c52014-09-29 20:55:24 -07008/**
9 * Base message for cluster-wide communications.
10 */
Madan Jampani890bc352014-10-01 22:35:29 -070011public class ClusterMessage {
tom1d416c52014-09-29 20:55:24 -070012
Madan Jampani890bc352014-10-01 22:35:29 -070013 private final NodeId sender;
tom1d416c52014-09-29 20:55:24 -070014 private final MessageSubject subject;
Madan Jampani53e44e62014-10-07 12:39:51 -070015 private final byte[] payload;
tom1d416c52014-09-29 20:55:24 -070016
17 /**
18 * Creates a cluster message.
19 *
20 * @param subject message subject
21 */
Madan Jampani53e44e62014-10-07 12:39:51 -070022 public ClusterMessage(NodeId sender, MessageSubject subject, byte[] payload) {
Madan Jampani890bc352014-10-01 22:35:29 -070023 this.sender = sender;
tom1d416c52014-09-29 20:55:24 -070024 this.subject = subject;
Madan Jampani890bc352014-10-01 22:35:29 -070025 this.payload = payload;
tom1d416c52014-09-29 20:55:24 -070026 }
27
28 /**
Madan Jampani890bc352014-10-01 22:35:29 -070029 * Returns the id of the controller sending this message.
30 *
31 * @return message sender id.
32 */
33 public NodeId sender() {
34 return sender;
35 }
36
37 /**
tom1d416c52014-09-29 20:55:24 -070038 * Returns the message subject indicator.
39 *
40 * @return message subject
41 */
42 public MessageSubject subject() {
43 return subject;
44 }
45
Madan Jampani890bc352014-10-01 22:35:29 -070046 /**
47 * Returns the message payload.
48 *
49 * @return message payload.
50 */
Madan Jampani53e44e62014-10-07 12:39:51 -070051 public byte[] payload() {
Madan Jampani890bc352014-10-01 22:35:29 -070052 return payload;
tom1d416c52014-09-29 20:55:24 -070053 }
Madan Jampani8a895092014-10-17 16:55:50 -070054
55 /**
56 * Sends a response to the sender.
57 *
58 * @param data payload response.
59 * @throws IOException
60 */
61 public void respond(byte[] data) throws IOException {
62 throw new IllegalStateException("One can only repond to message recived from others.");
63 }
tom1d416c52014-09-29 20:55:24 -070064}