Bug 7419 : Ids from id pool exhausted
[genius.git] / idmanager / idmanager-impl / src / main / java / org / opendaylight / genius / idmanager / IdLocalPool.java
1 /*
2  * Copyright (c) 2015 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.idmanager;
9
10 public class IdLocalPool {
11
12     private final String poolName;
13     private volatile IdHolder availableIds; // List of available IDs
14     private volatile IdHolder releasedIds; // List of released IDs
15
16     public IdLocalPool(IdUtils idUtils, String poolName, long low, long high) {
17         this.poolName = poolName;
18         availableIds = new AvailableIdHolder(idUtils, low, high);
19         releasedIds = new ReleasedIdHolder(idUtils, IdUtils.DEFAULT_DELAY_TIME);
20     }
21
22     public IdLocalPool(IdUtils idUtils, String poolName) {
23         this.poolName = poolName;
24         releasedIds = new ReleasedIdHolder(idUtils, IdUtils.DEFAULT_DELAY_TIME);
25     }
26
27     @Override
28     public int hashCode() {
29         final int prime = 31;
30         int result = 1;
31         result = prime * result + (availableIds == null ? 0 : availableIds.hashCode());
32         result = prime * result + (poolName == null ? 0 : poolName.hashCode());
33         result = prime * result + (releasedIds == null ? 0 : releasedIds.hashCode());
34         return result;
35     }
36
37     @Override
38     public String toString() {
39         return "IdLocalPool [poolName=" + poolName + ", availableIds="
40                 + availableIds + ", releasedIds=" + releasedIds + "]";
41     }
42
43     @Override
44     public boolean equals(Object obj) {
45         if (this == obj) {
46             return true;
47         }
48         if (obj == null) {
49             return false;
50         }
51         if (getClass() != obj.getClass()) {
52             return false;
53         }
54         IdLocalPool other = (IdLocalPool) obj;
55         if (availableIds == null) {
56             if (other.availableIds != null) {
57                 return false;
58             }
59         } else if (!availableIds.equals(other.availableIds)) {
60             return false;
61         }
62         if (poolName == null) {
63             if (other.poolName != null) {
64                 return false;
65             }
66         } else if (!poolName.equals(other.poolName)) {
67             return false;
68         }
69         if (releasedIds == null) {
70             if (other.releasedIds != null) {
71                 return false;
72             }
73         } else if (!releasedIds.equals(other.releasedIds)) {
74             return false;
75         }
76         return true;
77     }
78
79     public String getPoolName() {
80         return poolName;
81     }
82
83     public IdHolder getAvailableIds() {
84         return availableIds;
85     }
86
87     public void setAvailableIds(IdHolder availableIds) {
88         this.availableIds = availableIds;
89     }
90
91     public IdHolder getReleasedIds() {
92         return releasedIds;
93     }
94
95     public void setReleasedIds(IdHolder releasedIds) {
96         this.releasedIds = releasedIds;
97     }
98
99 }