blob: d4c3b768f9bb7ff27af7a500e8c408c3c6421949 [file] [log] [blame]
Tomek OsiƄski7a1db182018-02-03 17:15:06 +01001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16
17package org.onosproject.xmpp.pubsub;
18
19import static com.google.common.base.MoreObjects.toStringHelper;
20
21/**
22 * Abstracts event of XMPP Publish/Subscribe.
23 */
24public final class XmppPubSubEvent<S> {
25
26 /**
27 * Types of XMPP Publish/Subscribe messages.
28 */
29 public enum Type {
30 SUBSCRIBE,
31 UNSUBSCRIBE,
32 PUBLISH,
33 RETRACT
34 }
35
36 private final Type type;
37 private final S subject;
38
39 public XmppPubSubEvent(Type type, S subject) {
40 this.type = type;
41 this.subject = subject;
42 }
43
44 /**
45 * Returns the type of event.
46 *
47 * @return event type
48 */
49 public Type type() {
50 return type;
51 }
52
53 /**
54 * Returns the subject of event.
55 *
56 * @return subject to which this event pertains
57 */
58 public S subject() {
59 return subject;
60 }
61
62 @Override
63 public String toString() {
64 return toStringHelper(this).add("type", type())
65 .add("subject", subject()).toString();
66 }
67
68}