blob: b77334abef469bbb964614078b93f54dcd0c5ec2 [file] [log] [blame]
Charles Chanff79dd92018-06-01 16:33:48 -07001/*
2 * Copyright 2014-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 */
16package org.onosproject.net.host;
17
18import org.onlab.util.Tools;
19import org.onosproject.event.AbstractEvent;
20
21import static com.google.common.base.MoreObjects.toStringHelper;
22
23/**
24 * Describes host probing event.
25 */
26public class HostProbingEvent extends AbstractEvent<HostProbingEvent.Type, HostProbe> {
27
28 /**
29 * Type of host probing events.
30 */
31 public enum Type {
32 /**
33 * Probe has been requested.
34 */
35 PROBE_REQUESTED,
36
37 /**
38 * Probe timed out but still have not reach max retry.
39 */
40 PROBE_TIMEOUT,
41
42 /**
43 * Probe timed out and reach max retry.
44 */
45 PROBE_FAIL,
46
47 /**
48 * Probe has been complete normally.
49 */
50 PROBE_COMPLETED
51 }
52
53 private HostProbe prevSubject;
54
55 /**
56 * Creates an event of a given type and for the specified host probe and the
57 * current time.
58 *
59 * @param type probing host event type
60 * @param subject event subject
61 */
62 public HostProbingEvent(Type type, HostProbe subject) {
63 super(type, subject);
64 }
65
66 /**
67 * Creates an event of a given type and for the specified host probe and time.
68 *
69 * @param type probing host event type
70 * @param subject event subject
71 * @param time occurrence time
72 */
73 public HostProbingEvent(Type type, HostProbe subject, long time) {
74 super(type, subject, time);
75 }
76
77 /**
78 * Creates an event with previous subject.
79 * The previous subject is ignored if the type is not PROBE_TIMEOUT
80 *
81 * @param type host event type
82 * @param subject event subject
83 * @param prevSubject previous host subject
84 */
85 public HostProbingEvent(Type type, HostProbe subject, HostProbe prevSubject) {
86 super(type, subject);
87 this.prevSubject = prevSubject;
88 }
89
90 /**
91 * Creates an event with previous subject and specified time.
92 * The previous subject is ignored if the type is not PROBE_TIMEOUT
93 *
94 * @param type host event type
95 * @param subject event subject
96 * @param prevSubject previous host subject
97 * @param time occurrence time
98 */
99 public HostProbingEvent(Type type, HostProbe subject, HostProbe prevSubject, long time) {
100 super(type, subject, time);
101 this.prevSubject = prevSubject;
102 }
103
104 /**
105 * Gets the previous subject in this host probe event.
106 *
107 * @return the previous subject, or null if previous subject is not
108 * specified.
109 */
110 public HostProbe prevSubject() {
111 return this.prevSubject;
112 }
113
114 @Override
115 public String toString() {
116 return toStringHelper(this)
117 .add("time", Tools.defaultOffsetDataTime(time()))
118 .add("type", type())
119 .add("subject", subject())
120 .add("prevSubject", prevSubject())
121 .toString();
122 }
123}