1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
---|
2 | <!--NewPage--> |
---|
3 | <HTML> |
---|
4 | <HEAD> |
---|
5 | <!-- Generated by javadoc (build 1.6.0_18) on Tue Dec 11 11:47:09 GMT 2012 --> |
---|
6 | <TITLE> |
---|
7 | IntAllocator |
---|
8 | </TITLE> |
---|
9 | |
---|
10 | <META NAME="date" CONTENT="2012-12-11"> |
---|
11 | |
---|
12 | <LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style"> |
---|
13 | |
---|
14 | <SCRIPT type="text/javascript"> |
---|
15 | function windowTitle() |
---|
16 | { |
---|
17 | if (location.href.indexOf('is-external=true') == -1) { |
---|
18 | parent.document.title="IntAllocator"; |
---|
19 | } |
---|
20 | } |
---|
21 | </SCRIPT> |
---|
22 | <NOSCRIPT> |
---|
23 | </NOSCRIPT> |
---|
24 | |
---|
25 | </HEAD> |
---|
26 | |
---|
27 | <BODY BGCOLOR="white" onload="windowTitle();"> |
---|
28 | <HR> |
---|
29 | |
---|
30 | |
---|
31 | <!-- ========= START OF TOP NAVBAR ======= --> |
---|
32 | <A NAME="navbar_top"><!-- --></A> |
---|
33 | <A HREF="#skip-navbar_top" title="Skip navigation links"></A> |
---|
34 | <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> |
---|
35 | <TR> |
---|
36 | <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> |
---|
37 | <A NAME="navbar_top_firstrow"><!-- --></A> |
---|
38 | <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> |
---|
39 | <TR ALIGN="center" VALIGN="top"> |
---|
40 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> |
---|
41 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> |
---|
42 | <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> |
---|
43 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> |
---|
44 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> |
---|
45 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> |
---|
46 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> |
---|
47 | </TR> |
---|
48 | </TABLE> |
---|
49 | </TD> |
---|
50 | <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> |
---|
51 | </EM> |
---|
52 | </TD> |
---|
53 | </TR> |
---|
54 | |
---|
55 | <TR> |
---|
56 | <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> |
---|
57 | <A HREF="../../../com/rabbitmq/utility/BlockingValueOrException.html" title="class in com.rabbitmq.utility"><B>PREV CLASS</B></A> |
---|
58 | <A HREF="../../../com/rabbitmq/utility/SensibleClone.html" title="interface in com.rabbitmq.utility"><B>NEXT CLASS</B></A></FONT></TD> |
---|
59 | <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> |
---|
60 | <A HREF="../../../index.html?com/rabbitmq/utility/IntAllocator.html" target="_top"><B>FRAMES</B></A> |
---|
61 | <A HREF="IntAllocator.html" target="_top"><B>NO FRAMES</B></A> |
---|
62 | <SCRIPT type="text/javascript"> |
---|
63 | <!-- |
---|
64 | if(window==top) { |
---|
65 | document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>'); |
---|
66 | } |
---|
67 | //--> |
---|
68 | </SCRIPT> |
---|
69 | <NOSCRIPT> |
---|
70 | <A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A> |
---|
71 | </NOSCRIPT> |
---|
72 | |
---|
73 | |
---|
74 | </FONT></TD> |
---|
75 | </TR> |
---|
76 | <TR> |
---|
77 | <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> |
---|
78 | SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD> |
---|
79 | <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> |
---|
80 | DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD> |
---|
81 | </TR> |
---|
82 | </TABLE> |
---|
83 | <A NAME="skip-navbar_top"></A> |
---|
84 | <!-- ========= END OF TOP NAVBAR ========= --> |
---|
85 | |
---|
86 | <HR> |
---|
87 | <!-- ======== START OF CLASS DATA ======== --> |
---|
88 | <H2> |
---|
89 | <FONT SIZE="-1"> |
---|
90 | com.rabbitmq.utility</FONT> |
---|
91 | <BR> |
---|
92 | Class IntAllocator</H2> |
---|
93 | <PRE> |
---|
94 | java.lang.Object |
---|
95 | <IMG SRC="../../../resources/inherit.gif" ALT="extended by "><B>com.rabbitmq.utility.IntAllocator</B> |
---|
96 | </PRE> |
---|
97 | <HR> |
---|
98 | <DL> |
---|
99 | <DT><PRE>public class <B>IntAllocator</B><DT>extends java.lang.Object</DL> |
---|
100 | </PRE> |
---|
101 | |
---|
102 | <P> |
---|
103 | A class for allocating integers from a given range that uses a |
---|
104 | <CODE>BitSet</CODE> representation of the free integers. |
---|
105 | |
---|
106 | <p/><strong>Concurrent Semantics:</strong><br /> |
---|
107 | This class is <b><i>not</i></b> thread safe. |
---|
108 | |
---|
109 | <p/><b>Implementation notes:</b> |
---|
110 | <br/>This was originally an ordered chain of non-overlapping Intervals, |
---|
111 | together with a fixed size array cache for freed integers. |
---|
112 | <br/><A HREF="../../../com/rabbitmq/utility/IntAllocator.html#reserve(int)"><CODE>reserve(int)</CODE></A> was expensive in this scheme, whereas in the |
---|
113 | present implementation it is O(1), as is <A HREF="../../../com/rabbitmq/utility/IntAllocator.html#free(int)"><CODE>free(int)</CODE></A>. |
---|
114 | <p>Although <A HREF="../../../com/rabbitmq/utility/IntAllocator.html#allocate()"><CODE>allocate()</CODE></A> is slightly slower than O(1) and in the |
---|
115 | worst case could be O(N), the use of a "<code>lastIndex</code>" field |
---|
116 | for starting the next scan for free integers means this is negligible. |
---|
117 | </p> |
---|
118 | <p>The data representation overhead is O(N) where N is the size of the |
---|
119 | allocation range. One <code>long</code> is used for every 64 integers in the |
---|
120 | range. |
---|
121 | </p> |
---|
122 | <p>Very little Object creation and destruction occurs in use.</p> |
---|
123 | <P> |
---|
124 | |
---|
125 | <P> |
---|
126 | <HR> |
---|
127 | |
---|
128 | <P> |
---|
129 | |
---|
130 | <!-- ======== CONSTRUCTOR SUMMARY ======== --> |
---|
131 | |
---|
132 | <A NAME="constructor_summary"><!-- --></A> |
---|
133 | <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> |
---|
134 | <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> |
---|
135 | <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> |
---|
136 | <B>Constructor Summary</B></FONT></TH> |
---|
137 | </TR> |
---|
138 | <TR BGCOLOR="white" CLASS="TableRowColor"> |
---|
139 | <TD><CODE><B><A HREF="../../../com/rabbitmq/utility/IntAllocator.html#IntAllocator(int, int)">IntAllocator</A></B>(int bottom, |
---|
140 | int top)</CODE> |
---|
141 | |
---|
142 | <BR> |
---|
143 | Creates an IntAllocator allocating integer IDs within the |
---|
144 | inclusive range [<code>bottom</code>, <code>top</code>].</TD> |
---|
145 | </TR> |
---|
146 | </TABLE> |
---|
147 | |
---|
148 | <!-- ========== METHOD SUMMARY =========== --> |
---|
149 | |
---|
150 | <A NAME="method_summary"><!-- --></A> |
---|
151 | <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> |
---|
152 | <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> |
---|
153 | <TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"> |
---|
154 | <B>Method Summary</B></FONT></TH> |
---|
155 | </TR> |
---|
156 | <TR BGCOLOR="white" CLASS="TableRowColor"> |
---|
157 | <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
---|
158 | <CODE> int</CODE></FONT></TD> |
---|
159 | <TD><CODE><B><A HREF="../../../com/rabbitmq/utility/IntAllocator.html#allocate()">allocate</A></B>()</CODE> |
---|
160 | |
---|
161 | <BR> |
---|
162 | Allocate an unallocated integer from the range, or return -1 if no |
---|
163 | more integers are available.</TD> |
---|
164 | </TR> |
---|
165 | <TR BGCOLOR="white" CLASS="TableRowColor"> |
---|
166 | <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
---|
167 | <CODE> void</CODE></FONT></TD> |
---|
168 | <TD><CODE><B><A HREF="../../../com/rabbitmq/utility/IntAllocator.html#free(int)">free</A></B>(int reservation)</CODE> |
---|
169 | |
---|
170 | <BR> |
---|
171 | Make the provided integer available for allocation again.</TD> |
---|
172 | </TR> |
---|
173 | <TR BGCOLOR="white" CLASS="TableRowColor"> |
---|
174 | <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
---|
175 | <CODE> boolean</CODE></FONT></TD> |
---|
176 | <TD><CODE><B><A HREF="../../../com/rabbitmq/utility/IntAllocator.html#reserve(int)">reserve</A></B>(int reservation)</CODE> |
---|
177 | |
---|
178 | <BR> |
---|
179 | Attempt to reserve the provided ID as if it had been allocated.</TD> |
---|
180 | </TR> |
---|
181 | <TR BGCOLOR="white" CLASS="TableRowColor"> |
---|
182 | <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> |
---|
183 | <CODE> java.lang.String</CODE></FONT></TD> |
---|
184 | <TD><CODE><B><A HREF="../../../com/rabbitmq/utility/IntAllocator.html#toString()">toString</A></B>()</CODE> |
---|
185 | |
---|
186 | <BR> |
---|
187 | </TD> |
---|
188 | </TR> |
---|
189 | </TABLE> |
---|
190 | <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A> |
---|
191 | <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> |
---|
192 | <TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"> |
---|
193 | <TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH> |
---|
194 | </TR> |
---|
195 | <TR BGCOLOR="white" CLASS="TableRowColor"> |
---|
196 | <TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait</CODE></TD> |
---|
197 | </TR> |
---|
198 | </TABLE> |
---|
199 | |
---|
200 | <P> |
---|
201 | |
---|
202 | <!-- ========= CONSTRUCTOR DETAIL ======== --> |
---|
203 | |
---|
204 | <A NAME="constructor_detail"><!-- --></A> |
---|
205 | <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> |
---|
206 | <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> |
---|
207 | <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> |
---|
208 | <B>Constructor Detail</B></FONT></TH> |
---|
209 | </TR> |
---|
210 | </TABLE> |
---|
211 | |
---|
212 | <A NAME="IntAllocator(int, int)"><!-- --></A><H3> |
---|
213 | IntAllocator</H3> |
---|
214 | <PRE> |
---|
215 | public <B>IntAllocator</B>(int bottom, |
---|
216 | int top)</PRE> |
---|
217 | <DL> |
---|
218 | <DD>Creates an IntAllocator allocating integer IDs within the |
---|
219 | inclusive range [<code>bottom</code>, <code>top</code>]. |
---|
220 | <P> |
---|
221 | <DL> |
---|
222 | <DT><B>Parameters:</B><DD><CODE>bottom</CODE> - lower end of range<DD><CODE>top</CODE> - upper end of range (inclusive)</DL> |
---|
223 | </DL> |
---|
224 | |
---|
225 | <!-- ============ METHOD DETAIL ========== --> |
---|
226 | |
---|
227 | <A NAME="method_detail"><!-- --></A> |
---|
228 | <TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""> |
---|
229 | <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> |
---|
230 | <TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2"> |
---|
231 | <B>Method Detail</B></FONT></TH> |
---|
232 | </TR> |
---|
233 | </TABLE> |
---|
234 | |
---|
235 | <A NAME="allocate()"><!-- --></A><H3> |
---|
236 | allocate</H3> |
---|
237 | <PRE> |
---|
238 | public int <B>allocate</B>()</PRE> |
---|
239 | <DL> |
---|
240 | <DD>Allocate an unallocated integer from the range, or return -1 if no |
---|
241 | more integers are available. |
---|
242 | <P> |
---|
243 | <DD><DL> |
---|
244 | |
---|
245 | <DT><B>Returns:</B><DD>the allocated integer, or -1</DL> |
---|
246 | </DD> |
---|
247 | </DL> |
---|
248 | <HR> |
---|
249 | |
---|
250 | <A NAME="free(int)"><!-- --></A><H3> |
---|
251 | free</H3> |
---|
252 | <PRE> |
---|
253 | public void <B>free</B>(int reservation)</PRE> |
---|
254 | <DL> |
---|
255 | <DD>Make the provided integer available for allocation again. This operation |
---|
256 | runs in O(1) time. |
---|
257 | <br/>No error checking is performed, so if you double free or free an |
---|
258 | integer that was not originally allocated the results are undefined. |
---|
259 | <P> |
---|
260 | <DD><DL> |
---|
261 | <DT><B>Parameters:</B><DD><CODE>reservation</CODE> - the previously allocated integer to free</DL> |
---|
262 | </DD> |
---|
263 | </DL> |
---|
264 | <HR> |
---|
265 | |
---|
266 | <A NAME="reserve(int)"><!-- --></A><H3> |
---|
267 | reserve</H3> |
---|
268 | <PRE> |
---|
269 | public boolean <B>reserve</B>(int reservation)</PRE> |
---|
270 | <DL> |
---|
271 | <DD>Attempt to reserve the provided ID as if it had been allocated. Returns |
---|
272 | true if it is available, false otherwise. |
---|
273 | <br/> |
---|
274 | This operation runs in O(1) time. |
---|
275 | <P> |
---|
276 | <DD><DL> |
---|
277 | <DT><B>Parameters:</B><DD><CODE>reservation</CODE> - the integer to be allocated, if possible |
---|
278 | <DT><B>Returns:</B><DD><code><b>true</b></code> if allocated, <code><b>false</b></code> |
---|
279 | if already allocated</DL> |
---|
280 | </DD> |
---|
281 | </DL> |
---|
282 | <HR> |
---|
283 | |
---|
284 | <A NAME="toString()"><!-- --></A><H3> |
---|
285 | toString</H3> |
---|
286 | <PRE> |
---|
287 | public java.lang.String <B>toString</B>()</PRE> |
---|
288 | <DL> |
---|
289 | <DD><DL> |
---|
290 | <DT><B>Overrides:</B><DD><CODE>toString</CODE> in class <CODE>java.lang.Object</CODE></DL> |
---|
291 | </DD> |
---|
292 | <DD><DL> |
---|
293 | </DL> |
---|
294 | </DD> |
---|
295 | </DL> |
---|
296 | <!-- ========= END OF CLASS DATA ========= --> |
---|
297 | <HR> |
---|
298 | |
---|
299 | |
---|
300 | <!-- ======= START OF BOTTOM NAVBAR ====== --> |
---|
301 | <A NAME="navbar_bottom"><!-- --></A> |
---|
302 | <A HREF="#skip-navbar_bottom" title="Skip navigation links"></A> |
---|
303 | <TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""> |
---|
304 | <TR> |
---|
305 | <TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> |
---|
306 | <A NAME="navbar_bottom_firstrow"><!-- --></A> |
---|
307 | <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> |
---|
308 | <TR ALIGN="center" VALIGN="top"> |
---|
309 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> |
---|
310 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> |
---|
311 | <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> |
---|
312 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> |
---|
313 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> |
---|
314 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> |
---|
315 | <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> |
---|
316 | </TR> |
---|
317 | </TABLE> |
---|
318 | </TD> |
---|
319 | <TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM> |
---|
320 | </EM> |
---|
321 | </TD> |
---|
322 | </TR> |
---|
323 | |
---|
324 | <TR> |
---|
325 | <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> |
---|
326 | <A HREF="../../../com/rabbitmq/utility/BlockingValueOrException.html" title="class in com.rabbitmq.utility"><B>PREV CLASS</B></A> |
---|
327 | <A HREF="../../../com/rabbitmq/utility/SensibleClone.html" title="interface in com.rabbitmq.utility"><B>NEXT CLASS</B></A></FONT></TD> |
---|
328 | <TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> |
---|
329 | <A HREF="../../../index.html?com/rabbitmq/utility/IntAllocator.html" target="_top"><B>FRAMES</B></A> |
---|
330 | <A HREF="IntAllocator.html" target="_top"><B>NO FRAMES</B></A> |
---|
331 | <SCRIPT type="text/javascript"> |
---|
332 | <!-- |
---|
333 | if(window==top) { |
---|
334 | document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>'); |
---|
335 | } |
---|
336 | //--> |
---|
337 | </SCRIPT> |
---|
338 | <NOSCRIPT> |
---|
339 | <A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A> |
---|
340 | </NOSCRIPT> |
---|
341 | |
---|
342 | |
---|
343 | </FONT></TD> |
---|
344 | </TR> |
---|
345 | <TR> |
---|
346 | <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> |
---|
347 | SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD> |
---|
348 | <TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> |
---|
349 | DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD> |
---|
350 | </TR> |
---|
351 | </TABLE> |
---|
352 | <A NAME="skip-navbar_bottom"></A> |
---|
353 | <!-- ======== END OF BOTTOM NAVBAR ======= --> |
---|
354 | |
---|
355 | <HR> |
---|
356 | |
---|
357 | </BODY> |
---|
358 | </HTML> |
---|