本文整理汇总了Java中org.agrona.concurrent.UnsafeBuffer.getLongVolatile方法的典型用法代码示例。如果您正苦于以下问题:Java UnsafeBuffer.getLongVolatile方法的具体用法?Java UnsafeBuffer.getLongVolatile怎么用?Java UnsafeBuffer.getLongVolatile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.agrona.concurrent.UnsafeBuffer
的用法示例。
在下文中一共展示了UnsafeBuffer.getLongVolatile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapExistingCncFile
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
public static MappedByteBuffer mapExistingCncFile(
final File cncFile,
final int versionFieldOffset,
final int timestampFieldOffset,
final long timeoutMs,
final EpochClock epochClock,
final IntConsumer versionCheck,
final Consumer<String> logger)
{
final long startTimeMs = epochClock.time();
while (true)
{
while (!cncFile.exists())
{
if (epochClock.time() > (startTimeMs + timeoutMs))
{
throw new IllegalStateException("CnC file not found: " + cncFile.getName());
}
sleep(16);
}
final MappedByteBuffer cncByteBuffer = mapExistingFile(cncFile, logger);
final UnsafeBuffer cncBuffer = new UnsafeBuffer(cncByteBuffer);
int cncVersion;
while (0 == (cncVersion = cncBuffer.getIntVolatile(versionFieldOffset)))
{
if (epochClock.time() > (startTimeMs + timeoutMs))
{
throw new IllegalStateException("CnC file is created but not initialised.");
}
sleep(1);
}
versionCheck.accept(cncVersion);
while (0 == cncBuffer.getLongVolatile(timestampFieldOffset))
{
if (epochClock.time() > (startTimeMs + timeoutMs))
{
throw new IllegalStateException("No non-0 timestamp detected.");
}
sleep(1);
}
final long timeMs = epochClock.time();
if (cncBuffer.getLongVolatile(timestampFieldOffset) < (timeMs - timeoutMs))
{
if (timeMs > (startTimeMs + timeoutMs))
{
throw new IllegalStateException("No non-0 timestamp detected.");
}
IoUtil.unmap(cncByteBuffer);
sleep(100);
continue;
}
return cncByteBuffer;
}
}
示例2: isActive
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
public static boolean isActive(
final MappedByteBuffer cncByteBuffer,
final EpochClock epochClock,
final long timeoutMs,
final int versionFieldOffset,
final int timestampFieldOffset,
final IntConsumer versionCheck,
final Consumer<String> logger)
{
if (null == cncByteBuffer)
{
return false;
}
final UnsafeBuffer cncBuffer = new UnsafeBuffer(cncByteBuffer);
final long startTimeMs = epochClock.time();
int cncVersion;
while (0 == (cncVersion = cncBuffer.getIntVolatile(versionFieldOffset)))
{
if (epochClock.time() > (startTimeMs + timeoutMs))
{
throw new IllegalStateException("CnC file is created but not initialised.");
}
sleep(1);
}
versionCheck.accept(cncVersion);
final long timestamp = cncBuffer.getLongVolatile(timestampFieldOffset);
final long now = epochClock.time();
final long timestampAge = now - timestamp;
if (null != logger)
{
logger.accept("INFO: heartbeat is (ms): " + timestampAge);
}
return timestampAge <= timeoutMs;
}
示例3: endOfStreamPosition
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
* Get the value of the end of stream position.
*
* @param logMetaDataBuffer containing the meta data.
* @return the value of end of stream position
*/
public static long endOfStreamPosition(final UnsafeBuffer logMetaDataBuffer)
{
return logMetaDataBuffer.getLongVolatile(LOG_END_OF_STREAM_POSITION_OFFSET);
}
示例4: rawTailVolatile
import org.agrona.concurrent.UnsafeBuffer; //导入方法依赖的package包/类
/**
* Get the raw value of the tail for the given partition.
*
* @param logMetaDataBuffer containing the tail counters.
* @param partitionIndex for the tail counter.
* @return the raw value of the tail for the current active partition.
*/
public static long rawTailVolatile(final UnsafeBuffer logMetaDataBuffer, final int partitionIndex)
{
return logMetaDataBuffer.getLongVolatile(TERM_TAIL_COUNTERS_OFFSET + (SIZE_OF_LONG * partitionIndex));
}