Exemple #1
0
        /// <summary>
        /// Allocate a new counter with a given label.
        /// </summary>
        /// <param name="label"> to describe the counter. </param>
        /// <returns> the id allocated for the counter. </returns>
        public int Allocate(string label)
        {
            int counterId = NextCounterId();

            if ((CounterOffset(counterId) + COUNTER_LENGTH) > ValuesBuffer.Capacity)
            {
                throw new ArgumentException("Unable to allocated counter, values buffer is full");
            }

            int recordOffset = MetaDataOffset(counterId);

            if ((recordOffset + METADATA_LENGTH) > MetaDataBuffer.Capacity)
            {
                throw new ArgumentException("Unable to allocate counter, labels buffer is full");
            }

            MetaDataBuffer.PutInt(recordOffset + TYPE_ID_OFFSET, DEFAULT_TYPE_ID);
            MetaDataBuffer.PutStringUtf8(recordOffset + LABEL_OFFSET, label, MAX_LABEL_LENGTH);

            MetaDataBuffer.PutIntOrdered(recordOffset, RECORD_ALLOCATED);

            return(counterId);
        }
Exemple #2
0
        /// <summary>
        /// Allocate a new counter with a given label.
        ///
        /// The key function will be called with a buffer with the exact length of available key space
        /// in the record for the user to store what they want for the key. No offset is required.
        /// </summary>
        /// <param name="label">   to describe the counter. </param>
        /// <param name="typeId">  for the type of counter. </param>
        /// <param name="keyFunc"> for setting the key value for the counter. </param>
        /// <returns> the id allocated for the counter. </returns>
        public int Allocate(string label, int typeId, Action <IMutableDirectBuffer> keyFunc)
        {
            var counterId = NextCounterId();

            if (CounterOffset(counterId) + COUNTER_LENGTH > ValuesBuffer.Capacity)
            {
                throw new ArgumentException("Unable to allocated counter, values buffer is full");
            }

            var recordOffset = MetaDataOffset(counterId);

            if (recordOffset + METADATA_LENGTH > MetaDataBuffer.Capacity)
            {
                throw new ArgumentException("Unable to allocate counter, labels buffer is full");
            }

            MetaDataBuffer.PutInt(recordOffset + TYPE_ID_OFFSET, typeId);
            keyFunc(new UnsafeBuffer(MetaDataBuffer, recordOffset + KEY_OFFSET, MAX_KEY_LENGTH));
            MetaDataBuffer.PutStringUtf8(recordOffset + LABEL_OFFSET, label, MAX_LABEL_LENGTH);

            MetaDataBuffer.PutIntOrdered(recordOffset, RECORD_ALLOCATED);

            return(counterId);
        }