Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.cluster.messaging; |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 17 | |
Yuta HIGUCHI | 8a85138 | 2014-10-06 14:56:46 -0700 | [diff] [blame] | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import java.util.Objects; |
| 21 | |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 22 | /** |
| 23 | * Representation of a message subject. |
Madan Jampani | 3b0dfd5 | 2014-10-02 16:48:13 -0700 | [diff] [blame] | 24 | * Cluster messages have associated subjects that dictate how they get handled |
| 25 | * on the receiving side. |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 26 | */ |
Ray Milkey | 96495ca | 2015-07-07 11:02:10 -0700 | [diff] [blame] | 27 | public final class MessageSubject { |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 28 | |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 29 | private final String value; |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 30 | |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 31 | public MessageSubject(String value) { |
Yuta HIGUCHI | 8a85138 | 2014-10-06 14:56:46 -0700 | [diff] [blame] | 32 | this.value = checkNotNull(value); |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 33 | } |
tom | 28e1fa2 | 2014-09-30 10:38:21 -0700 | [diff] [blame] | 34 | |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 35 | public String value() { |
| 36 | return value; |
| 37 | } |
tom | d33e640 | 2014-09-30 03:14:43 -0700 | [diff] [blame] | 38 | |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 39 | @Override |
| 40 | public String toString() { |
| 41 | return value; |
| 42 | } |
Yuta HIGUCHI | 8a85138 | 2014-10-06 14:56:46 -0700 | [diff] [blame] | 43 | |
| 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 HIGUCHI | 3cc1907 | 2014-10-07 17:33:23 -0700 | [diff] [blame] | 63 | |
| 64 | // for serializer |
| 65 | protected MessageSubject() { |
| 66 | this.value = ""; |
| 67 | } |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 68 | } |