private boolean isDrained(final long producerPosition) { for (final ReadablePosition subscriberPosition : subscriberPositions) { if (subscriberPosition.getVolatile() < producerPosition) { return false; } } return true; }
public long availableWindow() { if (isClosed) { return CLOSED; } return positionLimit.getVolatile() - (termBeginPosition + termOffset); }
/** * Get the position limit beyond which this {@link Publication} will be back pressured. * <p> * This should only be used as a guide to determine when back pressure is likely to be applied. * * @return the position limit beyond which this {@link Publication} will be back pressured. */ public long positionLimit() { if (isClosed) { return CLOSED; } return positionLimit.getVolatile(); }
private long maxSpyPosition(final long senderPosition) { long position = senderPosition; for (final ReadablePosition spyPosition : spyPositions) { position = Math.max(position, spyPosition.getVolatile()); } return position; }
public long availableWindow() { if (isClosed) { return CLOSED; } return positionLimit.getVolatile() - position(); }
private boolean isDrained() { final long rebuildPosition = this.rebuildPosition.get(); for (final ReadablePosition subscriberPosition : subscriberPositions) { if (subscriberPosition.getVolatile() < rebuildPosition) { return false; } } return true; }
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; }
public void removeSubscriber(final ReadablePosition subscriberPosition) { consumerPosition = Math.max(consumerPosition, subscriberPosition.getVolatile()); subscriberPositions = ArrayUtil.remove(subscriberPositions, subscriberPosition); subscriberPosition.close(); if (subscriberPositions.length == 0) { LogBufferDescriptor.isConnected(metaDataBuffer, false); } }
final long position = subscriberPosition.getVolatile(); minSubscriberPosition = Math.min(minSubscriberPosition, position); maxSubscriberPosition = Math.max(maxSubscriberPosition, position);
/** * Update the publishers limit for flow control as part of the conductor duty cycle. * * @return 1 if the limit has been updated otherwise 0. */ final int updatePublisherLimit() { int workCount = 0; final long senderPosition = this.senderPosition.getVolatile(); if (hasReceivers || (spiesSimulateConnection && spyPositions.length > 0)) { long minConsumerPosition = senderPosition; for (final ReadablePosition spyPosition : spyPositions) { minConsumerPosition = Math.min(minConsumerPosition, spyPosition.getVolatile()); } final long proposedPublisherLimit = minConsumerPosition + termWindowLength; if (publisherLimit.proposeMaxOrdered(proposedPublisherLimit)) { cleanBuffer(proposedPublisherLimit); workCount = 1; } } else if (publisherLimit.get() > senderPosition) { publisherLimit.setOrdered(senderPosition); } return workCount; }
@Test public void shouldReportThatPublicationHasNotBeenConnectedYet() { when(publicationLimit.getVolatile()).thenReturn(0L); isConnected(logMetaDataBuffer, false); assertFalse(publication.isConnected()); }
final long limit = positionLimit.getVolatile(); final ExclusiveTermAppender termAppender = termAppenders[activePartitionIndex]; final long position = termBeginPosition + termOffset;
/** * Append a padding record log of a given length to make up the log to a position. * * @param length of the range to claim, in bytes.. * @return The new stream position, otherwise a negative error value of {@link #NOT_CONNECTED}, * {@link #BACK_PRESSURED}, {@link #ADMIN_ACTION}, {@link #CLOSED}, or {@link #MAX_POSITION_EXCEEDED}. * @throws IllegalArgumentException if the length is greater than {@link #maxMessageLength()}. */ public long appendPadding(final int length) { checkMaxMessageLength(length); long newPosition = CLOSED; if (!isClosed) { final long limit = positionLimit.getVolatile(); final ExclusiveTermAppender termAppender = termAppenders[activePartitionIndex]; final long position = termBeginPosition + termOffset; if (position < limit) { checkPositiveLength(length); final int result = termAppender.appendPadding(termId, termOffset, headerWriter, length); newPosition = newPosition(result); } else { newPosition = backPressureStatus(position, length); } } return newPosition; }
final long position = subscriberPosition.getVolatile(); minSubscriberPosition = Math.min(minSubscriberPosition, position); maxSubscriberPosition = Math.max(maxSubscriberPosition, position);
final long limit = positionLimit.getVolatile(); final ExclusiveTermAppender termAppender = termAppenders[activePartitionIndex]; final long position = termBeginPosition + termOffset;
if (!isClosed) final long limit = positionLimit.getVolatile(); final ExclusiveTermAppender termAppender = termAppenders[activePartitionIndex]; final long position = termBeginPosition + termOffset;
@Before public void setUp() when(publicationLimit.getVolatile()).thenReturn(2L * SEND_BUFFER_CAPACITY); when(logBuffers.duplicateTermBuffers()).thenReturn(termBuffers); when(logBuffers.termLength()).thenReturn(TERM_MIN_LENGTH);
if (!isClosed) final long limit = positionLimit.getVolatile(); final ExclusiveTermAppender termAppender = termAppenders[activePartitionIndex]; final long position = termBeginPosition + termOffset;
@Before public void setUp() throws Exception when(POSITION.getVolatile()) .thenReturn(computePosition(ACTIVE_TERM_ID, 0, POSITION_BITS_TO_SHIFT, ACTIVE_TERM_ID)); when(mockSystemCounters.get(any())).thenReturn(mock(AtomicCounter.class));
private long maxSpyPosition(final long senderPosition) { long position = senderPosition; for (final ReadablePosition spyPosition : spyPositions) { position = Math.max(position, spyPosition.getVolatile()); } return position; }