本文整理汇总了Java中org.agrona.BitUtil.isPowerOfTwo方法的典型用法代码示例。如果您正苦于以下问题:Java BitUtil.isPowerOfTwo方法的具体用法?Java BitUtil.isPowerOfTwo怎么用?Java BitUtil.isPowerOfTwo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.agrona.BitUtil
的用法示例。
在下文中一共展示了BitUtil.isPowerOfTwo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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;
}
示例5: 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);
}
}
示例6: checkCapacity
import org.agrona.BitUtil; //导入方法依赖的package包/类
/**
* Check the the buffer capacity is the correct size.
*
* @param capacity to be checked.
* @throws IllegalStateException if the buffer capacity is not a power of 2.
*/
public static void checkCapacity(final int capacity)
{
if (!BitUtil.isPowerOfTwo(capacity))
{
final String msg = "Capacity must be a positive power of 2 + TRAILER_LENGTH: capacity=" + capacity;
throw new IllegalStateException(msg);
}
}
示例7: checkCapacity
import org.agrona.BitUtil; //导入方法依赖的package包/类
/**
* Check the the buffer capacity is the correct size (a power of 2 + {@link RingBufferDescriptor#TRAILER_LENGTH}).
*
* @param capacity to be checked.
* @throws IllegalStateException if the buffer capacity is incorrect.
*/
public static void checkCapacity(final int capacity)
{
if (!BitUtil.isPowerOfTwo(capacity - TRAILER_LENGTH))
{
final String msg = "Capacity must be a positive power of 2 + TRAILER_LENGTH: capacity=" + capacity;
throw new IllegalStateException(msg);
}
}