Java Code Examples for org.agrona.MutableDirectBuffer#putLongAscii()

The following examples show how to use org.agrona.MutableDirectBuffer#putLongAscii() . 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: HeartbeatTimestamp.java    From aeron with Apache License 2.0 6 votes vote down vote up
/**
 * Allocate a counter id for tracking the last heartbeat of an entity.
 *
 * @param tempBuffer      to be used for labels and key.
 * @param name            of the counter for the label.
 * @param typeId          of the counter for classification.
 * @param countersManager from which to allocated the underlying storage.
 * @param registrationId  to be associated with the counter.
 * @return the counter id to be used.
 */
public static int allocateCounterId(
    final MutableDirectBuffer tempBuffer,
    final String name,
    final int typeId,
    final CountersManager countersManager,
    final long registrationId)
{
    tempBuffer.putLong(REGISTRATION_ID_OFFSET, registrationId);
    final int keyLength = REGISTRATION_ID_OFFSET + SIZE_OF_LONG;

    final int labelOffset = BitUtil.align(keyLength, SIZE_OF_INT);
    int labelLength = 0;
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, name);
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, ": ");
    labelLength += tempBuffer.putLongAscii(labelOffset + labelLength, registrationId);

    return countersManager.allocate(
        typeId,
        tempBuffer,
        0,
        keyLength,
        tempBuffer,
        labelOffset,
        labelLength);
}
 
Example 2
Source File: StreamCounter.java    From aeron with Apache License 2.0 4 votes vote down vote up
public static int allocateCounterId(
    final MutableDirectBuffer tempBuffer,
    final String name,
    final int typeId,
    final CountersManager countersManager,
    final long registrationId,
    final int sessionId,
    final int streamId,
    final String channel)
{
    tempBuffer.putLong(REGISTRATION_ID_OFFSET, registrationId);
    tempBuffer.putInt(SESSION_ID_OFFSET, sessionId);
    tempBuffer.putInt(STREAM_ID_OFFSET, streamId);

    final int channelLength = tempBuffer.putStringWithoutLengthAscii(
        CHANNEL_OFFSET + SIZE_OF_INT, channel, 0, MAX_CHANNEL_LENGTH);
    tempBuffer.putInt(CHANNEL_OFFSET, channelLength);
    final int keyLength = CHANNEL_OFFSET + SIZE_OF_INT + channelLength;

    final int labelOffset = BitUtil.align(keyLength, SIZE_OF_INT);
    int labelLength = 0;
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, name);
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, ": ");
    labelLength += tempBuffer.putLongAscii(labelOffset + labelLength, registrationId);
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, " ");
    labelLength += tempBuffer.putIntAscii(labelOffset + labelLength, sessionId);
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, " ");
    labelLength += tempBuffer.putIntAscii(labelOffset + labelLength, streamId);
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, " ");
    labelLength += tempBuffer.putStringWithoutLengthAscii(
        labelOffset + labelLength, channel, 0, MAX_LABEL_LENGTH - labelLength);

    return countersManager.allocate(
        typeId,
        tempBuffer,
        0,
        keyLength,
        tempBuffer,
        labelOffset,
        labelLength);
}
 
Example 3
Source File: StreamCounter.java    From aeron with Apache License 2.0 4 votes vote down vote up
/**
 * Allocate a counter for tracking a position on a stream of messages.
 *
 * @param tempBuffer      to be used for labels and key.
 * @param name            of the counter for the label.
 * @param typeId          of the counter for classification.
 * @param countersManager from which to allocated the underlying storage.
 * @param registrationId  to be associated with the counter.
 * @param sessionId       for the stream of messages.
 * @param streamId        for the stream of messages.
 * @param channel         for the stream of messages.
 * @param joinPosition    for the label.
 * @return a new {@link UnsafeBufferPosition} for tracking the stream.
 */
public static UnsafeBufferPosition allocate(
    final MutableDirectBuffer tempBuffer,
    final String name,
    final int typeId,
    final CountersManager countersManager,
    final long registrationId,
    final int sessionId,
    final int streamId,
    final String channel,
    final long joinPosition)
{
    tempBuffer.putLong(REGISTRATION_ID_OFFSET, registrationId);
    tempBuffer.putInt(SESSION_ID_OFFSET, sessionId);
    tempBuffer.putInt(STREAM_ID_OFFSET, streamId);

    final int channelLength = tempBuffer.putStringWithoutLengthAscii(
        CHANNEL_OFFSET + SIZE_OF_INT, channel, 0, MAX_CHANNEL_LENGTH);
    tempBuffer.putInt(CHANNEL_OFFSET, channelLength);
    final int keyLength = CHANNEL_OFFSET + SIZE_OF_INT + channelLength;

    final int labelOffset = BitUtil.align(keyLength, SIZE_OF_INT);
    int labelLength = 0;
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, name);
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, ": ");
    labelLength += tempBuffer.putLongAscii(labelOffset + labelLength, registrationId);
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, " ");
    labelLength += tempBuffer.putIntAscii(labelOffset + labelLength, sessionId);
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, " ");
    labelLength += tempBuffer.putIntAscii(labelOffset + labelLength, streamId);
    labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, " ");
    labelLength += tempBuffer.putStringWithoutLengthAscii(
        labelOffset + labelLength, channel, 0, MAX_LABEL_LENGTH - labelLength);

    if (labelLength < (MAX_LABEL_LENGTH - 20))
    {
        labelLength += tempBuffer.putStringWithoutLengthAscii(labelOffset + labelLength, " @");
        labelLength += tempBuffer.putLongAscii(labelOffset + labelLength, joinPosition);
    }

    final int counterId = countersManager.allocate(
        typeId,
        tempBuffer,
        0,
        keyLength,
        tempBuffer,
        labelOffset,
        labelLength);

    return new UnsafeBufferPosition((UnsafeBuffer)countersManager.valuesBuffer(), counterId, countersManager);
}