Ejemplo n.º 1
0
        public Node AddInHead(MruItem data, bool addInCache)
        {
            Node n = new Node(data);

            this.AddInHead(n, addInCache);
            return(n);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Save the unpersisted MRU items
 /// </summary>
 public virtual void Flush()
 {
     if ((SaveState & SaveTypes.CollectionSave) == SaveTypes.CollectionSave)
     {
         return;
     }
     SaveState |= SaveTypes.CollectionSave;
     if (CacheCollection.Count > 0)
     {
         const int batchLimit = 90;
         List <IInternalPersistent> dirtyNodes = new List <IInternalPersistent>(batchLimit);
         int batchCount = 0;
         foreach (Node n in mruManager)
         {
             MruItem itm = n.Data;
             if (itm.Value is IInternalPersistent)
             {
                 if (((IInternalPersistent)itm.Value).IsDirty)
                 {
                     dirtyNodes.Add((IInternalPersistent)itm.Value);
                     if (++batchCount > batchLimit)
                     {
                         if (mruManager.Collection != null)
                         {
                             if (dirtyNodes.Count > 0)
                             {
                                 mruManager.Collection.OnMaxCapacity(dirtyNodes);
                                 mruManager.Collection.OnMaxCapacity();
                             }
                         }
                         dirtyNodes.Clear();
                         batchCount = 0;
                     }
                 }
             }
             else
             {
                 break;
             }
         }
         if (mruManager.Collection != null)
         {
             if (dirtyNodes.Count > 0)
             {
                 mruManager.Collection.OnMaxCapacity(dirtyNodes);
                 mruManager.Collection.OnMaxCapacity();
             }
         }
     }
     SaveState ^= SaveTypes.CollectionSave;
 }
Ejemplo n.º 3
0
 public MruItem RemoveInTail(bool moveToRemoveList)
 {
     if (_tail != null)
     {
         Count--;
         MruItem d = _tail.Data;
         if (_tail.Previous != null)
         {
             _tail.Previous.Next = null;
             _tail = _tail.Previous;
         }
         else
         {
             _tail = null;
             _head = null;
         }
         //if (Collection != null)
         //{
         if (d.Value is Sop.DataBlock)
         {
             if (((DataBlock)d.Value).IsDirty)
             {
                 if (moveToRemoveList && DataDriver != null && !RemovedObjects.ContainsKey(d.Key))
                 {
                     RemovedObjects.Add(d.Key, d.Value);
                 }
             }
         }
         else if (moveToRemoveList && d.Value != null)
         {
             if (!RemovedObjects.ContainsKey(d.Key))
             {
                 if (d.Value is IInternalPersistent)
                 {
                     if (((IInternalPersistent)d.Value).IsDirty)
                     {
                         RemovedObjects.Add(d.Key, d.Value);
                     }
                 }
                 else
                 {
                     RemovedObjects.Add(d.Key, d.Value);
                 }
             }
         }
         //}
         return(d);
     }
     return(null);
 }
Ejemplo n.º 4
0
        public Node AddInTail(MruItem data)
        {
            Node n = null;

            if (_tail == null)
            {
                return(AddInHead(data));
            }
            n          = new Node(data);
            n.Previous = _tail;
            _tail.Next = n;
            _tail      = n;
            Count++;
            return(n);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Given a key, will return its value.
        /// If key is not found, will add a new entry having passed
        /// params key and value.
        /// </summary>
        public object this[object key]
        {
            get
            {
                // check if item is in removed objects, not likely but in case...
                if (mruManager.RemovedObjects.Count > 0 &&
                    mruManager.RemovedObjects.ContainsKey(key))
                {
                    return(mruManager.RemovedObjects.CurrentValue);
                }

                MruItem itm = (MruItem)this.CacheCollection[key];
                if (itm == null)
                {
                    return(null);
                }
                if ((SaveState & SaveTypes.CollectionSave) != SaveTypes.CollectionSave)
                {
                    if (itm.IndexToMruList != null)
                    {
                        mruManager.RemoveNode(itm.IndexToMruList, true);
                        mruManager.AddInHead(itm.IndexToMruList, true);
                    }
                }
                return(itm.Value);
            }
            set
            {
                if ((SaveState & SaveTypes.CollectionSave) == SaveTypes.CollectionSave)
                {
                    return;
                }
                MruItem itm = (MruItem)this.CacheCollection[key];
                if (itm != null)
                {
                    itm.Transaction = ((OnDisk.Algorithm.Collection.ICollectionOnDisk) this.mruManager.Collection).Transaction;
                    mruManager.RemoveNode(itm.IndexToMruList, true);
                    itm.Value = value;
                    mruManager.AddInHead(itm.IndexToMruList, true);
                }
                else
                {
                    Transaction = ((OnDisk.Algorithm.Collection.ICollectionOnDisk) this.mruManager.Collection).Transaction;
                    this.Add(key, value);
                }
            }
        }
Ejemplo n.º 6
0
        private void addInTail(object key, object value, Sop.Transaction.ITransactionLogger trans)
        {
            var itm = (MruItem)CacheCollection[key];

            if (itm == null)
            {
                itm = new MruItem(key, value, Transaction);
            }
            else
            {
                mruManager.RemoveNode(itm.IndexToMruList, true);
                itm.Transaction = Transaction;
                itm.Key         = key;
                itm.Value       = value;
            }
            itm.IndexToMruList   = mruManager.AddInTail(itm);
            CacheCollection[key] = itm;
        }
Ejemplo n.º 7
0
        // for use in VirtualStore to access MRU Item key/value pair.
        internal MruItem GetItem(object key)
        {
            // check if item is in removed objects, not likely but in case...
            //if (mruManager.RemovedObjects.Count > 0 &&
            //    mruManager.RemovedObjects.ContainsKey(key))
            //    return mruManager.RemovedObjects.CurrentValue;
            MruItem itm = (MruItem)this.CacheCollection[key];

            if (itm == null)
            {
                return(null);
            }
            if ((SaveState & SaveTypes.CollectionSave) != SaveTypes.CollectionSave)
            {
                if (itm.IndexToMruList != null)
                {
                    mruManager.RemoveNode(itm.IndexToMruList, true);
                    mruManager.AddInHead(itm.IndexToMruList, true);
                }
            }
            return(itm);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add Object to the cache
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public virtual void Add(object key, object value)
        {
            if (SaveState != SaveTypes.Default)
            {
                return;
            }
            MruItem itm = null;

            if (GeneratePruneEvent)
            {
                if (MaxCapacity > 0 && CacheCollection.Count >= this.MaxCapacity)
                {
                    if (mruManager.RemovedObjects.Count == 0)
                    {
                        bool ogp = GeneratePruneEvent;
                        GeneratePruneEvent = false;
                        itm = mruManager.PeekInTail();
                        // prevent pruning to occur if itm is Specialized Store and is locked by a thread...
                        if (!(itm.Value is SpecializedStoreBase &&
                              ((SpecializedStoreBase)itm.Value).Locker.IsLocked))
                        {
                            Log.Logger.Instance.Log(Log.LogLevels.Information, "MruManager.Add: pruning enter.");
                            for (int i = MaxCapacity; i > MinCapacity; i--)
                            {
                                itm = mruManager.RemoveInTail(mruManager.Collection != null);
                                CacheCollection.Remove(itm.Key);
                                if (!(itm.Value is IDisposable))
                                {
                                    continue;
                                }
                                var specializedStoreBase = itm.Value as SpecializedStoreBase;
                                if (specializedStoreBase != null)
                                {
                                    if (specializedStoreBase.Locker.IsLocked)
                                    {
                                        continue;
                                    }
                                    specializedStoreBase.InvokeFromMru = true;
                                }
                                if (mruManager.Collection == null)
                                {
                                    ((IDisposable)itm.Value).Dispose();
                                }
                                if (specializedStoreBase != null)
                                {
                                    specializedStoreBase.InvokeFromMru = false;
                                }
                            }
                            Log.Logger.Instance.Log(Log.LogLevels.Information, "MruManager.Add: pruning exit.");
                            SaveRemovedBlocks();
                        }
                        GeneratePruneEvent = ogp;
                    }
                }
            }
            itm = (MruItem)Remove(key, true);
            if (itm == null)
            {
                itm = new MruItem(key, value, Transaction);
                itm.IndexToMruList = mruManager.AddInHead(itm, false);
            }
            else
            {
                itm.Transaction = Transaction;
                itm.Key         = key;
                itm.Value       = value;
                mruManager.AddInHead(itm.IndexToMruList, true);
            }
            CacheCollection[key] = itm;
        }
Ejemplo n.º 9
0
 public Node AddInHead(MruItem data)
 {
     return(AddInHead(data, false));
 }