blob: 58ac0bb848bebbf0be6c1a3bc7886bf46b5a0cf1 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.host;
tom64b7aac2014-08-26 00:18:21 -070017
Charles Chanec0425c2015-11-11 12:09:38 -080018import org.joda.time.LocalDateTime;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.event.AbstractEvent;
20import org.onosproject.net.Host;
Charles Chanec0425c2015-11-11 12:09:38 -080021import org.onosproject.net.HostLocation;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
tom64b7aac2014-08-26 00:18:21 -070024
25/**
26 * Describes end-station host event.
27 */
28public 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 /**
tom7869ad92014-09-09 14:32:08 -070045 * Signifies that host data changed, e.g. IP address
46 */
47 HOST_UPDATED,
48
49 /**
tom64b7aac2014-08-26 00:18:21 -070050 * Signifies that a host location has changed.
51 */
52 HOST_MOVED
53 }
54
Charles Chanec0425c2015-11-11 12:09:38 -080055 private HostLocation prevLocation;
56
tom64b7aac2014-08-26 00:18:21 -070057 /**
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 Chanec0425c2015-11-11 12:09:38 -080079 /**
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 }
tom64b7aac2014-08-26 00:18:21 -0700110}