Java Code Examples for org.agrona.concurrent.status.CountersReader#maxCounterId()

The following examples show how to use org.agrona.concurrent.status.CountersReader#maxCounterId() . 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: RecordingPos.java    From aeron with Apache License 2.0 6 votes vote down vote up
/**
 * 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 &&
            countersReader.getCounterTypeId(i) == RECORDING_POSITION_TYPE_ID)
        {
            if (buffer.getLong(CountersReader.metaDataOffset(i) + KEY_OFFSET + RECORDING_ID_OFFSET) == recordingId)
            {
                return i;
            }
        }
    }

    return NULL_COUNTER_ID;
}
 
Example 2
Source File: RecordingPos.java    From aeron with Apache License 2.0 6 votes vote down vote up
/**
 * 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 &&
            countersReader.getCounterTypeId(i) == RECORDING_POSITION_TYPE_ID)
        {
            if (buffer.getInt(CountersReader.metaDataOffset(i) + KEY_OFFSET + SESSION_ID_OFFSET) == sessionId)
            {
                return i;
            }
        }
    }

    return NULL_COUNTER_ID;
}
 
Example 3
Source File: RecoveryState.java    From aeron with Apache License 2.0 6 votes vote down vote up
/**
 * Find the active counter id for recovery state.
 *
 * @param counters  to search within.
 * @param clusterId to constrain the search.
 * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}.
 */
public static int findCounterId(final CountersReader counters, final int clusterId)
{
    final DirectBuffer buffer = counters.metaDataBuffer();

    for (int i = 0, size = counters.maxCounterId(); i < size; i++)
    {
        if (counters.getCounterState(i) == RECORD_ALLOCATED &&
            counters.getCounterTypeId(i) == RECOVERY_STATE_TYPE_ID)
        {
            if (buffer.getInt(CountersReader.metaDataOffset(i) + KEY_OFFSET + CLUSTER_ID_OFFSET) == clusterId)
            {
                return i;
            }
        }
    }

    return NULL_COUNTER_ID;
}
 
Example 4
Source File: ClusterCounters.java    From aeron with Apache License 2.0 6 votes vote down vote up
/**
 * Find the counter id for a type of counter in a cluster.
 *
 * @param counters  to search within.
 * @param typeId    of the counter.
 * @param clusterId to which the allocated counter belongs.
 * @return the matching counter id or {@link Aeron#NULL_VALUE} if not found.
 */
public static int find(final CountersReader counters, final int typeId, final int clusterId)
{
    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 &&
            counters.getCounterTypeId(i) == typeId &&
            buffer.getInt(recordOffset + KEY_OFFSET) == clusterId)
        {
            return i;
        }
    }

    return Aeron.NULL_VALUE;
}
 
Example 5
Source File: HeartbeatTimestamp.java    From aeron with Apache License 2.0 6 votes vote down vote up
/**
 * Find the active counter id for a heartbeat timestamp.
 *
 * @param countersReader to search within.
 * @param counterTypeId  to match on.
 * @param registrationId for the active client.
 * @return the counter id if found otherwise {@link CountersReader#NULL_COUNTER_ID}.
 */
public static int findCounterIdByRegistrationId(
    final CountersReader countersReader, final int counterTypeId, final long registrationId)
{
    final DirectBuffer buffer = countersReader.metaDataBuffer();

    for (int i = 0, size = countersReader.maxCounterId(); i < size; i++)
    {
        if (countersReader.getCounterState(i) == RECORD_ALLOCATED &&
            countersReader.getCounterTypeId(i) == counterTypeId)
        {
            final int recordOffset = CountersReader.metaDataOffset(i);

            if (buffer.getLong(recordOffset + KEY_OFFSET + REGISTRATION_ID_OFFSET) == registrationId)
            {
                return i;
            }
        }
    }

    return NULL_COUNTER_ID;
}
 
Example 6
Source File: LocalSocketAddressStatus.java    From aeron with Apache License 2.0 5 votes vote down vote up
/**
 * Find the list of currently bound local sockets.
 *
 * @param countersReader  for the connected driver.
 * @param channelStatus   value for the channel which aggregates the transports.
 * @param channelStatusId identity of the counter for the channel which aggregates the transports.
 * @return the list of active bound local socket addresses.
 */
public static List<String> findAddresses(
    final CountersReader countersReader, final long channelStatus, final int channelStatusId)
{
    if (channelStatus != ChannelEndpointStatus.ACTIVE)
    {
        return Collections.emptyList();
    }

    final ArrayList<String> bindings = new ArrayList<>(2);
    final DirectBuffer buffer = countersReader.metaDataBuffer();

    for (int i = 0, size = countersReader.maxCounterId(); i < size; i++)
    {
        if (countersReader.getCounterState(i) == RECORD_ALLOCATED &&
            countersReader.getCounterTypeId(i) == LOCAL_SOCKET_ADDRESS_STATUS_TYPE_ID)
        {
            final int recordOffset = CountersReader.metaDataOffset(i);
            final int keyIndex = recordOffset + CountersReader.KEY_OFFSET;

            if (channelStatusId == buffer.getInt(keyIndex + CHANNEL_STATUS_ID_OFFSET) &&
                ChannelEndpointStatus.ACTIVE == countersReader.getCounterValue(i))
            {
                final int length = buffer.getInt(keyIndex + LOCAL_SOCKET_ADDRESS_LENGTH_OFFSET);
                if (length > 0)
                {
                    bindings.add(buffer.getStringWithoutLengthAscii(
                        keyIndex + LOCAL_SOCKET_ADDRESS_STRING_OFFSET, length));
                }
            }
        }
    }

    return bindings;
}