blob: 102e2a229cc6b98f18478b36601864296e4f064f [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
Madan Jampaniab6d3112014-10-02 16:30:14 -070016package org.onlab.netty;
17
Yuta HIGUCHI0a0b9e42015-02-11 16:57:12 -080018import org.onlab.util.ByteArraySizeHashPrinter;
Madan Jampanic26eede2015-04-16 11:42:16 -070019import org.onosproject.store.cluster.messaging.Endpoint;
Yuta HIGUCHI0a0b9e42015-02-11 16:57:12 -080020
21import com.google.common.base.MoreObjects;
22
Madan Jampaniab6d3112014-10-02 16:30:14 -070023/**
24 * Internal message representation with additional attributes
25 * for supporting, synchronous request/reply behavior.
26 */
Madan Jampanic26eede2015-04-16 11:42:16 -070027public final class InternalMessage {
Madan Jampaniab6d3112014-10-02 16:30:14 -070028
Madan Jampanic26eede2015-04-16 11:42:16 -070029 private final long id;
30 private final Endpoint sender;
31 private final String type;
32 private final byte[] payload;
Yuta HIGUCHIc65f5122014-10-07 10:05:59 -070033
Madan Jampanic26eede2015-04-16 11:42:16 -070034 public InternalMessage(long id, Endpoint sender, String type, byte[] payload) {
Yuta HIGUCHI91768e32014-11-22 05:06:35 -080035 this.id = id;
36 this.sender = sender;
37 this.type = type;
38 this.payload = payload;
39 }
40
Madan Jampaniab6d3112014-10-02 16:30:14 -070041 public long id() {
42 return id;
43 }
44
Madan Jampani49115e92015-03-14 10:43:33 -070045 public String type() {
Madan Jampaniab6d3112014-10-02 16:30:14 -070046 return type;
47 }
48
49 public Endpoint sender() {
50 return sender;
51 }
52
Madan Jampani53e44e62014-10-07 12:39:51 -070053 public byte[] payload() {
Madan Jampaniab6d3112014-10-02 16:30:14 -070054 return payload;
55 }
56
Yuta HIGUCHI0a0b9e42015-02-11 16:57:12 -080057 @Override
58 public String toString() {
59 return MoreObjects.toStringHelper(this)
60 .add("id", id)
61 .add("type", type)
62 .add("sender", sender)
63 .add("payload", ByteArraySizeHashPrinter.of(payload))
64 .toString();
65 }
Yuta HIGUCHI92626c02014-10-06 15:46:18 -070066}