Skip to content

Commit 333e0eb

Browse files
author
Steve Powell
committed
Removed old IntAllocator -- replaced with IntBitSetAllocator.
1 parent 21e91c1 commit 333e0eb

File tree

4 files changed

+15
-339
lines changed

4 files changed

+15
-339
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.IntAllocator;
27+
import com.rabbitmq.utility.IntBitSetAllocator;
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 IntAllocator channelNumberAllocator;
37+
private final IntBitSetAllocator 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 IntAllocator(1, channelMax);
53+
channelNumberAllocator = new IntBitSetAllocator(1, channelMax);
5454
}
5555

5656

src/com/rabbitmq/utility/IntAllocator.java

Lines changed: 0 additions & 260 deletions
This file was deleted.

test/src/com/rabbitmq/client/test/ChannelNumberAllocationTests.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ public void testAllocateAfterFreeingMany() throws Exception{
6969
for(int i = 1; i <= CHANNEL_COUNT; i++)
7070
channels.add(connection.createChannel());
7171

72-
// In the current implementation the list should actually
73-
// already be sorted, but we don't want to force that behaviour
72+
// In the current implementation the allocated numbers need not be increasing
7473
Collections.sort(channels, COMPARATOR);
7574

76-
int i = 1;
77-
for(Channel channel : channels)
78-
assertEquals(i++, channel.getChannelNumber());
75+
assertEquals("Didn't create the right number of channels!", CHANNEL_COUNT, channels.size());
76+
for(int i = 1; i < CHANNEL_COUNT; ++i) {
77+
assertTrue("Channel numbers should be distinct."
78+
, channels.get(i-1).getChannelNumber() < channels.get(i).getChannelNumber()
79+
);
80+
}
7981
}
8082

8183
public void testAllocateAfterManualAssign() throws Exception{

0 commit comments

Comments
 (0)