Beispiel #1
0
        public IRentableObject RentAnObject()
        {
            IRentableObject obj = null;

            lock (_sync)
            {
                if (_available.Count > 0)
                {
                    obj = (IRentableObject)_available[_availableRentIds[0]];
                    _available.Remove(obj.RentId);
                    _availableRentIds.Remove(obj.RentId);
                    _rented.Add(obj.RentId, obj);
                }
                else
                {
                    obj        = (IRentableObject)CreateObject();
                    obj.RentId = _rentid++;
                    if (obj != null)
                    {
                        _rented.Add(obj.RentId, obj);
                    }
                }
            }

            return(obj);
        }
Beispiel #2
0
 public void SubmittObject(IRentableObject obj)
 {
     lock (_sync)
     {
         if (_rented.Contains(obj.RentId))
         {
             _rented.Remove(obj.RentId);
             ResetObject(obj);
             _available.Add(obj.RentId, obj);
             _availableRentIds.Add(obj.RentId);
         }
     }
 }
Beispiel #3
0
        public void Initialize()
        {
            IRentableObject obj = null;

            lock (_sync)
            {
                for (int i = 0; i < _initialSize; i++)
                {
                    obj = CreateObject();
                    if (obj != null)
                    {
                        ResetObject(obj);
                        list.Add(obj);
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Cria uma instancia alugada.
        /// </summary>
        /// <returns></returns>
        public IRentableObject RentAnObject()
        {
            IRentableObject obj2 = null;

            lock (_sync)
            {
                if (_available.Count > 0)
                {
                    obj2 = (IRentableObject)_available[_availableRentIds[0]];
                    _available.Remove(obj2.RentId);
                    _availableRentIds.Remove(obj2.RentId);
                    _rented.Add(obj2.RentId, obj2);
                    return(obj2);
                }
                obj2        = this.CreateObject();
                obj2.RentId = _rentid++;
                if (obj2 != null)
                {
                    _rented.Add(obj2.RentId, obj2);
                }
            }
            return(obj2);
        }
Beispiel #5
0
 public void SubmittObject(IRentableObject obj)
 {
     lock (_sync)
     {
         if (_rented.Contains(obj.RentId))
         {
             _rented.Remove(obj.RentId);
             ResetObject(obj);
             _available.Add(obj.RentId,obj);
             _availableRentIds.Add(obj.RentId);
         }
     }
 }