Ejemplo n.º 1
0
        /// <summary>
        /// Allocate an indicator for tracking the status of a channel endpoint.
        /// </summary>
        /// <param name="tempBuffer">      to be used for labels and metadata. </param>
        /// <param name="name">            of the counter for the label. </param>
        /// <param name="typeId">          of the counter for classification. </param>
        /// <param name="countersManager"> from which to allocated the underlying storage. </param>
        /// <param name="channel">         for the stream of messages. </param>
        /// <returns> a new <seealso cref="AtomicCounter"/> for tracking the status. </returns>
        public static AtomicCounter Allocate(IMutableDirectBuffer tempBuffer, string name, int typeId,
                                             CountersManager countersManager, string channel)
        {
            int keyLength =
                tempBuffer.PutStringWithoutLengthAscii(CHANNEL_OFFSET + BitUtil.SIZE_OF_INT, channel, 0,
                                                       MAX_CHANNEL_LENGTH);

            tempBuffer.PutInt(CHANNEL_OFFSET, keyLength);

            int labelLength = 0;

            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, name);
            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, ": ");
            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, channel, 0,
                                                                  CountersReader.MAX_LABEL_LENGTH - labelLength);


            if (labelLength < CountersReader.MAX_LABEL_LENGTH)
            {
                tempBuffer.PutByte(keyLength + labelLength, (byte)' ');
                labelLength += 1;
            }

            return(countersManager.NewCounter(typeId, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelLength));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allocate a counter to represent the commit position on stream for the current leadership term.
        /// </summary>
        /// <param name="aeron">            to allocate the counter. </param>
        /// <param name="tempBuffer">       to use for building the key and label without allocation. </param>
        /// <param name="recordingId">      for the current term. </param>
        /// <param name="logPosition">      of the log at the beginning of the leadership term. </param>
        /// <param name="leadershipTermId"> of the log at the beginning of the leadership term. </param>
        /// <param name="sessionId">        of the active log for the current leadership term. </param>
        /// <returns> the <seealso cref="Counter"/> for the consensus position. </returns>
        public static Counter Allocate(Aeron.Aeron aeron, IMutableDirectBuffer tempBuffer, long recordingId, long logPosition, long leadershipTermId, int sessionId)
        {
            tempBuffer.PutLong(RECORDING_ID_OFFSET, recordingId);
            tempBuffer.PutLong(LOG_POSITION_OFFSET, logPosition);
            tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId);
            tempBuffer.PutInt(SESSION_ID_OFFSET, sessionId);

            int labelOffset = 0;

            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, NAME);
            labelOffset += tempBuffer.PutLongAscii(KEY_LENGTH + labelOffset, leadershipTermId);
            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, " logSessionId=");
            labelOffset += tempBuffer.PutIntAscii(KEY_LENGTH + labelOffset, sessionId);

            return(aeron.AddCounter(COMMIT_POSITION_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, KEY_LENGTH, labelOffset));
        }
        public ClusterMembersResponseEncoder ActiveMembers(string value)
        {
            int length = value.Length;

            if (length > 1073741824)
            {
                throw new InvalidOperationException("length > maxValue for type: " + length);
            }

            int headerLength = 4;
            int limit        = _parentMessage.Limit();

            _parentMessage.Limit(limit + headerLength + length);
            _buffer.PutInt(limit, unchecked ((int)length), ByteOrder.LittleEndian);
            _buffer.PutStringWithoutLengthAscii(limit + headerLength, value);

            return(this);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Allocate a counter to represent the snapshot services should load on start.
        /// </summary>
        /// <param name="aeron">           to allocate the counter. </param>
        /// <param name="tempBuffer">      to use for building the key and label without allocation. </param>
        /// <param name="leadershipTermId">    at which the snapshot was taken. </param>
        /// <param name="termPosition">     at which the snapshot was taken. </param>
        /// <param name="timestamp">       the snapshot was taken. </param>
        /// <param name="replayTermCount"> for the count of terms to be replayed during recovery after snapshot. </param>
        /// <returns> the <seealso cref="Counter"/> for the consensus position. </returns>
        public static Counter Allocate(Aeron.Aeron aeron, IMutableDirectBuffer tempBuffer, long termPosition, long leadershipTermId, long timestamp, int replayTermCount)
        {
            tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId);
            tempBuffer.PutLong(TERM_POSITION_OFFSET, termPosition);
            tempBuffer.PutLong(TIMESTAMP_OFFSET, timestamp);
            tempBuffer.PutInt(REPLAY_TERM_COUNT_OFFSET, replayTermCount);

            int labelOffset = 0;

            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, NAME);
            labelOffset += tempBuffer.PutLongAscii(KEY_LENGTH + labelOffset, leadershipTermId);
            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, " termPosition=");
            labelOffset += tempBuffer.PutLongAscii(KEY_LENGTH + labelOffset, termPosition);
            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, " replayTermCount=");
            labelOffset += tempBuffer.PutIntAscii(KEY_LENGTH + labelOffset, replayTermCount);

            return(aeron.AddCounter(RECOVERY_STATE_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, KEY_LENGTH, labelOffset));
        }
