private boolean isInvalid(final int termOffset, final int termLength) { final boolean isInvalid = (termOffset > (termLength - DataHeaderFlyweight.HEADER_LENGTH)) || (termOffset < 0); if (isInvalid) { invalidPackets.increment(); } return isInvalid; }
/** * Allocate a counter record and wrap it with a new {@link AtomicCounter} for use with a default type * of {@link #DEFAULT_TYPE_ID}. * * @param label to describe the counter. * @return a newly allocated {@link AtomicCounter} */ public AtomicCounter newCounter(final String label) { return new AtomicCounter(valuesBuffer, allocate(label), this); }
public void indicateActive() { final long currentStatus = statusIndicator.get(); if (currentStatus != ChannelEndpointStatus.INITIALIZING) { throw new IllegalStateException( "channel cannot be registered unless INITALIZING: status=" + status(currentStatus)); } statusIndicator.setOrdered(ChannelEndpointStatus.ACTIVE); }
public void closeStatusIndicator() { if (!statusIndicator.isClosed()) { statusIndicator.setOrdered(ChannelEndpointStatus.CLOSING); statusIndicator.close(); } }
private AtomicCounter fakeCounter() { final AtomicLong value = new AtomicLong(); final AtomicCounter atomicCounter = mock(AtomicCounter.class); final Answer<Long> get = inv -> value.get(); final Answer<?> set = inv -> { value.set(inv.getArgument(0)); return null; }; final Answer<?> add = (inv) -> value.getAndAdd(inv.getArgument(0)); when(atomicCounter.get()).then(get); when(atomicCounter.getWeak()).then(get); doAnswer(set).when(atomicCounter).set(anyLong()); doAnswer(set).when(atomicCounter).setOrdered(anyLong()); doAnswer(set).when(atomicCounter).setWeak(anyLong()); when(atomicCounter.getAndAdd(anyLong())).then(add); when(atomicCounter.getAndAddOrdered(anyLong())).then(add); return atomicCounter; }
private boolean isFlowControlUnderRun(final long packetPosition) { final boolean isFlowControlUnderRun = packetPosition < lastSmPosition; if (isFlowControlUnderRun) { flowControlUnderRuns.incrementOrdered(); } return isFlowControlUnderRun; }
/** * Get the {@link ToggleState} for a given control toggle. * * @param controlToggle to get the current state for. * @return the state for the current control toggle. * @throws ClusterException if the counter is not one of the valid values. */ public static ToggleState get(final AtomicCounter controlToggle) { final long toggleValue = controlToggle.get(); if (toggleValue < 0 || toggleValue > (STATES.length - 1)) { throw new ClusterException("invalid toggle value: " + toggleValue); } return STATES[(int)toggleValue]; } }
public void onRttMeasurement(final long nowNs, final long rttNs, final InetSocketAddress srcAddress) { outstandingRttMeasurements--; lastRttTimestampNs = nowNs; this.rttInNs = rttNs; rttIndicator.setOrdered(rttNs); }
public void close() { counter.close(); }
private int heartbeatMessageCheck( final long nowNs, final int activeTermId, final int termOffset, final boolean isEndOfStream) { int bytesSent = 0; if ((timeOfLastSendOrHeartbeatNs + PUBLICATION_HEARTBEAT_TIMEOUT_NS) - nowNs < 0) { heartbeatBuffer.clear(); heartbeatDataHeader .sessionId(sessionId) .streamId(streamId) .termId(activeTermId) .termOffset(termOffset) .flags((byte)(isEndOfStream ? BEGIN_END_AND_EOS_FLAGS : BEGIN_AND_END_FLAGS)); bytesSent = channelEndpoint.send(heartbeatBuffer); if (DataHeaderFlyweight.HEADER_LENGTH != bytesSent) { shortSends.increment(); } timeOfLastSendOrHeartbeatNs = nowNs; heartbeatsSent.incrementOrdered(); } return bytesSent; }
private int doSend(final long nowNs) { int bytesSent = 0; final NetworkPublication[] publications = this.networkPublications; final int length = publications.length; int startingIndex = roundRobinIndex++; if (startingIndex >= length) { roundRobinIndex = startingIndex = 0; } for (int i = startingIndex; i < length; i++) { bytesSent += publications[i].send(nowNs); } for (int i = 0; i < startingIndex; i++) { bytesSent += publications[i].send(nowNs); } totalBytesSent.getAndAddOrdered(bytesSent); return bytesSent; } }
public int statusIndicatorCounterId() { return statusIndicator.id(); }
/** * Reset the toggle to the {@link #NEUTRAL} state. * * @param controlToggle to be reset. */ public static void reset(final AtomicCounter controlToggle) { controlToggle.set(NEUTRAL.code()); }
public void closeStatusIndicator() { if (!statusIndicator.isClosed()) { statusIndicator.setOrdered(ChannelEndpointStatus.CLOSING); statusIndicator.close(); } }
private boolean isFlowControlOverRun(final long proposedPosition) { final boolean isFlowControlOverRun = proposedPosition > lastSmWindowLimit; if (isFlowControlOverRun) { flowControlOverRuns.incrementOrdered(); } return isFlowControlOverRun; }
/** * Get the {@link State} encoded in an {@link AtomicCounter}. * * @param counter to get the current state for. * @return the state for the {@link ConsensusModule}. * @throws ClusterException if the counter is not one of the valid values. */ public static State get(final AtomicCounter counter) { final long code = counter.get(); if (code < 0 || code > (STATES.length - 1)) { throw new ClusterException("invalid state counter code: " + code); } return STATES[(int)code]; } }
public void timeOfLastKeepaliveMs(final long nowMs) { timeOfLastKeepaliveMs = nowMs; heartbeatStatus.setOrdered(nowMs); }
void internalClose() { super.close(); isClosed = true; } }
public int doWork() { int workCount = commandQueue.drain(Runnable::run, Configuration.COMMAND_DRAIN_LIMIT); final int bytesReceived = dataTransportPoller.pollTransports(); totalBytesReceived.getAndAddOrdered(bytesReceived); final long nowNs = nanoClock.nanoTime(); final ArrayList<PublicationImage> publicationImages = this.publicationImages; for (int lastIndex = publicationImages.size() - 1, i = lastIndex; i >= 0; i--) { final PublicationImage image = publicationImages.get(i); if (image.hasActivityAndNotEndOfStream(nowNs)) { workCount += image.sendPendingStatusMessage(); workCount += image.processPendingLoss(); workCount += image.initiateAnyRttMeasurements(nowNs); } else { ArrayListUtil.fastUnorderedRemove(publicationImages, i, lastIndex--); image.removeFromDispatcher(); } } checkPendingSetupMessages(nowNs); return workCount + bytesReceived; }