Search in sources :

Example 6 with ReadablePosition

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

the class IpcPublication method updatePublisherLimit.

int updatePublisherLimit() {
    int workCount = 0;
    long minSubscriberPosition = Long.MAX_VALUE;
    long maxSubscriberPosition = consumerPosition;
    for (final ReadablePosition subscriberPosition : subscriberPositions) {
        final long position = subscriberPosition.getVolatile();
        minSubscriberPosition = Math.min(minSubscriberPosition, position);
        maxSubscriberPosition = Math.max(maxSubscriberPosition, position);
    }
    if (subscriberPositions.length > 0) {
        if (maxSubscriberPosition > consumerPosition) {
            consumerPosition = maxSubscriberPosition;
        }
        final long proposedLimit = minSubscriberPosition + termWindowLength;
        if (proposedLimit > tripLimit) {
            publisherLimit.setOrdered(proposedLimit);
            tripLimit = proposedLimit + tripGain;
            cleanBuffer(minSubscriberPosition);
            workCount = 1;
        }
    } else if (publisherLimit.get() > consumerPosition) {
        tripLimit = consumerPosition;
        publisherLimit.setOrdered(consumerPosition);
    }
    return workCount;
}
Also used : ReadablePosition(org.agrona.concurrent.status.ReadablePosition)

Example 7 with ReadablePosition

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

the class NetworkPublication method updatePublisherLimit.

/**
 * Update the publishers limit for flow control as part of the conductor duty cycle.
 *
 * @return 1 if the limit has been updated otherwise 0.
 */
int updatePublisherLimit() {
    int workCount = 0;
    if (State.ACTIVE == state) {
        final long senderPosition = this.senderPosition.getVolatile();
        if (hasRequiredReceivers() || (spiesSimulateConnection && spyPositions.length > 0)) {
            long minConsumerPosition = senderPosition;
            for (final ReadablePosition spyPosition : spyPositions) {
                minConsumerPosition = Math.min(minConsumerPosition, spyPosition.getVolatile());
            }
            final long proposedPublisherLimit = minConsumerPosition + termWindowLength;
            final long publisherLimit = this.publisherLimit.get();
            if (proposedPublisherLimit > publisherLimit) {
                cleanBufferTo(minConsumerPosition - termBufferLength);
                this.publisherLimit.setOrdered(proposedPublisherLimit);
                workCount = 1;
            }
        } else if (publisherLimit.get() > senderPosition) {
            publisherLimit.setOrdered(senderPosition);
            cleanBufferTo(senderPosition - termBufferLength);
            workCount = 1;
        }
    }
    return workCount;
}
Also used : SendChannelEndpoint(io.aeron.driver.media.SendChannelEndpoint) ReadablePosition(org.agrona.concurrent.status.ReadablePosition)

Example 8 with ReadablePosition

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

the class PublicationImage method positionArray.

private ReadablePosition[] positionArray(final ArrayList<SubscriberPosition> subscriberPositions, final long nowNs) {
    final int size = subscriberPositions.size();
    final ReadablePosition[] positions = new ReadablePosition[subscriberPositions.size()];
    for (int i = 0; i < size; i++) {
        final SubscriberPosition subscriberPosition = subscriberPositions.get(i);
        positions[i] = subscriberPosition.position();
        if (!subscriberPosition.subscription().isTether()) {
            untetheredSubscriptions.add(new UntetheredSubscription(subscriberPosition.subscription(), subscriberPosition.position(), nowNs));
        }
    }
    return positions;
}
Also used : ReceiveChannelEndpoint(io.aeron.driver.media.ReceiveChannelEndpoint) ReadablePosition(org.agrona.concurrent.status.ReadablePosition)

Example 9 with ReadablePosition

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

the class IpcPublication method updatePublisherLimit.

int updatePublisherLimit() {
    int workCount = 0;
    if (State.ACTIVE == state) {
        if (subscriberPositions.length > 0) {
            long minSubscriberPosition = Long.MAX_VALUE;
            long maxSubscriberPosition = consumerPosition;
            for (final ReadablePosition subscriberPosition : subscriberPositions) {
                final long position = subscriberPosition.getVolatile();
                minSubscriberPosition = Math.min(minSubscriberPosition, position);
                maxSubscriberPosition = Math.max(maxSubscriberPosition, position);
            }
            if (maxSubscriberPosition > consumerPosition) {
                consumerPosition = maxSubscriberPosition;
            }
            final long proposedLimit = minSubscriberPosition + termWindowLength;
            if (proposedLimit > tripLimit) {
                cleanBufferTo(minSubscriberPosition);
                publisherLimit.setOrdered(proposedLimit);
                tripLimit = proposedLimit + tripGain;
                workCount = 1;
            }
        } else if (publisherLimit.get() > consumerPosition) {
            tripLimit = consumerPosition;
            publisherLimit.setOrdered(consumerPosition);
            cleanBufferTo(consumerPosition);
        }
    }
    return workCount;
}
Also used : ReadablePosition(org.agrona.concurrent.status.ReadablePosition)

Example 10 with ReadablePosition

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

the class SubscriptionLink method close.

/**
 * {@inheritDoc}
 */
public void close() {
    for (final Map.Entry<Subscribable, ReadablePosition> entry : positionBySubscribableMap.entrySet()) {
        final Subscribable subscribable = entry.getKey();
        final ReadablePosition position = entry.getValue();
        subscribable.removeSubscriber(this, position);
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) Map(java.util.Map) 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