Ejemplo n.º 5
0
        public RecordingDescriptorEncoder StrippedChannel(string value)
        {
            int length = value.Length;

            if (length > 1073741824)
            {
                throw new InvalidOperationException("length > maxValue for type: " + length);
            }

            int headerLength = 4;
            int limit        = _parentMessage.Limit();

            _parentMessage.Limit(limit + headerLength + length);
            _buffer.PutInt(limit, unchecked ((int)length), ByteOrder.LittleEndian);
            _buffer.PutStringWithoutLengthAscii(limit + headerLength, value);

            return(this);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Allocate a counter to represent the heartbeat of a clustered service.
        /// </summary>
        /// <param name="aeron">      to allocate the counter. </param>
        /// <param name="tempBuffer"> to use for building the key and label without allocation. </param>
        /// <param name="serviceId">  of the service heartbeat. </param>
        /// <returns> the <seealso cref="Counter"/> for the commit position. </returns>
        public static Counter Allocate(Aeron.Aeron aeron, IMutableDirectBuffer tempBuffer, int serviceId)
        {
            int labelOffset = 0;

            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, NAME);
            labelOffset += tempBuffer.PutIntAscii(KEY_LENGTH + labelOffset, serviceId);

            return(aeron.AddCounter(SERVICE_HEARTBEAT_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, KEY_LENGTH, labelOffset));
        }
