/** * Called to indicate a retransmission is received that may obviate the need to send one ourselves. * <p> * NOTE: Currently only called from unit tests. Would be used for retransmitting from receivers for NAK suppression * * @param termId of the data * @param termOffset of the data */ public void onRetransmitReceived(final int termId, final int termOffset) { final RetransmitAction action = activeRetransmitsMap.get(termId, termOffset); if (null != action && DELAYED == action.state) { activeRetransmitsMap.remove(termId, termOffset); action.cancel(); // do not go into linger } }
/** * Compact the backing arrays by rehashing with a capacity just larger than current size * and giving consideration to the load factor. */ public void compact() { final int idealCapacity = (int)Math.round(size() * (1.0 / loadFactor)); rehash(findNextPositivePowerOfTwo(Math.max(MIN_CAPACITY, idealCapacity))); }
/** * If the specified key is not already associated with a value (or is mapped * to {@code null}), attempts to compute its value using the given mapping * function and enters it into this map unless {@code null}. * * @param keyPartA for the key * @param keyPartB for the key * @param mappingFunction creates values based upon keys if the key pair is missing * @return the newly created or stored value. */ public V computeIfAbsent(final int keyPartA, final int keyPartB, final EntryFunction<? extends V> mappingFunction) { V value = get(keyPartA, keyPartB); if (value == null) { value = mappingFunction.apply(keyPartA, keyPartB); if (value != null) { put(keyPartA, keyPartB, value); } } return value; }
/** * Called to process any outstanding timeouts. * * @param nowNs time in nanoseconds * @param retransmitSender to call on retransmissions */ public void processTimeouts(final long nowNs, final RetransmitSender retransmitSender) { if (activeRetransmitsMap.size() > 0) { for (final RetransmitAction action : retransmitActionPool) { if (DELAYED == action.state && (action.expireNs - nowNs < 0)) { retransmitSender.resend(action.termId, action.termOffset, action.length); action.linger(determineLingerTimeout(), nanoClock.nanoTime()); } else if (LINGERING == action.state && (action.expireNs - nowNs < 0)) { action.cancel(); activeRetransmitsMap.remove(action.termId, action.termOffset); } } } }
public void onRttMeasurement( final RttMeasurementFlyweight msg, final UnsafeBuffer buffer, final int length, final InetSocketAddress srcAddress) { final NetworkPublication publication = publicationBySessionAndStreamId.get(msg.sessionId(), msg.streamId()); if (null != publication) { publication.onRttMeasurement(msg, srcAddress); } }
@Test public void shouldIterateValues() { final Set<String> expectedSet = new HashSet<>(); final int count = 7; for (int i = 0; i < count; i++) { final String value = String.valueOf(i); expectedSet.add(value); map.put(i, i + 97, value); } final Set<String> actualSet = new HashSet<>(); map.forEach(actualSet::add); assertThat(actualSet, equalTo(expectedSet)); }
/** * Called from the {@link Sender} to add information to the control packet dispatcher. * * @param publication to add to the dispatcher */ public void registerForSend(final NetworkPublication publication) { publicationBySessionAndStreamId.put(publication.sessionId(), publication.streamId(), publication); }
/** * Called from the {@link Sender} to remove information from the control packet dispatcher. * * @param publication to remove */ public void unregisterForSend(final NetworkPublication publication) { publicationBySessionAndStreamId.remove(publication.sessionId(), publication.streamId()); }
private void increaseCapacity() { final int newCapacity = values.length << 1; if (newCapacity < 0) { throw new IllegalStateException("max capacity reached at size=" + size); } rehash(newCapacity); } }
/** * Remove a value from the map and return the value. * * @param keyPartA for the key * @param keyPartB for the key * @return the previous value if found otherwise null */ @SuppressWarnings("unchecked") public V remove(final int keyPartA, final int keyPartB) { final long key = compoundKey(keyPartA, keyPartB); final int mask = values.length - 1; int index = Hashing.hash(key, mask); Object value; while (null != (value = values[index])) { if (key == keys[index]) { values[index] = null; --size; compactChain(index); break; } index = ++index & mask; } return (V)value; }
/** * Remove a value from the map and return the value. * * @param keyPartA for the key * @param keyPartB for the key * @return the previous value if found otherwise null */ @SuppressWarnings("unchecked") public V remove(final int keyPartA, final int keyPartB) { final long key = compoundKey(keyPartA, keyPartB); final int mask = values.length - 1; int index = Hashing.hash(keyPartA, keyPartB, mask); Object value; while (null != (value = values[index])) { if (key == keys[index]) { values[index] = null; --size; compactChain(index); break; } index = ++index & mask; } return (V)value; }
public V put(final int keyPartA, final int keyPartB, final V value) final long key = compoundKey(keyPartA, keyPartB); increaseCapacity();
@Test public void shouldPutAndGetKeysOfNegativeValue() { map.put(721632679, 333118496, "a"); assertThat(map.get(721632679, 333118496), is("a")); map.put(721632719, -659033725, "b"); assertThat(map.get(721632719, -659033725), is("b")); map.put(721632767, -235401032, "c"); assertThat(map.get(721632767, -235401032), is("c")); map.put(721632839, 1791470537, "d"); assertThat(map.get(721632839, 1791470537), is("d")); map.put(721633069, -939458690, "e"); assertThat(map.get(721633069, -939458690), is("e")); map.put(721633127, 1620485039, "f"); assertThat(map.get(721633127, 1620485039), is("f")); map.put(721633163, -1503337805, "g"); assertThat(map.get(721633163, -1503337805), is("g")); map.put(721633229, -2073657736, "h"); assertThat(map.get(721633229, -2073657736), is("h")); map.put(721633255, -1278969172, "i"); assertThat(map.get(721633255, -1278969172), is("i")); map.put(721633257, -1230662585, "j"); assertThat(map.get(721633257, -1230662585), is("j")); map.put(721633319, -532637417, "k"); assertThat(map.get(721633319, -532637417), is("k")); }
/** * Called to indicate a retransmission is received that may obviate the need to send one ourselves. * <p> * NOTE: Currently only called from unit tests. Would be used for retransmitting from receivers for NAK suppression * * @param termId of the data * @param termOffset of the data */ public void onRetransmitReceived(final int termId, final int termOffset) { final RetransmitAction action = activeRetransmitsMap.get(termId, termOffset); if (null != action && DELAYED == action.state) { activeRetransmitsMap.remove(termId, termOffset); action.cancel(); // do not go into linger } }