blob: 95647e7d6370f7a46c94a3dfc513929fb4cad577 [file] [log] [blame]
Shravan Ambati7d199542016-04-22 16:09:05 -07001/**
2 * Copyright 2016-present Open Networking Laboratory
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6
7 * http://www.apache.org/licenses/LICENSE-2.0
8
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15package org.onosproject.kafkaintegration.api.dto;
16
17import static com.google.common.base.MoreObjects.toStringHelper;
18import static com.google.common.base.Preconditions.checkNotNull;
19
20import java.util.Objects;
21
22import org.onosproject.kafkaintegration.api.dto.OnosEvent.Type;
23
24/**
25 * Representation of a subscription to an event type.
26 *
27 */
28public final class EventSubscriber {
29 private final String appName;
30 private final EventSubscriberGroupId subscriberGroupId;
31 private final Type eventType;
32
33 /**
34 * Creates a new Event Subscriber.
35 *
36 * @param name Application Name
37 * @param groupId Subscriber group id of the application
38 * @param eventType ONOS event type
39 */
40 public EventSubscriber(String name, EventSubscriberGroupId groupId,
41 Type eventType) {
42 this.appName = checkNotNull(name);
43 this.subscriberGroupId = checkNotNull(groupId);
44 this.eventType = checkNotNull(eventType);
45 }
46
47 /**
48 * Returns the Application Name.
49 *
50 * @return application name
51 */
52 public String appName() {
53 return appName;
54 }
55
56 /**
57 * Returns the Subscriber Group Id.
58 *
59 * @return Subscriber Group Id
60 */
61 public EventSubscriberGroupId subscriberGroupId() {
62 return subscriberGroupId;
63 }
64
65 /**
66 * Returns the Event type.
67 *
68 * @return ONOS Event Type
69 */
70 public Type eventType() {
71 return eventType;
72 }
73
74 @Override
75 public int hashCode() {
76 return Objects.hash(appName, subscriberGroupId, eventType);
77 }
78
79 @Override
80 public boolean equals(Object o) {
81 if (o instanceof EventSubscriber) {
82 EventSubscriber sub = (EventSubscriber) o;
83 if (sub.appName.equals(appName)
84 && sub.subscriberGroupId.equals(subscriberGroupId)
85 && sub.eventType.equals(eventType)) {
86 return true;
87 }
88 }
89
90 return false;
91 }
92
93 @Override
94 public String toString() {
95 return toStringHelper(this).add("appName", appName)
96 .addValue(subscriberGroupId.toString())
97 .add("eventType", eventType).toString();
98 }
99}