Skip to content

Commit f1eea1e

Browse files
author
Steve Powell
committed
Removed original IntAllocator; renamed IntBitSetAllocator to IntAllocator.
1 parent 333e0eb commit f1eea1e

File tree

3 files changed

+17
-22
lines changed

3 files changed

+17
-22
lines changed

src/com/rabbitmq/client/impl/ChannelManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import java.util.Set;
2525

2626
import com.rabbitmq.client.ShutdownSignalException;
27-
import com.rabbitmq.utility.IntBitSetAllocator;
27+
import com.rabbitmq.utility.IntAllocator;
2828

2929
/**
3030
* Manages a set of channels, indexed by channel number.
@@ -34,7 +34,7 @@ public class ChannelManager {
3434
/** Mapping from channel number to AMQChannel instance */
3535
private final Map<Integer, ChannelN> _channelMap =
3636
Collections.synchronizedMap(new HashMap<Integer, ChannelN>());
37-
private final IntBitSetAllocator channelNumberAllocator;
37+
private final IntAllocator channelNumberAllocator;
3838

3939
/** Maximum channel number available on this connection. */
4040
public final int _channelMax;
@@ -50,7 +50,7 @@ public ChannelManager(int channelMax) {
5050
channelMax = (1 << 16) - 1;
5151
}
5252
_channelMax = channelMax;
53-
channelNumberAllocator = new IntBitSetAllocator(1, channelMax);
53+
channelNumberAllocator = new IntAllocator(1, channelMax);
5454
}
5555

5656

src/com/rabbitmq/utility/IntBitSetAllocator.java renamed to src/com/rabbitmq/utility/IntAllocator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* range.
3939
* <br/>Very little Object creation and destruction occurs in use.
4040
*/
41-
public class IntBitSetAllocator {
41+
public class IntAllocator {
4242

4343
private final int loRange; // the integer bit 0 represents
4444
private final int hiRange; // the integer(+1) the highest bit represents
@@ -50,12 +50,12 @@ public class IntBitSetAllocator {
5050
private final BitSet freeSet;
5151

5252
/**
53-
* Creates an IntBitSetAllocator allocating integer IDs within the
53+
* Creates an IntAllocator allocating integer IDs within the
5454
* inclusive range [<code>bottom</code>, <code>top</code>].
5555
* @param bottom lower end of range
5656
* @param top upper end of range (inclusive)
5757
*/
58-
public IntBitSetAllocator(int bottom, int top) {
58+
public IntAllocator(int bottom, int top) {
5959
this.loRange = bottom;
6060
this.hiRange = top + 1;
6161
this.numberOfBits = hiRange - loRange;
@@ -111,7 +111,7 @@ public boolean reserve(int reservation) {
111111
@Override
112112
public String toString() {
113113
StringBuilder sb
114-
= new StringBuilder("IntBitSetAllocator{allocated = [");
114+
= new StringBuilder("IntAllocator{allocated = [");
115115

116116
int firstClearBit = this.freeSet.nextClearBit(0);
117117
if (firstClearBit < this.numberOfBits) {

test/src/com/rabbitmq/utility/IntBitSetAllocatorTests.java renamed to test/src/com/rabbitmq/utility/IntAllocatorTests.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
import junit.framework.TestCase;
2525

26-
public class IntBitSetAllocatorTests extends TestCase {
26+
public class IntAllocatorTests extends TestCase {
2727

2828
private static final int TEST_ITERATIONS = 50000;
2929
private static final int HI_RANGE = 100000;
3030
private static final int LO_RANGE = 100;
31-
private IntBitSetAllocator iAll = new IntBitSetAllocator(LO_RANGE, HI_RANGE);
31+
private IntAllocator iAll = new IntAllocator(LO_RANGE, HI_RANGE);
3232

3333
private Random rand = new Random(70608L);
3434

@@ -40,15 +40,13 @@ public void testReserveAndFree() throws Exception {
4040
iAll.free(trial);
4141
set.remove(trial);
4242
} else {
43-
assertTrue("Did not reserve free integer " + trial,
44-
iAll.reserve(trial));
43+
assertTrue("Did not reserve free integer " + trial, iAll.reserve(trial));
4544
set.add(trial);
4645
}
4746
}
4847

4948
for (int trial : set) {
50-
assertFalse("Integer " + trial + " not allocated!",
51-
iAll.reserve(trial));
49+
assertFalse("Integer " + trial + " not allocated!", iAll.reserve(trial));
5250
}
5351
}
5452

@@ -62,31 +60,28 @@ public void testAllocateAndFree() throws Exception {
6260
} else {
6361
if (!set.isEmpty()) {
6462
int trial = extractOne(set);
65-
assertFalse("Allocator agreed to reserve " + trial,
66-
iAll.reserve(trial));
63+
assertFalse("Allocator agreed to reserve " + trial, iAll.reserve(trial));
6764
iAll.free(trial);
6865
}
6966
}
7067
}
7168

7269
for (int trial : set) {
73-
assertFalse("Integer " + trial + " should be allocated!",
74-
iAll.reserve(trial));
70+
assertFalse("Integer " + trial + " should be allocated!", iAll.reserve(trial));
7571
}
7672
}
7773

7874
public void testToString() throws Exception {
79-
IntBitSetAllocator ibs = new IntBitSetAllocator(LO_RANGE, HI_RANGE);
80-
assertEquals("IntBitSetAllocator{allocated = []}", ibs.toString());
75+
IntAllocator ibs = new IntAllocator(LO_RANGE, HI_RANGE);
76+
assertEquals("IntAllocator{allocated = []}", ibs.toString());
8177
ibs.allocate();
82-
assertEquals("IntBitSetAllocator{allocated = [100]}", ibs.toString());
78+
assertEquals("IntAllocator{allocated = [100]}", ibs.toString());
8379
for(int i = 200; i<211; i=i+4) {
8480
ibs.reserve(i);
8581
ibs.reserve(i+1);
8682
ibs.reserve(i+2);
8783
}
88-
assertEquals("IntBitSetAllocator{allocated = "
89-
+ "[100, 200..202, 204..206, 208..210]}"
84+
assertEquals("IntAllocator{allocated = [100, 200..202, 204..206, 208..210]}"
9085
, ibs.toString());
9186
}
9287

0 commit comments

Comments
 (0)