本文整理汇总了Java中io.aeron.protocol.HeaderFlyweight类的典型用法代码示例。如果您正苦于以下问题:Java HeaderFlyweight类的具体用法?Java HeaderFlyweight怎么用?Java HeaderFlyweight使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HeaderFlyweight类属于io.aeron.protocol包,在下文中一共展示了HeaderFlyweight类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldWriteCorrectValuesForGenericHeaderFields
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
@Test
public void shouldWriteCorrectValuesForGenericHeaderFields()
{
encodeHeader.wrap(aBuff);
encodeHeader.version((short)1);
encodeHeader.flags(DataHeaderFlyweight.BEGIN_AND_END_FLAGS);
encodeHeader.headerType(HeaderFlyweight.HDR_TYPE_DATA);
encodeHeader.frameLength(8);
// little endian
assertThat(buffer.get(0), is((byte)0x08));
assertThat(buffer.get(1), is((byte)0x00));
assertThat(buffer.get(2), is((byte)0x00));
assertThat(buffer.get(3), is((byte)0x00));
assertThat(buffer.get(4), is((byte)0x01));
assertThat(buffer.get(5), is((byte)0xC0));
assertThat(buffer.get(6), is((byte)HeaderFlyweight.HDR_TYPE_DATA));
assertThat(buffer.get(7), is((byte)0x00));
}
示例2: shouldReadAndWriteDataHeaderCorrectly
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
@Test
public void shouldReadAndWriteDataHeaderCorrectly()
{
encodeDataHeader.wrap(aBuff);
encodeDataHeader.version((short)1);
encodeDataHeader.flags(DataHeaderFlyweight.BEGIN_AND_END_FLAGS);
encodeDataHeader.headerType(HeaderFlyweight.HDR_TYPE_DATA);
encodeDataHeader.frameLength(DataHeaderFlyweight.HEADER_LENGTH);
encodeDataHeader.sessionId(0xdeadbeef);
encodeDataHeader.streamId(0x44332211);
encodeDataHeader.termId(0x99887766);
decodeDataHeader.wrap(aBuff);
assertThat(decodeDataHeader.version(), is((short)1));
assertThat(decodeDataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
assertThat(decodeDataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
assertThat(decodeDataHeader.frameLength(), is(DataHeaderFlyweight.HEADER_LENGTH));
assertThat(decodeDataHeader.sessionId(), is(0xdeadbeef));
assertThat(decodeDataHeader.streamId(), is(0x44332211));
assertThat(decodeDataHeader.termId(), is(0x99887766));
assertThat(decodeDataHeader.dataOffset(), is(DataHeaderFlyweight.HEADER_LENGTH));
}
示例3: shouldEncodeAndDecodeNakCorrectly
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
@Test
public void shouldEncodeAndDecodeNakCorrectly()
{
encodeNakHeader.wrap(aBuff);
encodeNakHeader.version((short)1);
encodeNakHeader.flags((byte)0);
encodeNakHeader.headerType(HeaderFlyweight.HDR_TYPE_NAK);
encodeNakHeader.frameLength(NakFlyweight.HEADER_LENGTH);
encodeNakHeader.sessionId(0xdeadbeef);
encodeNakHeader.streamId(0x44332211);
encodeNakHeader.termId(0x99887766);
encodeNakHeader.termOffset(0x22334);
encodeNakHeader.length(512);
decodeNakHeader.wrap(aBuff);
assertThat(decodeNakHeader.version(), is((short)1));
assertThat(decodeNakHeader.flags(), is((short)0));
assertThat(decodeNakHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_NAK));
assertThat(decodeNakHeader.frameLength(), is(NakFlyweight.HEADER_LENGTH));
assertThat(decodeNakHeader.sessionId(), is(0xdeadbeef));
assertThat(decodeNakHeader.streamId(), is(0x44332211));
assertThat(decodeNakHeader.termId(), is(0x99887766));
assertThat(decodeNakHeader.termOffset(), is(0x22334));
assertThat(decodeNakHeader.length(), is(512));
}
示例4: isValidFrame
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
/**
* Is the received frame valid. This method will do some basic checks on the header and can be
* overridden in a subclass for further validation.
*
* @param buffer containing the frame.
* @param length of the frame.
* @return true if the frame is believed valid otherwise false.
*/
public boolean isValidFrame(final UnsafeBuffer buffer, final int length)
{
boolean isFrameValid = true;
if (frameVersion(buffer, 0) != HeaderFlyweight.CURRENT_VERSION)
{
isFrameValid = false;
invalidPackets.increment();
}
else if (length < HeaderFlyweight.HEADER_LENGTH)
{
isFrameValid = false;
invalidPackets.increment();
}
return isFrameValid;
}
示例5: shouldSendSetupFrameOnChannelWhenTimeoutWithoutStatusMessage
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
@Test
public void shouldSendSetupFrameOnChannelWhenTimeoutWithoutStatusMessage()
{
sender.doWork();
assertThat(receivedFrames.size(), is(1));
currentTimestamp += Configuration.PUBLICATION_SETUP_TIMEOUT_NS - 1;
sender.doWork();
assertThat(receivedFrames.size(), is(1));
currentTimestamp += 10;
sender.doWork();
assertThat(receivedFrames.size(), is(2));
setupHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(setupHeader.frameLength(), is(SetupFlyweight.HEADER_LENGTH));
assertThat(setupHeader.initialTermId(), is(INITIAL_TERM_ID));
assertThat(setupHeader.activeTermId(), is(INITIAL_TERM_ID));
assertThat(setupHeader.streamId(), is(STREAM_ID));
assertThat(setupHeader.sessionId(), is(SESSION_ID));
assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));
assertThat(setupHeader.flags(), is((short)0));
assertThat(setupHeader.version(), is((short)HeaderFlyweight.CURRENT_VERSION));
}
示例6: shouldNotSendSetupFrameAfterReceivingStatusMessage
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
@Test
public void shouldNotSendSetupFrameAfterReceivingStatusMessage()
{
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(0);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(flowControl.onStatusMessage(msg, rcvAddress, ));
sender.doWork();
assertThat(receivedFrames.size(), is(1));
receivedFrames.remove();
currentTimestamp += Configuration.PUBLICATION_SETUP_TIMEOUT_NS + 10;
sender.doWork();
assertThat(receivedFrames.size(), is(1));
dataHeader.wrap(receivedFrames.remove());
assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA)); // heartbeat
assertThat(dataHeader.frameLength(), is(0));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
}
示例7: insertDataFrame
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
private void insertDataFrame(final int offset, final byte[] payload)
{
dataHeader
.termId(TERM_ID)
.streamId(STREAM_ID)
.sessionId(SESSION_ID)
.termOffset(offset)
.frameLength(payload.length + DataHeaderFlyweight.HEADER_LENGTH)
.headerType(HeaderFlyweight.HDR_TYPE_DATA)
.flags(DataHeaderFlyweight.BEGIN_AND_END_FLAGS)
.version(HeaderFlyweight.CURRENT_VERSION);
rcvBuffer.putBytes(dataHeader.dataOffset(), payload);
TermRebuilder.insert(termBuffer, offset, rcvBuffer, payload.length + DataHeaderFlyweight.HEADER_LENGTH);
}
示例8: addReceivedDataFrame
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
private void addReceivedDataFrame(final int msgNum)
{
dataHeader.wrap(rcvBuffer);
dataHeader.termId(TERM_ID)
.streamId(STREAM_ID)
.sessionId(SESSION_ID)
.termOffset(offsetOfFrame(msgNum))
.frameLength(MESSAGE_LENGTH)
.headerType(HeaderFlyweight.HDR_TYPE_DATA)
.flags(DataHeaderFlyweight.BEGIN_AND_END_FLAGS)
.version(HeaderFlyweight.CURRENT_VERSION);
rcvBuffer.putBytes(dataHeader.dataOffset(), DATA);
TermRebuilder.insert(termBuffer, offsetOfFrame(msgNum), rcvBuffer, MESSAGE_LENGTH);
}
示例9: shouldReadWhatIsWrittenToGenericHeaderFields
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
@Test
public void shouldReadWhatIsWrittenToGenericHeaderFields()
{
encodeHeader.wrap(aBuff);
encodeHeader.version((short)1);
encodeHeader.flags((short)0);
encodeHeader.headerType(HeaderFlyweight.HDR_TYPE_DATA);
encodeHeader.frameLength(8);
decodeHeader.wrap(aBuff);
assertThat(decodeHeader.version(), is((short)1));
assertThat(decodeHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
assertThat(decodeHeader.frameLength(), is(8));
}
示例10: shouldWriteAndReadMultipleFramesCorrectly
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
@Test
public void shouldWriteAndReadMultipleFramesCorrectly()
{
encodeHeader.wrap(aBuff);
encodeHeader.version((short)1);
encodeHeader.flags((short)0);
encodeHeader.headerType(HeaderFlyweight.HDR_TYPE_DATA);
encodeHeader.frameLength(8);
encodeHeader.wrap(aBuff, 8, aBuff.capacity() - 8);
encodeHeader.version((short)2);
encodeHeader.flags((short)0x01);
encodeHeader.headerType(HeaderFlyweight.HDR_TYPE_SM);
encodeHeader.frameLength(8);
decodeHeader.wrap(aBuff);
assertThat(decodeHeader.version(), is((short)1));
assertThat(decodeHeader.flags(), is((short)0));
assertThat(decodeHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
assertThat(decodeHeader.frameLength(), is(8));
decodeHeader.wrap(aBuff, 8, aBuff.capacity() - 8);
assertThat(decodeHeader.version(), is((short)2));
assertThat(decodeHeader.flags(), is((short)0x01));
assertThat(decodeHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SM));
assertThat(decodeHeader.frameLength(), is(8));
}
示例11: printError
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
/**
* Generic error handler that just prints message to stdout.
*
* @param channel for the error
* @param streamId for the error
* @param sessionId for the error, if source
* @param message indicating what the error was
* @param cause of the error
*/
public static void printError(
final String channel,
final int streamId,
final int sessionId,
final String message,
final HeaderFlyweight cause)
{
System.out.println(message);
}
示例12: NetworkPublicationThreadLocals
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
public NetworkPublicationThreadLocals()
{
final ByteBuffer byteBuffer = BufferUtil.allocateDirectAligned(192, BitUtil.CACHE_LINE_LENGTH);
byteBuffer.limit(DataHeaderFlyweight.HEADER_LENGTH);
heartbeatBuffer = byteBuffer.slice();
dataHeader = new DataHeaderFlyweight(heartbeatBuffer);
byteBuffer.limit(64 + SetupFlyweight.HEADER_LENGTH).position(64);
setupBuffer = byteBuffer.slice();
setupHeader = new SetupFlyweight(setupBuffer);
byteBuffer.limit(128 + RttMeasurementFlyweight.HEADER_LENGTH).position(128);
rttMeasurementBuffer = byteBuffer.slice();
rttMeasurementHeader = new RttMeasurementFlyweight(rttMeasurementBuffer);
dataHeader
.version(HeaderFlyweight.CURRENT_VERSION)
.flags((byte)DataHeaderFlyweight.BEGIN_AND_END_FLAGS)
.headerType(HeaderFlyweight.HDR_TYPE_DATA)
.frameLength(0);
setupHeader
.version(HeaderFlyweight.CURRENT_VERSION)
.headerType(HeaderFlyweight.HDR_TYPE_SETUP)
.frameLength(SetupFlyweight.HEADER_LENGTH);
rttMeasurementHeader
.version(HeaderFlyweight.CURRENT_VERSION)
.headerType(HeaderFlyweight.HDR_TYPE_RTTM)
.frameLength(RttMeasurementFlyweight.HEADER_LENGTH);
}
示例13: shouldSendSetupFrameAfterReceivingStatusMessageWithSetupBit
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
@Test
public void shouldSendSetupFrameAfterReceivingStatusMessageWithSetupBit()
{
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(
// flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));
final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
buffer.putBytes(0, PAYLOAD);
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);
sender.doWork();
assertThat(receivedFrames.size(), is(2)); // setup then data
receivedFrames.remove();
receivedFrames.remove();
publication.triggerSendSetupFrame();
sender.doWork();
assertThat(receivedFrames.size(), is(0)); // setup has been sent already, have to wait
currentTimestamp += Configuration.PUBLICATION_SETUP_TIMEOUT_NS + 10;
sender.doWork();
assertThat(receivedFrames.size(), is(1));
setupHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));
}
示例14: shouldBeAbleToSendOnChannel
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
@Test
public void shouldBeAbleToSendOnChannel()
{
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(
// flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));
final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
buffer.putBytes(0, PAYLOAD);
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);
sender.doWork();
assertThat(receivedFrames.size(), is(2));
setupHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));
dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
assertThat(dataHeader.streamId(), is(STREAM_ID));
assertThat(dataHeader.sessionId(), is(SESSION_ID));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
assertThat(dataHeader.version(), is((short)HeaderFlyweight.CURRENT_VERSION));
}
示例15: shouldNotSendUntilStatusMessageReceived
import io.aeron.protocol.HeaderFlyweight; //导入依赖的package包/类
@Test
public void shouldNotSendUntilStatusMessageReceived()
{
final UnsafeBuffer buffer = new UnsafeBuffer(ByteBuffer.allocateDirect(PAYLOAD.length));
buffer.putBytes(0, PAYLOAD);
termAppenders[0].appendUnfragmentedMessage(headerWriter, buffer, 0, PAYLOAD.length, null, INITIAL_TERM_ID);
sender.doWork();
assertThat(receivedFrames.size(), is(1));
setupHeader.wrap(receivedFrames.remove());
assertThat(setupHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_SETUP));
final StatusMessageFlyweight msg = mock(StatusMessageFlyweight.class);
when(msg.consumptionTermId()).thenReturn(INITIAL_TERM_ID);
when(msg.consumptionTermOffset()).thenReturn(0);
when(msg.receiverWindowLength()).thenReturn(ALIGNED_FRAME_LENGTH);
publication.onStatusMessage(msg, rcvAddress);
// publication.senderPositionLimit(
// flowControl.onStatusMessage(INITIAL_TERM_ID, 0, ALIGNED_FRAME_LENGTH, rcvAddress));
sender.doWork();
assertThat(receivedFrames.size(), is(1));
dataHeader.wrap(new UnsafeBuffer(receivedFrames.remove()));
assertThat(dataHeader.frameLength(), is(FRAME_LENGTH));
assertThat(dataHeader.termId(), is(INITIAL_TERM_ID));
assertThat(dataHeader.streamId(), is(STREAM_ID));
assertThat(dataHeader.sessionId(), is(SESSION_ID));
assertThat(dataHeader.termOffset(), is(offsetOfMessage(1)));
assertThat(dataHeader.headerType(), is(HeaderFlyweight.HDR_TYPE_DATA));
assertThat(dataHeader.flags(), is(DataHeaderFlyweight.BEGIN_AND_END_FLAGS));
assertThat(dataHeader.version(), is((short)HeaderFlyweight.CURRENT_VERSION));
}