/** * Get the value for a given counter id as a volatile read. * * @param counterId to be read. * @return the current value of the counter. */ public long getCounterValue(final int counterId) { validateCounterId(counterId); return valuesBuffer.getLongVolatile(counterOffset(counterId)); }
/** * 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) { if (countersReader.getCounterState(counterId) != CountersReader.RECORD_ALLOCATED) { throw new IllegalStateException("Counter id has not been allocated: " + counterId); } 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; }
/** * Iterate over the counters and provide the value and basic metadata. * * @param consumer for each allocated counter. */ public void forEach(final CounterConsumer consumer) { int counterId = 0; for (int i = 0, capacity = metaDataBuffer.capacity(); i < capacity; i += METADATA_LENGTH) { final int recordStatus = metaDataBuffer.getIntVolatile(i); if (RECORD_ALLOCATED == recordStatus) { consumer.accept(valuesBuffer.getLongVolatile(counterOffset(counterId)), counterId, labelValue(i)); } else if (RECORD_UNUSED == recordStatus) { break; } counterId++; } }
/** * Get the value for a given counter id as a volatile read. * * @param counterId to be read. * @return the current value of the counter. */ public long getCounterValue(final int counterId) { return valuesBuffer.getLongVolatile(counterOffset(counterId)); }
/** * Get the value for a given counter id as a volatile read. * * @param counterId to be read. * @return the current value of the counter. */ public long getCounterValue(final int counterId) { validateCounterId(counterId); return valuesBuffer.getLongVolatile(counterOffset(counterId)); }
/** * 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) { if (countersReader.getCounterState(counterId) != CountersReader.RECORD_ALLOCATED) { throw new IllegalStateException("Counter id has not been allocated: " + counterId); } 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; }
/** * 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) { if (countersReader.getCounterState(counterId) != CountersReader.RECORD_ALLOCATED) { throw new IllegalStateException("Counter id has not been allocated: " + counterId); } 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; }
/** * Iterate over the counters and provide the value and basic metadata. * * @param consumer for each allocated counter. */ public void forEach(final CounterConsumer consumer) { int counterId = 0; for (int i = 0, capacity = metaDataBuffer.capacity(); i < capacity; i += METADATA_LENGTH) { final int recordStatus = metaDataBuffer.getIntVolatile(i); if (RECORD_ALLOCATED == recordStatus) { consumer.accept(valuesBuffer.getLongVolatile(counterOffset(counterId)), counterId, labelValue(i)); } else if (RECORD_UNUSED == recordStatus) { break; } counterId++; } }