Ejemplo n.º 7
0
        public static int AllocateCounterId(
            IMutableDirectBuffer tempBuffer,
            string name,
            int typeId,
            CountersManager countersManager,
            long registrationId)
        {
            tempBuffer.PutLong(REGISTRATION_ID_OFFSET, registrationId);
            int keyLength = REGISTRATION_ID_OFFSET + BitUtil.SIZE_OF_LONG;

            int labelLength = 0;

            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, name);
            labelLength += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelLength, ": ");
            labelLength += tempBuffer.PutLongAscii(keyLength + labelLength, registrationId);

            return(countersManager.Allocate(typeId, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelLength));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Allocate a counter to represent the snapshot services should load on start.
        /// </summary>
        /// <param name="aeron">                to allocate the counter. </param>
        /// <param name="tempBuffer">           to use for building the key and label without allocation. </param>
        /// <param name="leadershipTermId">     at which the snapshot was taken. </param>
        /// <param name="logPosition">          at which the snapshot was taken. </param>
        /// <param name="timestamp">            the snapshot was taken. </param>
        /// <param name="hasReplay">            flag is true if all or part of the log must be replayed. </param>
        /// <param name="snapshotRecordingIds"> for the services to use during recovery indexed by service id. </param>
        /// <returns> the <seealso cref="Counter"/> for the recovery state. </returns>
        public static Counter Allocate(
            Aeron.Aeron aeron,
            IMutableDirectBuffer tempBuffer,
            long leadershipTermId,
            long logPosition,
            long timestamp,
            bool hasReplay,
            params long[] snapshotRecordingIds)
        {
            tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId);
            tempBuffer.PutLong(LOG_POSITION_OFFSET, logPosition);
            tempBuffer.PutLong(TIMESTAMP_OFFSET, timestamp);
            tempBuffer.PutInt(REPLAY_FLAG_OFFSET, hasReplay ? 1 : 0);

            int serviceCount = snapshotRecordingIds.Length;

            tempBuffer.PutInt(SERVICE_COUNT_OFFSET, serviceCount);

            int keyLength             = SNAPSHOT_RECORDING_IDS_OFFSET + (serviceCount * BitUtil.SIZE_OF_LONG);
            int maxRecordingIdsLength = SNAPSHOT_RECORDING_IDS_OFFSET + (serviceCount * BitUtil.SIZE_OF_LONG);

            if (maxRecordingIdsLength > CountersReader.MAX_KEY_LENGTH)
            {
                throw new ClusterException(maxRecordingIdsLength + " execeeds max key length " + CountersReader.MAX_KEY_LENGTH);
            }

            for (int i = 0; i < serviceCount; i++)
            {
                tempBuffer.PutLong(SNAPSHOT_RECORDING_IDS_OFFSET + (i * BitUtil.SIZE_OF_LONG), snapshotRecordingIds[i]);
            }


            int labelOffset = 0;

            labelOffset += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelOffset, NAME);
            labelOffset += tempBuffer.PutLongAscii(keyLength + labelOffset, leadershipTermId);
            labelOffset += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelOffset, " logPosition=");
            labelOffset += tempBuffer.PutLongAscii(keyLength + labelOffset, logPosition);
            labelOffset += tempBuffer.PutStringWithoutLengthAscii(keyLength + labelOffset, " hasReplay=" + hasReplay);

            return(aeron.AddCounter(RECOVERY_STATE_TYPE_ID, tempBuffer, 0, keyLength, tempBuffer, keyLength, labelOffset));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Allocate a counter to represent the heartbeat of a clustered service.
        /// </summary>
        /// <param name="aeron">      to allocate the counter. </param>
        /// <param name="tempBuffer"> to use for building the key and label without allocation. </param>
        /// <param name="serviceId">  of the service heartbeat. </param>
        /// <returns> the <seealso cref="Counter"/> for the commit position. </returns>
        public static Counter Allocate(Aeron.Aeron aeron, IMutableDirectBuffer tempBuffer, int serviceId)
        {
            tempBuffer.PutInt(SERVICE_ID_OFFSET, serviceId);

            int labelOffset = BitUtil.Align(KEY_LENGTH, BitUtil.SIZE_OF_INT);
            int labelLength = 0;

            labelLength += tempBuffer.PutStringWithoutLengthAscii(labelOffset + labelLength, NAME);
            labelLength += tempBuffer.PutIntAscii(labelOffset + labelLength, serviceId);

            return(aeron.AddCounter(SERVICE_HEARTBEAT_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, labelOffset, labelLength));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Allocate a counter to represent the commit position on stream for the current leadership term.
        /// </summary>
        /// <param name="aeron">                to allocate the counter. </param>
        /// <param name="tempBuffer">           to use for building the key and label without allocation. </param>
        /// <param name="leadershipTermId">     of the log at the beginning of the leadership term. </param>
        /// <param name="termBaseLogPosition">  of the log at the beginning of the leadership term. </param>
        /// <param name="leadershipTermLength"> length in bytes of the leadership term for the log. </param>
        /// <returns> the <seealso cref="Counter"/> for the commit position. </returns>
        public static Counter Allocate(
            Aeron.Aeron aeron,
            IMutableDirectBuffer tempBuffer,
            long leadershipTermId,
            long termBaseLogPosition,
            long leadershipTermLength)
        {
            tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId);
            tempBuffer.PutLong(TERM_BASE_LOG_POSITION_OFFSET, termBaseLogPosition);
            tempBuffer.PutLong(LEADERSHIP_TERM_LENGTH_OFFSET, leadershipTermLength);


            int labelOffset = 0;

            labelOffset += tempBuffer.PutStringWithoutLengthAscii(KEY_LENGTH + labelOffset, NAME);
            labelOffset += tempBuffer.PutLongAscii(KEY_LENGTH + labelOffset, leadershipTermId);

            return(aeron.AddCounter(COMMIT_POSITION_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, KEY_LENGTH, labelOffset));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Allocate a counter to represent the commit position on stream for the current leadership term.
        /// </summary>
        /// <param name="aeron">                to allocate the counter. </param>
        /// <param name="tempBuffer">           to use for building the key and label without allocation. </param>
        /// <param name="leadershipTermId">     of the log at the beginning of the leadership term. </param>
        /// <param name="logPosition">  of the log at the beginning of the leadership term. </param>
        /// <param name="maxLogPosition"> length in bytes of the leadership term for the log. </param>
        /// <returns> the <seealso cref="Counter"/> for the commit position. </returns>
        public static Counter Allocate(
            Aeron.Aeron aeron,
            IMutableDirectBuffer tempBuffer,
            long leadershipTermId,
            long logPosition,
            long maxLogPosition)
        {
            tempBuffer.PutLong(LEADERSHIP_TERM_ID_OFFSET, leadershipTermId);
            tempBuffer.PutLong(LOG_POSITION_OFFSET, logPosition);
            tempBuffer.PutLong(MAX_LOG_POSITION_OFFSET, maxLogPosition);

            int labelOffset = BitUtil.Align(KEY_LENGTH, BitUtil.SIZE_OF_INT);
            int labelLength = 0;

            labelLength += tempBuffer.PutStringWithoutLengthAscii(labelOffset + labelLength, NAME);
            labelLength += tempBuffer.PutLongAscii(labelOffset + labelLength, leadershipTermId);

            return(aeron.AddCounter(COMMIT_POSITION_TYPE_ID, tempBuffer, 0, KEY_LENGTH, tempBuffer, labelOffset, labelLength));
        }