public String toString() { final StringBuilder sb = new StringBuilder(); final String formattedFlags = String.format("%1$8s", Integer.toBinaryString(flags())).replace(' ', '0'); sb.append("STATUS Message{") .append("frame_length=").append(frameLength()) .append(" version=").append(version()) .append(" flags=").append(formattedFlags) .append(" type=").append(headerType()) .append(" session_id=").append(sessionId()) .append(" stream_id=").append(streamId()) .append(" consumption_term_id=").append(consumptionTermId()) .append(" consumption_term_offset=").append(consumptionTermOffset()) .append(" receiver_window_length=").append(receiverWindowLength()) .append("}"); return sb.toString(); } }
private static void dissect(final StatusMessageFlyweight msg, final StringBuilder builder) { builder .append("SM ") .append(msg.flags()) .append(" len ") .append(msg.frameLength()) .append(' ') .append(msg.sessionId()) .append(':') .append(msg.streamId()) .append(':') .append(msg.consumptionTermId()) .append(" @") .append(msg.consumptionTermOffset()) .append(' ') .append(msg.receiverWindowLength()) .append(' ') .append(msg.receiverId()); }
/** * Set the Application Specific Feedback for the Status Message. * * @param source of the feedback to set * @param offset of the feedback in the source * @param length of the feedback in bytes * @return flyweight */ public StatusMessageFlyweight applicationSpecificFeedback(final byte[] source, final int offset, final int length) { frameLength(HEADER_LENGTH + length); putBytes(APP_SPECIFIC_FEEDBACK_FIELD_OFFSET, source, offset, length); return this; }
public void sendSetupElicitingStatusMessage( final int transportIndex, final InetSocketAddress controlAddress, final int sessionId, final int streamId) { if (!isClosed) { smBuffer.clear(); statusMessageFlyweight .sessionId(sessionId) .streamId(streamId) .consumptionTermId(0) .consumptionTermOffset(0) .receiverWindowLength(0) .flags(SEND_SETUP_FLAG); send(smBuffer, StatusMessageFlyweight.HEADER_LENGTH, transportIndex, controlAddress); } }
/** * {@inheritDoc} */ public long onStatusMessage( final StatusMessageFlyweight flyweight, final InetSocketAddress receiverAddress, final long senderLimit, final int initialTermId, final int positionBitsToShift, final long timeNs) { final long position = computePosition( flyweight.consumptionTermId(), flyweight.consumptionTermOffset(), positionBitsToShift, initialTermId); lastPosition = Math.max(lastPosition, position); timeOfLastStatusMessage = timeNs; return Math.max(senderLimit, position + flyweight.receiverWindowLength()); }
sendChannelEndpoint.registerForRead(controlTransportPoller); statusMessage.wrap(buffer); statusMessage .streamId(STREAM_ID) .sessionId(SESSION_ID) .consumptionTermId(TERM_ID) .receiverWindowLength(1000) .consumptionTermOffset(0) .version(HeaderFlyweight.CURRENT_VERSION) .flags((short)0) .headerType(HeaderFlyweight.HDR_TYPE_SM) .frameLength(StatusMessageFlyweight.HEADER_LENGTH); byteBuffer.position(0).limit(statusMessage.frameLength());
flyweight.consumptionTermId(), flyweight.consumptionTermOffset(), positionBitsToShift, initialTermId); final long windowLength = flyweight.receiverWindowLength(); final long receiverId = flyweight.receiverId(); boolean isExisting = false; long minPosition = Long.MAX_VALUE;
statusHeader.wrap(new UnsafeBuffer(rcvBuffer)); assertThat(statusHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SM)); assertThat(statusHeader.streamId(), is(STREAM_ID)); assertThat(statusHeader.sessionId(), is(SESSION_ID)); assertThat(statusHeader.consumptionTermId(), is(ACTIVE_TERM_ID)); assertThat(statusHeader.frameLength(), is(StatusMessageFlyweight.HEADER_LENGTH));
final InetSocketAddress srcAddress) final int sessionId = msg.sessionId(); final int streamId = msg.streamId(); final NetworkPublication publication = publicationBySessionAndStreamId.get(sessionId, streamId); if (0 == sessionId && 0 == streamId && SEND_SETUP_FLAG == (msg.flags() & SEND_SETUP_FLAG)) if (SEND_SETUP_FLAG == (msg.flags() & SEND_SETUP_FLAG))
statusMessageFlyweight = new StatusMessageFlyweight(smBuffer); .applicationSpecificFeedback(applicationSpecificFeedback, 0, applicationSpecificFeedback.length) .receiverId(receiverId) .version(HeaderFlyweight.CURRENT_VERSION) .headerType(HeaderFlyweight.HDR_TYPE_SM) .frameLength(StatusMessageFlyweight.HEADER_LENGTH + applicationSpecificFeedback.length);
/** * Retrieve the Application Specific Feedback (if present) from the Status Message. * * @param destination to store the feedback * @return the number of bytes in the feedback copied into the destination */ public int applicationSpecificFeedback(final byte[] destination) { final int frameLength = frameLength(); int result = 0; if (frameLength > HEADER_LENGTH) { if (frameLength > capacity()) { throw new AeronException(String.format( "SM application specific feedback (%d) is truncated (%d)", frameLength - HEADER_LENGTH, capacity() - HEADER_LENGTH)); } final int copyLength = Math.min(destination.length, frameLength - HEADER_LENGTH); getBytes(APP_SPECIFIC_FEEDBACK_FIELD_OFFSET, destination, 0, copyLength); result = copyLength; } return result; }
public void onStatusMessage( final StatusMessageFlyweight msg, final UnsafeBuffer buffer, final int length, final InetSocketAddress srcAddress) { if (!controlLossGenerator.shouldDropFrame(srcAddress, msg, msg.frameLength())) { super.onStatusMessage(msg, buffer, length, srcAddress); } }
void onStatusMessage(final StatusMessageFlyweight msg, final InetSocketAddress address) { final long nowNs = nanoClock.nanoTime(); final ArrayList<Destination> destinations = this.destinations; boolean isExisting = false; final long receiverId = msg.receiverId(); for (int i = 0, size = destinations.size(); i < size; i++) { final Destination destination = destinations.get(i); if (receiverId == destination.receiverId && address.getPort() == destination.port) { destination.timeOfLastActivityNs = nowNs; isExisting = true; break; } } if (!isExisting) { destinations.add(new Destination(nowNs, receiverId, address)); } }
public void sendStatusMessage( final ImageConnection[] controlAddresses, final int sessionId, final int streamId, final int termId, final int termOffset, final int window, final short flags) { if (!isClosed) { smBuffer.clear(); statusMessageFlyweight .sessionId(sessionId) .streamId(streamId) .consumptionTermId(termId) .consumptionTermOffset(termOffset) .receiverWindowLength(window) .flags(flags); send(smBuffer, StatusMessageFlyweight.HEADER_LENGTH, controlAddresses); } }
/** * {@inheritDoc} */ public long onStatusMessage( final StatusMessageFlyweight flyweight, final InetSocketAddress receiverAddress, final long senderLimit, final int initialTermId, final int positionBitsToShift, final long timeNs) { final long position = computePosition( flyweight.consumptionTermId(), flyweight.consumptionTermOffset(), positionBitsToShift, initialTermId); lastPosition = Math.max(lastPosition, position); timeOfLastStatusMessage = timeNs; return Math.max(senderLimit, position + flyweight.receiverWindowLength()); }
flyweight.consumptionTermId(), flyweight.consumptionTermOffset(), positionBitsToShift, initialTermId); final long windowLength = flyweight.receiverWindowLength(); final long receiverId = flyweight.receiverId(); final boolean isFromPreferred = isFromPreferred(flyweight); final long lastPositionPlusWindow = position + windowLength;
final InetSocketAddress srcAddress) final int sessionId = msg.sessionId(); final int streamId = msg.streamId(); final NetworkPublication publication = publicationBySessionAndStreamId.get(sessionId, streamId); if (0 == sessionId && 0 == streamId && SEND_SETUP_FLAG == (msg.flags() & SEND_SETUP_FLAG)) if (SEND_SETUP_FLAG == (msg.flags() & SEND_SETUP_FLAG))
statusMessageFlyweight = new StatusMessageFlyweight(smBuffer); .applicationSpecificFeedback(applicationSpecificFeedback, 0, applicationSpecificFeedback.length) .receiverId(receiverId) .version(HeaderFlyweight.CURRENT_VERSION) .headerType(HeaderFlyweight.HDR_TYPE_SM) .frameLength(StatusMessageFlyweight.HEADER_LENGTH + applicationSpecificFeedback.length);
/** * Retrieve the Application Specific Feedback (if present) from the Status Message. * * @param destination to store the feedback * @return the number of bytes in the feedback copied into the destination */ public int applicationSpecificFeedback(final byte[] destination) { final int frameLength = frameLength(); int result = 0; if (frameLength > HEADER_LENGTH) { if (frameLength > capacity()) { throw new AeronException(String.format( "SM application specific feedback (%d) is truncated (%d)", frameLength - HEADER_LENGTH, capacity() - HEADER_LENGTH)); } final int copyLength = Math.min(destination.length, frameLength - HEADER_LENGTH); getBytes(APP_SPECIFIC_FEEDBACK_FIELD_OFFSET, destination, 0, copyLength); result = copyLength; } return result; }
/** * Set the Application Specific Feedback for the Status Message. * * @param source of the feedback to set * @param offset of the feedback in the source * @param length of the feedback in bytes * @return flyweight */ public StatusMessageFlyweight applicationSpecificFeedback(final byte[] source, final int offset, final int length) { frameLength(HEADER_LENGTH + length); putBytes(APP_SPECIFIC_FEEDBACK_FIELD_OFFSET, source, offset, length); return this; }