blob: f68b3c8a9fad22a705feba14298df6553ef1d1eb [file] [log] [blame]
CNlucius74fd4942015-07-20 14:28:04 +08001/*
2 * Copyright 2015 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 */
16package org.onosproject.ovsdb.controller;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19
20/**
21 * The abstract event of ovsdb.
22 */
23public final class OvsdbEvent<S> {
24
25 public enum Type {
26 /**
27 * Signifies that a new ovs port update has been detected.
28 */
29 PORT_ADDED,
30 /**
31 * Signifies that a ovs port has been removed.
32 */
33 PORT_REMOVED
34 }
35
36 private final Type type;
37 private final S subject;
38
39 /**
40 * Creates an event of a given type and for the specified event subject.
41 *
42 * @param type event type
43 * @param subject event subject
44 */
45 public OvsdbEvent(Type type, S subject) {
46 this.type = type;
47 this.subject = subject;
48 }
49
50 /**
BitOhenry6e204892015-11-04 22:09:04 +080051 * Returns the type of event.
CNlucius74fd4942015-07-20 14:28:04 +080052 *
53 * @return event type
54 */
55 public Type type() {
56 return type;
57 }
58
59 /**
BitOhenry6e204892015-11-04 22:09:04 +080060 * Returns the subject of event.
CNlucius74fd4942015-07-20 14:28:04 +080061 *
62 * @return subject to which this event pertains
63 */
64 public S subject() {
65 return subject;
66 }
67
68 @Override
69 public String toString() {
70 return toStringHelper(this).add("type", type())
71 .add("subject", subject()).toString();
72 }
73
74}