Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.host; |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 17 | |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 18 | import org.joda.time.LocalDateTime; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import org.onosproject.event.AbstractEvent; |
| 20 | import org.onosproject.net.Host; |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 21 | import org.onosproject.net.HostLocation; |
| 22 | |
| 23 | import static com.google.common.base.MoreObjects.toStringHelper; |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * Describes end-station host event. |
| 27 | */ |
| 28 | public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { |
| 29 | |
| 30 | /** |
| 31 | * Type of host events. |
| 32 | */ |
| 33 | public enum Type { |
| 34 | /** |
| 35 | * Signifies that a new host has been detected. |
| 36 | */ |
| 37 | HOST_ADDED, |
| 38 | |
| 39 | /** |
| 40 | * Signifies that a host has been removed. |
| 41 | */ |
| 42 | HOST_REMOVED, |
| 43 | |
| 44 | /** |
tom | 7869ad9 | 2014-09-09 14:32:08 -0700 | [diff] [blame] | 45 | * Signifies that host data changed, e.g. IP address |
| 46 | */ |
| 47 | HOST_UPDATED, |
| 48 | |
| 49 | /** |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 50 | * Signifies that a host location has changed. |
| 51 | */ |
| 52 | HOST_MOVED |
| 53 | } |
| 54 | |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 55 | private HostLocation prevLocation; |
| 56 | |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 57 | /** |
| 58 | * Creates an event of a given type and for the specified host and the |
| 59 | * current time. |
| 60 | * |
| 61 | * @param type host event type |
| 62 | * @param host event host subject |
| 63 | */ |
| 64 | public HostEvent(Type type, Host host) { |
| 65 | super(type, host); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Creates an event of a given type and for the specified host and time. |
| 70 | * |
| 71 | * @param type host event type |
| 72 | * @param host event host subject |
| 73 | * @param time occurrence time |
| 74 | */ |
| 75 | public HostEvent(Type type, Host host, long time) { |
| 76 | super(type, host, time); |
| 77 | } |
| 78 | |
Charles Chan | ec0425c | 2015-11-11 12:09:38 -0800 | [diff] [blame] | 79 | /** |
| 80 | * Creates an event with HOST_MOVED type along with the previous location |
| 81 | * of the host. |
| 82 | * |
| 83 | * @param host event host subject |
| 84 | * @param prevLocation previous location of the host |
| 85 | */ |
| 86 | public HostEvent(Host host, HostLocation prevLocation) { |
| 87 | super(Type.HOST_MOVED, host); |
| 88 | this.prevLocation = prevLocation; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Gets the previous location information in this host event. |
| 93 | * |
| 94 | * @return the previous location, or null if previous location is not |
| 95 | * specified. |
| 96 | */ |
| 97 | public HostLocation prevLocation() { |
| 98 | return this.prevLocation; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public String toString() { |
| 103 | return toStringHelper(this) |
| 104 | .add("time", new LocalDateTime(time())) |
| 105 | .add("type", type()) |
| 106 | .add("subject", subject()) |
| 107 | .add("prevLocation", prevLocation()) |
| 108 | .toString(); |
| 109 | } |
tom | 64b7aac | 2014-08-26 00:18:21 -0700 | [diff] [blame] | 110 | } |