void addSession( final long clusterSessionId, final int responseStreamId, final String responseChannel, final byte[] encodedPrincipal) { sessionByIdMap.put(clusterSessionId, new ClientSession( clusterSessionId, responseStreamId, responseChannel, encodedPrincipal, this)); }
public void onSessionClose(final long clusterSessionId) { final ClusterSession session = sessionByIdMap.get(clusterSessionId); if (null != session && Cluster.Role.LEADER == role) { session.close(CloseReason.CLIENT_ACTION); if (logPublisher.appendSessionClose(session, leadershipTermId, clusterTimeMs)) { sessionByIdMap.remove(clusterSessionId); } } }
public Map<Long, Long> create(final Object... entries) { final Long2ObjectHashMap<Long> map = new Long2ObjectHashMap<>( entries.length * 2, Hashing.DEFAULT_LOAD_FACTOR, 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; }
private LogBuffers logBuffers(final long registrationId, final String logFileName) { LogBuffers logBuffers = logBuffersByIdMap.get(registrationId); if (null == logBuffers) { logBuffers = logBuffersFactory.map(logFileName); logBuffersByIdMap.put(registrationId, logBuffers); } logBuffers.incRef(); return logBuffers; }
public void beginMonitoringSocketIdentifier(final InetSocketAddress socketAddress, final long socketIdentifier) { while (true) { final Long2ObjectHashMap<InetSocketAddress> candidateSnapshot = candidateSockets.get(); final Long2ObjectHashMap<InetSocketAddress> updated = new Long2ObjectHashMap<>(candidateSnapshot.size(), AGRONA_DEFAULT_LOAD_FACTOR); final Long2ObjectHashMap<InetSocketAddress>.KeyIterator keyIterator = candidateSnapshot.keySet().iterator(); while(keyIterator.hasNext()) { final long key = keyIterator.nextLong(); updated.put(key, candidateSnapshot.get(key)); } updated.put(socketIdentifier, socketAddress); if (candidateSockets.compareAndSet(candidateSnapshot, updated)) { break; } } }
void removeControlSession(final ControlSession controlSession) { controlSessionByIdMap.remove(controlSession.sessionId()); }
new Long2ObjectHashMap<>(); actual.forEach(r -> recordsByPosition.put(((TypedEventImpl) r).getPosition(), r)); r -> ((TypedEventImpl) r).getSourceEventPosition() > terminatingRecord.getPosition()) .map(r -> recordsByPosition.get(((TypedEventImpl) r).getSourceEventPosition())) .filter(r -> r.getValue().getScopeInstanceKey() == instanceKey) .filter(r -> isFlowEvaluatingState(r.getMetadata().getIntent()))
public ClientSession getClientSession(final long clusterSessionId) { return sessionByIdMap.get(clusterSessionId); }
private void createFile(final long correlationId, final long length, final String filename) { if (fileSessionByIdMap.containsKey(correlationId)) { throw new IllegalStateException("correlationId is in use: " + correlationId); } final File file = new File(storageDir, filename); if (file.exists() && !file.delete()) { throw new IllegalStateException("failed to delete existing file: " + file); } if (length == 0) { try { if (!file.createNewFile()) { throw new IllegalStateException("failed to create " + filename); } } catch (final IOException ex) { LangUtil.rethrowUnchecked(ex); } } else { fileSessionByIdMap.put(correlationId, new UnsafeBuffer(IoUtil.mapNewFile(file, length, false))); } }
@Test public void shouldRemoveElements() throws Exception { try { final List<EncodableKey> keyList = generateKeyList(numberOfElements); keyList.forEach(e -> { map.put(e, Long.toString(e.value)); comparison.put(e.value, Long.toString(e.value)); }); Collections.shuffle(keyList, random); keyList.forEach(e -> { assertThat(failureMessage("Expected comparison to contain a value for " + e), comparison.remove(e.value), is(not(nullValue()))); assertThat(failureMessage("Expected comparison to not contain key " + e), comparison.containsKey(e.value), is(false)); assertThat(failureMessage("Expected map to contain a value for " + e), map.remove(e), is(not(nullValue()))); assertThat(failureMessage("Expected map to not contain key " + e), map.containsKey(e), is(false)); }); } catch(RuntimeException e) { e.printStackTrace(); fail(failureMessage(e.getMessage())); } }
private final DriverEventsAdapter driverEventsAdapter; private final LogBuffersFactory logBuffersFactory; private final Long2ObjectHashMap<LogBuffers> logBuffersByIdMap = new Long2ObjectHashMap<>(); private final Long2ObjectHashMap<Object> resourceByRegIdMap = new Long2ObjectHashMap<>(); private final ArrayList<ManagedResource> lingeringResources = new ArrayList<>(); private final AvailableImageHandler defaultAvailableImageHandler; return (Counter)resourceByRegIdMap.get(registrationId);
void clearSessionsAfter(final long logPosition) { for (final Iterator<ClusterSession> i = sessionByIdMap.values().iterator(); i.hasNext(); ) { final ClusterSession session = i.next(); if (session.openedLogPosition() >= logPosition) { i.remove(); session.close(); } } for (final ClusterSession session : pendingSessions) { session.close(); } pendingSessions.clear(); }
final Long2ObjectHashMap<InetSocketAddress> candidateSocketsSnapshot = candidateSockets.getSnapshot(); if(candidateSocketsSnapshot.containsKey(socketIdentifier) || candidateSocketsSnapshot.containsKey(matchAllPortsSocketIdentifier) || candidateSocketsSnapshot.containsKey(entry.getSocketInstanceIndentifier()) || candidateSocketsSnapshot.containsKey(matchAllPortsSocketInstanceIdentifier)) if(!monitoredSockets.contains(socketInstanceIdentifier)) InetSocketAddress socketAddress = candidateSocketsSnapshot.get(socketIdentifier); if(socketAddress == null) socketAddress = candidateSocketsSnapshot.get(matchAllPortsSocketIdentifier); socketAddress = candidateSocketsSnapshot.get(entry.getSocketInstanceIndentifier()); socketAddress = candidateSocketsSnapshot.get(matchAllPortsSocketInstanceIdentifier);
final SourceLocation sourceLocation) if (recordingSessionByIdMap.size() >= maxConcurrentRecordings) if (recordingSessionByIdMap.containsKey(recordingId))
private void validateMaxConcurrentRecordings( final long correlationId, final ControlSession controlSession, final String originalChannel, final Image image) { if (recordingSessionByIdMap.size() >= maxConcurrentRecordings) { final String msg = "max concurrent recordings reached, cannot record " + image.subscription().streamId() + ":" + originalChannel; controlSession.attemptErrorResponse(correlationId, MAX_RECORDINGS, msg, controlResponseProxy); throw new ArchiveException(msg); } }
public EncodedData2ObjectHashMapFuzzTest(final int initialCapacity, final float loadFactor, final int numberOfElements) { this.numberOfElements = numberOfElements; map = new EncodedData2ObjectHashMap<>(initialCapacity, loadFactor, 8, this::encodeKey, encoded -> Long.hashCode(encoded.getLong(0)), new EncodableKey(Long.MIN_VALUE)); comparison = new Long2ObjectHashMap<>(initialCapacity, loadFactor); }
public boolean contains(final long socketInstanceIndentifier) { return monitoredSocketInstances.containsKey(socketInstanceIndentifier); }
private void forceCloseResources() { for (final Object resource : resourceByRegIdMap.values()) { if (resource instanceof Subscription) { final Subscription subscription = (Subscription)resource; subscription.internalClose(); } else if (resource instanceof Publication) { final Publication publication = (Publication)resource; publication.internalClose(); releaseLogBuffers(publication.logBuffers(), publication.originalRegistrationId()); } else if (resource instanceof Counter) { final Counter counter = (Counter)resource; counter.internalClose(); } } resourceByRegIdMap.clear(); } }
/** * Compact the {@link Map} backing arrays by rehashing with a capacity just larger than current size * and giving consideration to the load factor. */ public void compact() { @DoNotSub final int idealCapacity = (int)Math.round(size() * (1.0d / loadFactor)); rehash(BitUtil.findNextPositivePowerOfTwo(idealCapacity)); }
public void endMonitoringOfSocketIdentifier(final long socketIdentifier) { while (true) { final Long2ObjectHashMap<InetSocketAddress> candidateSnapshot = candidateSockets.get(); final Long2ObjectHashMap<InetSocketAddress> updated = new Long2ObjectHashMap<>(candidateSnapshot.size(), AGRONA_DEFAULT_LOAD_FACTOR); final Long2ObjectHashMap<InetSocketAddress>.KeyIterator keyIterator = candidateSnapshot.keySet().iterator(); while(keyIterator.hasNext()) { final long key = keyIterator.nextLong(); if(key != socketIdentifier) { updated.put(key, candidateSnapshot.get(key)); } } if (candidateSockets.compareAndSet(candidateSnapshot, updated)) { break; } } }