Java Code Examples for org.agrona.concurrent.AtomicBuffer#verifyAlignment()

The following examples show how to use org.agrona.concurrent.AtomicBuffer#verifyAlignment() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BroadcastReceiver.java    From agrona with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a new broadcast receiver based on an underlying {@link AtomicBuffer}.
 * The underlying buffer must a power of 2 in size plus sufficient space
 * for the {@link BroadcastBufferDescriptor#TRAILER_LENGTH}.
 *
 * @param buffer via which messages will be exchanged.
 * @throws IllegalStateException if the buffer capacity is not a power of 2
 * plus {@link BroadcastBufferDescriptor#TRAILER_LENGTH} in capacity.
 */
public BroadcastReceiver(final AtomicBuffer buffer)
{
    this.buffer = buffer;
    this.capacity = buffer.capacity() - TRAILER_LENGTH;

    checkCapacity(capacity);
    buffer.verifyAlignment();

    tailIntentCounterIndex = capacity + TAIL_INTENT_COUNTER_OFFSET;
    tailCounterIndex = capacity + TAIL_COUNTER_OFFSET;
    latestCounterIndex = capacity + LATEST_COUNTER_OFFSET;

    cursor = nextRecord = buffer.getLongVolatile(latestCounterIndex);
    recordOffset = (int)cursor & (capacity - 1);
}
 
Example 2
Source File: CountersManager.java    From agrona with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new counter buffer manager over two buffers.
 *
 * @param metaDataBuffer       containing the types, keys, and labels for the counters.
 * @param valuesBuffer         containing the values of the counters themselves.
 * @param labelCharset         for the label encoding.
 * @param epochClock           to use for determining time for keep counter from being reused after being freed.
 * @param freeToReuseTimeoutMs timeout (in milliseconds) to keep counter from being reused after being freed.
 */
public CountersManager(
    final AtomicBuffer metaDataBuffer,
    final AtomicBuffer valuesBuffer,
    final Charset labelCharset,
    final EpochClock epochClock,
    final long freeToReuseTimeoutMs)
{
    super(metaDataBuffer, valuesBuffer, labelCharset);

    valuesBuffer.verifyAlignment();
    this.epochClock = epochClock;
    this.freeToReuseTimeoutMs = freeToReuseTimeoutMs;

    if (metaDataBuffer.capacity() < (valuesBuffer.capacity() * 2))
    {
        throw new IllegalArgumentException("metadata buffer not sufficiently large");
    }
}
 
Example 3
Source File: OneToOneRingBuffer.java    From agrona with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a new {@link RingBuffer} based on an underlying {@link AtomicBuffer}.
 * The underlying buffer must a power of 2 in size plus sufficient space
 * for the {@link RingBufferDescriptor#TRAILER_LENGTH}.
 *
 * @param buffer via which events will be exchanged.
 * @throws IllegalStateException if the buffer capacity is not a power of 2 plus
 *                               {@link RingBufferDescriptor#TRAILER_LENGTH} in capacity.
 */
public OneToOneRingBuffer(final AtomicBuffer buffer)
{
    this.buffer = buffer;
    checkCapacity(buffer.capacity());
    capacity = buffer.capacity() - TRAILER_LENGTH;

    buffer.verifyAlignment();

    maxMsgLength = capacity >> 3;
    tailPositionIndex = capacity + TAIL_POSITION_OFFSET;
    headCachePositionIndex = capacity + HEAD_CACHE_POSITION_OFFSET;
    headPositionIndex = capacity + HEAD_POSITION_OFFSET;
    correlationIdCounterIndex = capacity + CORRELATION_COUNTER_OFFSET;
    consumerHeartbeatIndex = capacity + CONSUMER_HEARTBEAT_OFFSET;
}
 
Example 4
Source File: ManyToOneRingBuffer.java    From agrona with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a new {@link RingBuffer} based on an underlying {@link AtomicBuffer}.
 * The underlying buffer must a power of 2 in size plus sufficient space
 * for the {@link RingBufferDescriptor#TRAILER_LENGTH}.
 *
 * @param buffer via which events will be exchanged.
 * @throws IllegalStateException if the buffer capacity is not a power of 2
 *                               plus {@link RingBufferDescriptor#TRAILER_LENGTH} in capacity.
 */
public ManyToOneRingBuffer(final AtomicBuffer buffer)
{
    this.buffer = buffer;
    checkCapacity(buffer.capacity());
    capacity = buffer.capacity() - TRAILER_LENGTH;

    buffer.verifyAlignment();

    maxMsgLength = capacity >> 3;
    tailPositionIndex = capacity + TAIL_POSITION_OFFSET;
    headCachePositionIndex = capacity + HEAD_CACHE_POSITION_OFFSET;
    headPositionIndex = capacity + HEAD_POSITION_OFFSET;
    correlationIdCounterIndex = capacity + CORRELATION_COUNTER_OFFSET;
    consumerHeartbeatIndex = capacity + CONSUMER_HEARTBEAT_OFFSET;
}
 
Example 5
Source File: BroadcastTransmitter.java    From agrona with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new broadcast transmitter based on an underlying {@link org.agrona.concurrent.AtomicBuffer}.
 * The underlying buffer must a power of 2 in size plus sufficient space
 * for the {@link BroadcastBufferDescriptor#TRAILER_LENGTH}.
 *
 * @param buffer via which messages will be exchanged.
 * @throws IllegalStateException if the buffer capacity is not a power of 2
 * plus {@link BroadcastBufferDescriptor#TRAILER_LENGTH} in capacity.
 */
public BroadcastTransmitter(final AtomicBuffer buffer)
{
    this.buffer = buffer;
    this.capacity = buffer.capacity() - TRAILER_LENGTH;

    checkCapacity(capacity);
    buffer.verifyAlignment();

    this.maxMsgLength = calculateMaxMessageLength(capacity);
    this.tailIntentCountIndex = capacity + TAIL_INTENT_COUNTER_OFFSET;
    this.tailCounterIndex = capacity + TAIL_COUNTER_OFFSET;
    this.latestCounterIndex = capacity + LATEST_COUNTER_OFFSET;
}
 
Example 6
Source File: CountersManager.java    From agrona with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new counter buffer manager over two buffers.
 *
 * @param metaDataBuffer containing the types, keys, and labels for the counters.
 * @param valuesBuffer   containing the values of the counters themselves.
 */
public CountersManager(final AtomicBuffer metaDataBuffer, final AtomicBuffer valuesBuffer)
{
    super(metaDataBuffer, valuesBuffer);

    valuesBuffer.verifyAlignment();
    this.epochClock = () -> 0;
    this.freeToReuseTimeoutMs = 0;

    if (metaDataBuffer.capacity() < (valuesBuffer.capacity() * 2))
    {
        throw new IllegalArgumentException("metadata buffer not sufficiently large");
    }
}
 
Example 7
Source File: DistinctErrorLog.java    From agrona with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new error log that will be written to a provided {@link AtomicBuffer}.
 *
 * @param buffer  into which the observation records are recorded.
 * @param clock   to be used for time stamping records.
 * @param charset for encoding the errors.
 */
public DistinctErrorLog(final AtomicBuffer buffer, final EpochClock clock, final Charset charset)
{
    buffer.verifyAlignment();
    this.clock = clock;
    this.buffer = buffer;
    this.charset = charset;
}
 
Example 8
Source File: LossReport.java    From aeron with Apache License 2.0 2 votes vote down vote up
/**
 * Create a loss report which wraps a buffer which is ideally memory mapped so it can
 * be read from another process.
 *
 * @param buffer to be wrapped.
 */
public LossReport(final AtomicBuffer buffer)
{
    buffer.verifyAlignment();
    this.buffer = buffer;
}