Java Code Examples for org.agrona.concurrent.status.CountersReader#valuesBuffer()
The following examples show how to use
org.agrona.concurrent.status.CountersReader#valuesBuffer() .
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 |
/** * 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: StatusUtil.java From aeron with Apache License 2.0 | 6 votes |
/** * Return the controllable idle strategy {@link StatusIndicator}. * * @param countersReader that holds the status indicator. * @return status indicator to use or null if not found. */ public static StatusIndicator controllableIdleStrategy(final CountersReader countersReader) { StatusIndicator statusIndicator = null; final MutableInteger id = new MutableInteger(-1); countersReader.forEach( (counterId, label) -> { if (counterId == SystemCounterDescriptor.CONTROLLABLE_IDLE_STRATEGY.id() && label.equals(SystemCounterDescriptor.CONTROLLABLE_IDLE_STRATEGY.label())) { id.value = counterId; } }); if (Aeron.NULL_VALUE != id.value) { statusIndicator = new UnsafeBufferStatusIndicator(countersReader.valuesBuffer(), id.value); } return statusIndicator; }
Example 3
Source File: StatusUtil.java From aeron with Apache License 2.0 | 6 votes |
/** * Return the read-only status indicator for the given send channel URI. * * @param countersReader that holds the status indicator. * @param channel for the send channel. * @return read-only status indicator that can be used to query the status of the send channel or null * @see ChannelEndpointStatus for status values and indications. */ public static StatusIndicatorReader sendChannelStatus(final CountersReader countersReader, final String channel) { StatusIndicatorReader statusReader = null; final MutableInteger id = new MutableInteger(-1); countersReader.forEach( (counterId, typeId, keyBuffer, label) -> { if (typeId == SendChannelStatus.SEND_CHANNEL_STATUS_TYPE_ID) { if (channel.startsWith(keyBuffer.getStringAscii(ChannelEndpointStatus.CHANNEL_OFFSET))) { id.value = counterId; } } }); if (Aeron.NULL_VALUE != id.value) { statusReader = new UnsafeBufferStatusIndicator(countersReader.valuesBuffer(), id.value); } return statusReader; }
Example 4
Source File: StatusUtil.java From aeron with Apache License 2.0 | 6 votes |
/** * Return the read-only status indicator for the given receive channel URI. * * @param countersReader that holds the status indicator. * @param channel for the receive channel. * @return read-only status indicator that can be used to query the status of the receive channel or null. * @see ChannelEndpointStatus for status values and indications. */ public static StatusIndicatorReader receiveChannelStatus(final CountersReader countersReader, final String channel) { StatusIndicatorReader statusReader = null; final MutableInteger id = new MutableInteger(-1); countersReader.forEach( (counterId, typeId, keyBuffer, label) -> { if (typeId == ReceiveChannelStatus.RECEIVE_CHANNEL_STATUS_TYPE_ID) { if (channel.startsWith(keyBuffer.getStringAscii(ChannelEndpointStatus.CHANNEL_OFFSET))) { id.value = counterId; } } }); if (Aeron.NULL_VALUE != id.value) { statusReader = new UnsafeBufferStatusIndicator(countersReader.valuesBuffer(), id.value); } return statusReader; }
Example 5
Source File: ClusterControl.java From aeron with Apache License 2.0 | 5 votes |
/** * Find the control toggle counter or return null if not found. * * @param counters to search within. * @param clusterId to which the allocated counter belongs. * @return the control toggle counter or return null if not found. */ public static AtomicCounter findControlToggle(final CountersReader counters, final int clusterId) { final int counterId = ClusterCounters.find(counters, CONTROL_TOGGLE_TYPE_ID, clusterId); if (Aeron.NULL_VALUE != counterId) { return new AtomicCounter(counters.valuesBuffer(), counterId, null); } return null; }
Example 6
Source File: Counter.java From aeron with Apache License 2.0 | 5 votes |
/** * Construct a read-write 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 AeronException if the id has for the counter has not been allocated. */ public Counter(final CountersReader countersReader, final long registrationId, final int counterId) { super(countersReader.valuesBuffer(), counterId); if (countersReader.getCounterState(counterId) != CountersReader.RECORD_ALLOCATED) { throw new AeronException("Counter id is not allocated: " + counterId); } this.registrationId = registrationId; this.clientConductor = null; }