blob: 77afd22bd06c45b6c44b85bb6759d0deb5ff131c [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * 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
7 *
8 * 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.
15 */
tom1d416c52014-09-29 20:55:24 -070016package org.onlab.onos.store.cluster.messaging;
17
Yuta HIGUCHI8a851382014-10-06 14:56:46 -070018import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.Objects;
21
tom1d416c52014-09-29 20:55:24 -070022/**
23 * Representation of a message subject.
Madan Jampani3b0dfd52014-10-02 16:48:13 -070024 * Cluster messages have associated subjects that dictate how they get handled
25 * on the receiving side.
tom1d416c52014-09-29 20:55:24 -070026 */
Madan Jampani890bc352014-10-01 22:35:29 -070027public class MessageSubject {
tom1d416c52014-09-29 20:55:24 -070028
Madan Jampani890bc352014-10-01 22:35:29 -070029 private final String value;
tom1d416c52014-09-29 20:55:24 -070030
Madan Jampani890bc352014-10-01 22:35:29 -070031 public MessageSubject(String value) {
Yuta HIGUCHI8a851382014-10-06 14:56:46 -070032 this.value = checkNotNull(value);
Madan Jampani890bc352014-10-01 22:35:29 -070033 }
tom28e1fa22014-09-30 10:38:21 -070034
Madan Jampani890bc352014-10-01 22:35:29 -070035 public String value() {
36 return value;
37 }
tomd33e6402014-09-30 03:14:43 -070038
Madan Jampani890bc352014-10-01 22:35:29 -070039 @Override
40 public String toString() {
41 return value;
42 }
Yuta HIGUCHI8a851382014-10-06 14:56:46 -070043
44 @Override
45 public int hashCode() {
46 return value.hashCode();
47 }
48
49 @Override
50 public boolean equals(Object obj) {
51 if (this == obj) {
52 return true;
53 }
54 if (obj == null) {
55 return false;
56 }
57 if (getClass() != obj.getClass()) {
58 return false;
59 }
60 MessageSubject that = (MessageSubject) obj;
61 return Objects.equals(this.value, that.value);
62 }
Yuta HIGUCHI3cc19072014-10-07 17:33:23 -070063
64 // for serializer
65 protected MessageSubject() {
66 this.value = "";
67 }
tom1d416c52014-09-29 20:55:24 -070068}