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

The following examples show how to use org.agrona.concurrent.AtomicBuffer#addressOffset() . 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: ReadableCounter.java    From aeron with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a view of an existing counter.
 *
 * @param countersReader for getting access to the buffers.
 * @param registrationId assigned by the driver for the counter or {@link Aeron#NULL_VALUE} if not known.
 * @param counterId      for the counter to be viewed.
 * @throws IllegalStateException if the id has for the counter has not been allocated.
 */
public ReadableCounter(final CountersReader countersReader, final long registrationId, final int counterId)
{
    final int counterState = countersReader.getCounterState(counterId);
    if (counterState != CountersReader.RECORD_ALLOCATED)
    {
        throw new IllegalStateException("Counter not allocated: id=" + counterId + " state=" + counterState);
    }

    this.countersReader = countersReader;
    this.counterId = counterId;
    this.registrationId = registrationId;

    final AtomicBuffer valuesBuffer = countersReader.valuesBuffer();
    final int counterOffset = CountersReader.counterOffset(counterId);
    valuesBuffer.boundsCheck(counterOffset, SIZE_OF_LONG);

    this.buffer = valuesBuffer.byteArray();
    this.addressOffset = valuesBuffer.addressOffset() + counterOffset;
}
 
Example 2
Source File: AtomicCounter.java    From agrona with Apache License 2.0 5 votes vote down vote up
/**
 * Map a counter over a buffer. This version will free the counter on close.
 *
 * @param buffer          containing the counter.
 * @param counterId       identifier for the counter.
 * @param countersManager to be called to free the counter on close.
 */
public AtomicCounter(final AtomicBuffer buffer, final int counterId, final CountersManager countersManager)
{
    this.id = counterId;
    this.countersManager = countersManager;
    this.byteBuffer = buffer.byteBuffer();
    this.byteArray = buffer.byteArray();

    final int counterOffset = CountersManager.counterOffset(counterId);
    buffer.boundsCheck(counterOffset, SIZE_OF_LONG);
    this.addressOffset = buffer.addressOffset() + counterOffset;
}
 
Example 3
Source File: UnsafeBufferStatusIndicator.java    From agrona with Apache License 2.0 5 votes vote down vote up
/**
 * Map a status indicator over a buffer.
 *
 * @param buffer    containing the indicator.
 * @param counterId identifier of the indicator.
 */
public UnsafeBufferStatusIndicator(final AtomicBuffer buffer, final int counterId)
{
    this.counterId = counterId;
    this.byteArray = buffer.byteArray();
    this.byteBuffer = buffer.byteBuffer();

    final int counterOffset = CountersManager.counterOffset(counterId);
    buffer.boundsCheck(counterOffset, SIZE_OF_LONG);
    this.addressOffset = buffer.addressOffset() + counterOffset;
}