/** * Get the deadline (in milliseconds) for when a given counter id may be reused. * * @param counterId to be read. * @return deadline (in milliseconds) for when a given counter id may be reused or {@link #NOT_FREE_TO_REUSE} if * currently in use. */ public long getFreeForReuseDeadline(final int counterId) { validateCounterId(counterId); return metaDataBuffer.getLongVolatile(metaDataOffset(counterId) + FREE_FOR_REUSE_DEADLINE_OFFSET); }
/** * Get the label for a given counter id. * * @param counterId to be read. * @return the label for the given counter id. */ public String getCounterLabel(final int counterId) { validateCounterId(counterId); return labelValue(metaDataOffset(counterId)); }
/** * Get the state for a given counter id as a volatile read. * * @param counterId to be read. * @return the current state of the counter. * @see #RECORD_UNUSED * @see #RECORD_ALLOCATED * @see #RECORD_RECLAIMED */ public int getCounterState(final int counterId) { validateCounterId(counterId); return metaDataBuffer.getIntVolatile(metaDataOffset(counterId)); }
/** * Get the position at which the snapshot was taken. {@link Aeron#NULL_VALUE} if no snapshot for recovery. * * @param counters to search within. * @param counterId for the active recovery counter. * @return the log position if found otherwise {@link Aeron#NULL_VALUE}. */ public static long getLogPosition(final CountersReader counters, final int counterId) { final DirectBuffer buffer = counters.metaDataBuffer(); if (counters.getCounterState(counterId) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(counterId); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECOVERY_STATE_TYPE_ID) { return buffer.getLong(recordOffset + KEY_OFFSET + LOG_POSITION_OFFSET); } } return NULL_VALUE; }
/** * Has the recovery process got a log to replay? * * @param counters to search within. * @param counterId for the active recovery counter. * @return true if a replay is required. */ public static boolean hasReplay(final CountersReader counters, final int counterId) { final DirectBuffer buffer = counters.metaDataBuffer(); if (counters.getCounterState(counterId) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(counterId); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECOVERY_STATE_TYPE_ID) { return buffer.getInt(recordOffset + KEY_OFFSET + REPLAY_FLAG_OFFSET) == 1; } } return false; }
/** * Get the recording id for a given counter id. * * @param countersReader to search within. * @param counterId for the active recording. * @return the counter id if found otherwise {@link #NULL_RECORDING_ID}. */ public static long getRecordingId(final CountersReader countersReader, final int counterId) { final DirectBuffer buffer = countersReader.metaDataBuffer(); if (countersReader.getCounterState(counterId) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(counterId); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECORDING_POSITION_TYPE_ID) { return buffer.getLong(recordOffset + KEY_OFFSET + RECORDING_ID_OFFSET); } } return NULL_RECORDING_ID; }
/** * Get the {@link Image#sourceIdentity()} for the recording. * * @param countersReader to search within. * @param counterId for the active recording. * @return {@link Image#sourceIdentity()} for the recording or null if not found. */ public static String getSourceIdentity(final CountersReader countersReader, final int counterId) { final DirectBuffer buffer = countersReader.metaDataBuffer(); if (countersReader.getCounterState(counterId) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(counterId); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECORDING_POSITION_TYPE_ID) { return buffer.getStringAscii(recordOffset + KEY_OFFSET + SOURCE_IDENTITY_LENGTH_OFFSET); } } return null; }
/** * Find the active counter id for recovery state. * * @param counters to search within. * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}. */ public static int findCounterId(final CountersReader counters) { final DirectBuffer buffer = counters.metaDataBuffer(); for (int i = 0, size = counters.maxCounterId(); i < size; i++) { if (counters.getCounterState(i) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(i); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECOVERY_STATE_TYPE_ID) { return i; } } } return NULL_COUNTER_ID; }
/** * Is the recording counter still active. * * @param countersReader to search within. * @param counterId to search for. * @param recordingId to confirm it is still the same value. * @return true if the counter is still active otherwise false. */ public static boolean isActive(final CountersReader countersReader, final int counterId, final long recordingId) { final DirectBuffer buffer = countersReader.metaDataBuffer(); if (countersReader.getCounterState(counterId) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(counterId); return buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECORDING_POSITION_TYPE_ID && buffer.getLong(recordOffset + KEY_OFFSET + RECORDING_ID_OFFSET) == recordingId; } return false; } }
/** * Get the leadership term id for the snapshot state. {@link Aeron#NULL_VALUE} if no snapshot for recovery. * * @param counters to search within. * @param counterId for the active recovery counter. * @return the leadership term id if found otherwise {@link Aeron#NULL_VALUE}. */ public static long getLeadershipTermId(final CountersReader counters, final int counterId) { final DirectBuffer buffer = counters.metaDataBuffer(); if (counters.getCounterState(counterId) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(counterId); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECOVERY_STATE_TYPE_ID) { return buffer.getLong(recordOffset + KEY_OFFSET + LEADERSHIP_TERM_ID_OFFSET); } } return NULL_VALUE; }
/** * Get the timestamp at the beginning of recovery. {@link Aeron#NULL_VALUE} if no snapshot for recovery. * * @param counters to search within. * @param counterId for the active recovery counter. * @return the timestamp if found otherwise {@link Aeron#NULL_VALUE}. */ public static long getTimestamp(final CountersReader counters, final int counterId) { final DirectBuffer buffer = counters.metaDataBuffer(); if (counters.getCounterState(counterId) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(counterId); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECOVERY_STATE_TYPE_ID) { return buffer.getLong(recordOffset + KEY_OFFSET + TIMESTAMP_OFFSET); } } return NULL_VALUE; }
/** * Find the active counter id for a cluster commit position * * @param counters to search within. * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}. */ public static int findCounterId(final CountersReader counters) { final DirectBuffer buffer = counters.metaDataBuffer(); for (int i = 0, size = counters.maxCounterId(); i < size; i++) { if (counters.getCounterState(i) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(i); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == COMMIT_POSITION_TYPE_ID) { return i; } } } return NULL_COUNTER_ID; } }
/** * Find the active counter id for a cluster node role. * * @param counters to search within. * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}. */ public static int findCounterId(final CountersReader counters) { final DirectBuffer buffer = counters.metaDataBuffer(); for (int i = 0, size = counters.maxCounterId(); i < size; i++) { if (counters.getCounterState(i) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(i); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == CLUSTER_NODE_ROLE_TYPE_ID) { return i; } } } return NULL_COUNTER_ID; } }
/** * Find the active counter id for a stream based on the recording id. * * @param countersReader to search within. * @param recordingId for the active recording. * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}. */ public static int findCounterIdByRecording(final CountersReader countersReader, final long recordingId) { final DirectBuffer buffer = countersReader.metaDataBuffer(); for (int i = 0, size = countersReader.maxCounterId(); i < size; i++) { if (countersReader.getCounterState(i) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(i); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECORDING_POSITION_TYPE_ID && buffer.getLong(recordOffset + KEY_OFFSET + RECORDING_ID_OFFSET) == recordingId) { return i; } } } return NULL_COUNTER_ID; }
/** * Find the active counter id for a stream based on the session id. * * @param countersReader to search within. * @param sessionId for the active recording. * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}. */ public static int findCounterIdBySession(final CountersReader countersReader, final int sessionId) { final DirectBuffer buffer = countersReader.metaDataBuffer(); for (int i = 0, size = countersReader.maxCounterId(); i < size; i++) { if (countersReader.getCounterState(i) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(i); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == RECORDING_POSITION_TYPE_ID && buffer.getInt(recordOffset + KEY_OFFSET + SESSION_ID_OFFSET) == sessionId) { return i; } } } return NULL_COUNTER_ID; }
/** * Find the active counter id for heartbeat of a given service id. * * @param counters to search within. * @param serviceId to search for. * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}. */ public static int findCounterId(final CountersReader counters, final int serviceId) { final DirectBuffer buffer = counters.metaDataBuffer(); for (int i = 0, size = counters.maxCounterId(); i < size; i++) { if (counters.getCounterState(i) == RECORD_ALLOCATED) { final int recordOffset = CountersReader.metaDataOffset(i); if (buffer.getInt(recordOffset + TYPE_ID_OFFSET) == SERVICE_HEARTBEAT_TYPE_ID && buffer.getInt(recordOffset + KEY_OFFSET + SERVICE_ID_OFFSET) == serviceId) { return i; } } } return NULL_COUNTER_ID; } }
/** * Find the control toggle counter or return null if not found. * * @param counters to search for the control toggle. * @return the control toggle counter or return null if not found. */ public static AtomicCounter findControlToggle(final CountersReader counters) { final AtomicBuffer buffer = counters.metaDataBuffer(); for (int i = 0, size = counters.maxCounterId(); i < size; i++) { final int recordOffset = CountersReader.metaDataOffset(i); if (counters.getCounterState(i) == RECORD_ALLOCATED && buffer.getInt(recordOffset + TYPE_ID_OFFSET) == CONTROL_TOGGLE_TYPE_ID) { return new AtomicCounter(counters.valuesBuffer(), i, null); } } return null; }
final int recordOffset = CountersReader.metaDataOffset(counterId);
/** * Get the deadline (in milliseconds) for when a given counter id may be reused. * * @param counterId to be read. * @return deadline (in milliseconds) for when a given counter id may be reused or {@link #NOT_FREE_TO_REUSE} if * currently in use. */ public long getFreeForReuseDeadline(final int counterId) { validateCounterId(counterId); return metaDataBuffer.getLongVolatile(metaDataOffset(counterId) + FREE_FOR_REUSE_DEADLINE_OFFSET); }
/** * Get the label for a given counter id. * * @param counterId to be read. * @return the label for the given counter id. */ public String getCounterLabel(final int counterId) { validateCounterId(counterId); return labelValue(metaDataOffset(counterId)); }