Java Code Examples for org.agrona.collections.ArrayUtil#remove()
The following examples show how to use
org.agrona.collections.ArrayUtil#remove() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IpcPublication.java From aeron with Apache License 2.0 | 6 votes |
public void removeSubscriber(final SubscriptionLink subscriptionLink, final ReadablePosition subscriberPosition) { consumerPosition = Math.max(consumerPosition, subscriberPosition.getVolatile()); subscriberPositions = ArrayUtil.remove(subscriberPositions, subscriberPosition); subscriberPosition.close(); if (subscriberPositions.length == 0) { LogBufferDescriptor.isConnected(metaDataBuffer, false); } if (!subscriptionLink.isTether()) { for (int lastIndex = untetheredSubscriptions.size() - 1, i = lastIndex; i >= 0; i--) { if (untetheredSubscriptions.get(i).subscriptionLink == subscriptionLink) { ArrayListUtil.fastUnorderedRemove(untetheredSubscriptions, i, lastIndex); break; } } } }
Example 2
Source File: DynamicCompositeAgent.java From agrona with Apache License 2.0 | 6 votes |
private void remove(final Agent agent) { removeAgent.lazySet(null); final Agent[] newAgents = ArrayUtil.remove(agents, agent); try { if (newAgents != agents) { agent.onClose(); } } finally { agents = newAgents; } }
Example 3
Source File: NetworkPublication.java From aeron with Apache License 2.0 | 6 votes |
public void removeSubscriber(final SubscriptionLink subscriptionLink, final ReadablePosition position) { spyPositions = ArrayUtil.remove(spyPositions, position); hasSpies = spyPositions.length > 0; position.close(); if (!subscriptionLink.isTether()) { for (int lastIndex = untetheredSubscriptions.size() - 1, i = lastIndex; i >= 0; i--) { if (untetheredSubscriptions.get(i).subscriptionLink == subscriptionLink) { ArrayListUtil.fastUnorderedRemove(untetheredSubscriptions, i, lastIndex); break; } } } }
Example 4
Source File: DataTransportPoller.java From aeron with Apache License 2.0 | 6 votes |
public void cancelRead(final ReceiveChannelEndpoint channelEndpoint, final UdpChannelTransport transport) { final ChannelAndTransport[] transports = this.channelAndTransports; int index = ArrayUtil.UNKNOWN_INDEX; for (int i = 0, length = transports.length; i < length; i++) { if (channelEndpoint == transports[i].channelEndpoint && transport == transports[i].transport) { index = i; break; } } if (index != ArrayUtil.UNKNOWN_INDEX) { channelAndTransports = ArrayUtil.remove(transports, index); } }
Example 5
Source File: PublicationImage.java From aeron with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public void removeSubscriber(final SubscriptionLink subscriptionLink, final ReadablePosition subscriberPosition) { subscriberPositions = ArrayUtil.remove(subscriberPositions, subscriberPosition); subscriberPosition.close(); if (!subscriptionLink.isTether()) { for (int lastIndex = untetheredSubscriptions.size() - 1, i = lastIndex; i >= 0; i--) { if (untetheredSubscriptions.get(i).subscriptionLink == subscriptionLink) { ArrayListUtil.fastUnorderedRemove(untetheredSubscriptions, i, lastIndex); break; } } } if (subscriberPositions.length == 0) { isRebuilding = false; } }
Example 6
Source File: ReceiverEndPoints.java From artio with Apache License 2.0 | 6 votes |
void removeConnection(final long connectionId, final DisconnectReason reason) { final ReceiverEndPoint[] endPoints = this.endPoints; int index = findAndCloseEndPoint(connectionId, reason, endPoints); if (index != UNKNOWN_INDEX) { this.endPoints = ArrayUtil.remove(endPoints, index); } else { index = findAndCloseEndPoint(connectionId, reason, requiredPollingEndPoints); this.requiredPollingEndPoints = ArrayUtil.remove(requiredPollingEndPoints, index); } selectNowToForceProcessing(); }
Example 7
Source File: Subscription.java From aeron with Apache License 2.0 | 6 votes |
Image removeImage(final long correlationId) { final Image[] oldArray = images; Image removedImage = null; int i = 0; for (final Image image : oldArray) { if (image.correlationId() == correlationId) { removedImage = image; break; } i++; } if (null != removedImage) { removedImage.close(); images = ArrayUtil.remove(oldArray, i); conductor.releaseLogBuffers(removedImage.logBuffers(), correlationId); } return removedImage; }
Example 8
Source File: LibraryPoller.java From artio with Apache License 2.0 | 6 votes |
private int pollPendingInitiatorSessions(final long timeInMs) { InternalSession[] pendingSessions = this.pendingInitiatorSessions; int total = 0; for (int i = 0, size = pendingSessions.length; i < size;) { final InternalSession session = pendingSessions[i]; total += session.poll(timeInMs); if (session.state() == ACTIVE) { this.pendingInitiatorSessions = pendingSessions = ArrayUtil.remove(pendingSessions, i); size--; sessions = ArrayUtil.add(sessions, session); } else { i++; } } return total; }
Example 9
Source File: ReceiverEndPoints.java From artio with Apache License 2.0 | 6 votes |
void receiverEndPointPollingOptional(final long connectionId) { final ReceiverEndPoint[] requiredPollingEndPoints = this.requiredPollingEndPoints; final int index = findEndPoint(connectionId, requiredPollingEndPoints); if (index != UNKNOWN_INDEX) { final ReceiverEndPoint endPoint = requiredPollingEndPoints[index]; this.requiredPollingEndPoints = ArrayUtil.remove(requiredPollingEndPoints, index); addToNormalEndpoints(endPoint); } else { errorHandler.onError(new Exception(String.format( "Unable to make endpoint no longer required for polling due to it not being found, connectionId=%d", connectionId))); } }
Example 10
Source File: Sender.java From aeron with Apache License 2.0 | 4 votes |
public void onRemoveNetworkPublication(final NetworkPublication publication) { networkPublications = ArrayUtil.remove(networkPublications, publication); publication.channelEndpoint().unregisterForSend(publication); publication.senderRelease(); }
Example 11
Source File: IpcPublication.java From aeron with Apache License 2.0 | 4 votes |
private void checkUntetheredSubscriptions(final long nowNs, final DriverConductor conductor) { final long untetheredWindowLimit = (consumerPosition - termWindowLength) + (termWindowLength >> 3); for (int lastIndex = untetheredSubscriptions.size() - 1, i = lastIndex; i >= 0; i--) { final UntetheredSubscription untethered = untetheredSubscriptions.get(i); if (UntetheredSubscription.State.ACTIVE == untethered.state) { if (untethered.position.getVolatile() > untetheredWindowLimit) { untethered.timeOfLastUpdateNs = nowNs; } else if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0) { conductor.notifyUnavailableImageLink(registrationId, untethered.subscriptionLink); untethered.state(UntetheredSubscription.State.LINGER, nowNs, streamId, sessionId); } } else if (UntetheredSubscription.State.LINGER == untethered.state) { if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0) { subscriberPositions = ArrayUtil.remove(subscriberPositions, untethered.position); untethered.state(UntetheredSubscription.State.RESTING, nowNs, streamId, sessionId); } } else if (UntetheredSubscription.State.RESTING == untethered.state) { if ((untethered.timeOfLastUpdateNs + untetheredRestingTimeoutNs) - nowNs <= 0) { subscriberPositions = ArrayUtil.add(subscriberPositions, untethered.position); conductor.notifyAvailableImageLink( registrationId, sessionId, untethered.subscriptionLink, untethered.position.id(), consumerPosition, rawLog.fileName(), CommonContext.IPC_CHANNEL); untethered.state(UntetheredSubscription.State.ACTIVE, nowNs, streamId, sessionId); LogBufferDescriptor.isConnected(metaDataBuffer, true); } } } }
Example 12
Source File: LibraryPoller.java From artio with Apache License 2.0 | 4 votes |
public void remove(final ILink3Connection session) { iLink3Connections = ArrayUtil.remove(iLink3Connections, session); connectionIdToILink3Subscription.remove(session.connectionId()); }
Example 13
Source File: PublicationImage.java From aeron with Apache License 2.0 | 4 votes |
private void checkUntetheredSubscriptions(final long nowNs, final DriverConductor conductor) { final ArrayList<UntetheredSubscription> untetheredSubscriptions = this.untetheredSubscriptions; final int untetheredSubscriptionsSize = untetheredSubscriptions.size(); if (untetheredSubscriptionsSize > 0) { long maxConsumerPosition = 0; for (final ReadablePosition subscriberPosition : subscriberPositions) { final long position = subscriberPosition.getVolatile(); if (position > maxConsumerPosition) { maxConsumerPosition = position; } } final int windowLength = nextSmReceiverWindowLength; final long untetheredWindowLimit = (maxConsumerPosition - windowLength) + (windowLength >> 3); for (int lastIndex = untetheredSubscriptionsSize - 1, i = lastIndex; i >= 0; i--) { final UntetheredSubscription untethered = untetheredSubscriptions.get(i); if (UntetheredSubscription.State.ACTIVE == untethered.state) { if (untethered.position.getVolatile() > untetheredWindowLimit) { untethered.timeOfLastUpdateNs = nowNs; } else if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0) { conductor.notifyUnavailableImageLink(correlationId, untethered.subscriptionLink); untethered.state(UntetheredSubscription.State.LINGER, nowNs, streamId, sessionId); } } else if (UntetheredSubscription.State.LINGER == untethered.state) { if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0) { subscriberPositions = ArrayUtil.remove(subscriberPositions, untethered.position); untethered.state(UntetheredSubscription.State.RESTING, nowNs, streamId, sessionId); } } else if (UntetheredSubscription.State.RESTING == untethered.state) { if ((untethered.timeOfLastUpdateNs + untetheredRestingTimeoutNs) - nowNs <= 0) { subscriberPositions = ArrayUtil.add(subscriberPositions, untethered.position); conductor.notifyAvailableImageLink( correlationId, sessionId, untethered.subscriptionLink, untethered.position.id(), rebuildPosition.get(), rawLog.fileName(), Configuration.sourceIdentity(sourceAddress)); untethered.state(UntetheredSubscription.State.ACTIVE, nowNs, streamId, sessionId); } } } } }
Example 14
Source File: ControlTransportPoller.java From aeron with Apache License 2.0 | 4 votes |
public void cancelRead(final SendChannelEndpoint transport) { transports = ArrayUtil.remove(transports, transport); }
Example 15
Source File: LibraryPoller.java From artio with Apache License 2.0 | 4 votes |
void disableSession(final InternalSession session) { sessions = ArrayUtil.remove(sessions, session); session.disable(); cacheSession(session); }
Example 16
Source File: NetworkPublication.java From aeron with Apache License 2.0 | 4 votes |
private void checkUntetheredSubscriptions(final long nowNs, final DriverConductor conductor) { final ArrayList<UntetheredSubscription> untetheredSubscriptions = this.untetheredSubscriptions; final int untetheredSubscriptionsSize = untetheredSubscriptions.size(); if (untetheredSubscriptionsSize > 0) { final long senderPosition = this.senderPosition.getVolatile(); final long untetheredWindowLimit = (senderPosition - termWindowLength) + (termWindowLength >> 3); for (int lastIndex = untetheredSubscriptionsSize - 1, i = lastIndex; i >= 0; i--) { final UntetheredSubscription untethered = untetheredSubscriptions.get(i); if (UntetheredSubscription.State.ACTIVE == untethered.state) { if (untethered.position.getVolatile() > untetheredWindowLimit) { untethered.timeOfLastUpdateNs = nowNs; } else if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0) { conductor.notifyUnavailableImageLink(registrationId, untethered.subscriptionLink); untethered.state(UntetheredSubscription.State.LINGER, nowNs, streamId, sessionId); } } else if (UntetheredSubscription.State.LINGER == untethered.state) { if ((untethered.timeOfLastUpdateNs + untetheredWindowLimitTimeoutNs) - nowNs <= 0) { spyPositions = ArrayUtil.remove(spyPositions, untethered.position); untethered.state(UntetheredSubscription.State.RESTING, nowNs, streamId, sessionId); } } else if (UntetheredSubscription.State.RESTING == untethered.state) { if ((untethered.timeOfLastUpdateNs + untetheredRestingTimeoutNs) - nowNs <= 0) { spyPositions = ArrayUtil.add(spyPositions, untethered.position); conductor.notifyAvailableImageLink( registrationId, sessionId, untethered.subscriptionLink, untethered.position.id(), senderPosition, rawLog.fileName(), CommonContext.IPC_CHANNEL); untethered.state(UntetheredSubscription.State.ACTIVE, nowNs, streamId, sessionId); LogBufferDescriptor.isConnected(metaDataBuffer, true); } } } } }
Example 17
Source File: ClusterMember.java From aeron with Apache License 2.0 | 2 votes |
/** * Remove a member from an array if found, otherwise return the array unmodified. * * @param oldMembers to remove a member from. * @param memberId of the member to remove. * @return a new array with the member removed or the existing array if not found. */ public static ClusterMember[] removeMember(final ClusterMember[] oldMembers, final int memberId) { return ArrayUtil.remove(oldMembers, findMemberIndex(oldMembers, memberId)); }