本文整理汇总了Java中org.agrona.concurrent.UnsafeBuffer.getInt方法的典型用法代码示例。如果您正苦于以下问题:Java UnsafeBuffer.getInt方法的具体用法?Java UnsafeBuffer.getInt怎么用?Java UnsafeBuffer.getInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.agrona.concurrent.UnsafeBuffer
的用法示例。
在下文中一共展示了UnsafeBuffer.getInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifySendDescriptor
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
private Answer<Object> verifySendDescriptor(final MutableLong counter)
{
return (invocation) ->
{
final UnsafeBuffer b = invocation.getArgument(1);
wrapDescriptorDecoder(recordingDescriptorDecoder, b);
final int i = counter.intValue();
assertThat(recordingDescriptorDecoder.recordingId(), is(matchingRecordingIds[i]));
counter.set(i + 1);
return b.getInt(0);
};
}
示例2: verifySendDescriptor
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
private Answer<Object> verifySendDescriptor(final MutableLong counter)
{
return (invocation) ->
{
final UnsafeBuffer b = invocation.getArgument(1);
wrapDescriptorDecoder(recordingDescriptorDecoder, b);
final int i = counter.intValue();
assertThat(recordingDescriptorDecoder.recordingId(), is(recordingIds[i]));
counter.set(i + 1);
return b.getInt(0);
};
}
示例3: tryFillGap
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
* Try to gap fill the current term at a given offset if the gap contains no data.
* <p>
* Note: the gap offset plus gap length must end on a {@link FrameDescriptor#FRAME_ALIGNMENT} boundary.
*
* @param logMetaDataBuffer containing the default headers
* @param termBuffer to gap fill
* @param termId for the current term.
* @param gapOffset to fill from
* @param gapLength to length of the gap.
* @return true if the gap has been filled with a padding record or false if data found.
*/
public static boolean tryFillGap(
final UnsafeBuffer logMetaDataBuffer,
final UnsafeBuffer termBuffer,
final int termId,
final int gapOffset,
final int gapLength)
{
int offset = (gapOffset + gapLength) - FRAME_ALIGNMENT;
while (offset >= gapOffset)
{
if (0 != termBuffer.getInt(offset))
{
return false;
}
offset -= FRAME_ALIGNMENT;
}
applyDefaultHeader(logMetaDataBuffer, termBuffer, gapOffset);
frameType(termBuffer, gapOffset, HDR_TYPE_PAD);
frameTermOffset(termBuffer, gapOffset);
frameTermId(termBuffer, gapOffset, termId);
frameLengthOrdered(termBuffer, gapOffset, gapLength);
return true;
}
示例4: insert
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
* Insert a packet of frames into the log at the appropriate termOffset as indicated by the term termOffset header.
* <p>
* If the packet has already been inserted then this is a noop.
*
* @param termBuffer into which the packet should be inserted.
* @param termOffset in the term at which the packet should be inserted.
* @param packet containing a sequence of frames.
* @param length of the sequence of frames in bytes.
*/
public static void insert(
final UnsafeBuffer termBuffer, final int termOffset, final UnsafeBuffer packet, final int length)
{
if (0 == termBuffer.getInt(termOffset))
{
termBuffer.putBytes(termOffset + HEADER_LENGTH, packet, HEADER_LENGTH, length - HEADER_LENGTH);
termBuffer.putLong(termOffset + 24, packet.getLong(24));
termBuffer.putLong(termOffset + 16, packet.getLong(16));
termBuffer.putLong(termOffset + 8, packet.getLong(8));
termBuffer.putLongOrdered(termOffset, packet.getLong(0));
}
}
示例5: blockPoll
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
* Poll for new messages in a stream. If new messages are found beyond the last consumed position then they
* will be delivered to the {@link BlockHandler} up to a limited number of bytes.
*
* @param blockHandler to which block is delivered.
* @param blockLengthLimit up to which a block may be in length.
* @return the number of bytes that have been consumed.
*/
public int blockPoll(final BlockHandler blockHandler, final int blockLengthLimit)
{
if (isClosed)
{
return 0;
}
final long position = subscriberPosition.get();
final int termOffset = (int)position & termLengthMask;
final UnsafeBuffer termBuffer = activeTermBuffer(position);
final int limit = Math.min(termOffset + blockLengthLimit, termBuffer.capacity());
final int resultingOffset = TermBlockScanner.scan(termBuffer, termOffset, limit);
final int bytesConsumed = resultingOffset - termOffset;
if (resultingOffset > termOffset)
{
try
{
final int termId = termBuffer.getInt(termOffset + TERM_ID_FIELD_OFFSET, LITTLE_ENDIAN);
blockHandler.onBlock(termBuffer, termOffset, bytesConsumed, sessionId, termId);
}
catch (final Throwable t)
{
errorHandler.onError(t);
}
finally
{
subscriberPosition.setOrdered(position + bytesConsumed);
}
}
return bytesConsumed;
}
示例6: rawPoll
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
* Poll for new messages in a stream. If new messages are found beyond the last consumed position then they
* will be delivered to the {@link RawBlockHandler} up to a limited number of bytes.
* <p>
* This method is useful for operations like bulk archiving a stream to file.
*
* @param rawBlockHandler to which block is delivered.
* @param blockLengthLimit up to which a block may be in length.
* @return the number of bytes that have been consumed.
*/
public int rawPoll(final RawBlockHandler rawBlockHandler, final int blockLengthLimit)
{
if (isClosed)
{
return 0;
}
final long position = subscriberPosition.get();
final int termOffset = (int)position & termLengthMask;
final int activeIndex = indexByPosition(position, positionBitsToShift);
final UnsafeBuffer termBuffer = termBuffers[activeIndex];
final int capacity = termBuffer.capacity();
final int limit = Math.min(termOffset + blockLengthLimit, capacity);
final int resultingOffset = TermBlockScanner.scan(termBuffer, termOffset, limit);
final int length = resultingOffset - termOffset;
if (resultingOffset > termOffset)
{
try
{
final long fileOffset = ((long)capacity * activeIndex) + termOffset;
final int termId = termBuffer.getInt(termOffset + TERM_ID_FIELD_OFFSET, LITTLE_ENDIAN);
rawBlockHandler.onBlock(
logBuffers.fileChannel(), fileOffset, termBuffer, termOffset, length, sessionId, termId);
}
catch (final Throwable t)
{
errorHandler.onError(t);
}
finally
{
subscriberPosition.setOrdered(position + length);
}
}
return length;
}
示例7: saveErrorLog
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
* Read the error log to a given {@link PrintStream}
*
* @param out to write the error log contents to.
* @param cncByteBuffer containing the error log.
* @return the number of observations from the error log.
*/
public int saveErrorLog(final PrintStream out, final MappedByteBuffer cncByteBuffer)
{
if (null == cncByteBuffer)
{
return 0;
}
final UnsafeBuffer cncMetaDataBuffer = CncFileDescriptor.createMetaDataBuffer(cncByteBuffer);
final int cncVersion = cncMetaDataBuffer.getInt(CncFileDescriptor.cncVersionOffset(0));
if (CNC_VERSION != cncVersion)
{
throw new IllegalStateException(
"Aeron CnC version does not match: required=" + CNC_VERSION + " version=" + cncVersion);
}
final AtomicBuffer buffer = CncFileDescriptor.createErrorLogBuffer(cncByteBuffer, cncMetaDataBuffer);
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
final ErrorConsumer errorConsumer = (count, firstTimestamp, lastTimestamp, ex) ->
formatError(out, dateFormat, count, firstTimestamp, lastTimestamp, ex);
final int distinctErrorCount = ErrorLogReader.read(buffer, errorConsumer);
out.format("%n%d distinct errors observed.%n", distinctErrorCount);
return distinctErrorCount;
}
示例8: descriptorLength
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
static int descriptorLength(final UnsafeBuffer descriptorBuffer)
{
return descriptorBuffer.getInt(RecordingDescriptorHeaderDecoder.lengthEncodingOffset(), BYTE_ORDER);
}
示例9: sessionId
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
public static int sessionId(final UnsafeBuffer termBuffer, final int frameOffset)
{
return termBuffer.getInt(frameOffset + SESSION_ID_FIELD_OFFSET, LITTLE_ENDIAN);
}
示例10: streamId
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
public static int streamId(final UnsafeBuffer termBuffer, final int frameOffset)
{
return termBuffer.getInt(frameOffset + STREAM_ID_FIELD_OFFSET, LITTLE_ENDIAN);
}
示例11: termId
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
public static int termId(final UnsafeBuffer termBuffer, final int frameOffset)
{
return termBuffer.getInt(frameOffset + TERM_ID_FIELD_OFFSET, LITTLE_ENDIAN);
}
示例12: termOffset
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
public static int termOffset(final UnsafeBuffer termBuffer, final int frameOffset)
{
return termBuffer.getInt(frameOffset + TERM_OFFSET_FIELD_OFFSET, LITTLE_ENDIAN);
}
示例13: isHeartbeat
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
* Is the frame at data frame at the beginning of packet a heartbeat message?
*
* @param packet containing the data frame.
* @param length of the data frame.
* @return true if a heartbeat otherwise false.
*/
public static boolean isHeartbeat(final UnsafeBuffer packet, final int length)
{
return length == HEADER_LENGTH && packet.getInt(0) == 0;
}
示例14: frameLength
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
* Get the length of a frame from the header.
*
* @param buffer containing the frame.
* @param termOffset at which a frame begins.
* @return the value for the frame length.
*/
public static int frameLength(final UnsafeBuffer buffer, final int termOffset)
{
return buffer.getInt(termOffset, LITTLE_ENDIAN);
}
示例15: initialTermId
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
* Get the value of the initial Term id used for this log.
*
* @param logMetaDataBuffer containing the meta data.
* @return the value of the initial Term id used for this log.
*/
public static int initialTermId(final UnsafeBuffer logMetaDataBuffer)
{
return logMetaDataBuffer.getInt(LOG_INITIAL_TERM_ID_OFFSET);
}