CNlucius | 74fd494 | 2015-07-20 14:28:04 +0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.ovsdb.controller; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | |
| 20 | /** |
| 21 | * The abstract event of ovsdb. |
| 22 | */ |
| 23 | public 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 | /** |
| 51 | * Returns the type of the event. |
| 52 | * |
| 53 | * @return event type |
| 54 | */ |
| 55 | public Type type() { |
| 56 | return type; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the subject of the event. |
| 61 | * |
| 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 | } |