/** * Has the given leadershipTermId already been appended? * * @param leadershipTermId to check * @return true if term was already appended or false if not. */ public boolean hasTermBeenAppended(final long leadershipTermId) { final int index = (int)indexByLeadershipTermIdMap.get(leadershipTermId); return (NULL_VALUE != index); }
public Map<Long, Long> create(final Object... entries) { final Long2LongHashMap map = new Long2LongHashMap( entries.length * 2, Hashing.DEFAULT_LOAD_FACTOR, -1L, false); for (final Object o : entries) { @SuppressWarnings("unchecked") final Map.Entry<Long, Long> e = (Map.Entry<Long, Long>)o; map.put(e.getKey(), e.getValue()); } return map; }
/** * Primitive specialised version of {@link #replace(Object, Object, Object)} * * @param key key with which the specified value is associated * @param oldValue value expected to be associated with the specified key * @param newValue value to be associated with the specified key * @return {@code true} if the value was replaced */ public boolean replace(final long key, final long oldValue, final long newValue) { final long curValue = get(key); if (curValue != oldValue || curValue == missingValue) { return false; } put(key, newValue); return true; }
private void sendSlowStatus( final int libraryId, final long connectionId, final Long2LongHashMap toNotResend, final Long2LongHashMap toResend, final SlowStatus status) { toNotResend.remove(connectionId); final long position = inboundPublication.saveSlowStatusNotification(libraryId, connectionId, status); if (Pressure.isBackPressured(position)) { toResend.put(connectionId, libraryId); } } }
private void rehash(@DoNotSub final int newCapacity) { final long[] oldEntries = entries; final long missingValue = this.missingValue; @DoNotSub final int length = entries.length; capacity(newCapacity); for (@DoNotSub int i = 0; i < length; i += 2) { final long key = oldEntries[i]; if (key != missingValue) { put(key, oldEntries[i + 1]); } } }
private int resendSaveNotifications(final Long2LongHashMap resend, final SlowStatus status) { int actions = 0; if (!resend.isEmpty()) { final KeyIterator keyIterator = resend.keySet().iterator(); while (keyIterator.hasNext()) { final long connectionId = keyIterator.nextValue(); final int libraryId = (int)resend.get(connectionId); final long position = inboundPublication.saveSlowStatusNotification( libraryId, connectionId, status); if (position > 0) { actions++; keyIterator.remove(); } } } return actions; }
void snapshot(final ConsensusModuleSnapshotTaker snapshotTaker) { final Long2LongHashMap.EntryIterator iter = timerIdByCorrelationIdMap.entrySet().iterator(); while (iter.hasNext()) { iter.next(); final long correlationId = iter.getLongKey(); final long deadline = timerWheel.deadline(iter.getLongValue()); snapshotTaker.snapshotTimer(correlationId, deadline); } } }
/** * {@inheritDoc} */ public void forEach(final BiConsumer<? super Long, ? super Long> action) { longForEach(action::accept); }
private void rehash(@DoNotSub final int newCapacity) { final long[] oldEntries = entries; final long missingValue = this.missingValue; @DoNotSub final int length = entries.length; capacity(newCapacity); final long[] newEntries = entries; @DoNotSub final int mask = entries.length - 1; for (@DoNotSub int keyIndex = 0; keyIndex < length; keyIndex += 2) { final long value = oldEntries[keyIndex + 1]; if (value != missingValue) { final long key = oldEntries[keyIndex]; @DoNotSub int index = Hashing.evenHash(key, mask); while (newEntries[index + 1] != missingValue) { index = next(index, mask); } newEntries[index] = key; newEntries[index + 1] = value; } } }
/** * {@inheritDoc} */ public void clear() { Long2LongHashMap.this.clear(); }
/** * @param initialCapacity for the map to override {@link #MIN_CAPACITY} * @param loadFactor for the map to override {@link Hashing#DEFAULT_LOAD_FACTOR}. * @param missingValue for the map that represents null. * @param shouldAvoidAllocation should allocation be avoided by caching iterators and map entries. */ public Long2LongHashMap( @DoNotSub final int initialCapacity, @DoNotSub final float loadFactor, final long missingValue, final boolean shouldAvoidAllocation) { validateLoadFactor(loadFactor); this.loadFactor = loadFactor; this.missingValue = missingValue; this.shouldAvoidAllocation = shouldAvoidAllocation; capacity(findNextPositivePowerOfTwo(Math.max(MIN_CAPACITY, initialCapacity))); }
private final GatewayPublication outboundPublication; private final Long2LongHashMap resendSlowStatus = new Long2LongHashMap(-1); private final Long2LongHashMap resendNotSlowStatus = new Long2LongHashMap(-1); private final AgentInvoker conductorAgentInvoker; private final RecordingCoordinator recordingCoordinator;
/** * Primitive specialised version of {@link #replace(Object, Object)} * * @param key key with which the specified value is associated * @param value value to be associated with the specified key * @return the previous value associated with the specified key, or * {@link #missingValue()} if there was no mapping for the key. */ public long replace(final long key, final long value) { long curValue = get(key); if (curValue != missingValue) { curValue = put(key, value); } return curValue; }
private void quiesce() { final Long2LongHashMap inboundPositions = new Long2LongHashMap(CompletionPosition.MISSING_VALUE); inboundPositions.put(inboundPublication.id(), inboundPublication.position()); inboundCompletionPosition.complete(inboundPositions); final Long2LongHashMap outboundPositions = new Long2LongHashMap(CompletionPosition.MISSING_VALUE); idToLibrary.values().forEach(liveLibraryInfo -> { final int aeronSessionId = liveLibraryInfo.aeronSessionId(); final Image image = librarySubscription.imageBySessionId(aeronSessionId); if (image != null) { final long position = image.position(); outboundPositions.put(aeronSessionId, position); } }); outboundLibraryCompletionPosition.complete(outboundPositions); recordingCoordinator.completionPositions(inboundPositions, outboundPositions); }