@Override public boolean isFulFilled() throws IllegalStateException { mid.set(tracker.getNextMessageId()); return 0 <= mid.get(); } });
NetworkConfig config = NetworkConfig.createStandardWithoutFile().setInt(NetworkConfig.Keys.EXCHANGE_LIFETIME, exchangeLifetime); final GroupedMessageIdTracker tracker = new GroupedMessageIdTracker(INITIAL_MID, config); int groupSize = tracker.getGroupSize(); int nextMid = tracker.getNextMessageId(); if (nextMid < 0) break; int nextMid = tracker.getNextMessageId(); assertThat(nextMid, is(not(-1)));
@Test public void testGetNextMessageIdFailsIfAllMidsAreInUse() throws Exception { // GIVEN a tracker whose MIDs are half in use NetworkConfig config = NetworkConfig.createStandardWithoutFile(); GroupedMessageIdTracker tracker = new GroupedMessageIdTracker(INITIAL_MID, config); for (int i = 0; i < TOTAL_NO_OF_MIDS / 2; i++) { int mid = tracker.getNextMessageId(); assertThat(mid, is(not(-1))); } // THEN using the complete other half should not be possible for (int i = 0; i < TOTAL_NO_OF_MIDS / 2; i++) { int mid = tracker.getNextMessageId(); if (0 > mid) return; } fail("mids should run out."); }
private synchronized MessageIdTracker getTracker(final InetSocketAddress destination) { MessageIdTracker tracker = trackers.get(destination); if (tracker == null && 0 < trackers.remainingCapacity()) { // create new tracker for destination lazily int mid = null == random ? 0 : random.nextInt(MessageIdTracker.TOTAL_NO_OF_MIDS); switch (mode) { case NULL: tracker = new NullMessageIdTracker(mid); break; case MAPBASED: tracker = new MapBasedMessageIdTracker(mid, config); break; case GROUPED: default: tracker = new GroupedMessageIdTracker(mid, config); break; } trackers.put(destination, tracker); } return tracker; } }