Merge "Create McastMacs by Listening DS Changes"
[ovsdb.git] / openstack / net-virt / src / main / java / org / opendaylight / ovsdb / openstack / netvirt / AbstractEvent.java
1 /*
2  * Copyright (c) 2014, 2015 Red Hat, Inc. 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
9 package org.opendaylight.ovsdb.openstack.netvirt;
10
11 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
12
13 /**
14  * Abstract class for events used by neutron northbound and southbound events.
15  */
16 public abstract class AbstractEvent {
17
18     public enum HandlerType {
19         SOUTHBOUND,
20         NEUTRON_FLOATING_IP,
21         NEUTRON_NETWORK,
22         NEUTRON_PORT,
23         NEUTRON_PORT_SECURITY,
24         NEUTRON_ROUTER,
25         NEUTRON_SUBNET,
26         NEUTRON_FWAAS,
27         NEUTRON_LOAD_BALANCER,
28         NEUTRON_LOAD_BALANCER_POOL,
29         NEUTRON_LOAD_BALANCER_POOL_MEMBER,
30         NODE;
31
32         public static final int size = HandlerType.values().length;
33     }
34
35     private HandlerType handlerType;
36     private Action action;
37     private int transactionId;
38
39     public int getTransactionId() {
40         return transactionId;
41     }
42
43     private static int txId = 0;
44     private static int incTxId() {
45         return ++txId;
46     }
47     public static int getTxId() {
48         return txId;
49     }
50
51     private AbstractEvent() {
52         // this is private to force proper construction
53     }
54
55     protected AbstractEvent(HandlerType handlerType, Action action) {
56         this.handlerType = handlerType;
57         this.action = action;
58         this.transactionId = incTxId();
59     }
60
61     public HandlerType getHandlerType() {
62         return handlerType;
63     }
64
65     public Action getAction() {
66         return action;
67     }
68
69     @Override
70     public String toString() {
71         return "AbstractEvent [transactionId=" + transactionId
72                 + " handlerType=" + handlerType + " action=" + action + "]";
73     }
74
75     @Override
76     public int hashCode() {
77         final int prime = 31;
78         int result = 1;
79         result = prime * result + ((handlerType == null) ? 0 : handlerType.hashCode());
80         result = prime * result + ((action == null) ? 0 : action.hashCode());
81         return result;
82     }
83
84     @Override
85     public boolean equals(Object obj) {
86         if (this == obj) {
87             return true;
88         }
89         if (obj == null) {
90             return false;
91         }
92         if (getClass() != obj.getClass()) {
93             return false;
94         }
95         AbstractEvent other = (AbstractEvent) obj;
96         if (handlerType == null) {
97             if (other.handlerType != null) {
98                 return false;
99             }
100         } else if (!handlerType.equals(other.handlerType)) {
101             return false;
102         }
103         if (action == null) {
104             if (other.action != null) {
105                 return false;
106             }
107         } else if (!action.equals(other.action)) {
108             return false;
109         }
110         return true;
111     }
112 }