本文整理汇总了Java中org.agrona.BitUtil类的典型用法代码示例。如果您正苦于以下问题:Java BitUtil类的具体用法?Java BitUtil怎么用?Java BitUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BitUtil类属于org.agrona包,在下文中一共展示了BitUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: shouldUpdatePositionInWrite
import org.agrona.BitUtil; //导入依赖的package包/类
@Test
public void shouldUpdatePositionInWrite() throws Exception
{
int totalWrittenBytes = 0;
for (int i = 0; i < MESSAGE_COUNT; i++)
{
MESSAGE_BUFFER.putInt(i);
MESSAGE_BUFFER.flip();
final int writtenBytes = journalling.write(MESSAGE_BUFFER);
totalWrittenBytes += writtenBytes;
MESSAGE_BUFFER.clear();
assertTrue(writtenBytes == BitUtil.SIZE_OF_INT);
assertTrue(journalling.position() == totalWrittenBytes);
}
}
开发者ID:canepat,项目名称:Helios,代码行数:18,代码来源:AbstractJournallingTest.java
示例2: shouldTriggerSnapshotDepletionHandlerOnJournalDepletion
import org.agrona.BitUtil; //导入依赖的package包/类
@Test
public void shouldTriggerSnapshotDepletionHandlerOnJournalDepletion() throws Exception
{
final boolean[] lastJournalReached = { false };
journalling.depletionHandler((journalling) -> lastJournalReached[0] = true);
int totalWrittenBytes = 0;
while (!lastJournalReached[0])
{
MESSAGE_BUFFER.putInt(0);
MESSAGE_BUFFER.flip();
final int writtenBytes = journalling.write(MESSAGE_BUFFER);
totalWrittenBytes += writtenBytes;
MESSAGE_BUFFER.clear();
assertTrue(writtenBytes == BitUtil.SIZE_OF_INT);
}
assertTrue(totalWrittenBytes == (JOURNAL_FILE_SIZE+BitUtil.SIZE_OF_INT));
journalling.depletionHandler(null);
}
开发者ID:canepat,项目名称:Helios,代码行数:24,代码来源:AbstractJournallingTest.java
示例3: EncodedData2ObjectHashMap
import org.agrona.BitUtil; //导入依赖的package包/类
public EncodedData2ObjectHashMap(
final int initialCapacity,
final float loadFactor,
final int keyLengthInBytes,
final BiConsumer<K, ByteBuffer> keyEncoder,
final ToIntFunction<ByteBuffer> hashFunction,
final K nullKey)
{
this.capacity = BitUtil.findNextPositivePowerOfTwo(initialCapacity);
this.loadFactor = loadFactor;
this.keyLengthInBytes = keyLengthInBytes;
this.keyBuffer = ByteBuffer.allocate(keyLengthInBytes);
this.nullKeyBuffer = ByteBuffer.allocate(keyLengthInBytes);
this.keyEncoder = keyEncoder;
this.keySpace = ByteBuffer.allocate(keyLengthInBytes * capacity);
this.values = new Object[capacity];
this.hashFunction = hashFunction;
keyEncoder.accept(nullKey, nullKeyBuffer);
fillKeySpaceWithNullKey(keySpace, capacity);
if(loadFactor >= 1f)
{
throw new IllegalArgumentException("loadFactor must be < 1");
}
resizeThreshold = (int) (capacity * loadFactor);
}
开发者ID:LMAX-Exchange,项目名称:angler,代码行数:27,代码来源:EncodedData2ObjectHashMap.java
示例4: validateFragment1
import org.agrona.BitUtil; //导入依赖的package包/类
@SuppressWarnings("SameReturnValue")
private boolean validateFragment1(final UnsafeBuffer buffer, final int offset, final int length)
{
final DataHeaderFlyweight headerFlyweight = new DataHeaderFlyweight();
headerFlyweight.wrap(buffer.addressOffset() + offset - HEADER_LENGTH, HEADER_LENGTH);
if (headerFlyweight.headerType() == HDR_TYPE_PAD)
{
return true;
}
final int expectedLength = messageLengths[messageCount] - HEADER_LENGTH;
assertThat("on fragment[" + messageCount + "]", length, is(expectedLength));
assertThat(buffer.getInt(offset), is(messageCount));
assertThat(buffer.getByte(offset + 4), is((byte)'z'));
remaining -= BitUtil.align(messageLengths[messageCount], FrameDescriptor.FRAME_ALIGNMENT);
messageCount++;
return true;
}
开发者ID:real-logic,项目名称:aeron,代码行数:21,代码来源:ArchiveTest.java
示例5: checkTermLength
import org.agrona.BitUtil; //导入依赖的package包/类
/**
* Check that term length is valid and alignment is valid.
*
* @param termLength to be checked.
* @throws IllegalStateException if the length is not as expected.
*/
public static void checkTermLength(final int termLength)
{
if (termLength < TERM_MIN_LENGTH)
{
throw new IllegalStateException(
"Term length less than min length of " + TERM_MIN_LENGTH + ": length=" + termLength);
}
if (termLength > TERM_MAX_LENGTH)
{
throw new IllegalStateException(
"Term length more than max length of " + TERM_MAX_LENGTH + ": length=" + termLength);
}
if (!BitUtil.isPowerOfTwo(termLength))
{
throw new IllegalStateException("Term length not a power of 2: length=" + termLength);
}
}
开发者ID:real-logic,项目名称:aeron,代码行数:26,代码来源:LogBufferDescriptor.java
示例6: checkPageSize
import org.agrona.BitUtil; //导入依赖的package包/类
/**
* Check that page size is valid and alignment is valid.
*
* @param pageSize to be checked.
* @throws IllegalStateException if the size is not as expected.
*/
public static void checkPageSize(final int pageSize)
{
if (pageSize < PAGE_MIN_SIZE)
{
throw new IllegalStateException(
"Page size less than min size of " + PAGE_MIN_SIZE + ": page size=" + pageSize);
}
if (pageSize > PAGE_MAX_SIZE)
{
throw new IllegalStateException(
"Page size more than max size of " + PAGE_MAX_SIZE + ": page size=" + pageSize);
}
if (!BitUtil.isPowerOfTwo(pageSize))
{
throw new IllegalStateException("Page size not a power of 2: page size=" + pageSize);
}
}
开发者ID:real-logic,项目名称:aeron,代码行数:26,代码来源:LogBufferDescriptor.java
示例7: shouldInsertLastFrameIntoBuffer
import org.agrona.BitUtil; //导入依赖的package包/类
@Test
public void shouldInsertLastFrameIntoBuffer()
{
final int frameLength = BitUtil.align(256, FRAME_ALIGNMENT);
final int srcOffset = 0;
final int tail = TERM_BUFFER_CAPACITY - frameLength;
final int termOffset = tail;
final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocateDirect(frameLength));
packet.putShort(typeOffset(srcOffset), (short)PADDING_FRAME_TYPE, LITTLE_ENDIAN);
packet.putInt(srcOffset, frameLength, LITTLE_ENDIAN);
TermRebuilder.insert(termBuffer, termOffset, packet, frameLength);
verify(termBuffer).putBytes(
tail + HEADER_LENGTH, packet, srcOffset + HEADER_LENGTH, frameLength - HEADER_LENGTH);
}
开发者ID:real-logic,项目名称:aeron,代码行数:17,代码来源:TermRebuilderTest.java
示例8: shouldFillAfterAGap
import org.agrona.BitUtil; //导入依赖的package包/类
@Test
public void shouldFillAfterAGap()
{
final int frameLength = 50;
final int alignedFrameLength = BitUtil.align(frameLength, FRAME_ALIGNMENT);
final int srcOffset = 0;
final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocateDirect(alignedFrameLength));
final int termOffset = alignedFrameLength * 2;
TermRebuilder.insert(termBuffer, termOffset, packet, alignedFrameLength);
verify(termBuffer).putBytes(
(alignedFrameLength * 2) + HEADER_LENGTH,
packet,
srcOffset + HEADER_LENGTH,
alignedFrameLength - HEADER_LENGTH);
}
开发者ID:real-logic,项目名称:aeron,代码行数:18,代码来源:TermRebuilderTest.java
示例9: shouldFillGapButNotMoveTailOrHwm
import org.agrona.BitUtil; //导入依赖的package包/类
@Test
public void shouldFillGapButNotMoveTailOrHwm()
{
final int frameLength = 50;
final int alignedFrameLength = BitUtil.align(frameLength, FRAME_ALIGNMENT);
final int srcOffset = 0;
final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocateDirect(alignedFrameLength));
final int termOffset = alignedFrameLength * 2;
TermRebuilder.insert(termBuffer, termOffset, packet, alignedFrameLength);
verify(termBuffer).putBytes(
(alignedFrameLength * 2) + HEADER_LENGTH,
packet,
srcOffset + HEADER_LENGTH,
alignedFrameLength - HEADER_LENGTH);
}
开发者ID:real-logic,项目名称:aeron,代码行数:18,代码来源:TermRebuilderTest.java
示例10: shouldReadBlockOfThreeMessagesThatFillBuffer
import org.agrona.BitUtil; //导入依赖的package包/类
@Test
public void shouldReadBlockOfThreeMessagesThatFillBuffer()
{
final int offset = 0;
final int limit = termBuffer.capacity();
final int messageLength = 50;
final int alignedMessageLength = BitUtil.align(messageLength, FRAME_ALIGNMENT);
final int thirdMessageLength = limit - (alignedMessageLength * 2);
when(termBuffer.getIntVolatile(lengthOffset(offset))).thenReturn(messageLength);
when(termBuffer.getIntVolatile(lengthOffset(alignedMessageLength))).thenReturn(messageLength);
when(termBuffer.getIntVolatile(lengthOffset(alignedMessageLength * 2))).thenReturn(thirdMessageLength);
final int newOffset = TermBlockScanner.scan(termBuffer, offset, limit);
assertThat(newOffset, is(limit));
}
开发者ID:real-logic,项目名称:aeron,代码行数:18,代码来源:TermBlockScannerTest.java
示例11: shouldReadBlockOfTwoMessagesBecauseOfLimit
import org.agrona.BitUtil; //导入依赖的package包/类
@Test
public void shouldReadBlockOfTwoMessagesBecauseOfLimit()
{
final int offset = 0;
final int messageLength = 50;
final int alignedMessageLength = BitUtil.align(messageLength, FRAME_ALIGNMENT);
final int limit = (alignedMessageLength * 2) + 1;
when(termBuffer.getIntVolatile(lengthOffset(offset))).thenReturn(messageLength);
when(termBuffer.getIntVolatile(lengthOffset(alignedMessageLength))).thenReturn(messageLength);
when(termBuffer.getIntVolatile(lengthOffset(alignedMessageLength * 2))).thenReturn(messageLength);
final int newOffset = TermBlockScanner.scan(termBuffer, offset, limit);
assertThat(newOffset, is(alignedMessageLength * 2));
}
开发者ID:real-logic,项目名称:aeron,代码行数:17,代码来源:TermBlockScannerTest.java
示例12: validatePageSize
import org.agrona.BitUtil; //导入依赖的package包/类
/**
* Validate that page size is valid and alignment is valid.
*
* @param pageSize to be checked.
* @throws ConfigurationException if the size is not as expected.
*/
static void validatePageSize(final int pageSize)
{
if (pageSize < PAGE_MIN_SIZE)
{
throw new ConfigurationException(
"Page size less than min size of " + PAGE_MIN_SIZE + ": " + pageSize);
}
if (pageSize > PAGE_MAX_SIZE)
{
throw new ConfigurationException(
"Page size greater than max size of " + PAGE_MAX_SIZE + ": " + pageSize);
}
if (!BitUtil.isPowerOfTwo(pageSize))
{
throw new ConfigurationException("Page size not a power of 2: " + pageSize);
}
}
开发者ID:real-logic,项目名称:aeron,代码行数:26,代码来源:Configuration.java
示例13: shouldGetByteArrayFromBuffer
import org.agrona.BitUtil; //导入依赖的package包/类
@Theory
public void shouldGetByteArrayFromBuffer(final AtomicBuffer buffer)
{
final byte[] testArray = { 'H', 'e', 'l', 'l', 'o' };
int i = INDEX;
for (final byte v : testArray)
{
buffer.putByte(i, v);
i += BitUtil.SIZE_OF_BYTE;
}
final byte[] result = new byte[testArray.length];
buffer.getBytes(INDEX, result);
assertThat(result, is(testArray));
}
开发者ID:real-logic,项目名称:agrona,代码行数:18,代码来源:AtomicBufferTest.java
示例14: run
import org.agrona.BitUtil; //导入依赖的package包/类
public void run()
{
try
{
barrier.await();
}
catch (final Exception ignore)
{
}
final int length = BitUtil.SIZE_OF_INT * 2;
final int repsValueOffset = BitUtil.SIZE_OF_INT;
final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[1024]);
srcBuffer.putInt(0, producerId);
for (int i = 0; i < reps; i++)
{
srcBuffer.putInt(repsValueOffset, i);
while (!ringBuffer.write(MSG_TYPE_ID, srcBuffer, 0, length))
{
Thread.yield();
}
}
}
开发者ID:real-logic,项目名称:agrona,代码行数:27,代码来源:ManyToOneRingBufferConcurrentTest.java
示例15: getMediaDriverContext
import org.agrona.BitUtil; //导入依赖的package包/类
/**
* Get a media driver context
* for sending ndarrays
* based on a given length
* where length is the length (number of elements)
* in the ndarrays hat are being sent
* @param length the length to based the ipc length
* @return the media driver context based on the given length
*/
public static MediaDriver.Context getMediaDriverContext(int length) {
//length of array * sizeof(float)
int ipcLength = length * 16;
//padding for NDArrayMessage
ipcLength += 64;
//must be a power of 2
ipcLength *= 2;
//ipc length must be positive power of 2
while (!BitUtil.isPowerOfTwo(ipcLength))
ipcLength += 2;
// System.setProperty("aeron.term.buffer.size",String.valueOf(ipcLength));
final MediaDriver.Context ctx =
new MediaDriver.Context().threadingMode(ThreadingMode.SHARED).dirsDeleteOnStart(true)
/* .ipcTermBufferLength(ipcLength)
.publicationTermBufferLength(ipcLength)
.maxTermBufferLength(ipcLength)*/
.conductorIdleStrategy(new BusySpinIdleStrategy())
.receiverIdleStrategy(new BusySpinIdleStrategy())
.senderIdleStrategy(new BusySpinIdleStrategy());
return ctx;
}
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:31,代码来源:AeronUtil.java
示例16: AbstractJournalling
import org.agrona.BitUtil; //导入依赖的package包/类
protected AbstractJournalling(final long fileSize, final int pageSize, final JournalAllocator<T> journalAllocator)
{
Check.enforce(fileSize > 0, "Journal file size must be positive");
Check.enforce(BitUtil.isPowerOfTwo(pageSize), "Journal page size must be power of 2");
Check.enforce(fileSize % pageSize == 0, "Journal file size must be multiple of journal page size");
this.fileSize = fileSize;
this.pageSize = pageSize;
this.journalAllocator = journalAllocator;
}
开发者ID:canepat,项目名称:Helios,代码行数:11,代码来源:AbstractJournalling.java
示例17: checkZeroedAllocation
import org.agrona.BitUtil; //导入依赖的package包/类
public static void checkZeroedAllocation(final Path journalPath, final long journalSize)
{
try
{
FileChannel journal = FileChannel.open(journalPath, StandardOpenOption.READ);
assertThat(journal.size(), is(journalSize));
final ByteBuffer readBuffer = ByteBuffer.allocate(JournalAllocator.BLOCK_SIZE);
while (journal.read(readBuffer) != -1)
{
readBuffer.flip();
while (readBuffer.remaining() >= BitUtil.SIZE_OF_INT)
{
int readInt = readBuffer.getInt();
assertThat(readInt, anyOf(is(0xDEADCAFE), is(0x00000000)));
}
readBuffer.clear();
}
journal.close();
}
catch (IOException e)
{
throw new UncheckedIOException(e);
}
}
开发者ID:canepat,项目名称:Helios,代码行数:30,代码来源:FilePreallocatorTest.java
示例18: shouldSupportNullSnapshotDepletionHandlerOnJournalDepletion
import org.agrona.BitUtil; //导入依赖的package包/类
@Test
public void shouldSupportNullSnapshotDepletionHandlerOnJournalDepletion() throws Exception
{
int totalWrittenBytes = 0;
while (totalWrittenBytes < (JOURNAL_FILE_SIZE + BitUtil.SIZE_OF_INT))
{
MESSAGE_BUFFER.putInt(0);
MESSAGE_BUFFER.flip();
final int writtenBytes = journalling.write(MESSAGE_BUFFER);
totalWrittenBytes += writtenBytes;
MESSAGE_BUFFER.clear();
assertTrue(writtenBytes == BitUtil.SIZE_OF_INT);
}
}
开发者ID:canepat,项目名称:Helios,代码行数:16,代码来源:AbstractJournallingTest.java
示例19: shouldAllocateCacheAlignedDirectBufferWithSpecifiedCapacity
import org.agrona.BitUtil; //导入依赖的package包/类
@Test
public void shouldAllocateCacheAlignedDirectBufferWithSpecifiedCapacity()
{
final ByteBuffer buffer = DirectBufferAllocator.allocateCacheAligned(CAPACITY);
assertTrue(buffer.isDirect());
assertThat(buffer.capacity(), is(CAPACITY));
final long address = ((sun.nio.ch.DirectBuffer)buffer).address();
assertTrue(BitUtil.isAligned(address, BitUtil.CACHE_LINE_LENGTH));
}
开发者ID:canepat,项目名称:Helios,代码行数:12,代码来源:DirectBufferAllocatorTest.java
示例20: checkIndexFileSize
import org.agrona.BitUtil; //导入依赖的package包/类
static void checkIndexFileSize(final int indexFileSize)
{
if (!BitUtil.isPowerOfTwo(recordCapacity(indexFileSize)))
{
throw new IllegalStateException(
"IndexFileSize must be a positive power of 2 + INITIAL_RECORD_OFFSET: indexFileSize=" + indexFileSize);
}
}
开发者ID:real-logic,项目名称:artio,代码行数:9,代码来源:ReplayIndexDescriptor.java
注:本文中的org.agrona.BitUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论