L2GW HwvtepHACache Utility class add in genius
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / utils / hwvtep / NodeEvent.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.genius.utils.hwvtep;
9
10 import java.io.PrintStream;
11 import java.util.Objects;
12
13 public abstract class NodeEvent extends DebugEvent {
14
15     protected final String nodeId;
16
17     public NodeEvent(String nodeId) {
18         this.nodeId = nodeId;
19     }
20
21     public String getNodeId() {
22         return nodeId;
23     }
24
25     @Override
26     public boolean equals(Object other) {
27         if (this == other) {
28             return true;
29         }
30         if (other instanceof NodeEvent) {
31             return Objects.equals(nodeId, ((NodeEvent) other).nodeId);
32         }
33         return false;
34     }
35
36     @Override
37     public int hashCode() {
38         return nodeId != null ? nodeId.hashCode() : 0;
39     }
40
41     enum NodeStatus {
42         Connected,Disconnected
43     }
44
45     public static class NodeConnectedEvent extends NodeEvent {
46
47         public NodeConnectedEvent(String nodeId) {
48             super(nodeId);
49         }
50
51         public void print(PrintStream out) {
52             out.print(nodeId);
53             out.print(" connected");
54         }
55     }
56
57     public static class NodeDisconnectedEvent extends NodeEvent {
58
59         public NodeDisconnectedEvent(String nodeId) {
60             super(nodeId);
61         }
62
63         public void print(PrintStream out) {
64             out.print(nodeId);
65             out.print(" disconnected");
66         }
67     }
68
69     public static class ChildAddedEvent extends NodeEvent {
70
71         public ChildAddedEvent(String nodeId) {
72             super(nodeId);
73         }
74
75         public void print(PrintStream out) {
76             out.print(nodeId);
77             out.print(" became HA child");
78         }
79     }
80 }