public virtual long Peek()
 {
     if (IdValidator.isReservedId(_nextId))
     {
         _nextId++;
     }
     return(_nextId);
 }
        private void AssertNoReservedId(IdRange range)
        {
            foreach (long id in range.DefragIds)
            {
                assertFalse(IdValidator.isReservedId(id));
            }

            assertFalse(IdValidator.hasReservedIdInRange(range.RangeStart, range.RangeStart + range.RangeLength));
        }
        public override IdRange NextIdBatch(int size)
        {
            while (IdValidator.hasReservedIdInRange(_nextId, _nextId + size))
            {
                _nextId += size;
            }

            long startId = _nextId;

            _nextId += size;
            return(new IdRange(EMPTY_LONG_ARRAY, startId, size));
        }
Exemple #4
0
        /// <summary>
        /// Frees the <CODE>id</CODE> making it a defragged id that will be
        /// returned by next id before any new id (that hasn't been used yet) is
        /// returned.
        /// <para>
        /// This method will throw an <CODE>IOException</CODE> if id is negative or
        /// if id is greater than the highest returned id. However as stated in the
        /// class documentation above the id isn't validated to see if it really is
        /// free.
        ///
        /// </para>
        /// </summary>
        /// <param name="id">
        ///            The id to be made available again </param>
        public override void FreeId(long id)
        {
            lock (this)
            {
                _idContainer.assertStillOpen();

                if (IdValidator.isReservedId(id))
                {
                    return;
                }

                if (id < 0 || id >= _highId)
                {
                    throw new System.ArgumentException("Illegal id[" + id + "], highId is " + _highId);
                }
                _idContainer.freeId(id);
            }
        }
Exemple #5
0
        /// <summary>
        /// Returns the next "free" id. If a defragged id exist it will be returned
        /// else the next free id that hasn't been used yet is returned. If no id
        /// exist the capacity is exceeded (all values <= max are taken) and a
        /// <seealso cref="UnderlyingStorageException"/> will be thrown.
        /// </summary>
        /// <returns> The next free id </returns>
        /// <exception cref="UnderlyingStorageException">
        ///             If the capacity is exceeded </exception>
        /// <exception cref="IllegalStateException"> if this id generator has been closed </exception>
        public override long NextId()
        {
            lock (this)
            {
                AssertStillOpen();
                long nextDefragId = _idContainer.ReusableId;
                if (nextDefragId != IdContainer.NO_RESULT)
                {
                    return(nextDefragId);
                }

                if (IdValidator.isReservedId(_highId))
                {
                    _highId++;
                }
                IdValidator.assertValidId(_idType, _highId, _max);
                return(_highId++);
            }
        }
Exemple #6
0
        public override long NextId()
        {
            try
            {
                if (_position < _defrag.Length)
                {
                    return(_defrag[_position]);
                }

                long candidate = NextRangeCandidate();
                if (IdValidator.isReservedId(candidate))
                {
                    _position++;
                    candidate = NextRangeCandidate();
                }
                return(candidate);
            }
            finally
            {
                ++_position;
            }
        }
Exemple #7
0
 public static long LongFromIntAndMod(long @base, long modifier)
 {
     return(modifier == 0 && IdValidator.isReservedId(@base) ? -1 : @base | modifier);
 }