Search in sources :

Example 16 with ReadablePosition

use of org.agrona.concurrent.status.ReadablePosition in project Aeron by real-logic.

the class PublicationImage method checkUntetheredSubscriptions.

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 >> 2);
        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(), joinPosition(), rawLog.fileName(), Configuration.sourceIdentity(sourceAddress));
                    untethered.state(UntetheredSubscription.State.ACTIVE, nowNs, streamId, sessionId);
                }
            }
        }
    }
}
Also used : ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) ReadablePosition(org.agrona.concurrent.status.ReadablePosition)

Example 17 with ReadablePosition

use of org.agrona.concurrent.status.ReadablePosition in project Aeron by real-logic.

the class PublicationImage method trackRebuild.

int trackRebuild(final long nowNs) {
    int workCount = 0;
    if (isRebuilding) {
        final long hwmPosition = this.hwmPosition.getVolatile();
        long minSubscriberPosition = Long.MAX_VALUE;
        long maxSubscriberPosition = 0;
        for (final ReadablePosition subscriberPosition : subscriberPositions) {
            final long position = subscriberPosition.getVolatile();
            minSubscriberPosition = Math.min(minSubscriberPosition, position);
            maxSubscriberPosition = Math.max(maxSubscriberPosition, position);
        }
        final long rebuildPosition = Math.max(this.rebuildPosition.get(), maxSubscriberPosition);
        final long scanOutcome = lossDetector.scan(termBuffers[indexByPosition(rebuildPosition, positionBitsToShift)], rebuildPosition, hwmPosition, nowNs, termLengthMask, positionBitsToShift, initialTermId);
        final int rebuildTermOffset = (int) rebuildPosition & termLengthMask;
        final long newRebuildPosition = (rebuildPosition - rebuildTermOffset) + rebuildOffset(scanOutcome);
        this.rebuildPosition.proposeMaxOrdered(newRebuildPosition);
        final long ccOutcome = congestionControl.onTrackRebuild(nowNs, minSubscriberPosition, nextSmPosition, hwmPosition, rebuildPosition, newRebuildPosition, lossFound(scanOutcome));
        final int windowLength = CongestionControl.receiverWindowLength(ccOutcome);
        final int threshold = CongestionControl.threshold(windowLength);
        if (CongestionControl.shouldForceStatusMessage(ccOutcome) || (minSubscriberPosition > (nextSmPosition + threshold)) || windowLength != nextSmReceiverWindowLength) {
            cleanBufferTo(minSubscriberPosition - (termLengthMask + 1));
            scheduleStatusMessage(minSubscriberPosition, windowLength);
            workCount += 1;
        }
    }
    return workCount;
}
Also used : ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) ReadablePosition(org.agrona.concurrent.status.ReadablePosition)

Example 18 with ReadablePosition

use of org.agrona.concurrent.status.ReadablePosition in project Aeron by real-logic.

the class NetworkPublication method spiesFinishedConsuming.

private boolean spiesFinishedConsuming(final DriverConductor conductor, final long eosPosition) {
    if (spyPositions.length > 0) {
        for (final ReadablePosition spyPosition : spyPositions) {
            if (spyPosition.getVolatile() < eosPosition) {
                return false;
            }
        }
        hasSpies = false;
        conductor.cleanupSpies(this);
    }
    return true;
}
Also used : ReadablePosition(org.agrona.concurrent.status.ReadablePosition)

Aggregations

ReadablePosition (org.agrona.concurrent.status.ReadablePosition)18 ReceiveChannelEndpoint (io.aeron.driver.media.ReceiveChannelEndpoint)5 SendChannelEndpoint (io.aeron.driver.media.SendChannelEndpoint)4 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1