translator: remove dependency of neutron.spi
[netvirt.git] / openstack / net-virt / src / main / java / org / opendaylight / netvirt / openstack / netvirt / AbstractEvent.java
1 /*
2  * Copyright (c) 2014, 2016 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.netvirt.openstack.netvirt;
10
11 import org.opendaylight.netvirt.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         NEUTRON_L3_ADAPTER,
32         DISTRIBUTED_ARP_SERVICE;
33
34         public static final int size = HandlerType.values().length;
35     }
36
37     private HandlerType handlerType;
38     private Action action;
39     private int transactionId;
40
41     public int getTransactionId() {
42         return transactionId;
43     }
44
45     private static int txId = 0;
46     private static int incTxId() {
47         return ++txId;
48     }
49     public static int getTxId() {
50         return txId;
51     }
52
53     private AbstractEvent() {
54         // this is private to force proper construction
55     }
56
57     protected AbstractEvent(HandlerType handlerType, Action action) {
58         this.handlerType = handlerType;
59         this.action = action;
60         this.transactionId = incTxId();
61     }
62
63     public HandlerType getHandlerType() {
64         return handlerType;
65     }
66
67     public Action getAction() {
68         return action;
69     }
70
71     @Override
72     public String toString() {
73         return "AbstractEvent [transactionId=" + transactionId
74                 + " handlerType=" + handlerType + " action=" + action + "]";
75     }
76
77     @Override
78     public int hashCode() {
79         final int prime = 31;
80         int result = 1;
81         result = prime * result + ((handlerType == null) ? 0 : handlerType.hashCode());
82         result = prime * result + ((action == null) ? 0 : action.hashCode());
83         return result;
84     }
85
86     @Override
87     public boolean equals(Object obj) {
88         if (this == obj) {
89             return true;
90         }
91         if (obj == null) {
92             return false;
93         }
94         if (getClass() != obj.getClass()) {
95             return false;
96         }
97         AbstractEvent other = (AbstractEvent) obj;
98         if (handlerType == null) {
99             if (other.handlerType != null) {
100                 return false;
101             }
102         } else if (!handlerType.equals(other.handlerType)) {
103             return false;
104         }
105         if (action == null) {
106             if (other.action != null) {
107                 return false;
108             }
109         } else if (!action.equals(other.action)) {
110             return false;
111         }
112         return true;
113     }
114 }