Exemplo n.º 1
0
 /// <summary>
 /// Map a counter over a buffer. This version will free the counter on close.
 /// </summary>
 /// <param name="buffer">          containing the counter. </param>
 /// <param name="counterId">       identifier for the counter. </param>
 /// <param name="countersManager"> to be called to free the counter on close. </param>
 public AtomicCounter(IAtomicBuffer buffer, int counterId, CountersManager countersManager)
 {
     _buffer          = buffer;
     Id               = counterId;
     _countersManager = countersManager;
     _offset          = CountersReader.CounterOffset(counterId);
     buffer.BoundsCheck(_offset, BitUtil.SIZE_OF_LONG);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Construct a view of an existing counter.
        /// </summary>
        /// <param name="countersReader"> for getting access to the buffers. </param>
        /// <param name="registrationId"> assigned by the driver for the counter or -1 if not known. </param>
        /// <param name="counterId">      for the counter to be viewed. </param>
        /// <exception cref="InvalidOperationException"> if the id has for the counter has not been allocated. </exception>
        public ReadableCounter(CountersReader countersReader, long registrationId, int counterId)
        {
            if (countersReader.GetCounterState(counterId) != CountersReader.RECORD_ALLOCATED)
            {
                throw new InvalidOperationException("Counter id has not been allocated: " + counterId);
            }

            this.countersReader = countersReader;
            this.counterId      = counterId;
            this.registrationId = registrationId;

            valuesBuffer = countersReader.ValuesBuffer;
            var counterOffset = CountersReader.CounterOffset(counterId);

            valuesBuffer.BoundsCheck(counterOffset, BitUtil.SIZE_OF_LONG);

            buffer        = valuesBuffer.ByteArray;
            addressOffset = counterOffset;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Construct a view of an existing counter.
        /// </summary>
        /// <param name="countersReader"> for getting access to the buffers. </param>
        /// <param name="registrationId"> assigned by the driver for the counter or <see cref="Adaptive.Aeron.Aeron.NULL_VALUE"/> if not known. </param>
        /// <param name="counterId">      for the counter to be viewed. </param>
        /// <exception cref="InvalidOperationException"> if the id has for the counter has not been allocated. </exception>
        public ReadableCounter(CountersReader countersReader, long registrationId, int counterId)
        {
            var counterState = countersReader.GetCounterState(counterId);

            if (counterState != CountersReader.RECORD_ALLOCATED)
            {
                throw new InvalidOperationException("Counter not allocated: id=" + counterId + " state=" + counterState);
            }

            _countersReader = countersReader;
            _counterId      = counterId;
            _registrationId = registrationId;

            _valuesBuffer = countersReader.ValuesBuffer;
            var counterOffset = CountersReader.CounterOffset(counterId);

            _valuesBuffer.BoundsCheck(counterOffset, BitUtil.SIZE_OF_LONG);

            _buffer        = _valuesBuffer.ByteArray;
            _addressOffset = counterOffset;
        }