/** * Print out the values from {@link #countersReader()} which can be useful for debugging. * * @param out to where the counters get printed. */ public void printCounters(final PrintStream out) { final CountersReader counters = countersReader(); counters.forEach((value, id, label) -> out.format("%3d: %,20d - %s%n", id, value, label)); }
public void print(final PrintStream out) { counters.forEach( (counterId, typeId, keyBuffer, label) -> { if (filter(typeId, keyBuffer)) { final long value = counters.getCounterValue(counterId); out.format("%3d: %,20d - %s%n", counterId, value, label); } }); }
/** * Take a snapshot of all the counters and group them by streams. * * @return a snapshot of all the counters and group them by streams. */ public Map<StreamCompositeKey, List<StreamPosition>> snapshot() { final Map<StreamCompositeKey, List<StreamPosition>> streams = new HashMap<>(); counters.forEach( (counterId, typeId, keyBuffer, label) -> { if ((typeId >= PUBLISHER_LIMIT_TYPE_ID && typeId <= RECEIVER_POS_TYPE_ID) || typeId == SENDER_LIMIT_TYPE_ID || typeId == PER_IMAGE_TYPE_ID || typeId == PUBLISHER_POS_TYPE_ID) { final StreamCompositeKey key = new StreamCompositeKey( keyBuffer.getInt(SESSION_ID_OFFSET), keyBuffer.getInt(STREAM_ID_OFFSET), keyBuffer.getStringAscii(CHANNEL_OFFSET)); final StreamPosition position = new StreamPosition( keyBuffer.getLong(REGISTRATION_ID_OFFSET), counters.getCounterValue(counterId), typeId); streams .computeIfAbsent(key, (ignore) -> new ArrayList<>()) .add(position); } }); return streams; }
/** * 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; }
final MutableInteger id = new MutableInteger(-1); countersReader.forEach( (counterId, typeId, keyBuffer, label) ->
private int countersOfType(final CountersReader countersReader, final int typeIdToCount) { final MutableInteger count = new MutableInteger(); countersReader.forEach( (counterId, typeId, keyBuffer, label) -> { if (typeId == typeIdToCount) { count.value++; } }); return count.get(); }
/** * 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; }
@Test public void shouldTruncateLongLabel() { final int labelLength = MAX_LABEL_LENGTH + 10; final StringBuilder sb = new StringBuilder(labelLength); for (int i = 0; i < labelLength; i++) { sb.append('x'); } final String label = sb.toString(); final int counterId = manager.allocate(label); reader.forEach(consumer); verify(consumer).accept(counterId, label.substring(0, MAX_LABEL_LENGTH)); }
@Test public void shouldStoreLabels() { final int counterId = manager.allocate("abc"); reader.forEach(consumer); verify(consumer).accept(counterId, "abc"); }
@Test public void shouldStoreMultipleLabels() { final int abc = manager.allocate("abc"); final int def = manager.allocate("def"); final int ghi = manager.allocate("ghi"); reader.forEach(consumer); final InOrder inOrder = Mockito.inOrder(consumer); inOrder.verify(consumer).accept(abc, "abc"); inOrder.verify(consumer).accept(def, "def"); inOrder.verify(consumer).accept(ghi, "ghi"); inOrder.verifyNoMoreInteractions(); }
Election.State electionState() { final MutableInteger electionStateValue = new MutableInteger(NULL_VALUE); countersReader().forEach( (counterId, typeId, keyBuffer, label) -> { if (typeId == Election.ELECTION_STATE_TYPE_ID) { electionStateValue.value = (int)countersReader().getCounterValue(counterId); } }); return NULL_VALUE != electionStateValue.value ? Election.State.get(electionStateValue.value) : null; }
@Test public void shouldFreeAndReuseCounters() { final int abc = manager.allocate("abc"); final int def = manager.allocate("def"); final int ghi = manager.allocate("ghi"); manager.free(def); reader.forEach(consumer); final InOrder inOrder = Mockito.inOrder(consumer); inOrder.verify(consumer).accept(abc, "abc"); inOrder.verify(consumer).accept(ghi, "ghi"); inOrder.verifyNoMoreInteractions(); assertThat(manager.allocate("the next label"), is(def)); }
/** * Print out the values from {@link #countersReader()} which can be useful for debugging. * * @param out to where the counters get printed. */ public void printCounters(final PrintStream out) { final CountersReader counters = countersReader(); counters.forEach((value, id, label) -> out.format("%3d: %,20d - %s%n", id, value, label)); }
/** * Print out the values from {@link #countersReader()} which can be useful for debugging. * * @param out to where the counters get printed. */ public void printCounters(final PrintStream out) { final CountersReader counters = countersReader(); counters.forEach((value, id, label) -> out.format("%3d: %,20d - %s%n", id, value, label)); }
public void print(final PrintStream out) { counters.forEach((counterId, typeId, keyBuffer, label) -> { if (filter(typeId, keyBuffer)) { final long value = counters.getCounterValue(counterId); out.format("%3d: %,20d - %s%n", counterId, value, label); } }); }
final MutableInteger id = new MutableInteger(-1); countersReader.forEach( (counterId, typeId, keyBuffer, label) ->
final MutableInteger id = new MutableInteger(-1); countersReader.forEach( (counterId, typeId, keyBuffer, label) ->
/** * 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; }
/** * 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; }
/** * 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; }