blob: bd9c234cac1e14af518c272069d8f9e853a0da6f [file] [log] [blame]
Charles Chanf7b1b4b2019-01-16 15:30:39 -08001/*
2 * Copyright 2018-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 */
16
17package org.onosproject.portloadbalancer.api;
18
19import org.onlab.util.Tools;
20import org.onosproject.event.AbstractEvent;
21import java.util.Objects;
22
23import static com.google.common.base.MoreObjects.toStringHelper;
24
25/**
26 * Port load balancer event.
27 */
28public class PortLoadBalancerEvent extends AbstractEvent<PortLoadBalancerEvent.Type, PortLoadBalancerData> {
29
30 private PortLoadBalancerData prevSubject;
31
32 /**
33 * Port load balancer event type.
34 */
35 public enum Type {
36 /**
37 * Port load balancer creation is requested.
38 */
39 ADDED,
40
41 /**
42 * Port load balancer deletion is requested.
43 */
44 REMOVED,
45
46 /**
47 * Port load balancer update is requested.
48 * E.g. member change.
49 */
50 UPDATED,
51
52 /**
53 * Port load balancer creation/update is completed successfully.
54 */
55 INSTALLED,
56
57 /**
58 * Port load balancer deletion is completed successfully.
59 */
60 UNINSTALLED,
61
62 /**
63 * Error occurs during creation/update/deletion of a port load balancer.
64 */
65 FAILED
66 }
67
68 /**
69 * Constructs a port load balancer event.
70 *
71 * @param type event type
72 * @param subject current port load balancer information
73 * @param prevSubject previous port load balancer information
74 */
75 public PortLoadBalancerEvent(Type type, PortLoadBalancerData subject, PortLoadBalancerData prevSubject) {
76 super(type, subject);
77 this.prevSubject = prevSubject;
78 }
79
80 /**
81 * Gets previous port load balancer information.
82 *
83 * @return previous subject
84 */
85 public PortLoadBalancerData prevSubject() {
86 return prevSubject;
87 }
88
89 @Override
90 public int hashCode() {
91 return Objects.hash(subject(), time(), prevSubject);
92 }
93
94 @Override
95 public boolean equals(Object other) {
96 if (this == other) {
97 return true;
98 }
99
100 if (!(other instanceof PortLoadBalancerEvent)) {
101 return false;
102 }
103
104 PortLoadBalancerEvent that = (PortLoadBalancerEvent) other;
105 return Objects.equals(this.subject(), that.subject()) &&
106 Objects.equals(this.type(), that.type()) &&
107 Objects.equals(this.prevSubject, that.prevSubject);
108 }
109
110 @Override
111 public String toString() {
112 return toStringHelper(this)
113 .add("type", type())
114 .add("subject", subject())
115 .add("prevSubject", prevSubject)
116 .add("time", Tools.defaultOffsetDataTime(time()))
117 .toString();
118 }
119}